[Scummvm-cvs-logs] SF.net SVN: scummvm:[47933] scummvm/trunk/test/sound

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sat Feb 6 17:41:27 CET 2010


Revision: 47933
          http://scummvm.svn.sourceforge.net/scummvm/?rev=47933&view=rev
Author:   lordhoto
Date:     2010-02-06 16:41:27 +0000 (Sat, 06 Feb 2010)

Log Message:
-----------
Move test AudioStream creation to a new file.

Modified Paths:
--------------
    scummvm/trunk/test/sound/raw.h

Added Paths:
-----------
    scummvm/trunk/test/sound/helper.h

Added: scummvm/trunk/test/sound/helper.h
===================================================================
--- scummvm/trunk/test/sound/helper.h	                        (rev 0)
+++ scummvm/trunk/test/sound/helper.h	2010-02-06 16:41:27 UTC (rev 47933)
@@ -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
+


Property changes on: scummvm/trunk/test/sound/helper.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: scummvm/trunk/test/sound/raw.h
===================================================================
--- scummvm/trunk/test/sound/raw.h	2010-02-06 16:30:32 UTC (rev 47932)
+++ scummvm/trunk/test/sound/raw.h	2010-02-06 16:41:27 UTC (rev 47933)
@@ -2,70 +2,10 @@
 
 #include "sound/decoders/raw.h"
 
-#include "common/stream.h"
-#include "common/endian.h"
+#include "helper.h"
 
-#include <math.h>
-#include <limits>
-
 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) {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list