diff options
author | Paweł Kołodziejski | 2004-05-23 19:32:11 +0000 |
---|---|---|
committer | Paweł Kołodziejski | 2004-05-23 19:32:11 +0000 |
commit | a26cfc8a382333998f15c2d4f9106b595b7d2ddc (patch) | |
tree | 4b860b6947105752722717e476ac7b7a945a8da5 | |
parent | 4a93fa1421dba349320c9f2bc98ad9c8494b2fed (diff) | |
download | scummvm-rg350-a26cfc8a382333998f15c2d4f9106b595b7d2ddc.tar.gz scummvm-rg350-a26cfc8a382333998f15c2d4f9106b595b7d2ddc.tar.bz2 scummvm-rg350-a26cfc8a382333998f15c2d4f9106b595b7d2ddc.zip |
some optimisations in imuse digi
svn-id: r13851
-rw-r--r-- | scumm/imuse_digi/dimuse.cpp | 223 | ||||
-rw-r--r-- | scumm/imuse_digi/dimuse.h | 5 | ||||
-rw-r--r-- | scumm/imuse_digi/dimuse_bndmgr.cpp | 43 | ||||
-rw-r--r-- | scumm/imuse_digi/dimuse_bndmgr.h | 14 | ||||
-rw-r--r-- | scumm/imuse_digi/dimuse_codecs.cpp | 162 | ||||
-rw-r--r-- | scumm/imuse_digi/dimuse_script.cpp | 79 | ||||
-rw-r--r-- | scumm/imuse_digi/dimuse_sndmgr.cpp | 7 | ||||
-rw-r--r-- | scumm/imuse_digi/dimuse_track.cpp | 265 |
8 files changed, 395 insertions, 403 deletions
diff --git a/scumm/imuse_digi/dimuse.cpp b/scumm/imuse_digi/dimuse.cpp index 5ac31b305d..e40c185ffd 100644 --- a/scumm/imuse_digi/dimuse.cpp +++ b/scumm/imuse_digi/dimuse.cpp @@ -15,7 +15,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header$ */ #include "stdafx.h" @@ -126,23 +125,24 @@ void IMuseDigital::saveOrLoad(Serializer *ser) { ser->saveLoadEntries(this, mainEntries); for (int i = 0; i < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; i++) { - ser->saveLoadEntries(_track[i], trackEntries); + Track *track = _track[i]; + ser->saveLoadEntries(track, trackEntries); if (!ser->isSaving()) { - if (!_track[i]->used) + if (!track->used) continue; - if (_track[i]->souStream) { - _track[i]->stream2 = NULL; - _track[i]->stream = NULL; - _track[i]->used = false; + if (track->souStream) { + track->stream2 = NULL; + track->stream = NULL; + track->used = false; } else { - _track[i]->soundHandle = _sound->openSound(_track[i]->soundId, - _track[i]->soundName, _track[i]->soundType, - _track[i]->volGroupId); - int32 streamBufferSize = _track[i]->iteration; - int freq = _sound->getFreq(_track[i]->soundHandle); - _track[i]->stream2 = NULL; - _track[i]->stream = makeAppendableAudioStream(freq, _track[i]->mixerFlags, streamBufferSize); - _vm->_mixer->playInputStream(&_track[i]->handle, _track[i]->stream, false, _track[i]->vol / 1000, _track[i]->pan, -1); + track->soundHandle = _sound->openSound(track->soundId, + track->soundName, track->soundType, + track->volGroupId); + int32 streamBufferSize = track->iteration; + int freq = _sound->getFreq(track->soundHandle); + track->stream2 = NULL; + track->stream = makeAppendableAudioStream(freq, track->mixerFlags, streamBufferSize); + _vm->_mixer->playInputStream(&track->handle, track->stream, false, track->vol / 1000, track->pan, -1); } } } @@ -150,95 +150,95 @@ void IMuseDigital::saveOrLoad(Serializer *ser) { void IMuseDigital::callback() { Common::StackLock lock(_mutex, "IMuseDigital::callback()"); - int l = 0; if (_pause || !_vm) return; - for (l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) { - if (_track[l]->used) { - if (_track[l]->stream2) { - if (!_track[l]->handle.isActive() && _track[l]->started) { - debug(5, "IMuseDigital::callback() A: stopped sound: %d", _track[l]->soundId); + for (int l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) { + Track *track = _track[l]; + if (track->used) { + if (track->stream2) { + if (!track->handle.isActive() && track->started) { + debug(5, "IMuseDigital::callback() A: stopped sound: %d", track->soundId); delete _track[l]->stream2; - _track[l]->stream2 = NULL; - _track[l]->used = false; + track->stream2 = NULL; + track->used = false; continue; } - } else if (_track[l]->stream) { - if (_track[l]->toBeRemoved) { - debug(5, "IMuseDigital::callback() B: stopped sound: %d", _track[l]->soundId); - _track[l]->stream->finish(); - _track[l]->stream = NULL; - _sound->closeSound(_track[l]->soundHandle); - _track[l]->soundHandle = NULL; - _track[l]->used = false; + } else if (track->stream) { + if (track->toBeRemoved) { + debug(5, "IMuseDigital::callback() B: stopped sound: %d", track->soundId); + track->stream->finish(); + track->stream = NULL; + _sound->closeSound(track->soundHandle); + track->soundHandle = NULL; + track->used = false; continue; } } - if (_track[l]->volFadeUsed) { - if (_track[l]->volFadeStep < 0) { - if (_track[l]->vol > _track[l]->volFadeDest) { - _track[l]->vol += _track[l]->volFadeStep; - if (_track[l]->vol < _track[l]->volFadeDest) { - _track[l]->vol = _track[l]->volFadeDest; - _track[l]->volFadeUsed = false; + if (track->volFadeUsed) { + if (track->volFadeStep < 0) { + if (track->vol > track->volFadeDest) { + track->vol += track->volFadeStep; + if (track->vol < track->volFadeDest) { + track->vol = track->volFadeDest; + track->volFadeUsed = false; } - if (_track[l]->vol == 0) { - _track[l]->toBeRemoved = true; + if (track->vol == 0) { + track->toBeRemoved = true; } } - } else if (_track[l]->volFadeStep > 0) { - if (_track[l]->vol < _track[l]->volFadeDest) { - _track[l]->vol += _track[l]->volFadeStep; - if (_track[l]->vol > _track[l]->volFadeDest) { - _track[l]->vol = _track[l]->volFadeDest; - _track[l]->volFadeUsed = false; + } else if (track->volFadeStep > 0) { + if (track->vol < track->volFadeDest) { + track->vol += track->volFadeStep; + if (track->vol > track->volFadeDest) { + track->vol = track->volFadeDest; + track->volFadeUsed = false; } } } - debug(5, "Fade: sound(%d), Vol(%d)", _track[l]->soundId, _track[l]->vol / 1000); + debug(5, "Fade: sound(%d), Vol(%d)", track->soundId, track->vol / 1000); } - int pan = (_track[l]->pan != 64) ? 2 * _track[l]->pan - 127 : 0; - int vol = _track[l]->vol / 1000; + int pan = (track->pan != 64) ? 2 * track->pan - 127 : 0; + int vol = track->vol / 1000; - if (_track[l]->volGroupId == 1) + if (track->volGroupId == 1) vol = (vol * _volVoice) / 128; - if (_track[l]->volGroupId == 2) + if (track->volGroupId == 2) vol = (vol * _volSfx) / 128; - if (_track[l]->volGroupId == 3) + if (track->volGroupId == 3) vol = (vol * _volMusic) / 128; if (_vm->_mixer->isReady()) { - if (_track[l]->stream2) { - if (!_track[l]->started) { - _track[l]->started = true; - _vm->_mixer->playInputStream(&_track[l]->handle, _track[l]->stream2, false, _track[l]->vol / 1000, _track[l]->pan, -1, false); + if (track->stream2) { + if (!track->started) { + track->started = true; + _vm->_mixer->playInputStream(&track->handle, track->stream2, false, track->vol / 1000, track->pan, -1, false); } else { - _vm->_mixer->setChannelVolume(_track[l]->handle, vol); - _vm->_mixer->setChannelBalance(_track[l]->handle, pan); + _vm->_mixer->setChannelVolume(track->handle, vol); + _vm->_mixer->setChannelBalance(track->handle, pan); } continue; } } - if (_track[l]->stream) { + if (track->stream) { byte *data = NULL; int32 result = 0; - if (_track[l]->curRegion == -1) { + if (track->curRegion == -1) { switchToNextRegion(l); - if (_track[l]->toBeRemoved) + if (track->toBeRemoved) continue; } - int bits = _sound->getBits(_track[l]->soundHandle); - int channels = _sound->getChannels(_track[l]->soundHandle); + int bits = _sound->getBits(track->soundHandle); + int channels = _sound->getChannels(track->soundHandle); -// int32 bufferUsage = _track[l]->iteration - _track[l]->stream->getFreeSpace(); - int32 bufferMin = _track[l]->iteration / 25; +// int32 bufferUsage = track->iteration - track->stream->getFreeSpace(); + int32 bufferMin = track->iteration / 25; // if (bufferMin < bufferUsage) // continue; @@ -261,18 +261,18 @@ void IMuseDigital::callback() { if (bits == 12) { byte *ptr = NULL; - mixer_size += _track[l]->mod; + mixer_size += track->mod; int mixer_size_12 = (mixer_size * 3) / 4; int length = (mixer_size_12 / 3) * 4; - _track[l]->mod = mixer_size - length; + track->mod = mixer_size - length; - int32 offset = (_track[l]->regionOffset * 3) / 4; - int result2 = _sound->getDataFromRegion(_track[l]->soundHandle, _track[l]->curRegion, &ptr, offset, mixer_size_12); + int32 offset = (track->regionOffset * 3) / 4; + int result2 = _sound->getDataFromRegion(track->soundHandle, track->curRegion, &ptr, offset, mixer_size_12); result = BundleCodecs::decode12BitsSample(ptr, &data, result2); free(ptr); } else if (bits == 16) { - result = _sound->getDataFromRegion(_track[l]->soundHandle, _track[l]->curRegion, &data, _track[l]->regionOffset, mixer_size); + result = _sound->getDataFromRegion(track->soundHandle, track->curRegion, &data, track->regionOffset, mixer_size); if (channels == 1) { result &= ~1; } @@ -280,7 +280,7 @@ void IMuseDigital::callback() { result &= ~3; } } else if (bits == 8) { - result = _sound->getDataFromRegion(_track[l]->soundHandle, _track[l]->curRegion, &data, _track[l]->regionOffset, mixer_size); + result = _sound->getDataFromRegion(track->soundHandle, track->curRegion, &data, track->regionOffset, mixer_size); if (channels == 2) { result &= ~1; } @@ -290,16 +290,16 @@ void IMuseDigital::callback() { result = mixer_size; if (_vm->_mixer->isReady()) { - _vm->_mixer->setChannelVolume(_track[l]->handle, vol); - _vm->_mixer->setChannelBalance(_track[l]->handle, pan); - _track[l]->stream->append(data, result); - _track[l]->regionOffset += result; + _vm->_mixer->setChannelVolume(track->handle, vol); + _vm->_mixer->setChannelBalance(track->handle, pan); + track->stream->append(data, result); + track->regionOffset += result; free(data); } - if (_sound->isEndOfRegion(_track[l]->soundHandle, _track[l]->curRegion)) { + if (_sound->isEndOfRegion(track->soundHandle, track->curRegion)) { switchToNextRegion(l); - if (_track[l]->toBeRemoved) + if (track->toBeRemoved) break; } mixer_size -= result; @@ -310,60 +310,65 @@ void IMuseDigital::callback() { } } -void IMuseDigital::switchToNextRegion(int track) { - debug(5, "switchToNextRegion(track:%d)", track); +void IMuseDigital::switchToNextRegion(int trackId) { + debug(5, "switchToNextRegion(track:%d)", trackId); + + Track *track = _track[trackId]; - if (track >= MAX_DIGITAL_TRACKS) { - _track[track]->toBeRemoved = true; - debug(5, "exit (fadetrack can't go next region) switchToNextRegion(track:%d)", track); + if (trackId >= MAX_DIGITAL_TRACKS) { + track->toBeRemoved = true; + debug(5, "exit (fadetrack can't go next region) switchToNextRegion(trackId:%d)", trackId); return; } - int num_regions = _sound->getNumRegions(_track[track]->soundHandle); + int num_regions = _sound->getNumRegions(track->soundHandle); - if (++_track[track]->curRegion == num_regions) { - _track[track]->toBeRemoved = true; - debug(5, "exit (end of regions) switchToNextRegion(track:%d)", track); + if (++track->curRegion == num_regions) { + track->toBeRemoved = true; + debug(5, "exit (end of regions) switchToNextRegion(track:%d)", trackId); return; } - int jumpId = _sound->getJumpIdByRegionAndHookId(_track[track]->soundHandle, _track[track]->curRegion, _track[track]->curHookId); + ImuseDigiSndMgr::soundStruct *soundHandle = track->soundHandle; + int jumpId = _sound->getJumpIdByRegionAndHookId(soundHandle, track->curRegion, track->curHookId); if (jumpId == -1) - jumpId = _sound->getJumpIdByRegionAndHookId(_track[track]->soundHandle, _track[track]->curRegion, 0); + jumpId = _sound->getJumpIdByRegionAndHookId(soundHandle, track->curRegion, 0); if (jumpId != -1) { - int region = _sound->getRegionIdByJumpId(_track[track]->soundHandle, jumpId); + int region = _sound->getRegionIdByJumpId(soundHandle, jumpId); assert(region != -1); - int sampleHookId = _sound->getJumpHookId(_track[track]->soundHandle, jumpId); + int sampleHookId = _sound->getJumpHookId(soundHandle, jumpId); assert(sampleHookId != -1); - int fadeDelay = (60 * _sound->getJumpFade(_track[track]->soundHandle, jumpId)) / 1000; + int fadeDelay = (60 * _sound->getJumpFade(soundHandle, jumpId)) / 1000; if (sampleHookId != 0) { - if (_track[track]->curHookId == sampleHookId) { + if (track->curHookId == sampleHookId) { if (fadeDelay != 0) { - int fadeTrack = cloneToFadeOutTrack(track, fadeDelay, false); - _track[fadeTrack]->dataOffset = _sound->getRegionOffset(_track[fadeTrack]->soundHandle, _track[fadeTrack]->curRegion); - _track[fadeTrack]->regionOffset = 0; - debug(5, "switchToNextRegion-sound(%d) select %d region, curHookId: %d", _track[fadeTrack]->soundId, _track[fadeTrack]->curRegion, _track[fadeTrack]->curHookId); - _track[fadeTrack]->curHookId = 0; + int fadeTrackId = cloneToFadeOutTrack(trackId, fadeDelay, false); + Track *fadeTrack = _track[fadeTrackId]; + fadeTrack->dataOffset = _sound->getRegionOffset(fadeTrack->soundHandle, fadeTrack->curRegion); + fadeTrack->regionOffset = 0; + debug(5, "switchToNextRegion-sound(%d) select %d region, curHookId: %d", fadeTrack->soundId, fadeTrack->curRegion, fadeTrack->curHookId); + fadeTrack->curHookId = 0; } - _track[track]->curRegion = region; - debug(5, "switchToNextRegion-sound(%d) jump to %d region, curHookId: %d", _track[track]->soundId, _track[track]->curRegion, _track[track]->curHookId); - _track[track]->curHookId = 0; + track->curRegion = region; + debug(5, "switchToNextRegion-sound(%d) jump to %d region, curHookId: %d", track->soundId, track->curRegion, track->curHookId); + track->curHookId = 0; } } else { if (fadeDelay != 0) { - int fadeTrack = cloneToFadeOutTrack(track, fadeDelay, false); - _track[fadeTrack]->dataOffset = _sound->getRegionOffset(_track[fadeTrack]->soundHandle, _track[fadeTrack]->curRegion); - _track[fadeTrack]->regionOffset = 0; - debug(5, "switchToNextRegion-sound(%d) select %d region, curHookId: %d", _track[fadeTrack]->soundId, _track[fadeTrack]->curRegion, _track[fadeTrack]->curHookId); + int fadeTrackId = cloneToFadeOutTrack(trackId, fadeDelay, false); + Track *fadeTrack = _track[fadeTrackId]; + fadeTrack->dataOffset = _sound->getRegionOffset(fadeTrack->soundHandle, fadeTrack->curRegion); + fadeTrack->regionOffset = 0; + debug(5, "switchToNextRegion-sound(%d) select %d region, curHookId: %d", fadeTrack->soundId, fadeTrack->curRegion, fadeTrack->curHookId); } - _track[track]->curRegion = region; - debug(5, "switchToNextRegion-sound(%d) jump to %d region, curHookId: %d", _track[track]->soundId, _track[track]->curRegion, _track[track]->curHookId); + track->curRegion = region; + debug(5, "switchToNextRegion-sound(%d) jump to %d region, curHookId: %d", track->soundId, track->curRegion, track->curHookId); } } - debug(5, "switchToNextRegion-sound(%d) select %d region, curHookId: %d", _track[track]->soundId, _track[track]->curRegion, _track[track]->curHookId); - _track[track]->dataOffset = _sound->getRegionOffset(_track[track]->soundHandle, _track[track]->curRegion); - _track[track]->regionOffset = 0; + debug(5, "switchToNextRegion-sound(%d) select %d region, curHookId: %d", track->soundId, track->curRegion, track->curHookId); + track->dataOffset = _sound->getRegionOffset(soundHandle, track->curRegion); + track->regionOffset = 0; } } // End of namespace Scumm diff --git a/scumm/imuse_digi/dimuse.h b/scumm/imuse_digi/dimuse.h index c61edbbd62..e2bbd9db83 100644 --- a/scumm/imuse_digi/dimuse.h +++ b/scumm/imuse_digi/dimuse.h @@ -15,7 +15,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header$ */ #ifndef IMUSE_DIGI_H @@ -99,7 +98,7 @@ private: static void timer_handler(void *refConf); void callback(); - void switchToNextRegion(int track); + void switchToNextRegion(int trackId); bool allocSlot(int priority); void startSound(int soundId, const char *soundName, int soundType, int volGroupId, AudioStream *input, int hookId, int volume, int priority); void selectVolumeGroup(int soundId, int volGroupId); @@ -109,7 +108,7 @@ private: int getSoundIdByName(const char *soundName); void fadeOutMusic(int fadeDelay); - int cloneToFadeOutTrack(int track, int fadeDelay, int killNormalTrack); + int cloneToFadeOutTrack(int trackId, int fadeDelay, int killNormalTrack); void setFtMusicState(int stateId); void setFtMusicSequence(int seqId); diff --git a/scumm/imuse_digi/dimuse_bndmgr.cpp b/scumm/imuse_digi/dimuse_bndmgr.cpp index 49dc33169f..3f87c88470 100644 --- a/scumm/imuse_digi/dimuse_bndmgr.cpp +++ b/scumm/imuse_digi/dimuse_bndmgr.cpp @@ -15,7 +15,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header$ */ #include "stdafx.h" @@ -140,7 +139,7 @@ bool BundleMgr::openFile(const char *filename, const char *directory) { _bundleTable = _cache->getTable(filename, directory); assert(_bundleTable); _compTableLoaded = false; - _lastCacheOutputSize = 0; + _outputSize = 0; _lastBlock = -1; return true; @@ -154,10 +153,14 @@ void BundleMgr::closeFile() { _numCompItems = 0; _compTableLoaded = false; _lastBlock = -1; - _lastCacheOutputSize = 0; + _outputSize = 0; _curSample = -1; free(_compTable); _compTable = NULL; + if (_compInput) { + free(_compInput); + _compInput = NULL; + } } } @@ -167,7 +170,6 @@ int32 BundleMgr::decompressSampleByCurIndex(int32 offset, int32 size, byte **com int32 BundleMgr::decompressSampleByIndex(int32 index, int32 offset, int32 size, byte **comp_final, int header_size, bool header_outside) { int32 i, tag, num, final_size, output_size; - byte *comp_input, *comp_output; int skip, first_block, last_block; if (index != -1) @@ -191,23 +193,27 @@ int32 BundleMgr::decompressSampleByIndex(int32 index, int32 offset, int32 size, } _compTable = (CompTable *)malloc(sizeof(CompTable) * num); + int32 maxSize = 0; for (i = 0; i < num; i++) { _compTable[i].offset = _file.readUint32BE(); _compTable[i].size = _file.readUint32BE(); _compTable[i].codec = _file.readUint32BE(); _file.readUint32BE(); + if (_compTable[i].size > maxSize) + maxSize = _compTable[i].size; } + // CMI hack: one more byte at the end of input buffer + _compInput = (byte *)malloc(maxSize + 1); _compTableLoaded = true; } first_block = (offset + header_size) / 0x2000; last_block = (offset + size + header_size - 1) / 0x2000; - // workaround for bug when (offset + size + header_size - 1) is more one byte after sound resource + // case when (offset + size + header_size - 1) is more one byte after sound resource if ((last_block >= _numCompItems) && (_numCompItems > 0)) last_block = _numCompItems - 1; - comp_output = (byte *)malloc(0x2000); int32 blocks_final_size = 0x2000 * (1 + last_block - first_block); *comp_final = (byte *)malloc(blocks_final_size); final_size = 0; @@ -215,26 +221,17 @@ int32 BundleMgr::decompressSampleByIndex(int32 index, int32 offset, int32 size, skip = offset - (first_block * 0x2000) + header_size; for (i = first_block; i <= last_block; i++) { - byte *curBuf; if (_lastBlock != i) { // CMI hack: one more zero byte at the end of input buffer - comp_input = (byte *)malloc(_compTable[i].size + 1); - comp_input[_compTable[i].size] = 0; + _compInput[_compTable[i].size] = 0; _file.seek(_bundleTable[index].offset + _compTable[i].offset, SEEK_SET); - _file.read(comp_input, _compTable[i].size); - - output_size = BundleCodecs::decompressCodec(_compTable[i].codec, comp_input, comp_output, _compTable[i].size); - assert(output_size <= 0x2000); + _file.read(_compInput, _compTable[i].size); + _outputSize = BundleCodecs::decompressCodec(_compTable[i].codec, _compInput, _compOutput, _compTable[i].size); _lastBlock = i; - _lastCacheOutputSize = output_size; - memcpy(_blockChache, comp_output, output_size); - curBuf = comp_output; - free(comp_input); - } else { - output_size = _lastCacheOutputSize; - curBuf = _blockChache; } + output_size = _outputSize; + if (header_outside) { output_size -= skip; } else { @@ -247,16 +244,16 @@ int32 BundleMgr::decompressSampleByIndex(int32 index, int32 offset, int32 size, assert(final_size + output_size <= blocks_final_size); - memcpy(*comp_final + final_size, curBuf + skip, output_size); - + memcpy(*comp_final + final_size, _compOutput + skip, output_size); final_size += output_size; + size -= output_size; assert(size >= 0); if (size == 0) break; + skip = 0; } - free(comp_output); return final_size; } diff --git a/scumm/imuse_digi/dimuse_bndmgr.h b/scumm/imuse_digi/dimuse_bndmgr.h index a8819a500e..f4749cdc8f 100644 --- a/scumm/imuse_digi/dimuse_bndmgr.h +++ b/scumm/imuse_digi/dimuse_bndmgr.h @@ -15,7 +15,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header$ */ #ifndef BUNDLE_MGR_H @@ -63,15 +62,16 @@ private: BundleDirCache *_cache; BundleDirCache::AudioTable *_bundleTable; CompTable *_compTable; - int32 _numFiles; - int32 _numCompItems; - int32 _curSample; + int _numFiles; + int _numCompItems; + int _curSample; File _file; bool _compTableLoaded; int _fileBundleId; - byte _blockChache[0x2000]; - int32 _lastCacheOutputSize; - int32 _lastBlock; + byte _compOutput[0x2000]; + byte *_compInput; + int _outputSize; + int _lastBlock; public: diff --git a/scumm/imuse_digi/dimuse_codecs.cpp b/scumm/imuse_digi/dimuse_codecs.cpp index efab0a6382..e4b4be6c7c 100644 --- a/scumm/imuse_digi/dimuse_codecs.cpp +++ b/scumm/imuse_digi/dimuse_codecs.cpp @@ -15,7 +15,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header$ */ #include "stdafx.h" @@ -194,7 +193,7 @@ static int32 compDecode(byte *src, byte *dst) { int data, size, bit, bitsleft = 16, mask = READ_LE_UINT16(srcptr); srcptr += 2; - while (1) { + for (;;) { NextBit; if (bit) { *dstptr++ = *srcptr++; @@ -269,22 +268,23 @@ int32 decompressCodec(int32 codec, byte *comp_input, byte *comp_output, int32 in memset(t_table, 0, output_size); src = comp_output; - length = (output_size * 8) / 12; + length = (output_size << 3) / 12; k = 0; if (length > 0) { c = -12; s = 0; j = 0; do { - ptr = src + length + k / 2; + ptr = src + length + (k >> 1); + t_tmp2 = src[j]; if (k & 1) { - r = c / 8; - t_table[r + 2] = ((src[j] & 0x0f) << 4) | (ptr[1] >> 4); - t_table[r + 1] = (src[j] & 0xf0) | (t_table[r + 1]); + r = c >> 3; + t_table[r + 2] = ((t_tmp2 & 0x0f) << 4) | (ptr[1] >> 4); + t_table[r + 1] = (t_tmp2 & 0xf0) | (t_table[r + 1]); } else { - r = s / 8; - t_table[r + 0] = ((src[j] & 0x0f) << 4) | (ptr[0] & 0x0f); - t_table[r + 1] = src[j] >> 4; + r = s >> 3; + t_table[r + 0] = ((t_tmp2 & 0x0f) << 4) | (ptr[0] & 0x0f); + t_table[r + 1] = t_tmp2 >> 4; } s += 12; c += 12; @@ -292,7 +292,7 @@ int32 decompressCodec(int32 codec, byte *comp_input, byte *comp_output, int32 in j++; } while (k < length); } - offset1 = ((length - 1) * 3) / 2; + offset1 = ((length - 1) * 3) >> 1; t_table[offset1 + 1] = (t_table[offset1 + 1]) | (src[length - 1] & 0xf0); memcpy(src, t_table, output_size); free(t_table); @@ -310,24 +310,25 @@ int32 decompressCodec(int32 codec, byte *comp_input, byte *comp_output, int32 in memset(t_table, 0, output_size); src = comp_output; - length = (output_size * 8) / 12; + length = (output_size << 3) / 12; k = 1; c = 0; s = 12; - t_table[0] = src[length] / 16; + t_table[0] = src[length] >> 4; t = length + k; j = 1; if (t > k) { do { - ptr = src + length + k / 2; + t_tmp1 = *(src + length + (k >> 1)); + t_tmp2 = src[j - 1]; if (k & 1) { - r = c / 8; - t_table[r + 0] = (src[j - 1] & 0xf0) | t_table[r]; - t_table[r + 1] = ((src[j - 1] & 0x0f) << 4) | (ptr[0] & 0x0f); + r = c >> 3; + t_table[r + 0] = (t_tmp2 & 0xf0) | t_table[r]; + t_table[r + 1] = ((t_tmp2 & 0x0f) << 4) | (t_tmp1 & 0x0f); } else { - r = s / 8; - t_table[r + 0] = src[j - 1] >> 4; - t_table[r - 1] = ((src[j - 1] & 0x0f) << 4) | (ptr[0] >> 4); + r = s >> 3; + t_table[r + 0] = t_tmp2 >> 4; + t_table[r - 1] = ((t_tmp2 & 0x0f) << 4) | (t_tmp1 >> 4); } s += 12; c += 12; @@ -351,7 +352,7 @@ int32 decompressCodec(int32 codec, byte *comp_input, byte *comp_output, int32 in memset(t_table, 0, output_size); src = comp_output; - length = (output_size * 8) / 12; + length = (output_size << 3) / 12; k = 0; c = 0; j = 0; @@ -361,15 +362,16 @@ int32 decompressCodec(int32 codec, byte *comp_input, byte *comp_output, int32 in t = length - 1; if (t > 0) { do { - ptr = src + length + k / 2; + t_tmp1 = *(src + length + (k >> 1)); + t_tmp2 = src[j]; if (k & 1) { - r = s / 8; - t_table[r + 2] = (src[j] & 0xf0) | *(t_table + r + 2); - t_table[r + 3] = ((src[j] & 0x0f) << 4) | (ptr[0] >> 4); + r = s >> 3; + t_table[r + 2] = (t_tmp2 & 0xf0) | t_table[r + 2]; + t_table[r + 3] = ((t_tmp2 & 0x0f) << 4) | (t_tmp1 >> 4); } else { - r = c / 8; - t_table[r + 2] = src[j] >> 4; - t_table[r + 1] = ((src[j] & 0x0f) << 4) | (ptr[0] & 0x0f); + r = c >> 3; + t_table[r + 2] = t_tmp2 >> 4; + t_table[r + 1] = ((t_tmp2 & 0x0f) << 4) | (t_tmp1 & 0x0f); } s += 12; c += 12; @@ -393,36 +395,33 @@ int32 decompressCodec(int32 codec, byte *comp_input, byte *comp_output, int32 in memcpy(t_table, p, output_size); offset1 = output_size / 3; - offset2 = offset1 * 2; + offset2 = offset1 << 1; offset3 = offset2; src = comp_output; - do { - if (offset1 == 0) - break; - offset1--; + + while (offset1--) { offset2 -= 2; offset3--; t_table[offset2 + 0] = src[offset1]; t_table[offset2 + 1] = src[offset3]; - } while (1); + } src = comp_output; - length = (output_size * 8) / 12; + length = (output_size << 3) / 12; k = 0; if (length > 0) { c = -12; s = 0; do { - j = length + k / 2; + j = length + (k >> 1); + t_tmp1 = t_table[k]; if (k & 1) { - r = c / 8; - t_tmp1 = t_table[k]; + r = c >> 3; t_tmp2 = t_table[j + 1]; src[r + 2] = ((t_tmp1 & 0x0f) << 4) | (t_tmp2 >> 4); src[r + 1] = (src[r + 1]) | (t_tmp1 & 0xf0); } else { - r = s / 8; - t_tmp1 = t_table[k]; + r = s >> 3; t_tmp2 = t_table[j]; src[r + 0] = ((t_tmp1 & 0x0f) << 4) | (t_tmp2 & 0x0f); src[r + 1] = t_tmp1 >> 4; @@ -432,7 +431,7 @@ int32 decompressCodec(int32 codec, byte *comp_input, byte *comp_output, int32 in k++; } while (k < length); } - offset1 = ((length - 1) * 3) / 2; + offset1 = ((length - 1) * 3) >> 1; src[offset1 + 1] = (t_table[length] & 0xf0) | src[offset1 + 1]; free(t_table); break; @@ -449,40 +448,36 @@ int32 decompressCodec(int32 codec, byte *comp_input, byte *comp_output, int32 in memcpy(t_table, p, output_size); offset1 = output_size / 3; - offset2 = offset1 * 2; + offset2 = offset1 << 1; offset3 = offset2; src = comp_output; - do { - if (offset1 == 0) - break; - offset1--; + + while (offset1--) { offset2 -= 2; offset3--; t_table[offset2 + 0] = src[offset1]; t_table[offset2 + 1] = src[offset3]; - } while (1); + } src = comp_output; - length = (output_size * 8) / 12; + length = (output_size << 3) / 12; k = 1; c = 0; s = 12; - t_tmp1 = t_table[length] / 16; + t_tmp1 = t_table[length] >> 4; src[0] = t_tmp1; t = length + k; if (t > k) { do { - j = length + k / 2; + j = length + (k >> 1); + t_tmp1 = t_table[k - 1]; + t_tmp2 = t_table[j]; if (k & 1) { - r = c / 8; - t_tmp1 = t_table[k - 1]; - t_tmp2 = t_table[j]; + r = c >> 3; src[r + 0] = (src[r]) | (t_tmp1 & 0xf0); src[r + 1] = ((t_tmp1 & 0x0f) << 4) | (t_tmp2 & 0x0f); } else { - r = s / 8; - t_tmp1 = t_table[k - 1]; - t_tmp2 = t_table[j]; + r = s >> 3; src[r + 0] = t_tmp1 >> 4; src[r - 1] = ((t_tmp1 & 0x0f) << 4) | (t_tmp2 >> 4); } @@ -506,21 +501,19 @@ int32 decompressCodec(int32 codec, byte *comp_input, byte *comp_output, int32 in memcpy(t_table, p, output_size); offset1 = output_size / 3; - offset2 = offset1 * 2; + offset2 = offset1 << 1; offset3 = offset2; src = comp_output; - do { - if (offset1 == 0) - break; - offset1--; + + while (offset1--) { offset2 -= 2; offset3--; t_table[offset2 + 0] = src[offset1]; t_table[offset2 + 1] = src[offset3]; - } while (1); + } src = comp_output; - length = (output_size * 8) / 12; + length = (output_size << 3) / 12; k = 0; c = 0; s = -12; @@ -529,17 +522,15 @@ int32 decompressCodec(int32 codec, byte *comp_input, byte *comp_output, int32 in t = length - 1; if (t > 0) { do { - j = length + k / 2; + j = length + (k >> 1); + t_tmp1 = t_table[k]; + t_tmp2 = t_table[j]; if (k & 1) { - r = s / 8; - t_tmp1 = t_table[k]; - t_tmp2 = t_table[j]; + r = s >> 3; src[r + 2] = (src[r + 2]) | (t_tmp1 & 0xf0); src[r + 3] = ((t_tmp1 & 0x0f) << 4) | (t_tmp2 >> 4); } else { - r = c / 8; - t_tmp1 = t_table[k]; - t_tmp2 = t_table[j]; + r = c >> 3; src[r + 2] = t_tmp1 >> 4; src[r + 1] = ((t_tmp1 & 0x0f) << 4) | (t_tmp2 & 0x0f); } @@ -592,8 +583,8 @@ int32 decompressCodec(int32 codec, byte *comp_input, byte *comp_output, int32 in left = 0x2000 - firstWord; output_size = left; } else { - left = 0x1000 - firstWord / 2; - output_size = left * 2; + left = 0x1000 - (firstWord >> 1); + output_size = left << 1; } output_size += firstWord; } else { @@ -621,38 +612,19 @@ int32 decompressCodec(int32 codec, byte *comp_input, byte *comp_output, int32 in } left = origLeft; - destPos = l * 2; + destPos = l << 1; if (channels == 2) { if (l == 0) left++; - left /= 2; + left >>= 1; } while (left--) { curTableEntry = _destImcTable[curTablePos]; decompTable = (byte)(curTableEntry - 2); bitMask = 2 << decompTable; - readPos = src + tableEntrySum / 8; - - // FIXME - it seems the decoder often reads exactly one byte too - // far - that is, it reads 2 bytes at once, and the second byte - // is just outside the buffer. However, it seems of these two bytes, - // only the upper one is actually used, so this should be fine. - // Still, I put this error message into place. If somebody one day - // encounters a situation where the second byte would be used, too, - // then this would indicate there is a bug in the decoder... - if (readPos + 1 >= comp_input + input_size) { - // OK an overflow... if it is more than one byte or if we - // need more than 8 bit of data -> error - if (readPos + 1 > comp_input + input_size || - curTableEntry + (tableEntrySum & 7) > 8) { - error("decompressCodec: input buffer overflow: %d bytes over (we need %d bits of data)", - (int)((readPos + 1) - (comp_input + input_size)) + 1, - curTableEntry + (tableEntrySum & 7) - ); - } - } + readPos = src + (tableEntrySum >> 3); readWord = (uint16)(READ_BE_UINT16(readPos) << (tableEntrySum & 7)); otherTablePos = (byte)(readWord >> (16 - curTableEntry)); tableEntrySum += curTableEntry; @@ -682,7 +654,7 @@ int32 decompressCodec(int32 codec, byte *comp_input, byte *comp_output, int32 in curTablePos = 0; imcTableEntry = imcTable[curTablePos]; - destPos += channels * 2; + destPos += channels << 1; } } } diff --git a/scumm/imuse_digi/dimuse_script.cpp b/scumm/imuse_digi/dimuse_script.cpp index 43fa626845..bd824a2fcc 100644 --- a/scumm/imuse_digi/dimuse_script.cpp +++ b/scumm/imuse_digi/dimuse_script.cpp @@ -15,7 +15,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header$ */ #include "stdafx.h" @@ -205,8 +204,9 @@ void IMuseDigital::getLipSync(int soundId, int syncId, int32 msPos, int32 &width msPos /= 16; if (msPos < 65536) { for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if ((_track[l]->soundId == soundId) && _track[l]->used) { - _sound->getSyncSizeAndPtrById(_track[l]->soundHandle, syncId, sync_size, &sync_ptr); + Track *track = _track[l]; + if ((track->soundId == soundId) && track->used) { + _sound->getSyncSizeAndPtrById(track->soundHandle, syncId, sync_size, &sync_ptr); if ((sync_size != 0) && (sync_ptr != NULL)) { sync_size /= 4; while (sync_size--) { @@ -231,8 +231,9 @@ void IMuseDigital::getLipSync(int soundId, int syncId, int32 msPos, int32 &width int32 IMuseDigital::getPosInMs(int soundId) { for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if ((_track[l]->soundId == soundId) && (_track[l]->used)) { - int32 pos = (5 * (_track[l]->dataOffset + _track[l]->regionOffset)) / (_track[l]->iteration / 200); + Track *track = _track[l]; + if ((track->soundId == soundId) && (track->used)) { + int32 pos = (5 * (track->dataOffset + track->regionOffset)) / (track->iteration / 200); return pos; } } @@ -244,7 +245,8 @@ int IMuseDigital::getSoundStatus(int sound) const { Common::StackLock lock(_mutex, "IMuseDigital::getSoundStatus()"); debug(5, "IMuseDigital::getSoundStatus(%d)", sound); for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if ((_track[l]->soundId == sound) && _track[l]->handle.isActive()) { + Track *track = _track[l]; + if ((track->soundId == sound) && track->handle.isActive()) { return 1; } } @@ -256,19 +258,20 @@ void IMuseDigital::stopSound(int soundId) { Common::StackLock lock(_mutex, "IMuseDigital::stopSound()"); debug(5, "IMuseDigital::stopSound(%d)", soundId); for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if ((_track[l]->soundId == soundId) && (_track[l]->used)) { - if (_track[l]->stream) { - _track[l]->stream->finish(); - _track[l]->stream = NULL; - _vm->_mixer->stopHandle(_track[l]->handle); - _sound->closeSound(_track[l]->soundHandle); - _track[l]->soundHandle = NULL; - } else if (_track[l]->stream2) { - _vm->_mixer->stopHandle(_track[l]->handle); - delete _track[l]->stream2; - _track[l]->stream2 = NULL; + Track *track = _track[l]; + if ((track->soundId == soundId) && (track->used)) { + if (track->stream) { + track->stream->finish(); + track->stream = NULL; + _vm->_mixer->stopHandle(track->handle); + _sound->closeSound(track->soundHandle); + track->soundHandle = NULL; + } else if (track->stream2) { + _vm->_mixer->stopHandle(track->handle); + delete track->stream2; + track->stream2 = NULL; } - _track[l]->used = false; + track->used = false; } } } @@ -278,8 +281,9 @@ int32 IMuseDigital::getCurMusicPosInMs() { int soundId = -1; for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if ((_track[l]->used) && (_track[l]->volGroupId == IMUSE_VOLGRP_MUSIC)) { - soundId = _track[l]->soundId; + Track *track = _track[l]; + if ((track->used) && (track->volGroupId == IMUSE_VOLGRP_MUSIC)) { + soundId = track->soundId; } } @@ -313,8 +317,9 @@ int32 IMuseDigital::getCurMusicLipSyncWidth(int syncId) { int soundId = -1; for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if ((_track[l]->used) && (_track[l]->volGroupId == IMUSE_VOLGRP_MUSIC)) { - soundId = _track[l]->soundId; + Track *track = _track[l]; + if ((track->used) && (track->volGroupId == IMUSE_VOLGRP_MUSIC)) { + soundId = track->soundId; } } @@ -331,8 +336,9 @@ int32 IMuseDigital::getCurMusicLipSyncHeight(int syncId) { int soundId = -1; for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if ((_track[l]->used) && (_track[l]->volGroupId == IMUSE_VOLGRP_MUSIC)) { - soundId = _track[l]->soundId; + Track *track = _track[l]; + if ((track->used) && (track->volGroupId == IMUSE_VOLGRP_MUSIC)) { + soundId = track->soundId; } } @@ -349,19 +355,20 @@ void IMuseDigital::stopAllSounds() { debug(5, "IMuseDigital::stopAllSounds"); for (int l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) { - if (_track[l]->used) { - if (_track[l]->stream) { - _track[l]->stream->finish(); - _track[l]->stream = NULL; - _vm->_mixer->stopHandle(_track[l]->handle); - _sound->closeSound(_track[l]->soundHandle); - _track[l]->soundHandle = NULL; - } else if (_track[l]->stream2) { - _vm->_mixer->stopHandle(_track[l]->handle); - delete _track[l]->stream2; - _track[l]->stream2 = NULL; + Track *track = _track[l]; + if (track->used) { + if (track->stream) { + track->stream->finish(); + track->stream = NULL; + _vm->_mixer->stopHandle(track->handle); + _sound->closeSound(track->soundHandle); + track->soundHandle = NULL; + } else if (track->stream2) { + _vm->_mixer->stopHandle(track->handle); + delete track->stream2; + track->stream2 = NULL; } - _track[l]->used = false; + track->used = false; } } } diff --git a/scumm/imuse_digi/dimuse_sndmgr.cpp b/scumm/imuse_digi/dimuse_sndmgr.cpp index e30ee61cd3..05e0a13941 100644 --- a/scumm/imuse_digi/dimuse_sndmgr.cpp +++ b/scumm/imuse_digi/dimuse_sndmgr.cpp @@ -15,7 +15,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header$ */ #include "stdafx.h" @@ -431,8 +430,9 @@ int ImuseDigiSndMgr::getJumpIdByRegionAndHookId(soundStruct *soundHandle, int re debug(5, "getJumpIdByRegionAndHookId() region:%d, hookId:%d", region, hookId); assert(soundHandle && checkForProperHandle(soundHandle)); assert(region >= 0 && region < soundHandle->numRegions); + int32 offset = soundHandle->region[region].offset; for (int l = 0; l < soundHandle->numJumps; l++) { - if (soundHandle->jump[l].offset == soundHandle->region[region].offset) { + if (offset == soundHandle->jump[l].offset) { if (soundHandle->jump[l].hookId == hookId) return l; } @@ -457,8 +457,9 @@ int ImuseDigiSndMgr::getRegionIdByJumpId(soundStruct *soundHandle, int jumpId) { debug(5, "getRegionIdByJumpId() jumpId:%d", jumpId); assert(soundHandle && checkForProperHandle(soundHandle)); assert(jumpId >= 0 && jumpId < soundHandle->numJumps); + int32 dest = soundHandle->jump[jumpId].dest; for (int l = 0; l < soundHandle->numRegions; l++) { - if (soundHandle->jump[jumpId].dest == soundHandle->region[l].offset) { + if (dest == soundHandle->region[l].offset) { return l; } } diff --git a/scumm/imuse_digi/dimuse_track.cpp b/scumm/imuse_digi/dimuse_track.cpp index 3c1359db8d..0ceaa901f9 100644 --- a/scumm/imuse_digi/dimuse_track.cpp +++ b/scumm/imuse_digi/dimuse_track.cpp @@ -15,7 +15,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header$ */ #include "stdafx.h" @@ -45,27 +44,30 @@ bool IMuseDigital::allocSlot(int priority) { if (!found_free) { debug(5, "IMuseDigital::startSound(): All slots are full"); for (l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if (_track[l]->used && _track[l]->handle.isActive() && - (lower_priority > _track[l]->priority) && (!_track[l]->stream2)) - lower_priority = _track[l]->priority; + Track *track = _track[l]; + if (track->used && track->handle.isActive() && + (lower_priority > track->priority) && (!track->stream2)) + lower_priority = track->priority; } if (lower_priority <= priority) { - int track_id = -1; + int trackId = -1; for (l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if (_track[l]->used && _track[l]->handle.isActive() && - (lower_priority == _track[l]->priority) && (!_track[l]->stream2)) { - track_id = l; + Track *track = _track[l]; + if (track->used && track->handle.isActive() && + (lower_priority == track->priority) && (!track->stream2)) { + trackId = l; } } - assert(track_id != -1); - _track[track_id]->stream->finish(); - _track[track_id]->stream = NULL; - _vm->_mixer->stopHandle(_track[track_id]->handle); - _sound->closeSound(_track[track_id]->soundHandle); - _track[track_id]->soundHandle = NULL; - _track[track_id]->used = false; - assert(!_track[track_id]->handle.isActive()); - debug(5, "IMuseDigital::startSound(): Removed sound %d from track %d", _track[track_id]->soundId, track_id); + assert(trackId != -1); + Track *track = _track[trackId]; + track->stream->finish(); + track->stream = NULL; + _vm->_mixer->stopHandle(track->handle); + _sound->closeSound(track->soundHandle); + track->soundHandle = NULL; + track->used = false; + assert(!track->handle.isActive()); + debug(5, "IMuseDigital::startSound(): Removed sound %d from track %d", track->soundId, trackId); } else { debug(5, "IMuseDigital::startSound(): Priority sound too low"); return false; @@ -86,52 +88,53 @@ void IMuseDigital::startSound(int soundId, const char *soundName, int soundType, } for (l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if (!_track[l]->used && !_track[l]->handle.isActive()) { - _track[l]->pan = 64; - _track[l]->vol = volume * 1000; - _track[l]->volFadeDest = 0; - _track[l]->volFadeStep = 0; - _track[l]->volFadeDelay = 0; - _track[l]->volFadeUsed = false; - _track[l]->soundId = soundId; - _track[l]->started = false; - _track[l]->volGroupId = volGroupId; - _track[l]->curHookId = hookId; - _track[l]->priority = priority; - _track[l]->curRegion = -1; - _track[l]->dataOffset = 0; - _track[l]->regionOffset = 0; - _track[l]->mod = 0; - _track[l]->mixerFlags = 0; - _track[l]->mixerPan = 0; - _track[l]->mixerVol = volume; - _track[l]->toBeRemoved = false; - _track[l]->soundType = soundType; + Track *track = _track[l]; + if (!track->used && !track->handle.isActive()) { + track->pan = 64; + track->vol = volume * 1000; + track->volFadeDest = 0; + track->volFadeStep = 0; + track->volFadeDelay = 0; + track->volFadeUsed = false; + track->soundId = soundId; + track->started = false; + track->volGroupId = volGroupId; + track->curHookId = hookId; + track->priority = priority; + track->curRegion = -1; + track->dataOffset = 0; + track->regionOffset = 0; + track->mod = 0; + track->mixerFlags = 0; + track->mixerPan = 0; + track->mixerVol = volume; + track->toBeRemoved = false; + track->soundType = soundType; int bits = 0, freq = 0, channels = 0; if (input) { - _track[l]->iteration = 0; - _track[l]->souStream = true; - _track[l]->soundName[0] = 0; + track->iteration = 0; + track->souStream = true; + track->soundName[0] = 0; } else { - _track[l]->souStream = false; - strcpy(_track[l]->soundName, soundName); - _track[l]->soundHandle = _sound->openSound(soundId, soundName, soundType, volGroupId); + track->souStream = false; + strcpy(track->soundName, soundName); + track->soundHandle = _sound->openSound(soundId, soundName, soundType, volGroupId); - if (_track[l]->soundHandle == NULL) + if (track->soundHandle == NULL) return; - bits = _sound->getBits(_track[l]->soundHandle); - channels = _sound->getChannels(_track[l]->soundHandle); - freq = _sound->getFreq(_track[l]->soundHandle); + bits = _sound->getBits(track->soundHandle); + channels = _sound->getChannels(track->soundHandle); + freq = _sound->getFreq(track->soundHandle); if ((soundId == kTalkSoundID) && (soundType == IMUSE_BUNDLE)) { if (_vm->_actorToPrintStrFor != 0xFF && _vm->_actorToPrintStrFor != 0) { Actor *a = _vm->derefActor(_vm->_actorToPrintStrFor, "IMuseDigital::startSound"); freq = (freq * a->talkFrequency) / 256; - _track[l]->pan = a->talkPan; - _track[l]->vol = a->talkVolume * 1000; + track->pan = a->talkPan; + track->vol = a->talkVolume * 1000; } } @@ -139,33 +142,33 @@ void IMuseDigital::startSound(int soundId, const char *soundName, int soundType, assert(channels == 1 || channels == 2); assert(0 < freq && freq <= 65535); - _track[l]->iteration = freq * channels; + track->iteration = freq * channels; if (channels == 2) - _track[l]->mixerFlags = SoundMixer::FLAG_STEREO | SoundMixer::FLAG_REVERSE_STEREO; + track->mixerFlags = SoundMixer::FLAG_STEREO | SoundMixer::FLAG_REVERSE_STEREO; if ((bits == 12) || (bits == 16)) { - _track[l]->mixerFlags |= SoundMixer::FLAG_16BITS; - _track[l]->iteration *= 2; + track->mixerFlags |= SoundMixer::FLAG_16BITS; + track->iteration *= 2; } else if (bits == 8) { - _track[l]->mixerFlags |= SoundMixer::FLAG_UNSIGNED; + track->mixerFlags |= SoundMixer::FLAG_UNSIGNED; } else error("IMuseDigital::startSound(): Can't handle %d bit samples", bits); } if (input) { - _track[l]->stream2 = input; - _track[l]->stream = NULL; - _track[l]->started = false; + track->stream2 = input; + track->stream = NULL; + track->started = false; } else { // setup 1 second stream wrapped buffer - int32 streamBufferSize = _track[l]->iteration; - _track[l]->stream2 = NULL; - _track[l]->stream = makeAppendableAudioStream(freq, _track[l]->mixerFlags, streamBufferSize); - _vm->_mixer->playInputStream(&_track[l]->handle, _track[l]->stream, false, _track[l]->vol / 1000, _track[l]->pan, -1); - _track[l]->started = true; + int32 streamBufferSize = track->iteration; + track->stream2 = NULL; + track->stream = makeAppendableAudioStream(freq, track->mixerFlags, streamBufferSize); + _vm->_mixer->playInputStream(&track->handle, track->stream, false, track->vol / 1000, track->pan, -1); + track->started = true; } - _track[l]->used = true; + track->used = true; return; } } @@ -180,8 +183,9 @@ void IMuseDigital::setPriority(int soundId, int priority) { assert ((priority >= 0) && (priority <= 127)); for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if ((_track[l]->soundId == soundId) && _track[l]->used) { - _track[l]->priority = priority; + Track *track = _track[l]; + if ((track->soundId == soundId) && track->used) { + track->priority = priority; } } } @@ -190,8 +194,9 @@ void IMuseDigital::setVolume(int soundId, int volume) { Common::StackLock lock(_mutex, "IMuseDigital::setVolume()"); debug(5, "IMuseDigital::setVolume(%d, %d)", soundId, volume); for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if ((_track[l]->soundId == soundId) && _track[l]->used) { - _track[l]->vol = volume * 1000; + Track *track = _track[l]; + if ((track->soundId == soundId) && track->used) { + track->vol = volume * 1000; } } } @@ -200,8 +205,9 @@ void IMuseDigital::setPan(int soundId, int pan) { Common::StackLock lock(_mutex, "IMuseDigital::setPan()"); debug(5, "IMuseDigital::setPan(%d, %d)", soundId, pan); for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if ((_track[l]->soundId == soundId) && _track[l]->used) { - _track[l]->pan = pan; + Track *track = _track[l]; + if ((track->soundId == soundId) && track->used) { + track->pan = pan; } } } @@ -215,8 +221,9 @@ void IMuseDigital::selectVolumeGroup(int soundId, int volGroupId) { volGroupId = 3; for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if ((_track[l]->soundId == soundId) && _track[l]->used) { - _track[l]->volGroupId = volGroupId; + Track *track = _track[l]; + if ((track->soundId == soundId) && track->used) { + track->volGroupId = volGroupId; } } } @@ -225,11 +232,12 @@ void IMuseDigital::setFade(int soundId, int destVolume, int delay60HzTicks) { Common::StackLock lock(_mutex, "IMuseDigital::setFade()"); debug(5, "IMuseDigital::setFade(%d, %d, %d)", soundId, destVolume, delay60HzTicks); for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if ((_track[l]->soundId == soundId) && _track[l]->used) { - _track[l]->volFadeDelay = delay60HzTicks; - _track[l]->volFadeDest = destVolume * 1000; - _track[l]->volFadeStep = (_track[l]->volFadeDest - _track[l]->vol) * 60 * 40 / (1000 * delay60HzTicks); - _track[l]->volFadeUsed = true; + Track *track = _track[l]; + if ((track->soundId == soundId) && track->used) { + track->volFadeDelay = delay60HzTicks; + track->volFadeDest = destVolume * 1000; + track->volFadeStep = (track->volFadeDest - track->vol) * 60 * 40 / (1000 * delay60HzTicks); + track->volFadeUsed = true; } } } @@ -238,78 +246,81 @@ void IMuseDigital::fadeOutMusic(int fadeDelay) { Common::StackLock lock(_mutex, "IMuseDigital::fadeOutMusic()"); debug(5, "IMuseDigital::fadeOutMusic"); for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { - if ((_track[l]->used) && (_track[l]->volGroupId == IMUSE_VOLGRP_MUSIC)) { + Track *track = _track[l]; + if ((track->used) && (track->volGroupId == IMUSE_VOLGRP_MUSIC)) { cloneToFadeOutTrack(l, fadeDelay, true); } } } -int IMuseDigital::cloneToFadeOutTrack(int track, int fadeDelay, int killNormalTrack) { +int IMuseDigital::cloneToFadeOutTrack(int trackId, int fadeDelay, int killNormalTrack) { Common::StackLock lock(_mutex, "IMuseDigital::cloneToFadeOutTrack()"); - debug(5, "IMuseDigital::cloneToFadeOutTrack(%d, %d)", track, fadeDelay); - int fadeTrack = -1; + debug(5, "IMuseDigital::cloneToFadeOutTrack(%d, %d)", trackId, fadeDelay); + int fadeTrackId = -1; for (int l = MAX_DIGITAL_TRACKS; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) { if (!_track[l]->used) { - fadeTrack = l; + fadeTrackId = l; break; } } - if (fadeTrack == -1) - error("IMuseDigital::cloneToFadeTrack() Can't find free fade track"); + if (fadeTrackId == -1) + error("IMuseDigital::cloneTofadeTrackId() Can't find free fade track"); // swap track to fade track - Track *tmpTrack = _track[track]; - _track[track] = _track[fadeTrack]; - _track[fadeTrack] = tmpTrack; + Track *tmpTrack = _track[trackId]; + _track[trackId] = _track[fadeTrackId]; + _track[fadeTrackId] = tmpTrack; // copy track params from swaped fade track to new track - _track[track]->pan = _track[fadeTrack]->pan; - _track[track]->vol = _track[fadeTrack]->vol; - _track[track]->volGroupId = _track[fadeTrack]->volGroupId; - _track[track]->volFadeDelay = _track[fadeTrack]->volFadeDelay; - _track[track]->volFadeDest = _track[fadeTrack]->volFadeDest; - _track[track]->volFadeStep = _track[fadeTrack]->volFadeStep; - _track[track]->volFadeUsed = _track[fadeTrack]->volFadeUsed; - _track[track]->priority = _track[fadeTrack]->priority; - _track[track]->soundId = _track[fadeTrack]->soundId; - _track[track]->dataOffset = _track[fadeTrack]->dataOffset; - _track[track]->regionOffset = _track[fadeTrack]->regionOffset; - _track[track]->curRegion = _track[fadeTrack]->curRegion; - _track[track]->curHookId = _track[fadeTrack]->curHookId; - _track[track]->iteration = _track[fadeTrack]->iteration; - _track[track]->mixerFlags = _track[fadeTrack]->mixerFlags; - _track[track]->mixerVol = _track[fadeTrack]->mixerVol; - _track[track]->mixerPan = _track[fadeTrack]->mixerPan; - _track[track]->mod = _track[fadeTrack]->mod; - _track[track]->used = _track[fadeTrack]->used; - _track[track]->toBeRemoved = _track[fadeTrack]->toBeRemoved; - _track[track]->souStream = _track[fadeTrack]->souStream; - _track[track]->started = _track[fadeTrack]->started; - _track[track]->stream2 = _track[fadeTrack]->stream2; - strcpy(_track[track]->soundName, _track[fadeTrack]->soundName); - _track[track]->soundType = _track[fadeTrack]->soundType; - - _track[track]->soundHandle = NULL; - _track[track]->stream = NULL; - - _track[fadeTrack]->volFadeDelay = fadeDelay; - _track[fadeTrack]->volFadeDest = 0; - _track[fadeTrack]->volFadeStep = (_track[fadeTrack]->volFadeDest - _track[fadeTrack]->vol) * 60 * 40 / (1000 * fadeDelay); - _track[fadeTrack]->volFadeUsed = true; + Track *track = _track[trackId]; + Track *fadeTrack = _track[fadeTrackId]; + track->pan = fadeTrack->pan; + track->vol = fadeTrack->vol; + track->volGroupId = fadeTrack->volGroupId; + track->volFadeDelay = fadeTrack->volFadeDelay; + track->volFadeDest = fadeTrack->volFadeDest; + track->volFadeStep = fadeTrack->volFadeStep; + track->volFadeUsed = fadeTrack->volFadeUsed; + track->priority = fadeTrack->priority; + track->soundId = fadeTrack->soundId; + track->dataOffset = fadeTrack->dataOffset; + track->regionOffset = fadeTrack->regionOffset; + track->curRegion = fadeTrack->curRegion; + track->curHookId = fadeTrack->curHookId; + track->iteration = fadeTrack->iteration; + track->mixerFlags = fadeTrack->mixerFlags; + track->mixerVol = fadeTrack->mixerVol; + track->mixerPan = fadeTrack->mixerPan; + track->mod = fadeTrack->mod; + track->used = fadeTrack->used; + track->toBeRemoved = fadeTrack->toBeRemoved; + track->souStream = fadeTrack->souStream; + track->started = fadeTrack->started; + track->stream2 = fadeTrack->stream2; + strcpy(track->soundName, fadeTrack->soundName); + track->soundType = fadeTrack->soundType; + + track->soundHandle = NULL; + track->stream = NULL; + + fadeTrack->volFadeDelay = fadeDelay; + fadeTrack->volFadeDest = 0; + fadeTrack->volFadeStep = (fadeTrack->volFadeDest - fadeTrack->vol) * 60 * 40 / (1000 * fadeDelay); + fadeTrack->volFadeUsed = true; if (killNormalTrack) { - _track[track]->used = false; + track->used = false; } else { - _track[track]->soundHandle = _sound->cloneSound(_track[fadeTrack]->soundHandle); + track->soundHandle = _sound->cloneSound(fadeTrack->soundHandle); // setup 1 second stream wrapped buffer - int32 streamBufferSize = _track[track]->iteration; - _track[track]->stream = makeAppendableAudioStream(_sound->getFreq(_track[track]->soundHandle), _track[track]->mixerFlags, streamBufferSize); - _vm->_mixer->playInputStream(&_track[track]->handle, _track[track]->stream, false, _track[track]->vol / 1000, _track[track]->pan, -1); - _track[track]->started = true; + int32 streamBufferSize = track->iteration; + track->stream = makeAppendableAudioStream(_sound->getFreq(track->soundHandle), track->mixerFlags, streamBufferSize); + _vm->_mixer->playInputStream(&track->handle, track->stream, false, track->vol / 1000, track->pan, -1); + track->started = true; } - return fadeTrack; + return fadeTrackId; } } // End of namespace Scumm |