[Scummvm-cvs-logs] CVS: scummvm/sound audiostream.cpp,1.41,1.42 mixer.h,1.58,1.59

Robert G?ffringmann lavosspawn at users.sourceforge.net
Mon Dec 15 18:12:00 CET 2003


Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1:/tmp/cvs-serv19356/sound

Modified Files:
	audiostream.cpp mixer.h 
Log Message:
added mixer flag for little endian samples

Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.cpp,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- audiostream.cpp	9 Dec 2003 23:01:36 -0000	1.41
+++ audiostream.cpp	16 Dec 2003 02:11:04 -0000	1.42
@@ -35,12 +35,15 @@
 #define READSAMPLE(is16Bit, isUnsigned, ptr) \
 	((is16Bit ? READ_BE_UINT16(ptr) : (*ptr << 8)) ^ (isUnsigned ? 0x8000 : 0))
 
+#define READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, ptr, isLE) \
+	((is16Bit ? (isLE ? READ_LE_UINT16(ptr) : READ_BE_UINT16(ptr)) : (*ptr << 8)) ^ (isUnsigned ? 0x8000 : 0))
+
 #pragma mark -
 #pragma mark --- LinearMemoryStream ---
 #pragma mark -
 
 
-template<bool stereo, bool is16Bit, bool isUnsigned>
+template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
 class LinearMemoryStream : public AudioInputStream {
 protected:
 	const byte *_ptr;
@@ -50,7 +53,7 @@
 
 	inline int16 readIntern() {
 		//assert(_ptr < _end);
-		int16 val = READSAMPLE(is16Bit, isUnsigned, _ptr);
+		int16 val = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _ptr, isLE);
 		_ptr += (is16Bit ? 2 : 1);
 		if (_loopPtr && eosIntern()) {
 			_ptr = _loopPtr;
@@ -83,13 +86,13 @@
 	bool isStereo() const		{ return stereo; }
 };
 
-template<bool stereo, bool is16Bit, bool isUnsigned>
-int LinearMemoryStream<stereo, is16Bit, isUnsigned>::readBuffer(int16 *buffer, const int numSamples) {
+template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
+int LinearMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buffer, const int numSamples) {
 	int samples = 0;
 	while (samples < numSamples && !eosIntern()) {
 		const int len = MIN(numSamples, samples + (int)(_end - _ptr) / (is16Bit ? 2 : 1));
 		while (samples < len) {
-			*buffer++ = READSAMPLE(is16Bit, isUnsigned, _ptr);
+			*buffer++ = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _ptr, isLE);
 			_ptr += (is16Bit ? 2 : 1);
 			samples++;
 		}
@@ -576,17 +579,23 @@
 
 
 template<bool stereo>
-static AudioInputStream *makeLinearInputStream(const byte *ptr, uint32 len, bool is16Bit, bool isUnsigned, uint loopOffset, uint loopLen) {
+static AudioInputStream *makeLinearInputStream(const byte *ptr, uint32 len, bool is16Bit, bool isUnsigned, bool isLE, uint loopOffset, uint loopLen) {
 	if (isUnsigned) {
-		if (is16Bit)
-			return new LinearMemoryStream<stereo, true, true>(ptr, len, loopOffset, loopLen);
-		else
-			return new LinearMemoryStream<stereo, false, true>(ptr, len, loopOffset, loopLen);
+		if (is16Bit) {
+			if (isLE)
+				return new LinearMemoryStream<stereo, true, true, true>(ptr, len, loopOffset, loopLen);
+			else 
+				return new LinearMemoryStream<stereo, true, true, false>(ptr, len, loopOffset, loopLen);
+		} else
+			return new LinearMemoryStream<stereo, false, true, false>(ptr, len, loopOffset, loopLen);
 	} else {
-		if (is16Bit)
-			return new LinearMemoryStream<stereo, true, false>(ptr, len, loopOffset, loopLen);
-		else
-			return new LinearMemoryStream<stereo, false, false>(ptr, len, loopOffset, loopLen);
+		if (is16Bit) {
+			if (isLE)
+				return new LinearMemoryStream<stereo, true, false, true>(ptr, len, loopOffset, loopLen);
+			else
+				return new LinearMemoryStream<stereo, true, false, false>(ptr, len, loopOffset, loopLen);
+		} else
+			return new LinearMemoryStream<stereo, false, false, false>(ptr, len, loopOffset, loopLen);
 	}
 }
 
@@ -608,10 +617,11 @@
 AudioInputStream *makeLinearInputStream(byte _flags, const byte *ptr, uint32 len, uint loopOffset, uint loopLen) {
 	const bool is16Bit = (_flags & SoundMixer::FLAG_16BITS) != 0;
 	const bool isUnsigned = (_flags & SoundMixer::FLAG_UNSIGNED) != 0;
+	const bool isLE    = (_flags & SoundMixer::FLAG_LITTLE_ENDIAN) != 0;
 	if (_flags & SoundMixer::FLAG_STEREO) {
-		return makeLinearInputStream<true>(ptr, len, is16Bit, isUnsigned, loopOffset, loopLen);
+		return makeLinearInputStream<true>(ptr, len, is16Bit, isUnsigned, isLE, loopOffset, loopLen);
 	} else {
-		return makeLinearInputStream<false>(ptr, len, is16Bit, isUnsigned, loopOffset, loopLen);
+		return makeLinearInputStream<false>(ptr, len, is16Bit, isUnsigned, isLE, loopOffset, loopLen);
 	}
 }
 

Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- mixer.h	8 Nov 2003 23:05:04 -0000	1.58
+++ mixer.h	16 Dec 2003 02:11:04 -0000	1.59
@@ -55,7 +55,8 @@
 		FLAG_16BITS = 1 << 2,           // sound is 16 bits wide (default: 8bit)
 		FLAG_AUTOFREE = 1 << 3,         // sound buffer is freed automagically at the end of playing
 		FLAG_REVERSE_STEREO = 1 << 4,   // reverse the left and right stereo channel
-		FLAG_LOOP = 1 << 5              // loop the audio
+		FLAG_LOOP = 1 << 5,             // loop the audio
+		FLAG_LITTLE_ENDIAN = 1 << 6		// sample is little endian (default: big endian)
 			
 	};
 





More information about the Scummvm-git-logs mailing list