Ticket #8408: midi-mapping.diff
File midi-mapping.diff, 18.3 KB (added by , 20 years ago) |
---|
-
kyra/sound.cpp
diff -ur ScummVM-cvs20050321/kyra/sound.cpp ScummVM-cvs20050321+hack/kyra/sound.cpp
old new 22 22 #include "sound.h" 23 23 #include "resource.h" 24 24 25 // Instrument mapping for MT32 tracks emulated under GM.26 static const byte mt32_to_gm[128] = {27 // 0 1 2 3 4 5 6 7 8 9 A B C D E F28 0, 1, 0, 2, 4, 4, 5, 3, 16, 17, 18, 16, 16, 19, 20, 21, // 0x29 6, 6, 6, 7, 7, 7, 8, 112, 62, 62, 63, 63, 38, 38, 39, 39, // 1x30 88, 95, 52, 98, 97, 99, 14, 54, 102, 96, 53, 102, 81, 100, 14, 80, // 2x31 48, 48, 49, 45, 41, 40, 42, 42, 43, 46, 45, 24, 25, 28, 27, 104, // 3x32 32, 32, 34, 33, 36, 37, 35, 35, 79, 73, 72, 72, 74, 75, 64, 65, // 4x33 66, 67, 71, 71, 68, 69, 70, 22, 56, 59, 57, 57, 60, 60, 58, 61, // 5x34 61, 11, 11, 98, 14, 9, 14, 13, 12, 107, 107, 77, 78, 78, 76, 76, // 6x35 47, 117, 127, 118, 118, 116, 115, 119, 115, 112, 55, 124, 123, 0, 14, 117 // 7x36 };37 38 25 namespace Kyra { 39 26 MusicPlayer::MusicPlayer(MidiDriver* driver, KyraEngine* engine) { 40 27 _engine = engine; … … 108 95 volume = volume * _volume / 255; 109 96 b = (b & 0xFF00FFFF) | (volume << 16); 110 97 } else if ((b & 0xF0) == 0xC0 && !_nativeMT32) { 111 b = (b & 0xFFFF00FF) | mt32_to_gm[(b >> 8) & 0xFF] << 8;98 b = (b & 0xFFFF00FF) | MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8; 112 99 } else if ((b & 0xFFF0) == 0x007BB0) { 113 100 //Only respond to All Notes Off if this channel 114 101 //has currently been allocated -
queen/music.cpp
diff -ur ScummVM-cvs20050321/queen/music.cpp ScummVM-cvs20050321+hack/queen/music.cpp
old new 29 29 30 30 namespace Queen { 31 31 32 // Instrument mapping for MT32 tracks emulated under GM.33 static const byte mt32_to_gm[128] = {34 // 0 1 2 3 4 5 6 7 8 9 A B C D E F35 0, 1, 0, 2, 4, 4, 5, 3, 16, 17, 18, 16, 16, 19, 20, 21, // 0x36 6, 6, 6, 7, 7, 7, 8, 112, 62, 62, 63, 63, 38, 38, 39, 39, // 1x37 88, 95, 52, 98, 97, 99, 14, 54, 102, 96, 53, 102, 81, 100, 14, 80, // 2x38 48, 48, 49, 45, 41, 40, 42, 42, 43, 46, 45, 24, 25, 28, 27, 104, // 3x39 32, 32, 34, 33, 36, 37, 35, 35, 79, 73, 72, 72, 74, 75, 64, 65, // 4x40 66, 67, 71, 71, 68, 69, 70, 22, 56, 59, 57, 57, 60, 60, 58, 61, // 5x41 61, 11, 11, 98, 14, 9, 14, 13, 12, 107, 107, 77, 78, 78, 76, 76, // 6x42 47, 117, 127, 118, 118, 116, 115, 119, 115, 112, 55, 124, 123, 0, 14, 117 // 7x43 };44 45 32 MusicPlayer::MusicPlayer(MidiDriver *driver, byte *data, uint32 size) : _driver(driver), _isPlaying(false), _looping(false), _randomLoop(false), _masterVolume(192), _queuePos(0), _musicData(data), _musicDataSize(size), _passThrough(false), _buf(0) { 46 33 memset(_channel, 0, sizeof(_channel)); 47 34 queueClear(); … … 142 129 volume = volume * _masterVolume / 255; 143 130 b = (b & 0xFF00FFFF) | (volume << 16); 144 131 } else if ((b & 0xF0) == 0xC0 && !_nativeMT32) { 145 b = (b & 0xFFFF00FF) | mt32_to_gm[(b >> 8) & 0xFF] << 8;132 b = (b & 0xFFFF00FF) | MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8; 146 133 } 147 134 else if ((b & 0xFFF0) == 0x007BB0) { 148 135 //Only respond to All Notes Off if this channel -
saga/music.cpp
diff -ur ScummVM-cvs20050321/saga/music.cpp ScummVM-cvs20050321+hack/saga/music.cpp
old new 33 33 34 34 namespace Saga { 35 35 36 // Instrument mapping for MT32 tracks emulated under GM.37 static const byte mt32_to_gm[128] = {38 // 0 1 2 3 4 5 6 7 8 9 A B C D E F39 0, 1, 0, 2, 4, 4, 5, 3, 16, 17, 18, 16, 16, 19, 20, 21, // 0x40 6, 6, 6, 7, 7, 7, 8, 112, 62, 62, 63, 63, 38, 38, 39, 39, // 1x41 88, 95, 52, 98, 97, 99, 14, 54, 102, 96, 53, 102, 81, 100, 14, 80, // 2x42 48, 48, 49, 45, 41, 40, 42, 42, 43, 46, 45, 24, 25, 28, 27, 104, // 3x43 32, 32, 34, 33, 36, 37, 35, 35, 79, 73, 72, 72, 74, 75, 64, 65, // 4x44 66, 67, 71, 71, 68, 69, 70, 22, 56, 59, 57, 57, 60, 60, 58, 61, // 5x45 61, 11, 11, 98, 14, 9, 14, 13, 12, 107, 107, 77, 78, 78, 76, 76, // 6x46 47, 117, 127, 118, 118, 116, 115, 119, 115, 112, 55, 124, 123, 0, 14, 117 // 7x47 };48 49 36 #define BUFFER_SIZE 4096 50 37 51 38 // I haven't decided yet if it's a good idea to make looping part of the audio … … 239 226 volume = volume * _masterVolume / 255; 240 227 b = (b & 0xFF00FFFF) | (volume << 16); 241 228 } else if ((b & 0xF0) == 0xC0 && !_isGM && !_nativeMT32) { 242 b = (b & 0xFFFF00FF) | mt32_to_gm[(b >> 8) & 0xFF] << 8;229 b = (b & 0xFFFF00FF) | MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8; 243 230 } 244 231 else if ((b & 0xFFF0) == 0x007BB0) { 245 232 //Only respond to All Notes Off if this channel -
scumm/instrument.cpp
diff -ur ScummVM-cvs20050321/scumm/instrument.cpp ScummVM-cvs20050321+hack/scumm/instrument.cpp
old new 29 29 30 30 static bool _native_mt32 = false; 31 31 32 static const byte mt32_to_gm[128] = {33 // 0 1 2 3 4 5 6 7 8 9 A B C D E F34 0, 1, 0, 2, 4, 4, 5, 3, 16, 17, 18, 16, 16, 19, 20, 21, // 0x35 6, 6, 6, 7, 7, 7, 8, 112, 62, 62, 63, 63, 38, 38, 39, 39, // 1x36 88, 95, 52, 98, 97, 99, 14, 54, 102, 96, 53, 102, 81, 100, 14, 80, // 2x37 48, 48, 49, 45, 41, 40, 42, 42, 43, 46, 45, 24, 25, 28, 27, 104, // 3x38 32, 32, 34, 33, 36, 37, 35, 35, 79, 73, 72, 72, 74, 75, 64, 65, // 4x39 66, 67, 71, 71, 68, 69, 70, 22, 56, 59, 57, 57, 60, 60, 58, 61, // 5x40 61, 11, 11, 98, 14, 9, 14, 13, 12, 107, 107, 77, 78, 78, 76, 76, // 6x41 47, 117, 127, 118, 118, 116, 115, 119, 115, 112, 55, 124, 123, 0, 14, 117 // 7x42 };43 44 static const byte gm_to_mt32[128] = {45 5, 1, 2, 7, 3, 5, 16, 21, 22, 101, 101, 97, 104, 103, 102, 20,46 8, 9, 11, 12, 14, 15, 87, 15, 59, 60, 61, 62, 67, 44, 79, 23,47 64, 67, 66, 70, 68, 69, 28, 31, 52, 54, 55, 56, 49, 51, 57, 112,48 48, 50, 45, 26, 34, 35, 45, 122, 89, 90, 94, 81, 92, 95, 24, 25,49 80, 78, 79, 78, 84, 85, 86, 82, 74, 72, 76, 77, 110, 107, 108, 76,50 47, 44, 111, 45, 44, 34, 44, 30, 32, 33, 88, 34, 35, 35, 38, 33,51 41, 36, 100, 37, 40, 34, 43, 40, 63, 21, 99, 105, 103, 86, 55, 84,52 101, 103, 100, 120, 117, 113, 99, 128, 128, 128, 128, 124, 123, 128, 128, 128,53 };54 55 32 static struct { 56 33 const char *name; 57 34 byte program; … … 148 125 void saveOrLoad (Serializer *s); 149 126 void send (MidiChannel *mc); 150 127 void copy_to (Instrument *dest) { dest->program (_program, _mt32); } 151 bool is_valid() { return (_program < 128) && ((_native_mt32 == _mt32) || _native_mt32 ? ( gm_to_mt32[_program] < 128) : (mt32_to_gm[_program] < 128)); }128 bool is_valid() { return (_program < 128) && ((_native_mt32 == _mt32) || _native_mt32 ? (MidiDriver::_gmToMt32[_program] < 128) : (MidiDriver::_mt32ToGm[_program] < 128)); } 152 129 operator int() { return (_program < 128) ? _program : 255; } 153 130 }; 154 131 … … 360 337 361 338 byte program = _program; 362 339 if (_native_mt32 != _mt32) 363 program = _native_mt32 ? gm_to_mt32 [program] : mt32_to_gm [program];340 program = _native_mt32 ? MidiDriver::_gmToMt32 [program] : MidiDriver::_mt32ToGm [program]; 364 341 if (program < 128) 365 342 mc->programChange (program); 366 343 } -
simon/midi.cpp
diff -ur ScummVM-cvs20050321/simon/midi.cpp ScummVM-cvs20050321+hack/simon/midi.cpp
old new 35 35 // and just provide a factory function. 36 36 extern MidiParser *MidiParser_createS1D(); 37 37 38 39 // Instrument mapping for MT32 tracks emulated under GM.40 static const byte mt32_to_gm[128] = {41 // 0 1 2 3 4 5 6 7 8 9 A B C D E F42 0, 1, 0, 2, 4, 4, 5, 3, 16, 17, 18, 16, 16, 19, 20, 21, // 0x43 6, 6, 6, 7, 7, 7, 8, 112, 62, 62, 63, 63, 38, 38, 39, 39, // 1x44 88, 95, 52, 98, 97, 99, 14, 54, 102, 96, 53, 102, 81, 100, 14, 80, // 2x45 48, 48, 49, 45, 41, 40, 42, 42, 43, 46, 45, 24, 25, 28, 27, 104, // 3x46 32, 32, 34, 33, 36, 37, 35, 35, 79, 73, 72, 72, 74, 75, 64, 65, // 4x47 66, 67, 71, 71, 68, 69, 70, 22, 56, 59, 57, 57, 60, 60, 58, 61, // 5x48 61, 11, 11, 98, 14, 9, 14, 13, 12, 107, 107, 77, 78, 78, 76, 76, // 6x49 47, 117, 127, 118, 118, 116, 115, 119, 115, 112, 55, 124, 123, 0, 14, 117 // 7x50 };51 52 53 54 38 MidiPlayer::MidiPlayer(OSystem *system) { 55 39 // Since initialize() is called every time the music changes, 56 40 // this is where we'll initialize stuff that must persist … … 117 101 volume = volume * _masterVolume / 255; 118 102 b = (b & 0xFF00FFFF) | (volume << 16); 119 103 } else if ((b & 0xF0) == 0xC0 && _map_mt32_to_gm) { 120 b = (b & 0xFFFF00FF) | ( mt32_to_gm[(b >> 8) & 0xFF] << 8);104 b = (b & 0xFFFF00FF) | (MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8); 121 105 } else if ((b & 0xFFF0) == 0x007BB0) { 122 106 // Only respond to an All Notes Off if this channel 123 107 // has already been allocated. -
sky/music/gmchannel.cpp
diff -ur ScummVM-cvs20050321/sky/music/gmchannel.cpp ScummVM-cvs20050321+hack/sky/music/gmchannel.cpp
old new 25 25 26 26 namespace Sky { 27 27 28 GmChannel::GmChannel(uint8 *pMusicData, uint16 startOfData, MidiDriver *pMidiDrv, byte *pInstMap, uint8*veloTab) {28 GmChannel::GmChannel(uint8 *pMusicData, uint16 startOfData, MidiDriver *pMidiDrv, const byte *pInstMap, const byte *veloTab) { 29 29 30 30 _musicData = pMusicData; 31 31 _midiDrv = pMidiDrv; … … 34 34 _channelData.eventDataPtr = startOfData; 35 35 _channelData.channelActive = 1; 36 36 _channelData.nextEventTime = getNextEventTime(); 37 _ mt32_to_gm= pInstMap;37 _instMap = pInstMap; 38 38 _veloTab = veloTab; 39 39 40 40 _musicVolume = 0x7F; … … 130 130 } 131 131 } else { 132 132 _channelData.note = opcode; 133 uint8 velocity = _veloTab[_musicData[_channelData.eventDataPtr]]; 133 byte velocity = _musicData[_channelData.eventDataPtr]; 134 if (_veloTab) 135 velocity = _veloTab[velocity]; 134 136 _channelData.eventDataPtr++; 135 137 _midiDrv->send((0x90 | _channelData.midiChannelNumber) | (opcode << 8) | (velocity << 16)); 136 138 } … … 155 157 } 156 158 157 159 void GmChannel::com90_setupInstrument(void) { 158 159 _midiDrv->send((0xC0 | _channelData.midiChannelNumber) | (_mt32_to_gm[_musicData[_channelData.eventDataPtr]] << 8)); 160 byte instrument = _musicData[_channelData.eventDataPtr]; 161 if (_instMap) 162 instrument = _instMap[instrument]; 163 _midiDrv->send((0xC0 | _channelData.midiChannelNumber) | (instrument << 8)); 160 164 _channelData.eventDataPtr++; 161 165 } 162 166 -
sky/music/gmchannel.h
diff -ur ScummVM-cvs20050321/sky/music/gmchannel.h ScummVM-cvs20050321+hack/sky/music/gmchannel.h
old new 39 39 40 40 class GmChannel : public ChannelBase { 41 41 public: 42 GmChannel(uint8 *pMusicData, uint16 startOfData, MidiDriver *pMidiDrv, byte *pInstMap, uint8*veloTab);42 GmChannel(uint8 *pMusicData, uint16 startOfData, MidiDriver *pMidiDrv, const byte *pInstMap, const byte *veloTab); 43 43 virtual void stopNote(void); 44 44 virtual uint8 process(uint16 aktTime); 45 45 virtual void updateVolume(uint16 pVolume); 46 46 virtual bool isActive(void); 47 47 private: 48 byte *_mt32_to_gm;49 uint8*_veloTab;48 const byte *_instMap; 49 const byte *_veloTab; 50 50 MidiDriver *_midiDrv; 51 51 uint8 *_musicData; 52 52 uint16 _musicVolume; -
sky/music/gmmusic.cpp
diff -ur ScummVM-cvs20050321/sky/music/gmmusic.cpp ScummVM-cvs20050321+hack/sky/music/gmmusic.cpp
old new 89 89 channelData++; 90 90 for (uint8 cnt = 0; cnt < _numberOfChannels; cnt++) { 91 91 uint16 chDataStart = ((channelData[(cnt << 1) | 1] << 8) | channelData[cnt << 1]) + _musicDataLoc; 92 _channels[cnt] = new GmChannel(_musicData, chDataStart, _midiDrv, _mt32_to_gm, _veloTab);92 _channels[cnt] = new GmChannel(_musicData, chDataStart, _midiDrv, MidiDriver::_mt32ToGm, _veloTab); 93 93 _channels[cnt]->updateVolume(_musicVolume); 94 94 } 95 95 } … … 102 102 // skip all sysEx as it can't be handled anyways. 103 103 } 104 104 105 byte GmMusic::_mt32_to_gm[128] = { 106 // 0 1 2 3 4 5 6 7 8 9 A B C D E F 107 0, 1, 0, 2, 4, 4, 5, 3, 16, 17, 18, 16, 16, 19, 20, 21, // 0x 108 6, 6, 6, 7, 7, 7, 8, 112, 62, 62, 63, 63, 38, 38, 39, 39, // 1x 109 88, 95, 52, 98, 97, 99, 14, 54, 102, 96, 53, 102, 81, 100, 14, 80, // 2x 110 48, 48, 49, 45, 41, 40, 42, 42, 43, 46, 45, 24, 25, 28, 27, 104, // 3x 111 32, 32, 34, 33, 36, 37, 35, 35, 79, 73, 72, 72, 74, 75, 64, 65, // 4x 112 66, 67, 71, 71, 68, 69, 70, 22, 56, 59, 57, 57, 60, 60, 58, 61, // 5x 113 61, 11, 11, 98, 14, 9, 14, 13, 12, 107, 107, 77, 78, 78, 76, 76, // 6x 114 47, 117, 127, 118, 118, 116, 115, 119, 115, 112, 55, 124, 123, 0, 14, 117, // 7x 115 }; 116 117 uint8 GmMusic::_veloTab[128] = { 105 const byte GmMusic::_veloTab[128] = { 118 106 0x00, 0x40, 0x41, 0x41, 0x42, 0x42, 0x43, 0x43, 0x44, 0x44, 119 107 0x45, 0x45, 0x46, 0x46, 0x47, 0x47, 0x48, 0x48, 0x49, 0x49, 120 108 0x4A, 0x4A, 0x4B, 0x4B, 0x4C, 0x4C, 0x4D, 0x4D, 0x4E, 0x4E, -
sky/music/gmmusic.h
diff -ur ScummVM-cvs20050321/sky/music/gmmusic.h ScummVM-cvs20050321+hack/sky/music/gmmusic.h
old new 40 40 uint32 _timerCount; 41 41 uint8 *_sysExSequence; 42 42 MidiDriver *_midiDrv; 43 static byte _mt32_to_gm[128]; 44 static uint8 _veloTab[128]; 43 static const byte _veloTab[128]; 45 44 46 45 virtual void setupPointers(void); 47 46 virtual void setupChannels(uint8 *channelData); -
sky/music/mt32music.cpp
diff -ur ScummVM-cvs20050321/sky/music/mt32music.cpp ScummVM-cvs20050321+hack/sky/music/mt32music.cpp
old new 40 40 int midiRes = _midiDrv->open(); 41 41 if (midiRes != 0) 42 42 error("Can't open midi device. Errorcode: %d",midiRes); 43 for (uint8 cnt = 0; cnt < 128; cnt++)44 _dummyMap[cnt] = cnt;45 43 _timerCount = 0; 46 44 _midiDrv->setTimerCallback(this, passTimerFunc); 47 45 } … … 86 84 channelData++; 87 85 for (uint8 cnt = 0; cnt < _numberOfChannels; cnt++) { 88 86 uint16 chDataStart = ((channelData[(cnt << 1) | 1] << 8) | channelData[cnt << 1]) + _musicDataLoc; 89 _channels[cnt] = new GmChannel(_musicData, chDataStart, _midiDrv, _dummyMap, _dummyMap);87 _channels[cnt] = new GmChannel(_musicData, chDataStart, _midiDrv, NULL, NULL); 90 88 _channels[cnt]->updateVolume(_musicVolume); 91 89 } 92 90 } -
sky/music/mt32music.h
diff -ur ScummVM-cvs20050321/sky/music/mt32music.h ScummVM-cvs20050321+hack/sky/music/mt32music.h
old new 41 41 uint32 _timerCount; 42 42 uint8 *_sysExSequence; 43 43 MidiDriver *_midiDrv; 44 uint8 _dummyMap[128];45 44 46 45 virtual void setupPointers(void); 47 46 virtual void setupChannels(uint8 *channelData); -
sound/mididrv.cpp
diff -ur ScummVM-cvs20050321/sound/mididrv.cpp ScummVM-cvs20050321+hack/sound/mididrv.cpp
old new 69 69 {0, 0, 0} 70 70 }; 71 71 72 const byte MidiDriver::_mt32ToGm[128] = { 73 // 0 1 2 3 4 5 6 7 8 9 A B C D E F 74 0, 1, 0, 2, 4, 4, 5, 3, 16, 17, 18, 16, 16, 19, 20, 21, // 0x 75 6, 6, 6, 7, 7, 7, 8, 112, 62, 62, 63, 63, 38, 38, 39, 39, // 1x 76 88, 95, 52, 98, 97, 99, 14, 54, 102, 96, 53, 102, 81, 100, 14, 80, // 2x 77 48, 48, 49, 45, 41, 40, 42, 42, 43, 46, 45, 24, 25, 28, 27, 104, // 3x 78 32, 32, 34, 33, 36, 37, 35, 35, 79, 73, 72, 72, 74, 75, 64, 65, // 4x 79 66, 67, 71, 71, 68, 69, 70, 22, 56, 59, 57, 57, 60, 60, 58, 61, // 5x 80 61, 11, 11, 98, 14, 9, 14, 13, 12, 107, 107, 77, 78, 78, 76, 76, // 6x 81 47, 117, 127, 118, 118, 116, 115, 119, 115, 112, 55, 124, 123, 0, 14, 117 // 7x 82 }; 83 84 const byte MidiDriver::_gmToMt32[128] = { 85 // 0 1 2 3 4 5 6 7 8 9 A B C D E F 86 5, 1, 2, 7, 3, 5, 16, 21, 22, 101, 101, 97, 104, 103, 102, 20, // 0x 87 8, 9, 11, 12, 14, 15, 87, 15, 59, 60, 61, 62, 67, 44, 79, 23, // 1x 88 64, 67, 66, 70, 68, 69, 28, 31, 52, 54, 55, 56, 49, 51, 57, 112, // 2x 89 48, 50, 45, 26, 34, 35, 45, 122, 89, 90, 94, 81, 92, 95, 24, 25, // 3x 90 80, 78, 79, 78, 84, 85, 86, 82, 74, 72, 76, 77, 110, 107, 108, 76, // 4x 91 47, 44, 111, 45, 44, 34, 44, 30, 32, 33, 88, 34, 35, 35, 38, 33, // 5x 92 41, 36, 100, 37, 40, 34, 43, 40, 63, 21, 99, 105, 103, 86, 55, 84, // 6x 93 101, 103, 100, 120, 117, 113, 99, 128, 128, 128, 128, 124, 123, 128, 128, 128, // 7x 94 }; 72 95 73 96 const MidiDriverDescription *MidiDriver::getAvailableMidiDrivers() { 74 97 return midiDrivers; -
sound/mididrv.h
diff -ur ScummVM-cvs20050321/sound/mididrv.h ScummVM-cvs20050321+hack/sound/mididrv.h
old new 91 91 public: 92 92 virtual ~MidiDriver() { } 93 93 94 static const byte _mt32ToGm[128]; 95 static const byte _gmToMt32[128]; 96 94 97 /** 95 98 * Error codes returned by open. 96 99 * Can be converted to a string with getErrorName().