diff options
-rw-r--r-- | engines/sci/sound/music.cpp | 34 | ||||
-rw-r--r-- | engines/sci/sound/music.h | 11 |
2 files changed, 44 insertions, 1 deletions
diff --git a/engines/sci/sound/music.cpp b/engines/sci/sound/music.cpp index bfa2c3b3ee..1d186647f8 100644 --- a/engines/sci/sound/music.cpp +++ b/engines/sci/sound/music.cpp @@ -173,6 +173,21 @@ void SciMusic::sortPlayList() { MusicEntry ** pData = _playList.begin(); qsort(pData, _playList.size(), sizeof(MusicEntry *), &f_compare); } + +void SciMusic::findUsedChannels() { + // Reset list + for (int k = 0; k < 16; k++) + _usedChannels[k] = false; + + const MusicList::iterator end = _playList.end(); + for (MusicList::iterator i = _playList.begin(); i != end; ++i) { + for (int channel = 0; channel < 16; channel++) { + if ((*i)->soundRes && (*i)->soundRes->isChannelUsed(channel)) + _usedChannels[channel] = true; + } + } +} + void SciMusic::soundInitSnd(MusicEntry *pSnd) { int channelFilterMask = 0; SoundResource::Track *track = pSnd->soundRes->getTrackByType(_pMidiDrv->getPlayId()); @@ -220,6 +235,25 @@ void SciMusic::soundInitSnd(MusicEntry *pSnd) { channelFilterMask = pSnd->soundRes->getChannelFilterMask(_pMidiDrv->getPlayId(), _pMidiDrv->hasRhythmChannel()); pSnd->pMidiParser->loadMusic(track, pSnd, channelFilterMask, _soundVersion); + // TODO: Fix channel remapping. This doesn't quite work... (e.g. no difference in LSL1VGA) +#if 0 + // Remap channels + findUsedChannels(); + + for (int i = 0; i < 16; i++) { + if (_usedChannels[i] && pSnd->soundRes->isChannelUsed(i)) { + int16 newChannel = getNextUnusedChannel(); + if (newChannel >= 0) { + _usedChannels[newChannel] = true; + debug("Remapping channel %d to %d\n", i, newChannel); + pSnd->pMidiParser->remapChannel(i, newChannel); + } else { + warning("Attempt to remap channel %d, but no unused channels exist", i); + } + } + } +#endif + // Fast forward to the last position and perform associated events when loading pSnd->pMidiParser->jumpToTick(pSnd->ticker, true); _mutex.unlock(); diff --git a/engines/sci/sound/music.h b/engines/sci/sound/music.h index 8f08065b99..f5eb7ce8d9 100644 --- a/engines/sci/sound/music.h +++ b/engines/sci/sound/music.h @@ -197,7 +197,6 @@ public: Common::Mutex _mutex; protected: - byte findAudEntry(uint16 nAud, byte&oVolume, uint32& oOffset, uint32&oSize); void sortPlayList(); SciVersion _soundVersion; @@ -211,10 +210,20 @@ protected: bool _bMultiMidi; private: static void miditimerCallback(void *p); + void findUsedChannels(); + int16 getNextUnusedChannel() { + for (int i = 0; i < 16; i++) { + if (!_usedChannels[i]) + return i; + } + + return -1; + } MusicList _playList; bool _soundOn; byte _masterVolume; + bool _usedChannels[16]; }; } // End of namespace Sci |