mirror of
https://github.com/libretro/scummvm.git
synced 2025-04-03 23:31:57 +00:00
Add test cases for RawStream playing from a stream via a block list.
svn-id: r48014
This commit is contained in:
parent
3a1e7ccbae
commit
a4f46767d9
@ -24,7 +24,40 @@ static T *createSine(const int sampleRate, const int time) {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static Audio::SeekableAudioStream *createSineStream(const int sampleRate, const int time, int16 **comp, bool le, bool isStereo) {
|
||||
static Common::SeekableReadStream *createPartitionStream(T *sine, const int samples, Audio::RawStreamBlockList &blockList) {
|
||||
const int block1Len = samples / 2;
|
||||
const int block1Size = block1Len * sizeof(T);
|
||||
const int block2Len = samples - block1Len;
|
||||
const int block2Size = block2Len * sizeof(T);
|
||||
|
||||
const int bufferLen = samples * 2;
|
||||
const int bufferSize = bufferLen * sizeof(T);
|
||||
T *partition = (T *)calloc(1, bufferSize);
|
||||
|
||||
Audio::RawStreamBlock block;
|
||||
|
||||
// The will layout the buffer like the following:
|
||||
// [Zero], [Part2], [Zero], [Part1]
|
||||
|
||||
// The first part of the stream is at the end of the memory buffer
|
||||
block.pos = bufferSize - block1Size;
|
||||
block.len = block1Len;
|
||||
memcpy(partition + bufferLen - block1Len, sine, block1Size);
|
||||
blockList.push_back(block);
|
||||
|
||||
// The second part of the stream is near the beginning of the memory buffer
|
||||
block.pos = block2Size;
|
||||
block.len = block2Len;
|
||||
memcpy(partition + block2Len, sine + block1Len, block2Size);
|
||||
blockList.push_back(block);
|
||||
|
||||
free(sine);
|
||||
|
||||
return new Common::MemoryReadStream((const byte *)partition, bufferSize, DisposeAfterUse::YES);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static Audio::SeekableAudioStream *createSineStream(const int sampleRate, const int time, int16 **comp, bool le, bool isStereo, bool makePartition = false) {
|
||||
T *sine = createSine<T>(sampleRate, time * (isStereo ? 2 : 1));
|
||||
|
||||
const bool isUnsigned = !std::numeric_limits<T>::is_signed;
|
||||
@ -54,12 +87,23 @@ static Audio::SeekableAudioStream *createSineStream(const int sampleRate, const
|
||||
}
|
||||
}
|
||||
|
||||
Common::SeekableReadStream *sD = new Common::MemoryReadStream((const byte *)sine, sizeof(T) * samples, DisposeAfterUse::YES);
|
||||
Audio::SeekableAudioStream *s = Audio::makeRawStream(sD, sampleRate,
|
||||
(is16Bits ? Audio::FLAG_16BITS : 0)
|
||||
| (isUnsigned ? Audio::FLAG_UNSIGNED : 0)
|
||||
| (le ? Audio::FLAG_LITTLE_ENDIAN : 0)
|
||||
| (isStereo ? Audio::FLAG_STEREO : 0));
|
||||
Audio::SeekableAudioStream *s = 0;
|
||||
if (makePartition) {
|
||||
Audio::RawStreamBlockList blockList;
|
||||
Common::SeekableReadStream *sD = createPartitionStream<T>(sine, samples, blockList);
|
||||
s = Audio::makeRawStream(sD, blockList, sampleRate,
|
||||
(is16Bits ? Audio::FLAG_16BITS : 0)
|
||||
| (isUnsigned ? Audio::FLAG_UNSIGNED : 0)
|
||||
| (le ? Audio::FLAG_LITTLE_ENDIAN : 0)
|
||||
| (isStereo ? Audio::FLAG_STEREO : 0));
|
||||
} else {
|
||||
Common::SeekableReadStream *sD = new Common::MemoryReadStream((const byte *)sine, sizeof(T) * samples, DisposeAfterUse::YES);
|
||||
s = Audio::makeRawStream(sD, sampleRate,
|
||||
(is16Bits ? Audio::FLAG_16BITS : 0)
|
||||
| (isUnsigned ? Audio::FLAG_UNSIGNED : 0)
|
||||
| (le ? Audio::FLAG_LITTLE_ENDIAN : 0)
|
||||
| (isStereo ? Audio::FLAG_STEREO : 0));
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
142
test/sound/raw.h
142
test/sound/raw.h
@ -8,9 +8,9 @@ class RawStreamTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
private:
|
||||
template<typename T>
|
||||
void readBufferTestTemplate(const int sampleRate, const int time, const bool le, const bool isStereo) {
|
||||
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);
|
||||
Audio::SeekableAudioStream *s = createSineStream<int8>(sampleRate, time, &sine, le, isStereo, makePartition);
|
||||
|
||||
const int totalSamples = sampleRate * time * (isStereo ? 2 : 1);
|
||||
int16 *buffer = new int16[totalSamples];
|
||||
@ -48,10 +48,18 @@ public:
|
||||
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);
|
||||
}
|
||||
@ -60,12 +68,57 @@ public:
|
||||
readBufferTestTemplate<uint16>(11025, 2, true, true);
|
||||
}
|
||||
|
||||
void test_partial_read() {
|
||||
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);
|
||||
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);
|
||||
@ -84,8 +137,17 @@ public:
|
||||
delete[] buffer;
|
||||
delete s;
|
||||
}
|
||||
public:
|
||||
void test_partial_read() {
|
||||
partialReadTest(false);
|
||||
}
|
||||
|
||||
void test_read_after_end() {
|
||||
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);
|
||||
@ -101,10 +163,20 @@ public:
|
||||
delete s;
|
||||
}
|
||||
|
||||
void test_rewind() {
|
||||
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);
|
||||
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);
|
||||
@ -119,8 +191,17 @@ public:
|
||||
delete[] buffer;
|
||||
delete s;
|
||||
}
|
||||
public:
|
||||
void test_rewind() {
|
||||
rewindTest(false);
|
||||
}
|
||||
|
||||
void test_length() {
|
||||
void test_rewind_parted() {
|
||||
rewindTest(true);
|
||||
}
|
||||
|
||||
private:
|
||||
void lengthTest(const bool makePartition) {
|
||||
int sampleRate = 0;
|
||||
const int time = 4;
|
||||
|
||||
@ -128,57 +209,66 @@ public:
|
||||
|
||||
// 11025 Hz tests
|
||||
sampleRate = 11025;
|
||||
s = createSineStream<int8>(sampleRate, time, 0, false, false);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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) {
|
||||
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;
|
||||
|
||||
@ -186,7 +276,7 @@ private:
|
||||
Audio::SeekableAudioStream *s = 0;
|
||||
int16 *sine = 0;
|
||||
|
||||
s = createSineStream<int8>(sampleRate, time, &sine, false, isStereo);
|
||||
s = createSineStream<int8>(sampleRate, time, &sine, false, isStereo, makePartition);
|
||||
|
||||
// Seek to 500ms
|
||||
const Audio::Timestamp a(0, 1, 2);
|
||||
@ -251,10 +341,18 @@ private:
|
||||
|
||||
public:
|
||||
void test_seek_mono() {
|
||||
seekTest(11025, 2, false);
|
||||
seekTest(11025, 2, false, false);
|
||||
}
|
||||
|
||||
void test_seek_stereo() {
|
||||
seekTest(11025, 2, true);
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user