2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3 * Copyright (C) 1999 - 2008 Simon Peter, <dn.tlp@gmx.net>, et al.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * rol.h - ROL Player by OPLx <oplx@yahoo.com>
21 * Visit: http://tenacity.hispeed.com/aomit/oplx/
32 class CrolPlayer: public CPlayer
35 static CPlayer *factory(Copl *newopl);
37 CrolPlayer(Copl *newopl);
41 bool load (const std::string &filename, const CFileProvider &fp);
43 void rewind (int subsong); // rewinds to specified subsong
44 float getrefresh(); // returns needed timer refresh rate
46 std::string gettype() { return std::string("Adlib Visual Composer"); }
49 typedef unsigned short uint16;
50 typedef signed short int16;
52 typedef signed int int32;
54 typedef signed long int int32;
63 uint16 ticks_per_beat;
64 uint16 beats_per_measure;
106 typedef std::vector<SNoteEvent> TNoteEvents;
107 typedef std::vector<SInstrumentEvent> TInstrumentEvents;
108 typedef std::vector<SVolumeEvent> TVolumeEvents;
109 typedef std::vector<SPitchEvent> TPitchEvents;
111 #define bit_pos( pos ) (1<<pos)
118 kES_NoteEnd = bit_pos( 0 ),
119 kES_PitchEnd = bit_pos( 1 ),
120 kES_InstrEnd = bit_pos( 2 ),
121 kES_VolumeEnd = bit_pos( 3 ),
126 explicit CVoiceData()
127 : mForceNote ( true )
128 ,mEventStatus ( kES_None )
130 ,current_note_duration( 0 )
132 ,next_instrument_event( 0 )
133 ,next_volume_event ( 0 )
134 ,next_pitch_event ( 0 )
141 mEventStatus = kES_None;
143 current_note_duration = 0;
145 next_instrument_event = 0;
146 next_volume_event = 0;
147 next_pitch_event = 0;
150 TNoteEvents note_events;
151 TInstrumentEvents instrument_events;
152 TVolumeEvents volume_events;
153 TPitchEvents pitch_events;
157 unsigned int current_note;
158 int current_note_duration;
160 unsigned int next_instrument_event;
161 unsigned int next_volume_event;
162 unsigned int next_pitch_event;
172 typedef std::vector<SInstrumentName> TInstrumentNames;
179 uint16 number_of_list_entries_used;
180 uint16 total_number_of_list_entries;
181 int32 abs_offset_of_name_list;
182 int32 abs_offset_of_data;
184 TInstrumentNames ins_name_list;
189 unsigned char key_scale_level;
190 unsigned char freq_multiplier;
191 unsigned char feed_back;
192 unsigned char attack_rate;
193 unsigned char sustain_level;
194 unsigned char sustaining_sound;
195 unsigned char decay_rate;
196 unsigned char release_rate;
197 unsigned char output_level;
198 unsigned char amplitude_vibrato;
199 unsigned char frequency_vibrato;
200 unsigned char envelope_scaling;
201 unsigned char fm_type;
206 unsigned char ammulti;
211 unsigned char waveform;
225 SRolInstrument instrument;
228 void load_tempo_events ( binistream *f );
229 bool load_voice_data ( binistream *f, std::string const &bnk_filename, const CFileProvider &fp );
230 void load_note_events ( binistream *f, CVoiceData &voice );
231 void load_instrument_events( binistream *f, CVoiceData &voice,
232 binistream *bnk_file, SBnkHeader const &bnk_header );
233 void load_volume_events ( binistream *f, CVoiceData &voice );
234 void load_pitch_events ( binistream *f, CVoiceData &voice );
236 bool load_bnk_info ( binistream *f, SBnkHeader &header );
237 int load_rol_instrument ( binistream *f, SBnkHeader const &header, std::string &name );
238 void read_rol_instrument ( binistream *f, SRolInstrument &ins );
239 void read_fm_operator ( binistream *f, SOPL2Op &opl2_op );
240 int get_ins_index( std::string const &name ) const;
242 void UpdateVoice( int const voice, CVoiceData &voiceData );
243 void SetNote( int const voice, int const note );
244 void SetNoteMelodic( int const voice, int const note );
245 void SetNotePercussive( int const voice, int const note );
246 void SetFreq ( int const voice, int const note, bool const keyOn=false );
247 void SetPitch ( int const voice, real32 const variation );
248 void SetVolume ( int const voice, int const volume );
249 void SetRefresh( float const multiplier );
250 void send_ins_data_to_chip( int const voice, int const ins_index );
251 void send_operator( int const voice, SOPL2Op const &modulator, SOPL2Op const &carrier );
256 bool operator()( SInstrumentName const &lhs, SInstrumentName const &rhs ) const
258 return keyLess(lhs.name, rhs.name);
261 bool operator()( SInstrumentName const &lhs, std::string const &rhs ) const
263 return keyLess(lhs.name, rhs.c_str());
266 bool operator()( std::string const &lhs, SInstrumentName const &rhs ) const
268 return keyLess(lhs.c_str(), rhs.name);
271 bool keyLess( const char *const lhs, const char *const rhs ) const
273 return stricmp(lhs, rhs) < 0;
277 typedef std::vector<CVoiceData> TVoiceData;
279 SRolHeader *rol_header;
280 std::vector<STempoEvent> mTempoEvents;
281 TVoiceData voice_data;
282 std::vector<SUsedList> ins_list;
284 unsigned int mNextTempoEvent;
288 unsigned char bdRegister;
289 unsigned char bxRegister[9];
290 unsigned char volumeCache[11];
291 uint16 freqCache[11];
292 real32 pitchCache[11];
294 static int const kSizeofDataRecord;
295 static int const kMaxTickBeat;
296 static int const kSilenceNote;
297 static int const kNumMelodicVoices;
298 static int const kNumPercussiveVoices;
299 static int const kBassDrumChannel;
300 static int const kSnareDrumChannel;
301 static int const kTomtomChannel;
302 static int const kTomtomFreq;
303 static int const kSnareDrumFreq;
304 static float const kDefaultUpdateTme;
305 static float const kPitchFactor;
306 static uint16 const kNoteTable[12];