Ticket #8542: simon-adlib.diff
File simon-adlib.diff, 4.9 KB (added by , 19 years ago) |
---|
-
engines/simon/simon.cpp
450 450 if (_native_mt32) { 451 451 driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE); 452 452 } 453 if (midiDriver == MD_ADLIB) { 454 midi.property(PROP_ADLIB, 1); 455 } 453 456 } 454 457 455 458 midi.mapMT32toGM (getGameType() == GType_SIMON1 && !_native_mt32); -
engines/simon/midi.h
34 34 35 35 namespace Simon { 36 36 37 enum { 38 PROP_ADLIB 39 }; 40 37 41 struct MusicInfo { 38 42 MidiParser *parser; 39 43 byte *data; … … 59 63 MidiDriver *_driver; 60 64 bool _map_mt32_to_gm; 61 65 bool _passThrough; 66 bool _adlib; 62 67 63 68 MusicInfo _music; 64 69 MusicInfo _sfx; … … 74 79 byte _queuedTrack; 75 80 bool _loopQueuedTrack; 76 81 82 byte *_adlibPatches; 83 77 84 protected: 78 85 static void onTimer(void *data); 79 86 void clearConstructs(); 80 87 void clearConstructs(MusicInfo &info); 81 88 void resetVolumeTable(); 89 void loadAdlibPatches(); 90 void unloadAdlibPatches(); 82 91 83 92 public: 84 93 bool _enable_sfx; … … 110 119 int open(); 111 120 void close(); 112 121 void send(uint32 b); 122 uint32 property(int prop, uint32 param); 113 123 114 124 void metaEvent(byte type, byte *data, uint16 length); 115 125 void setPassThrough(bool b) { _passThrough = b; } -
engines/simon/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 … … 84 87 _driver->close(); 85 88 _driver = NULL; 86 89 clearConstructs(); 90 unloadAdlibPatches(); 87 91 // _system->unlockMutex(_mutex); 88 92 } 89 93 … … 103 107 _current->volume[channel] = volume; 104 108 volume = volume * _masterVolume / 255; 105 109 b = (b & 0xFF00FFFF) | (volume << 16); 106 } else if ((b & 0xF0) == 0xC0 && _map_mt32_to_gm) { 107 b = (b & 0xFFFF00FF) | (MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8); 110 } else if ((b & 0xF0) == 0xC0) { 111 if (_map_mt32_to_gm && (!_adlib || !_adlibPatches)) { 112 b = (b & 0xFFFF00FF) | (MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8); 113 } 108 114 } else if ((b & 0xFFF0) == 0x007BB0) { 109 115 // Only respond to an All Notes Off if this channel 110 116 // has already been allocated. … … 129 135 if (_current->channel[channel]) { 130 136 if (channel == 9) 131 137 _current->channel[9]->volume(_current->volume[9] * _masterVolume / 255); 132 _current->channel[channel]->send(b); 138 if ((b & 0xF0) == 0xC0 && _adlib && _adlibPatches) { 139 // NOTE: In the percussion channel, this function is a 140 // no-op. Any percussion instruments you hear may 141 // be the stock ones from adlib.cpp. 142 _driver->sysEx_customInstrument(_current->channel[channel]->getNumber(), 'ADL ', _adlibPatches + 30 * ((b >> 8) & 0xFF)); 143 } else { 144 _current->channel[channel]->send(b); 145 } 133 146 if ((b & 0xFFF0) == 0x79B0) { 134 147 // We have received a "Reset All Controllers" message 135 148 // and passed it on to the MIDI driver. This may or may … … 142 155 } 143 156 } 144 157 158 uint32 MidiPlayer::property(int prop, uint32 param) { 159 if (prop == PROP_ADLIB) { 160 uint32 ret = _adlib ? 1 : 0; 161 _adlib = (param != 0); 162 if (_adlib) 163 loadAdlibPatches(); 164 else 165 unloadAdlibPatches(); 166 return ret; 167 } 168 return MidiDriver::property(prop, param); 169 } 170 145 171 void MidiPlayer::metaEvent(byte type, byte *data, uint16 length) { 146 172 // Only thing we care about is End of Track. 147 173 if (!_current || type != 0x2F) { … … 352 378 } 353 379 } 354 380 381 void MidiPlayer::loadAdlibPatches() { 382 if (!_adlib) 383 return; 384 385 Common::File ibk; 386 387 if (!ibk.open("mt_fm.ibk")) 388 return; 389 390 if (ibk.readUint32BE() == 0x49424b1a) { 391 _adlibPatches = new byte[128 * 30]; 392 byte *ptr = _adlibPatches; 393 394 memset(_adlibPatches, 0, 128 * 30); 395 396 for (int i = 0; i < 128; i++) { 397 byte instr[16]; 398 399 ibk.read(instr, 16); 400 401 ptr[0] = instr[0]; // Modulator Sound Characteristics 402 ptr[1] = instr[2]; // Modulator Scaling/Output Level 403 ptr[2] = ~instr[4]; // Modulator Attack/Decay 404 ptr[3] = ~instr[6]; // Modulator Sustain/Release 405 ptr[4] = instr[8]; // Modulator Wave Select 406 ptr[5] = instr[1]; // Carrier Sound Characteristics 407 ptr[6] = instr[3]; // Carrier Scaling/Output Level 408 ptr[7] = ~instr[5]; // Carrier Attack/Delay 409 ptr[8] = ~instr[7]; // Carrier Sustain/Release 410 ptr[9] = instr[9]; // Carrier Wave Select 411 ptr[10] = instr[10]; // Feedback/Connection 412 413 // The remaining six bytes are reserved for future use 414 415 ptr += 30; 416 } 417 } 418 } 419 420 void MidiPlayer::unloadAdlibPatches() { 421 delete[] _adlibPatches; 422 _adlibPatches = NULL; 423 } 424 355 425 static int simon1_gmf_size[] = { 356 426 8900, 12166, 2848, 3442, 4034, 4508, 7064, 9730, 6014, 4742, 3138, 357 427 6570, 5384, 8909, 6457, 16321, 2742, 8968, 4804, 8442, 7717,