aboutsummaryrefslogtreecommitdiff
path: root/test/sound/raw.h
diff options
context:
space:
mode:
authorMax Horn2011-02-09 01:09:01 +0000
committerMax Horn2011-02-09 01:09:01 +0000
commit42ab839dd6c8a1570b232101eb97f4e54de57935 (patch)
tree3b763d8913a87482b793e0348c88b9a5f40eecc9 /test/sound/raw.h
parent386203a3d6ce1abf457c9110d695408ec5f01b85 (diff)
downloadscummvm-rg350-42ab839dd6c8a1570b232101eb97f4e54de57935.tar.gz
scummvm-rg350-42ab839dd6c8a1570b232101eb97f4e54de57935.tar.bz2
scummvm-rg350-42ab839dd6c8a1570b232101eb97f4e54de57935.zip
AUDIO: Rename sound/ dir to audio/
svn-id: r55850
Diffstat (limited to 'test/sound/raw.h')
-rw-r--r--test/sound/raw.h358
1 files changed, 0 insertions, 358 deletions
diff --git a/test/sound/raw.h b/test/sound/raw.h
deleted file mode 100644
index b8f7b2dae6..0000000000
--- a/test/sound/raw.h
+++ /dev/null
@@ -1,358 +0,0 @@
-#include <cxxtest/TestSuite.h>
-
-#include "sound/decoders/raw.h"
-
-#include "helper.h"
-
-class RawStreamTestSuite : public CxxTest::TestSuite
-{
-private:
- template<typename T>
- void readBufferTestTemplate(const int sampleRate, const int time, const bool le, const bool isStereo, const bool makePartition = false) {
- int16 *sine;
- Audio::SeekableAudioStream *s = createSineStream<int8>(sampleRate, time, &sine, le, isStereo, makePartition);
-
- const int totalSamples = sampleRate * time * (isStereo ? 2 : 1);
- int16 *buffer = new int16[totalSamples];
- TS_ASSERT_EQUALS(s->readBuffer(buffer, totalSamples), totalSamples);
- TS_ASSERT_EQUALS(memcmp(sine, buffer, sizeof(int16) * totalSamples), 0);
- TS_ASSERT_EQUALS(s->endOfData(), true);
-
- delete[] sine;
- delete[] buffer;
- delete s;
- }
-
-public:
- void test_read_buffer_8_bit_signed_mono() {
- readBufferTestTemplate<int8>(11025, 2, false, false);
- }
-
- void test_read_buffer_8_bit_signed_stereo() {
- readBufferTestTemplate<int8>(11025, 2, false, true);
- }
-
- void test_read_buffer_8_bit_unsigned_mono() {
- readBufferTestTemplate<uint8>(11025, 2, false, false);
- }
-
- void test_read_buffer_16_bit_signed_be_mono() {
- readBufferTestTemplate<int16>(11025, 2, false, false);
- }
-
- void test_read_buffer_16_bit_signed_be_stereo() {
- readBufferTestTemplate<int16>(11025, 2, false, true);
- }
-
- void test_read_buffer_16_bit_unsigned_be_mono() {
- readBufferTestTemplate<uint16>(11025, 2, false, false);
- }
-
- void test_read_buffer_16_bit_unsigned_be_stereo() {
- readBufferTestTemplate<uint16>(11025, 2, false, true);
- }
-
- void test_read_buffer_16_bit_signed_le_mono() {
- readBufferTestTemplate<int16>(11025, 2, true, false);
- }
-
- void test_read_buffer_16_bit_signed_le_stereo() {
- readBufferTestTemplate<int16>(11025, 2, true, true);
- }
-
- void test_read_buffer_16_bit_unsigned_le_mono() {
- readBufferTestTemplate<uint16>(11025, 2, true, false);
- }
-
- void test_read_buffer_16_bit_unsigned_le_stereo() {
- readBufferTestTemplate<uint16>(11025, 2, true, true);
- }
-
- void test_read_buffer_8_bit_signed_mono_parted() {
- readBufferTestTemplate<int8>(11025, 2, false, false, true);
- }
-
- void test_read_buffer_8_bit_signed_stereo_parted() {
- readBufferTestTemplate<int8>(11025, 2, false, true, true);
- }
-
- void test_read_buffer_8_bit_unsigned_mono_parted() {
- readBufferTestTemplate<uint8>(11025, 2, false, false, true);
- }
-
- void test_read_buffer_16_bit_signed_be_mono_parted() {
- readBufferTestTemplate<int16>(11025, 2, false, false, true);
- }
-
- void test_read_buffer_16_bit_signed_be_stereo_parted() {
- readBufferTestTemplate<int16>(11025, 2, false, true, true);
- }
-
- void test_read_buffer_16_bit_unsigned_be_mono_parted() {
- readBufferTestTemplate<uint16>(11025, 2, false, false, true);
- }
-
- void test_read_buffer_16_bit_unsigned_be_stereo_parted() {
- readBufferTestTemplate<uint16>(11025, 2, false, true, true);
- }
-
- void test_read_buffer_16_bit_signed_le_mono_parted() {
- readBufferTestTemplate<int16>(11025, 2, true, false, true);
- }
-
- void test_read_buffer_16_bit_signed_le_stereo_parted() {
- readBufferTestTemplate<int16>(11025, 2, true, true, true);
- }
-
- void test_read_buffer_16_bit_unsigned_le_mono_parted() {
- readBufferTestTemplate<uint16>(11025, 2, true, false, true);
- }
-
- void test_read_buffer_16_bit_unsigned_le_stereo_parted() {
- readBufferTestTemplate<uint16>(11025, 2, true, true, true);
- }
-
-private:
- void partialReadTest(const bool makePartition) {
- const int sampleRate = 11025;
- const int time = 4;
-
- int16 *sine;
- Audio::SeekableAudioStream *s = createSineStream<int8>(sampleRate, time, &sine, false, false, makePartition);
- int16 *buffer = new int16[sampleRate * time];
-
- TS_ASSERT_EQUALS(s->readBuffer(buffer, sampleRate), sampleRate);
- TS_ASSERT_EQUALS(memcmp(sine, buffer, sampleRate), 0);
- TS_ASSERT_EQUALS(s->endOfData(), false);
-
- TS_ASSERT_EQUALS(s->readBuffer(buffer, sampleRate * 2), sampleRate * 2);
- TS_ASSERT_EQUALS(memcmp(sine + sampleRate, buffer, sampleRate * 2), 0);
- TS_ASSERT_EQUALS(s->endOfData(), false);
-
- TS_ASSERT_EQUALS(s->readBuffer(buffer, sampleRate), sampleRate);
- TS_ASSERT_EQUALS(memcmp(sine + sampleRate * 3, buffer, sampleRate), 0);
- TS_ASSERT_EQUALS(s->endOfData(), true);
-
- delete[] sine;
- delete[] buffer;
- delete s;
- }
-public:
- void test_partial_read() {
- partialReadTest(false);
- }
-
- void test_partial_read_parted() {
- partialReadTest(true);
- }
-
-private:
- void readAfterEndTest(const bool makePartition) {
- const int sampleRate = 11025;
- const int time = 1;
- Audio::SeekableAudioStream *s = createSineStream<int8>(sampleRate, time, 0, false, false);
- int16 *buffer = new int16[sampleRate * time];
-
- TS_ASSERT_EQUALS(s->readBuffer(buffer, sampleRate * time), sampleRate * time);
- TS_ASSERT_EQUALS(s->endOfData(), true);
-
- TS_ASSERT_EQUALS(s->readBuffer(buffer, sampleRate * time), 0);
- TS_ASSERT_EQUALS(s->endOfData(), true);
-
- delete[] buffer;
- delete s;
- }
-
-public:
- void test_read_after_end() {
- readAfterEndTest(false);
- }
-
- void test_read_after_end_parted() {
- readAfterEndTest(true);
- }
-
-private:
- void rewindTest(const bool makePartition) {
- const int sampleRate = 11025;
- const int time = 2;
- Audio::SeekableAudioStream *s = createSineStream<int8>(sampleRate, time, 0, false, false, makePartition);
- int16 *buffer = new int16[sampleRate * time];
-
- TS_ASSERT_EQUALS(s->readBuffer(buffer, sampleRate * time), sampleRate * time);
- TS_ASSERT_EQUALS(s->endOfData(), true);
-
- s->rewind();
- TS_ASSERT_EQUALS(s->endOfData(), false);
-
- TS_ASSERT_EQUALS(s->readBuffer(buffer, sampleRate * time), sampleRate * time);
- TS_ASSERT_EQUALS(s->endOfData(), true);
-
- delete[] buffer;
- delete s;
- }
-public:
- void test_rewind() {
- rewindTest(false);
- }
-
- void test_rewind_parted() {
- rewindTest(true);
- }
-
-private:
- void lengthTest(const bool makePartition) {
- int sampleRate = 0;
- const int time = 4;
-
- Audio::SeekableAudioStream *s = 0;
-
- // 11025 Hz tests
- sampleRate = 11025;
- s = createSineStream<int8>(sampleRate, time, 0, false, false, makePartition);
- TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
- delete s;
-
- s = createSineStream<uint16>(sampleRate, time, 0, false, false, makePartition);
- TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
- delete s;
-
- // 48000 Hz tests
- sampleRate = 48000;
- s = createSineStream<int8>(sampleRate, time, 0, false, false, makePartition);
- TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
- delete s;
-
- s = createSineStream<uint16>(sampleRate, time, 0, true, false, makePartition);
- TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
- delete s;
-
- // 11840 Hz tests
- sampleRate = 11840;
- s = createSineStream<int8>(sampleRate, time, 0, false, false, makePartition);
- TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
- delete s;
-
- s = createSineStream<uint16>(sampleRate, time, 0, false, false, makePartition);
- TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
- delete s;
-
- // 11111 Hz tests
- sampleRate = 11111;
- s = createSineStream<int8>(sampleRate, time, 0, false, false, makePartition);
- TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
- delete s;
-
- s = createSineStream<uint16>(sampleRate, time, 0, false, false, makePartition);
- TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
- delete s;
-
- // 22050 Hz stereo test
- sampleRate = 22050;
- s = createSineStream<int8>(sampleRate, time, 0, false, true, makePartition);
- TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
- delete s;
-
- s = createSineStream<uint16>(sampleRate, time, 0, true, true, makePartition);
- TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
- delete s;
- }
-
-public:
- void test_length() {
- lengthTest(false);
- }
-
- void test_length_parted() {
- lengthTest(true);
- }
-
-private:
- void seekTest(const int sampleRate, const int time, const bool isStereo, const bool makePartition) {
- const int totalFrames = sampleRate * time * (isStereo ? 2 : 1);
- int readData = 0, offset = 0;
-
- int16 *buffer = new int16[totalFrames];
- Audio::SeekableAudioStream *s = 0;
- int16 *sine = 0;
-
- s = createSineStream<int8>(sampleRate, time, &sine, false, isStereo, makePartition);
-
- // Seek to 500ms
- const Audio::Timestamp a(0, 1, 2);
- offset = Audio::convertTimeToStreamPos(a, sampleRate, isStereo).totalNumberOfFrames();
- readData = totalFrames - offset;
-
- TS_ASSERT_EQUALS(s->seek(a), true);
- TS_ASSERT_EQUALS(s->endOfData(), false);
- TS_ASSERT_EQUALS(s->readBuffer(buffer, readData), readData);
- TS_ASSERT_EQUALS(memcmp(buffer, sine + offset, readData * sizeof(int16)), 0);
- TS_ASSERT_EQUALS(s->endOfData(), true);
-
- // Seek to 3/4 of a second
- const Audio::Timestamp b(0, 3, 4);
- offset = Audio::convertTimeToStreamPos(b, sampleRate, isStereo).totalNumberOfFrames();
- readData = totalFrames - offset;
-
- TS_ASSERT_EQUALS(s->seek(b), true);
- TS_ASSERT_EQUALS(s->endOfData(), false);
- TS_ASSERT_EQUALS(s->readBuffer(buffer, readData), readData);
- TS_ASSERT_EQUALS(memcmp(buffer, sine + offset, readData * sizeof(int16)), 0);
- TS_ASSERT_EQUALS(s->endOfData(), true);
-
- // Seek to the start of the stream
- TS_ASSERT_EQUALS(s->seek(0), true);
- TS_ASSERT_EQUALS(s->endOfData(), false);
-
- // Seek to the mid of the stream
- const Audio::Timestamp c(time * 1000 / 2, 1000);
- offset = Audio::convertTimeToStreamPos(c, sampleRate, isStereo).totalNumberOfFrames();
- readData = totalFrames - offset;
-
- TS_ASSERT_EQUALS(s->seek(c), true);
- TS_ASSERT_EQUALS(s->endOfData(), false);
- TS_ASSERT_EQUALS(s->readBuffer(buffer, readData), readData);
- TS_ASSERT_EQUALS(memcmp(buffer, sine + offset, readData * sizeof(int16)), 0);
- TS_ASSERT_EQUALS(s->endOfData(), true);
-
- // Seek to the 1/4th of the last second of the stream
- const Audio::Timestamp d(time - 1, 1, 4);
- offset = Audio::convertTimeToStreamPos(d, sampleRate, isStereo).totalNumberOfFrames();
- readData = totalFrames - offset;
-
- TS_ASSERT_EQUALS(s->seek(d), true);
- TS_ASSERT_EQUALS(s->endOfData(), false);
- TS_ASSERT_EQUALS(s->readBuffer(buffer, readData), readData);
- TS_ASSERT_EQUALS(memcmp(buffer, sine + offset, readData * sizeof(int16)), 0);
- TS_ASSERT_EQUALS(s->endOfData(), true);
-
- // Try to seek after the end of the stream
- TS_ASSERT_EQUALS(s->seek(Audio::Timestamp(time, 1, 100000)), false);
- TS_ASSERT_EQUALS(s->endOfData(), true);
-
- // Try to seek exactly at the end of the stream
- TS_ASSERT_EQUALS(s->seek(Audio::Timestamp(time * 1000, 1000)), true);
- TS_ASSERT_EQUALS(s->endOfData(), true);
-
- delete[] sine;
- delete s;
- delete[] buffer;
- }
-
-public:
- void test_seek_mono() {
- seekTest(11025, 2, false, false);
- }
-
- void test_seek_stereo() {
- seekTest(11025, 2, true, false);
- }
-
- void test_seek_mono_parted() {
- seekTest(11025, 2, false, true);
- }
-
- void test_seek_stereo_parted() {
- seekTest(11025, 2, true, true);
- }
-};