aboutsummaryrefslogtreecommitdiff
path: root/test/sound/helper.h
diff options
context:
space:
mode:
Diffstat (limited to 'test/sound/helper.h')
-rw-r--r--test/sound/helper.h58
1 files changed, 51 insertions, 7 deletions
diff --git a/test/sound/helper.h b/test/sound/helper.h
index c389a9c576..394287c884 100644
--- a/test/sound/helper.h
+++ b/test/sound/helper.h
@@ -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;
}