aboutsummaryrefslogtreecommitdiff
path: root/test/sound
diff options
context:
space:
mode:
authorJohannes Schickel2010-02-03 15:24:24 +0000
committerJohannes Schickel2010-02-03 15:24:24 +0000
commitc0f5a5d2d959c3f1631ec5c500179db2d139f3a8 (patch)
tree9dcc0118b2c1b6d2252dd4f31db40c26e7aebd73 /test/sound
parentba5e2b336279ba524f5e86fa0ca0b732ac157e58 (diff)
downloadscummvm-rg350-c0f5a5d2d959c3f1631ec5c500179db2d139f3a8.tar.gz
scummvm-rg350-c0f5a5d2d959c3f1631ec5c500179db2d139f3a8.tar.bz2
scummvm-rg350-c0f5a5d2d959c3f1631ec5c500179db2d139f3a8.zip
Test both BE and LE 16bit samples.
svn-id: r47853
Diffstat (limited to 'test/sound')
-rw-r--r--test/sound/raw.h60
1 files changed, 46 insertions, 14 deletions
diff --git a/test/sound/raw.h b/test/sound/raw.h
index 69ee4d182f..f9e56f2973 100644
--- a/test/sound/raw.h
+++ b/test/sound/raw.h
@@ -20,21 +20,34 @@ public:
for (int i = 0; i < time * sampleRate; ++i)
sine[i] = (T)(sin((double)i / sampleRate * 2 * PI) * maxValue);
- // Convert to BE
- if (sizeof(T) == 2) {
- for (int i = 0; i < time * sampleRate; ++i)
- WRITE_BE_UINT16(&sine[i], sine[i]);
- }
-
return sine;
}
- template<typename T>
- static Audio::SeekableAudioStream *createSineStream(int sampleRate, int time, const T **sineP) {
- T *sine = createSine<T>(sampleRate, time);
+ static Audio::SeekableAudioStream *createSineStream8Bit(int sampleRate, int time, const int8 **sineP) {
+ int8 *sine = createSine<int8>(sampleRate, time);
+
+ Common::SeekableReadStream *sD = new Common::MemoryReadStream((const byte *)sine, sampleRate * time, DisposeAfterUse::YES);
+ Audio::SeekableAudioStream *s = Audio::makeRawStream(sD, sampleRate, 0);
+
+ if (sineP)
+ *sineP = sine;
- Common::SeekableReadStream *sD = new Common::MemoryReadStream((const byte *)sine, sizeof(T) * sampleRate * time, DisposeAfterUse::YES);
- Audio::SeekableAudioStream *s = Audio::makeRawStream(sD, sampleRate, (sizeof(T) == 2) ? Audio::FLAG_16BITS : 0);
+ return s;
+ }
+
+ static Audio::SeekableAudioStream *createSineStream16Bit(int sampleRate, int time, bool le, const int16 **sineP) {
+ int16 *sine = createSine<int16>(sampleRate, time);
+
+ if (le) {
+ for (int i = 0; i < sampleRate * time; ++i)
+ WRITE_LE_UINT16(&sine[i], sine[i]);
+ } else {
+ for (int i = 0; i < sampleRate * time; ++i)
+ WRITE_BE_UINT16(&sine[i], sine[i]);
+ }
+
+ Common::SeekableReadStream *sD = new Common::MemoryReadStream((const byte *)sine, sizeof(int16) * sampleRate * time, DisposeAfterUse::YES);
+ Audio::SeekableAudioStream *s = Audio::makeRawStream(sD, sampleRate, Audio::FLAG_16BITS | (le ? Audio::FLAG_LITTLE_ENDIAN : 0));
if (sineP)
*sineP = sine;
@@ -46,8 +59,8 @@ public:
const int sampleRate = 11025;
const int time = 2;
- const int8 *sine = 0;
- Audio::SeekableAudioStream *s = createSineStream<int8>(sampleRate, time, &sine);
+ const int8 *sine;
+ Audio::SeekableAudioStream *s = createSineStream8Bit(sampleRate, time, &sine);
int16 *buffer = new int16[sampleRate * time];
TS_ASSERT_EQUALS(s->readBuffer(buffer, sampleRate * time), sampleRate * time);
@@ -66,7 +79,7 @@ public:
const int time = 2;
const int16 *sine = 0;
- Audio::SeekableAudioStream *s = createSineStream<int16>(sampleRate, time, &sine);
+ Audio::SeekableAudioStream *s = createSineStream16Bit(sampleRate, time, false, &sine);
int16 *buffer = new int16[sampleRate * time];
TS_ASSERT_EQUALS(s->readBuffer(buffer, sampleRate * time), sampleRate * time);
@@ -79,4 +92,23 @@ public:
delete[] buffer;
delete s;
}
+
+ void test_read_buffer_16_bit_le_mono() {
+ const int sampleRate = 11025;
+ const int time = 2;
+
+ const int16 *sine = 0;
+ Audio::SeekableAudioStream *s = createSineStream16Bit(sampleRate, time, true, &sine);
+
+ int16 *buffer = new int16[sampleRate * time];
+ TS_ASSERT_EQUALS(s->readBuffer(buffer, sampleRate * time), sampleRate * time);
+
+ for (int i = 0; i < sampleRate * time; ++i)
+ TS_ASSERT_EQUALS(buffer[i], (int16)READ_LE_UINT16(&sine[i]));
+
+ TS_ASSERT_EQUALS(s->endOfData(), true);
+
+ delete[] buffer;
+ delete s;
+ }
};