Ticket #8542: agos_adlib.diff
File agos_adlib.diff, 4.9 KB (added by , 15 years ago) |
---|
-
engines/agos/midi.h
36 36 37 37 namespace AGOS { 38 38 39 enum { 40 PROP_ADLIB 41 }; 42 39 43 struct MusicInfo { 40 44 MidiParser *parser; 41 45 byte *data; … … 61 65 MidiDriver *_driver; 62 66 bool _map_mt32_to_gm; 63 67 bool _passThrough; 68 bool _adlib; 64 69 65 70 MusicInfo _music; 66 71 MusicInfo _sfx; … … 78 83 byte _queuedTrack; 79 84 bool _loopQueuedTrack; 80 85 86 byte *_adlibPatches; 87 81 88 protected: 82 89 static void onTimer(void *data); 83 90 void clearConstructs(); 84 91 void clearConstructs(MusicInfo &info); 85 92 void resetVolumeTable(); 93 void loadAdlibPatches(); 94 void unloadAdlibPatches(); 86 95 87 96 public: 88 97 bool _enable_sfx; … … 115 124 int open(); 116 125 void close(); 117 126 void send(uint32 b); 127 uint32 property(int prop, uint32 param); 118 128 119 129 void metaEvent(byte type, byte *data, uint16 length); 120 130 void setPassThrough(bool b) { _passThrough = b; } -
engines/agos/agos.cpp
560 560 _driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE); 561 561 } 562 562 563 if (midiDriver == MD_ADLIB) { 564 _midi.property(PROP_ADLIB, 1); 565 } 566 563 567 _midi.mapMT32toGM (getGameType() != GType_SIMON2 && !_nativeMT32); 564 568 565 569 _midi.setDriver(_driver); -
engines/agos/midi.cpp
46 46 _map_mt32_to_gm = false; 47 47 _passThrough = false; 48 48 49 _adlib = false; 50 _adlibPatches = NULL; 51 49 52 _enable_sfx = true; 50 53 _current = 0; 51 54 … … 92 95 _driver->close(); 93 96 _driver = NULL; 94 97 clearConstructs(); 98 unloadAdlibPatches(); 95 99 // _system->unlockMutex(_mutex); 96 100 } 97 101 … … 114 118 else if (_current == &_music) 115 119 volume = volume * _musicVolume / 255; 116 120 b = (b & 0xFF00FFFF) | (volume << 16); 117 } else if ((b & 0xF0) == 0xC0 && _map_mt32_to_gm) { 118 b = (b & 0xFFFF00FF) | (MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8); 121 } else if ((b & 0xF0) == 0xC0) { 122 if (_map_mt32_to_gm && (!_adlib || !_adlibPatches)) { 123 b = (b & 0xFFFF00FF) | (MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8); 124 } 119 125 } else if ((b & 0xFFF0) == 0x007BB0) { 120 126 // Only respond to an All Notes Off if this channel 121 127 // has already been allocated. … … 144 150 else if (_current == &_music) 145 151 _current->channel[9]->volume(_current->volume[9] * _musicVolume / 255); 146 152 } 147 _current->channel[channel]->send(b); 153 if ((b & 0xF0) == 0xC0 && _adlib && _adlibPatches) { 154 // NOTE: In the percussion channel, this function is a 155 // no-op. Any percussion instruments you hear may 156 // be the stock ones from adlib.cpp. 157 _driver->sysEx_customInstrument(_current->channel[channel]->getNumber(), 'ADL ', _adlibPatches + 30 * ((b >> 8) & 0xFF)); 158 } else { 159 _current->channel[channel]->send(b); 160 } 148 161 if ((b & 0xFFF0) == 0x79B0) { 149 162 // We have received a "Reset All Controllers" message 150 163 // and passed it on to the MIDI driver. This may or may … … 160 173 } 161 174 } 162 175 176 uint32 MidiPlayer::property(int prop, uint32 param) { 177 if (prop == PROP_ADLIB) { 178 uint32 ret = _adlib ? 1 : 0; 179 _adlib = (param != 0); 180 if (_adlib) 181 loadAdlibPatches(); 182 else 183 unloadAdlibPatches(); 184 return ret; 185 } 186 return MidiDriver::property(prop, param); 187 } 188 163 189 void MidiPlayer::metaEvent(byte type, byte *data, uint16 length) { 164 190 // Only thing we care about is End of Track. 165 191 if (!_current || type != 0x2F) { … … 376 402 } 377 403 } 378 404 405 void MidiPlayer::loadAdlibPatches() { 406 if (!_adlib) 407 return; 408 409 Common::File ibk; 410 411 if (!ibk.open("mt_fm.ibk")) 412 return; 413 414 if (ibk.readUint32BE() == 0x49424b1a) { 415 _adlibPatches = new byte[128 * 30]; 416 byte *ptr = _adlibPatches; 417 418 memset(_adlibPatches, 0, 128 * 30); 419 420 for (int i = 0; i < 128; i++) { 421 byte instr[16]; 422 423 ibk.read(instr, 16); 424 425 ptr[0] = instr[0]; // Modulator Sound Characteristics 426 ptr[1] = instr[2]; // Modulator Scaling/Output Level 427 ptr[2] = ~instr[4]; // Modulator Attack/Decay 428 ptr[3] = ~instr[6]; // Modulator Sustain/Release 429 ptr[4] = instr[8]; // Modulator Wave Select 430 ptr[5] = instr[1]; // Carrier Sound Characteristics 431 ptr[6] = instr[3]; // Carrier Scaling/Output Level 432 ptr[7] = ~instr[5]; // Carrier Attack/Delay 433 ptr[8] = ~instr[7]; // Carrier Sustain/Release 434 ptr[9] = instr[9]; // Carrier Wave Select 435 ptr[10] = instr[10]; // Feedback/Connection 436 437 // The remaining six bytes are reserved for future use 438 439 ptr += 30; 440 } 441 } 442 } 443 444 void MidiPlayer::unloadAdlibPatches() { 445 delete[] _adlibPatches; 446 _adlibPatches = NULL; 447 } 448 379 449 static const int simon1_gmf_size[] = { 380 450 8900, 12166, 2848, 3442, 4034, 4508, 7064, 9730, 6014, 4742, 3138, 381 451 6570, 5384, 8909, 6457, 16321, 2742, 8968, 4804, 8442, 7717,