[Scummvm-cvs-logs] SF.net SVN: scummvm:[47128] scummvm/trunk

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Thu Jan 7 17:18:03 CET 2010


Revision: 47128
          http://scummvm.svn.sourceforge.net/scummvm/?rev=47128&view=rev
Author:   lordhoto
Date:     2010-01-07 16:18:03 +0000 (Thu, 07 Jan 2010)

Log Message:
-----------
Create a wrapper makeLoopingAudioStream to reduce code duplcation.

Modified Paths:
--------------
    scummvm/trunk/engines/mohawk/sound.cpp
    scummvm/trunk/sound/audiostream.cpp
    scummvm/trunk/sound/audiostream.h
    scummvm/trunk/sound/flac.cpp
    scummvm/trunk/sound/mp3.cpp
    scummvm/trunk/sound/vorbis.cpp
    scummvm/trunk/sound/wave.cpp

Modified: scummvm/trunk/engines/mohawk/sound.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/sound.cpp	2010-01-07 16:08:41 UTC (rev 47127)
+++ scummvm/trunk/engines/mohawk/sound.cpp	2010-01-07 16:18:03 UTC (rev 47128)
@@ -444,12 +444,7 @@
 		Common::MemoryReadStream *dataStream = new Common::MemoryReadStream(data_chunk.audio_data, data_chunk.size, Common::DisposeAfterUse::YES);
 		uint32 blockAlign = data_chunk.channels * data_chunk.bitsPerSample / 8;
 
-		Audio::RewindableAudioStream *audio = Audio::makeADPCMStream(dataStream, true, data_chunk.size, Audio::kADPCMIma, data_chunk.sample_rate, data_chunk.channels, blockAlign);
-
-		if (loop)
-			return new Audio::LoopingAudioStream(audio, 0);
-		else
-			return audio;
+		return makeLoopingAudioStream(Audio::makeADPCMStream(dataStream, true, data_chunk.size, Audio::kADPCMIma, data_chunk.sample_rate, data_chunk.channels, blockAlign), loop ? 0 : 1);
 	} else if (data_chunk.encoding == kCodecMPEG2) {
 #ifdef USE_MAD
 		Common::MemoryReadStream *dataStream = new Common::MemoryReadStream(data_chunk.audio_data, data_chunk.size, Common::DisposeAfterUse::YES);

Modified: scummvm/trunk/sound/audiostream.cpp
===================================================================
--- scummvm/trunk/sound/audiostream.cpp	2010-01-07 16:08:41 UTC (rev 47127)
+++ scummvm/trunk/sound/audiostream.cpp	2010-01-07 16:18:03 UTC (rev 47128)
@@ -137,6 +137,13 @@
 	return (_loops != 0 && (_completeIterations == _loops));
 }
 
+AudioStream *makeLoopingAudioStream(RewindableAudioStream *stream, uint loops) {
+	if (loops != 1)
+		return new LoopingAudioStream(stream, loops);
+	else
+		return stream;
+}
+
 #pragma mark -
 #pragma mark --- SubSeekableAudioStream ---
 #pragma mark -

