From fa2a1cd22dd3a7a7192bfcdfccff3df80e2f3297 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 9 Feb 2010 21:52:08 +0000 Subject: Add some additional tests for SubLoopingAudioStream and LoopingAudioStream. (Currently SubLoopingAudioStream tests fail for a reason unknown to me...) svn-id: r48019 --- test/sound/audiostream.h | 75 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 19 deletions(-) diff --git a/test/sound/audiostream.h b/test/sound/audiostream.h index e0d3ece059..ba3adcb34c 100644 --- a/test/sound/audiostream.h +++ b/test/sound/audiostream.h @@ -101,51 +101,64 @@ private: } public: - void test_looping_audio_stream_mono_fixed_iter() { + void test_looping_audio_stream_mono_11025_fixed_iter() { + testLoopingAudioStreamFixedIter(11025, false); + } + + void test_looping_audio_stream_mono_22050_fixed_iter() { testLoopingAudioStreamFixedIter(22050, false); } - void test_looping_audio_stream_stereo_fixed_iter() { + void test_looping_audio_stream_stereo_11025_fixed_iter() { + testLoopingAudioStreamFixedIter(11025, true); + } + + void test_looping_audio_stream_stereo_22050_fixed_iter() { testLoopingAudioStreamFixedIter(22050, true); } private: - void testSubLoopingAudioStreamFixedIter(const int sampleRate, const bool isStereo) { + void testSubLoopingAudioStreamFixedIter(const int sampleRate, const bool isStereo, const int time, const int loopEndTime) { 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(); + + const Audio::Timestamp loopStart(500, 1000), loopEnd(loopEndTime * 1000, 1000); + + const int32 loopStartPos = Audio::convertTimeToStreamPos(loopStart, sampleRate, isStereo).totalNumberOfFrames(); + const int32 loopEndPos = Audio::convertTimeToStreamPos(loopEnd, sampleRate, isStereo).totalNumberOfFrames(); + + const int32 loopIteration = loopEndPos - loopStartPos; int16 *sine = 0; - Audio::SeekableAudioStream *s = createSineStream(sampleRate, 3, &sine, false, isStereo); + Audio::SeekableAudioStream *s = createSineStream(sampleRate, time, &sine, false, isStereo); Audio::SubLoopingAudioStream *loop = new Audio::SubLoopingAudioStream(s, 5, loopStart, loopEnd); - int16 *buffer = new int16[secondLength * 2]; + const int32 bufferLen = MAX(loopIteration * 3, loopEndPos); + int16 *buffer = new int16[bufferLen]; // 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); + // Read the non-looped part + one iteration + TS_ASSERT_EQUALS(loop->readBuffer(buffer, loopEndPos), loopEndPos); + TS_ASSERT_EQUALS(memcmp(buffer, sine, loopEndPos * 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(memcmp(buffer, sine + loopStartPos, 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(memcmp(buffer + loopIteration * 0, sine + loopStartPos, loopIteration * sizeof(int16)), 0); + TS_ASSERT_EQUALS(memcmp(buffer + loopIteration * 1, sine + loopStartPos, loopIteration * sizeof(int16)), 0); + TS_ASSERT_EQUALS(memcmp(buffer + loopIteration * 2, sine + loopStartPos, loopIteration * sizeof(int16)), 0); TS_ASSERT_EQUALS(loop->endOfData(), true); // We should have five full iterations now, thus the stream should be done @@ -161,12 +174,36 @@ private: } public: - void test_sub_looping_audio_stream_mono_fixed_iter() { - testSubLoopingAudioStreamFixedIter(22050, false); + void test_sub_looping_audio_stream_mono_11025_mid_fixed_iter() { + testSubLoopingAudioStreamFixedIter(11025, false, 2, 1); + } + + void test_sub_looping_audio_stream_mono_22050_mid_fixed_iter() { + testSubLoopingAudioStreamFixedIter(22050, false, 2, 1); + } + + void test_sub_looping_audio_stream_stereo_11025_mid_fixed_iter() { + testSubLoopingAudioStreamFixedIter(11025, true, 2, 1); + } + + void test_sub_looping_audio_stream_stereo_22050_mid_fixed_iter() { + testSubLoopingAudioStreamFixedIter(22050, true, 2, 1); + } + + void test_sub_looping_audio_stream_mono_11025_end_fixed_iter() { + testSubLoopingAudioStreamFixedIter(11025, false, 2, 2); + } + + void test_sub_looping_audio_stream_mono_22050_end_fixed_iter() { + testSubLoopingAudioStreamFixedIter(22050, false, 2, 2); + } + + void test_sub_looping_audio_stream_stereo_11025_end_fixed_iter() { + testSubLoopingAudioStreamFixedIter(11025, true, 2, 2); } - void test_sub_looping_audio_stream_stereo_fixed_iter() { - testSubLoopingAudioStreamFixedIter(22050, true); + void test_sub_looping_audio_stream_stereo_22050_end_fixed_iter() { + testSubLoopingAudioStreamFixedIter(22050, true, 2, 2); } }; -- cgit v1.2.3