diff options
author | Johannes Schickel | 2010-02-09 21:52:08 +0000 |
---|---|---|
committer | Johannes Schickel | 2010-02-09 21:52:08 +0000 |
commit | fa2a1cd22dd3a7a7192bfcdfccff3df80e2f3297 (patch) | |
tree | 17c82eefdc4e87ce14308f2153bb95fb27a4d96f | |
parent | f6aa8d00689b4f4d4f3c3cf840efc1a4eb460aaf (diff) | |
download | scummvm-rg350-fa2a1cd22dd3a7a7192bfcdfccff3df80e2f3297.tar.gz scummvm-rg350-fa2a1cd22dd3a7a7192bfcdfccff3df80e2f3297.tar.bz2 scummvm-rg350-fa2a1cd22dd3a7a7192bfcdfccff3df80e2f3297.zip |
Add some additional tests for SubLoopingAudioStream and LoopingAudioStream. (Currently SubLoopingAudioStream tests fail for a reason unknown to me...)
svn-id: r48019
-rw-r--r-- | test/sound/audiostream.h | 75 |
1 files 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<int16>(sampleRate, 3, &sine, false, isStereo); + Audio::SeekableAudioStream *s = createSineStream<int16>(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<int32>(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); } }; |