aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2010-02-06 16:41:27 +0000
committerJohannes Schickel2010-02-06 16:41:27 +0000
commit4fca64d1b049d5d94b0ca844c7dad301ddaf8718 (patch)
tree3af7123a88382def023ca1fa0d85463c0a83a460
parent2cfa5e428cecbf27509018c34d847be0301c302e (diff)
downloadscummvm-rg350-4fca64d1b049d5d94b0ca844c7dad301ddaf8718.tar.gz
scummvm-rg350-4fca64d1b049d5d94b0ca844c7dad301ddaf8718.tar.bz2
scummvm-rg350-4fca64d1b049d5d94b0ca844c7dad301ddaf8718.zip
Move test AudioStream creation to a new file.
svn-id: r47933
-rw-r--r--test/sound/helper.h68
-rw-r--r--test/sound/raw.h62
2 files changed, 69 insertions, 61 deletions
diff --git a/test/sound/helper.h b/test/sound/helper.h
new file mode 100644
index 0000000000..c389a9c576
--- /dev/null
+++ b/test/sound/helper.h
@@ -0,0 +1,68 @@
+#ifndef TEST_SOUND_HELPER_H
+#define TEST_SOUND_HELPER_H
+
+#include "sound/decoders/raw.h"
+
+#include "common/stream.h"
+#include "common/endian.h"
+
+#include <math.h>
+#include <limits>
+
+template<typename T>
+static T *createSine(const int sampleRate, const int time) {
+ T *sine = (T *)malloc(sizeof(T) * time * sampleRate);
+
+ const bool isUnsigned = !std::numeric_limits<T>::is_signed;
+ const T xorMask = isUnsigned ? (1 << (std::numeric_limits<T>::digits - 1)) : 0;
+ const T maxValue = std::numeric_limits<T>::max() ^ xorMask;
+
+ for (int i = 0; i < time * sampleRate; ++i)
+ sine[i] = ((T)(sin((double)i / sampleRate * 2 * PI) * maxValue)) ^ xorMask;
+
+ return sine;
+}
+
+template<typename T>
+static Audio::SeekableAudioStream *createSineStream(const int sampleRate, const int time, int16 **comp, bool le, bool isStereo) {
+ T *sine = createSine<T>(sampleRate, time * (isStereo ? 2 : 1));
+
+ const bool isUnsigned = !std::numeric_limits<T>::is_signed;
+ const T xorMask = isUnsigned ? (1 << (std::numeric_limits<T>::digits - 1)) : 0;
+ const bool is16Bits = (sizeof(T) == 2);
+ assert(sizeof(T) == 2 || sizeof(T) == 1);
+
+ const int samples = sampleRate * time * (isStereo ? 2 : 1);
+
+ if (comp) {
+ *comp = new int16[samples];
+ for (int i = 0; i < samples; ++i) {
+ if (is16Bits)
+ (*comp)[i] = sine[i] ^ xorMask;
+ else
+ (*comp)[i] = (sine[i] ^ xorMask) << 8;
+ }
+ }
+
+ if (is16Bits) {
+ if (le) {
+ for (int i = 0; i < samples; ++i)
+ WRITE_LE_UINT16(&sine[i], sine[i]);
+ } else {
+ for (int i = 0; i < samples; ++i)
+ WRITE_BE_UINT16(&sine[i], sine[i]);
+ }
+ }
+
+ 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));
+
+ return s;
+}
+
+#endif
+
diff --git a/test/sound/raw.h b/test/sound/raw.h
index 33f000566b..564ea2b266 100644
--- a/test/sound/raw.h
+++ b/test/sound/raw.h
@@ -2,70 +2,10 @@
#include "sound/decoders/raw.h"
-#include "common/stream.h"
-#include "common/endian.h"
-
-#include <math.h>
-#include <limits>
+#include "helper.h"
class RawStreamTestSuite : public CxxTest::TestSuite
{
-public:
- template<typename T>
- static T *createSine(const int sampleRate, const int time) {
- T *sine = (T *)malloc(sizeof(T) * time * sampleRate);
-
- const bool isUnsigned = !std::numeric_limits<T>::is_signed;
- const T xorMask = isUnsigned ? (1 << (std::numeric_limits<T>::digits - 1)) : 0;
- const T maxValue = std::numeric_limits<T>::max() ^ xorMask;
-
- for (int i = 0; i < time * sampleRate; ++i)
- sine[i] = ((T)(sin((double)i / sampleRate * 2 * PI) * maxValue)) ^ xorMask;
-
- return sine;
- }
-
- template<typename T>
- static Audio::SeekableAudioStream *createSineStream(const int sampleRate, const int time, int16 **comp, bool le, bool isStereo) {
- T *sine = createSine<T>(sampleRate, time * (isStereo ? 2 : 1));
-
- const bool isUnsigned = !std::numeric_limits<T>::is_signed;
- const T xorMask = isUnsigned ? (1 << (std::numeric_limits<T>::digits - 1)) : 0;
- const bool is16Bits = (sizeof(T) == 2);
- assert(sizeof(T) == 2 || sizeof(T) == 1);
-
- const int samples = sampleRate * time * (isStereo ? 2 : 1);
-
- if (comp) {
- *comp = new int16[samples];
- for (int i = 0; i < samples; ++i) {
- if (is16Bits)
- (*comp)[i] = sine[i] ^ xorMask;
- else
- (*comp)[i] = (sine[i] ^ xorMask) << 8;
- }
- }
-
- if (is16Bits) {
- if (le) {
- for (int i = 0; i < samples; ++i)
- WRITE_LE_UINT16(&sine[i], sine[i]);
- } else {
- for (int i = 0; i < samples; ++i)
- WRITE_BE_UINT16(&sine[i], sine[i]);
- }
- }
-
- 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));
-
- return s;
- }
-
private:
template<typename T>
void readBufferTestTemplate(const int sampleRate, const int time, const bool le, const bool isStereo) {