diff options
author | Max Horn | 2004-11-24 09:47:32 +0000 |
---|---|---|
committer | Max Horn | 2004-11-24 09:47:32 +0000 |
commit | 666d7d106d35ebae690ca99d34fc42b851125d14 (patch) | |
tree | 9cf9f96cdc2e8f40ad6ee7806f9864529ab3be1b /scumm | |
parent | 31e434dcf1e46510606efa3025c24c17ace379c6 (diff) | |
download | scummvm-rg350-666d7d106d35ebae690ca99d34fc42b851125d14.tar.gz scummvm-rg350-666d7d106d35ebae690ca99d34fc42b851125d14.tar.bz2 scummvm-rg350-666d7d106d35ebae690ca99d34fc42b851125d14.zip |
Some code transformations (no functional change)
svn-id: r15874
Diffstat (limited to 'scumm')
-rw-r--r-- | scumm/imuse_digi/dimuse.cpp | 23 | ||||
-rw-r--r-- | scumm/imuse_digi/dimuse.h | 8 | ||||
-rw-r--r-- | scumm/imuse_digi/dimuse_script.cpp | 3 | ||||
-rw-r--r-- | scumm/imuse_digi/dimuse_track.cpp | 220 |
4 files changed, 122 insertions, 132 deletions
diff --git a/scumm/imuse_digi/dimuse.cpp b/scumm/imuse_digi/dimuse.cpp index 4cdb08f1a7..9d482dac62 100644 --- a/scumm/imuse_digi/dimuse.cpp +++ b/scumm/imuse_digi/dimuse.cpp @@ -53,6 +53,7 @@ IMuseDigital::IMuseDigital(ScummEngine *scumm, int fps) resetState(); for (int l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) { _track[l] = new Track; + _track[l]->trackId = l; _track[l]->used = false; } _vm->_timer->installTimerProc(timer_handler, 1000000 / _callbackFps, this); @@ -209,7 +210,7 @@ void IMuseDigital::callback() { int32 result = 0; if (track->curRegion == -1) { - switchToNextRegion(l); + switchToNextRegion(track); if (track->toBeRemoved) continue; } @@ -277,7 +278,7 @@ void IMuseDigital::callback() { } if (_sound->isEndOfRegion(track->soundHandle, track->curRegion)) { - switchToNextRegion(l); + switchToNextRegion(track); if (track->toBeRemoved) break; } @@ -299,13 +300,13 @@ void IMuseDigital::callback() { } } -void IMuseDigital::switchToNextRegion(int trackId) { - debug(5, "switchToNextRegion(track:%d)", trackId); +void IMuseDigital::switchToNextRegion(Track *track) { + assert(track); + debug(5, "switchToNextRegion(track:%d)", track->trackId); - Track *track = _track[trackId]; - if (trackId >= MAX_DIGITAL_TRACKS) { + if (track->trackId >= MAX_DIGITAL_TRACKS) { track->toBeRemoved = true; - debug(5, "exit (fadetrack can't go next region) switchToNextRegion(trackId:%d)", trackId); + debug(5, "exit (fadetrack can't go next region) switchToNextRegion(trackId:%d)", track->trackId); return; } @@ -313,7 +314,7 @@ void IMuseDigital::switchToNextRegion(int trackId) { if (++track->curRegion == num_regions) { track->toBeRemoved = true; - debug(5, "exit (end of regions) switchToNextRegion(track:%d)", trackId); + debug(5, "exit (end of regions) switchToNextRegion(track:%d)", track->trackId); return; } @@ -330,8 +331,7 @@ void IMuseDigital::switchToNextRegion(int trackId) { if (sampleHookId != 0) { if (track->curHookId == sampleHookId) { if (fadeDelay != 0) { - int fadeTrackId = cloneToFadeOutTrack(trackId, fadeDelay); - Track *fadeTrack = _track[fadeTrackId]; + Track *fadeTrack = cloneToFadeOutTrack(track, fadeDelay); 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); @@ -343,8 +343,7 @@ void IMuseDigital::switchToNextRegion(int trackId) { } } else { if (fadeDelay != 0) { - int fadeTrackId = cloneToFadeOutTrack(trackId, fadeDelay); - Track *fadeTrack = _track[fadeTrackId]; + Track *fadeTrack = cloneToFadeOutTrack(track, fadeDelay); 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); diff --git a/scumm/imuse_digi/dimuse.h b/scumm/imuse_digi/dimuse.h index 6381b0ecf9..d145e28376 100644 --- a/scumm/imuse_digi/dimuse.h +++ b/scumm/imuse_digi/dimuse.h @@ -46,6 +46,8 @@ private: int _callbackFps; struct Track { + int trackId; + int8 pan; // pan int32 vol; // volume int32 volFadeDest; // @@ -101,7 +103,7 @@ private: static void timer_handler(void *refConf); void callback(); - void switchToNextRegion(int trackId); + void switchToNextRegion(Track *track); int 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); @@ -111,7 +113,7 @@ private: int getSoundIdByName(const char *soundName); void fadeOutMusic(int fadeDelay); - int cloneToFadeOutTrack(int trackId, int fadeDelay); + Track *cloneToFadeOutTrack(Track *track, int fadeDelay); void setFtMusicState(int stateId); void setFtMusicSequence(int seqId); @@ -156,7 +158,7 @@ public: void stopSound(int sound); void stopAllSounds(); void pause(bool pause); - void parseScriptCmds(int a, int b, int c, int d, int e, int f, int g, int h); + void parseScriptCmds(int cmd, int soundId, int sub_cmd, int d, int e, int f, int g, int h); void refreshScripts(); void flushTracks(); int getSoundStatus(int sound) const; diff --git a/scumm/imuse_digi/dimuse_script.cpp b/scumm/imuse_digi/dimuse_script.cpp index 22a44ea8de..5c52d9ec5e 100644 --- a/scumm/imuse_digi/dimuse_script.cpp +++ b/scumm/imuse_digi/dimuse_script.cpp @@ -32,8 +32,7 @@ namespace Scumm { -void IMuseDigital::parseScriptCmds(int a, int b, int c, int d, int e, int f, int g, int h) { - int cmd = a; +void IMuseDigital::parseScriptCmds(int cmd, int b, int c, int d, int e, int f, int g, int h) { int soundId = b; int sub_cmd = c; diff --git a/scumm/imuse_digi/dimuse_track.cpp b/scumm/imuse_digi/dimuse_track.cpp index 8afb3f6886..2a20a166e9 100644 --- a/scumm/imuse_digi/dimuse_track.cpp +++ b/scumm/imuse_digi/dimuse_track.cpp @@ -33,7 +33,7 @@ namespace Scumm { int IMuseDigital::allocSlot(int priority) { - int l, lower_priority = 127; + int l, lowest_priority = 127; int trackId = -1; for (l = 0; l < MAX_DIGITAL_TRACKS; l++) { @@ -48,17 +48,12 @@ int IMuseDigital::allocSlot(int priority) { for (l = 0; l < MAX_DIGITAL_TRACKS; l++) { Track *track = _track[l]; if (track->used && !track->toBeRemoved && - (lower_priority > track->priority) && !track->stream2) - lower_priority = track->priority; - } - if (lower_priority <= priority) { - for (l = 0; l < MAX_DIGITAL_TRACKS; l++) { - Track *track = _track[l]; - if (track->used && !track->toBeRemoved && - (lower_priority == track->priority) && !track->stream2) { - trackId = l; - } + (lowest_priority > track->priority) && !track->stream2) { + lowest_priority = track->priority; + trackId = l; } + } + if (lowest_priority <= priority) { assert(trackId != -1); _track[trackId]->toBeRemoved = true; debug(5, "IMuseDigital::startSound(): Removed sound %d from track %d", _track[trackId]->soundId, trackId); @@ -81,108 +76,106 @@ void IMuseDigital::startSound(int soundId, const char *soundName, int soundType, } Track *track = _track[l]; - for (;;) { + while (track->used) { #if defined(_WIN32_WCE) || defined (__PALM_OS__) _vm->parseEvents(); // timers are events, we need to consume them #endif flushTracks(); - if (!track->used) { - 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->readyToRemove = false; - track->soundType = soundType; - - int bits = 0, freq = 0, channels = 0; - - if (input) { - track->iteration = 0; - track->souStream = true; - track->soundName[0] = 0; - } else { - track->souStream = false; - strcpy(track->soundName, soundName); - track->soundHandle = _sound->openSound(soundId, soundName, soundType, volGroupId, -1); - - if (track->soundHandle == NULL) - return; - - 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->pan = a->talkPan; - track->vol = a->talkVolume * 1000; - } - } - - assert(bits == 8 || bits == 12 || bits == 16); - assert(channels == 1 || channels == 2); - assert(0 < freq && freq <= 65535); - - track->iteration = freq * channels; - if (channels == 2) - track->mixerFlags = SoundMixer::FLAG_STEREO | SoundMixer::FLAG_REVERSE_STEREO; - - if ((bits == 12) || (bits == 16)) { - track->mixerFlags |= SoundMixer::FLAG_16BITS; - track->iteration *= 2; - } else if (bits == 8) { - track->mixerFlags |= SoundMixer::FLAG_UNSIGNED; - } else - error("IMuseDigital::startSound(): Can't handle %d bit samples", bits); - } - - if (input) { - track->stream2 = input; - track->stream = NULL; - track->started = false; - } else { - int pan = (track->pan != 64) ? 2 * track->pan - 127 : 0; - int vol = track->vol / 1000; - - if (track->volGroupId == 1) - vol = (vol * _volVoice) / 128; - if (track->volGroupId == 2) - vol = (vol * _volSfx) / 128; - if (track->volGroupId == 3) - vol = (vol * _volMusic) / 128; - - track->mixerPan = pan; - track->mixerVol = vol; - - // setup 1 second stream wrapped buffer - int32 streamBufferSize = track->iteration; - track->stream2 = NULL; - track->stream = makeAppendableAudioStream(freq, track->mixerFlags, streamBufferSize); - _vm->_mixer->playInputStream(&track->handle, track->stream, false, track->mixerVol, track->mixerPan, -1, false); - track->started = true; - } + } - track->used = true; + 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->readyToRemove = false; + track->soundType = soundType; + + int bits = 0, freq = 0, channels = 0; + + if (input) { + track->iteration = 0; + track->souStream = true; + track->soundName[0] = 0; + } else { + track->souStream = false; + strcpy(track->soundName, soundName); + track->soundHandle = _sound->openSound(soundId, soundName, soundType, volGroupId, -1); + + if (track->soundHandle == NULL) return; + + 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->pan = a->talkPan; + track->vol = a->talkVolume * 1000; + } } + + assert(bits == 8 || bits == 12 || bits == 16); + assert(channels == 1 || channels == 2); + assert(0 < freq && freq <= 65535); + + track->iteration = freq * channels; + if (channels == 2) + track->mixerFlags = SoundMixer::FLAG_STEREO | SoundMixer::FLAG_REVERSE_STEREO; + + if ((bits == 12) || (bits == 16)) { + track->mixerFlags |= SoundMixer::FLAG_16BITS; + track->iteration *= 2; + } else if (bits == 8) { + track->mixerFlags |= SoundMixer::FLAG_UNSIGNED; + } else + error("IMuseDigital::startSound(): Can't handle %d bit samples", bits); + } + + if (input) { + track->stream2 = input; + track->stream = NULL; + track->started = false; + } else { + int pan = (track->pan != 64) ? 2 * track->pan - 127 : 0; + int vol = track->vol / 1000; + + if (track->volGroupId == 1) + vol = (vol * _volVoice) / 128; + if (track->volGroupId == 2) + vol = (vol * _volSfx) / 128; + if (track->volGroupId == 3) + vol = (vol * _volMusic) / 128; + + track->mixerPan = pan; + track->mixerVol = vol; + + // setup 1 second stream wrapped buffer + int32 streamBufferSize = track->iteration; + track->stream2 = NULL; + track->stream = makeAppendableAudioStream(freq, track->mixerFlags, streamBufferSize); + _vm->_mixer->playInputStream(&track->handle, track->stream, false, track->mixerVol, track->mixerPan, -1, false); + track->started = true; } + + track->used = true; } void IMuseDigital::setPriority(int soundId, int priority) { @@ -254,32 +247,29 @@ void IMuseDigital::fadeOutMusic(int fadeDelay) { for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { Track *track = _track[l]; if (track->used && !track->toBeRemoved && (track->volGroupId == IMUSE_VOLGRP_MUSIC)) { - cloneToFadeOutTrack(l, fadeDelay); + cloneToFadeOutTrack(track, fadeDelay); track->toBeRemoved = true; } } } -int IMuseDigital::cloneToFadeOutTrack(int trackId, int fadeDelay) { - int fadeTrackId = -1; - Track *track; +IMuseDigital::Track *IMuseDigital::cloneToFadeOutTrack(Track *track, int fadeDelay) { + assert(track); Track *fadeTrack; - debug(5, "IMuseDigital::cloneToFadeOutTrack(%d, %d)", trackId, fadeDelay); + debug(5, "IMuseDigital::cloneToFadeOutTrack(%d, %d)", track->trackId, fadeDelay); { Common::StackLock lock(_mutex, "IMuseDigital::cloneToFadeOutTrack()"); for (int l = MAX_DIGITAL_TRACKS; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) { if (!_track[l]->used) { - fadeTrackId = l; + fadeTrack = _track[l]; break; } } - if (fadeTrackId == -1) + if (fadeTrack == 0) error("IMuseDigital::cloneTofadeTrackId() Can't find free fade track"); - track = _track[trackId]; - fadeTrack = _track[fadeTrackId]; fadeTrack->pan = track->pan; fadeTrack->vol = track->vol; fadeTrack->volGroupId = track->volGroupId; @@ -317,7 +307,7 @@ int IMuseDigital::cloneToFadeOutTrack(int trackId, int fadeDelay) { fadeTrack->started = true; fadeTrack->used = true; - return fadeTrackId; + return fadeTrack; } } // End of namespace Scumm |