[Scummvm-git-logs] scummvm master -> dfd8c001a47dcc0c5f0c4f3770b19bfabcbd657e

dreammaster dreammaster at scummvm.org
Sat Aug 19 02:45:14 CEST 2017


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
dfd8c001a4 TITANIC: Simplify sound looping by using LoopingAudioStream


Commit: dfd8c001a47dcc0c5f0c4f3770b19bfabcbd657e
    https://github.com/scummvm/scummvm/commit/dfd8c001a47dcc0c5f0c4f3770b19bfabcbd657e
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-08-18T20:45:10-04:00

Commit Message:
TITANIC: Simplify sound looping by using LoopingAudioStream

Changed paths:
    engines/titanic/sound/qmixer.cpp
    engines/titanic/sound/wave_file.cpp
    engines/titanic/sound/wave_file.h


diff --git a/engines/titanic/sound/qmixer.cpp b/engines/titanic/sound/qmixer.cpp
index 5c511c3..beb1502 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 8a4755a..c1aab42 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 17c7b62..c14891e 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





More information about the Scummvm-git-logs mailing list