From dfd8c001a47dcc0c5f0c4f3770b19bfabcbd657e Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 18 Aug 2017 20:45:10 -0400 Subject: TITANIC: Simplify sound looping by using LoopingAudioStream --- engines/titanic/sound/qmixer.cpp | 22 +++++++++------------- engines/titanic/sound/wave_file.cpp | 9 +++++++-- engines/titanic/sound/wave_file.h | 6 +++++- 3 files changed, 21 insertions(+), 16 deletions(-) (limited to 'engines/titanic') 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 -- cgit v1.2.3