[Scummvm-cvs-logs] SF.net SVN: scummvm:[48017] scummvm/trunk/test/sound/audiostream.h

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Tue Feb 9 22:51:29 CET 2010


Revision: 48017
          http://scummvm.svn.sourceforge.net/scummvm/?rev=48017&view=rev
Author:   lordhoto
Date:     2010-02-09 21:51:28 +0000 (Tue, 09 Feb 2010)

Log Message:
-----------
Add unit test for SubLoopingAudioStream. (Currently they fail though :-/)

Modified Paths:
--------------
    scummvm/trunk/test/sound/audiostream.h

Modified: scummvm/trunk/test/sound/audiostream.h
===================================================================
--- scummvm/trunk/test/sound/audiostream.h	2010-02-09 21:09:29 UTC (rev 48016)
+++ scummvm/trunk/test/sound/audiostream.h	2010-02-09 21:51:28 UTC (rev 48017)
@@ -108,5 +108,65 @@
 	void test_looping_audio_stream_stereo_fixed_iter() {
 		testLoopingAudioStreamFixedIter(22050, true);
 	}
+
+private:
+	void testSubLoopingAudioStreamFixedIter(const int sampleRate, const bool isStereo) {
+		const int secondLength = sampleRate * (isStereo ? 2 : 1);
+		const Audio::Timestamp loopStart(500, 1000), loopEnd(1000, 1000);
+		const int32 loopOffset = Audio::convertTimeToStreamPos(loopStart, sampleRate, isStereo).totalNumberOfFrames();
+		const int32 loopIteration = Audio::convertTimeToStreamPos((loopEnd - loopStart), sampleRate, isStereo).totalNumberOfFrames();
+
+		int16 *sine = 0;
+		Audio::SeekableAudioStream *s = createSineStream<int16>(sampleRate, 3, &sine, false, isStereo);
+		Audio::SubLoopingAudioStream *loop = new Audio::SubLoopingAudioStream(s, 5, loopStart, loopEnd);
+
+		int16 *buffer = new int16[secondLength * 2];
+
+		// Check parameters
+		TS_ASSERT_EQUALS(loop->isStereo(), isStereo);
+		TS_ASSERT_EQUALS(loop->getRate(), sampleRate);
+		TS_ASSERT_EQUALS(loop->endOfData(), false);
+
+		// Read one sceond (this is the non-looped part + one iteration)
+		TS_ASSERT_EQUALS(loop->readBuffer(buffer, secondLength), secondLength);
+		TS_ASSERT_EQUALS(memcmp(buffer, sine, secondLength * sizeof(int16)), 0);
+		TS_ASSERT_EQUALS(loop->endOfData(), false);
+
+		// We should have one full iteration now
+
+		// Read another loop iteration
+		TS_ASSERT_EQUALS(loop->readBuffer(buffer, loopIteration), loopIteration);
+		TS_ASSERT_EQUALS(memcmp(buffer, sine + loopOffset, loopIteration * sizeof(int16)), 0);
+		TS_ASSERT_EQUALS(loop->endOfData(), false);
+
+		// We should have two full iterations now
+
+		// Read three loop iterations at once
+		TS_ASSERT_EQUALS(loop->readBuffer(buffer, loopIteration * 3), loopIteration * 3);
+		TS_ASSERT_EQUALS(memcmp(buffer + loopIteration * 0, sine + loopOffset, loopIteration * sizeof(int16)), 0);
+		TS_ASSERT_EQUALS(memcmp(buffer + loopIteration * 1, sine + loopOffset, loopIteration * sizeof(int16)), 0);
+		TS_ASSERT_EQUALS(memcmp(buffer + loopIteration * 2, sine + loopOffset, loopIteration * sizeof(int16)), 0);
+		TS_ASSERT_EQUALS(loop->endOfData(), true);
+
+		// We should have five full iterations now, thus the stream should be done
+
+		// Try to read beyond the end of the stream (note this only applies, till we define that SubLoopingAudioStream should
+		// stop playing after the looped area).
+		TS_ASSERT_EQUALS(loop->readBuffer(buffer, secondLength), 0);
+		TS_ASSERT_EQUALS(loop->endOfData(), true);
+
+		delete[] buffer;
+		delete loop;
+		delete[] sine;
+	}
+
+public:
+	void test_sub_looping_audio_stream_mono_fixed_iter() {
+		testSubLoopingAudioStreamFixedIter(22050, false);
+	}
+
+	void test_sub_looping_audio_stream_stereo_fixed_iter() {
+		testSubLoopingAudioStreamFixedIter(22050, true);
+	}
 };
 


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