diff options
author | Paul Gilbert | 2017-08-18 20:45:10 -0400 |
---|---|---|
committer | Paul Gilbert | 2017-08-18 20:45:10 -0400 |
commit | dfd8c001a47dcc0c5f0c4f3770b19bfabcbd657e (patch) | |
tree | 325ca12a09fefd03399b5f0acfa8f7325aa1c8a7 /engines | |
parent | 5eff8ab961ae3f09b8f612939b55d9c90441966c (diff) | |
download | scummvm-rg350-dfd8c001a47dcc0c5f0c4f3770b19bfabcbd657e.tar.gz scummvm-rg350-dfd8c001a47dcc0c5f0c4f3770b19bfabcbd657e.tar.bz2 scummvm-rg350-dfd8c001a47dcc0c5f0c4f3770b19bfabcbd657e.zip |
TITANIC: Simplify sound looping by using LoopingAudioStream
Diffstat (limited to 'engines')
-rw-r--r-- | engines/titanic/sound/qmixer.cpp | 22 | ||||
-rw-r--r-- | engines/titanic/sound/wave_file.cpp | 9 | ||||
-rw-r--r-- | engines/titanic/sound/wave_file.h | 6 |
3 files changed, 21 insertions, 16 deletions
diff --git a/engines/titanic/sound/qmixer.cpp b/engines/titanic/sound/qmixer.cpp index 5c511c3cae..beb1502ab4 100644 --- a/engines/titanic/sound/qmixer.cpp +++ b/engines/titanic/sound/qmixer.cpp @@ -208,18 +208,13 @@ void QMixer::qsWaveMixPump() { if (!channel._sounds.empty()) { SoundEntry &sound = channel._sounds.front(); if (sound._started && !_mixer->isSoundHandleActive(sound._soundHandle)) { - if (sound._loops == -1 || sound._loops-- > 0) { - // Need to loop (replay) the sound again - sound._soundHandle = sound._waveFile->play(channel.getRawVolume()); - } else { - // Sound is finished - if (sound._callback) - // Call the callback to signal end - sound._callback(iChannel, sound._waveFile, sound._userData); - - // Remove sound record from channel - channel._sounds.erase(channel._sounds.begin()); - } + // Sound is finished + if (sound._callback) + // Call the callback to signal end + sound._callback(iChannel, sound._waveFile, sound._userData); + + // Remove sound record from channel + channel._sounds.erase(channel._sounds.begin()); } } @@ -232,7 +227,8 @@ void QMixer::qsWaveMixPump() { channel._distance = 0.0; // Play the wave - sound._soundHandle = sound._waveFile->play(channel.getRawVolume()); + sound._soundHandle = sound._waveFile->play( + sound._loops, channel.getRawVolume()); sound._started = true; } } diff --git a/engines/titanic/sound/wave_file.cpp b/engines/titanic/sound/wave_file.cpp index 8a4755ac97..c1aab42a7f 100644 --- a/engines/titanic/sound/wave_file.cpp +++ b/engines/titanic/sound/wave_file.cpp @@ -204,10 +204,15 @@ void CWaveFile::unlock(const int16 *ptr) { // No implementation needed in ScummVM } -Audio::SoundHandle CWaveFile::play(byte volume) { - Audio::SeekableAudioStream *stream = createAudioStream(); +Audio::SoundHandle CWaveFile::play(int numLoops, byte volume) { + Audio::SeekableAudioStream *audioStream = createAudioStream(); Audio::SoundHandle handle; + Audio::AudioStream *stream = audioStream; + if (numLoops != 0) + stream = new Audio::LoopingAudioStream(audioStream, + (numLoops == -1) ? 0 : numLoops); + _mixer->playStream(_soundType, &handle, stream, -1, volume, 0, DisposeAfterUse::NO); return handle; diff --git a/engines/titanic/sound/wave_file.h b/engines/titanic/sound/wave_file.h index 17c7b62f4b..c14891e2e4 100644 --- a/engines/titanic/sound/wave_file.h +++ b/engines/titanic/sound/wave_file.h @@ -126,8 +126,12 @@ public: /** * Plays the wave file + * @param numLoops Number of times to loop. 0 for none, + * -1 for infinite, and >0 for specified number of times + * @param volume Volume to play at + * @returns Audio handle for started sound */ - Audio::SoundHandle play(byte volume); + Audio::SoundHandle play(int numLoops, byte volume); }; } // End of namespace Titanic |