Modified: scummvm/trunk/sound/audiostream.h
===================================================================
--- scummvm/trunk/sound/audiostream.h	2010-01-07 16:08:41 UTC (rev 47127)
+++ scummvm/trunk/sound/audiostream.h	2010-01-07 16:18:03 UTC (rev 47128)
@@ -125,6 +125,8 @@
 	/**
 	 * Creates a looping audio stream object.
 	 *
+	 * @see makeLoopingAudioStream
+	 *
 	 * @param stream Stream to loop
 	 * @param loops How often to loop (0 = infinite)
 	 * @param disposeAfteruse Destroy the stream after the LoopingAudioStream has finished playback.
@@ -152,6 +154,20 @@
 };
 
 /**
+ * Wrapper functionallity to efficiently create a stream, which might be looped.
+ *
+ * Note that this function does not return a LoopingAudioStream, because it does
+ * not create one, when the loop count is "1". This allows to keep the runtime
+ * overhead down, when the code does not require any functionallity only offered
+ * by LoopingAudioStream.
+ *
+ * @param stream Stream to loop (will be automatically destroyed, when the looping is done)
+ * @param loops How often to loop (0 = infinite)
+ * @return A new AudioStream, which offers the desired functionallity.
+ */
+AudioStream *makeLoopingAudioStream(RewindableAudioStream *stream, uint loops);
+
+/**
  * A seekable audio stream. Subclasses of this class implement an
  * interface for seeking. The seeking itself is not required to be
  * working while the stream is being played by Mixer!

Modified: scummvm/trunk/sound/flac.cpp
===================================================================
--- scummvm/trunk/sound/flac.cpp	2010-01-07 16:08:41 UTC (rev 47127)
+++ scummvm/trunk/sound/flac.cpp	2010-01-07 16:18:03 UTC (rev 47128)
@@ -745,10 +745,7 @@
 		assert(input);
 	}
 
-	if (numLoops)
-		return new LoopingAudioStream(input, numLoops);
-	else
-		return input;
+	return makeLoopingAudioStream(input, numLoops);
 }
 
 SeekableAudioStream *makeFlacStream(

Modified: scummvm/trunk/sound/mp3.cpp
===================================================================
--- scummvm/trunk/sound/mp3.cpp	2010-01-07 16:08:41 UTC (rev 47127)
+++ scummvm/trunk/sound/mp3.cpp	2010-01-07 16:18:03 UTC (rev 47128)
@@ -358,10 +358,7 @@
 		assert(mp3);
 	}
 
-	if (numLoops)
-		return new LoopingAudioStream(mp3, numLoops);
-	else
-		return mp3;
+	return makeLoopingAudioStream(mp3, numLoops);
 }
 
 SeekableAudioStream *makeMP3Stream(

Modified: scummvm/trunk/sound/vorbis.cpp
===================================================================
--- scummvm/trunk/sound/vorbis.cpp	2010-01-07 16:08:41 UTC (rev 47127)
+++ scummvm/trunk/sound/vorbis.cpp	2010-01-07 16:18:03 UTC (rev 47128)
@@ -260,10 +260,7 @@
 		assert(input);
 	}
 
-	if (numLoops)
-		return new LoopingAudioStream(input, numLoops);
-	else
-		return input;
+	return makeLoopingAudioStream(input, numLoops);
 }
 
 SeekableAudioStream *makeVorbisStream(

Modified: scummvm/trunk/sound/wave.cpp
===================================================================
--- scummvm/trunk/sound/wave.cpp	2010-01-07 16:08:41 UTC (rev 47127)
+++ scummvm/trunk/sound/wave.cpp	2010-01-07 16:18:03 UTC (rev 47128)
@@ -173,21 +173,10 @@
 		return 0;
 	}
 
-	if (type == 17) { // MS IMA ADPCM
-		RewindableAudioStream *adpcm = makeADPCMStream(stream, disposeAfterUse, size, Audio::kADPCMMSIma, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
-
-		if (loop)
-			return new LoopingAudioStream(adpcm, 0);
-		else
-			return adpcm;
-	} else if (type == 2) { // MS ADPCM
-		RewindableAudioStream *adpcm = makeADPCMStream(stream, disposeAfterUse, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
-
-		if (loop)
-			return new LoopingAudioStream(adpcm, 0);
-		else
-			return adpcm;
-	}
+	if (type == 17) // MS IMA ADPCM
+		return makeLoopingAudioStream(makeADPCMStream(stream, disposeAfterUse, size, Audio::kADPCMMSIma, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign), loop ? 0 : 1);
+	else if (type == 2) // MS ADPCM
+		return makeLoopingAudioStream(makeADPCMStream(stream, disposeAfterUse, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign), loop ? 0 : 1);
 	
 	// Raw PCM. Just read everything at once.
 	// TODO: More elegant would be to wrap the stream.


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list