[Scummvm-cvs-logs] CVS: scummvm/sound audiostream.cpp,1.5,1.6 audiostream.h,1.8,1.9

Max Horn fingolfin at users.sourceforge.net
Mon Jul 28 11:02:17 CEST 2003


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

Modified Files:
	audiostream.cpp audiostream.h 
Log Message:
make wrapped stream work (I can hear some music in CoMI now before it segfaults :-)

Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- audiostream.cpp	28 Jul 2003 17:28:29 -0000	1.5
+++ audiostream.cpp	28 Jul 2003 18:01:56 -0000	1.6
@@ -21,6 +21,7 @@
 
 #include "audiostream.h"
 #include "mixer.h"
+#include "common/engine.h"
 
 
 template<bool is16Bit, bool isUnsigned>
@@ -39,7 +40,7 @@
 }
 
 #pragma mark -
-#pragma mark --- WrappedMemoryStream ---
+#pragma mark --- LinearMemoryStream ---
 #pragma mark -
 
 
@@ -75,17 +76,41 @@
 #pragma mark -
 
 
+// Wrapped memory stream, to be used by the ChannelStream class (and possibly others?)
 template<bool stereo, bool is16Bit, bool isUnsigned>
-WrappedMemoryStream<stereo, is16Bit, isUnsigned>::WrappedMemoryStream(const byte *buffer, uint bufferSize)
-	: _bufferStart(buffer), _bufferEnd(buffer+bufferSize), _pos(buffer), _end(buffer) {
+class WrappedMemoryStream : public WrappedAudioInputStream {
+protected:
+	byte *_bufferStart;
+	byte *_bufferEnd;
+	byte *_pos;
+	byte *_end;
+	
+public:
+	WrappedMemoryStream(uint bufferSize);
+	~WrappedMemoryStream() { free(_bufferStart); }
+	int16 read();
+	int size() const;
+	bool isStereo() const {
+		return stereo;
+	}
+
+	void append(const byte *data, uint32 len);
+};
+
+
+template<bool stereo, bool is16Bit, bool isUnsigned>
+WrappedMemoryStream<stereo, is16Bit, isUnsigned>::WrappedMemoryStream(uint bufferSize) {
 	if (stereo)	// Stereo requires an even sized buffer
 		assert(bufferSize % 2 == 0);
+	_bufferStart = (byte *)malloc(bufferSize);
+	_pos = _end = _bufferStart;
+	_bufferEnd = _bufferStart + bufferSize;
 }
 
 template<bool stereo, bool is16Bit, bool isUnsigned>
 int16 WrappedMemoryStream<stereo, is16Bit, isUnsigned>::read() {
 	assert(_pos != _end);
-	int16 val = readSample<is16Bit, isUnsigned>(_ptr);
+	int16 val = readSample<is16Bit, isUnsigned>(_pos);
 	_pos += (is16Bit ? 2 : 1);
 
 	// Wrap around?
@@ -113,8 +138,8 @@
 			debug(2, "WrappedMemoryStream: buffer overflow (A)");
 			return;
 		}
-		memcpy(_end, (byte*)data, size_to_end_of_buffer);
-		memcpy(_bufferStart, (byte *)data + size_to_end_of_buffer, len);
+		memcpy(_end, data, size_to_end_of_buffer);
+		memcpy(_bufferStart, data + size_to_end_of_buffer, len);
 		_end = _bufferStart + len;
 	} else {
 		if ((_end < _pos) && (_end + len >= _pos)) {
@@ -133,7 +158,7 @@
 
 
 template<bool stereo>
-static AudioInputStream *makeInputStream(const byte *ptr, uint32 len, bool isUnsigned, bool is16Bit) {
+static AudioInputStream *makeLinearInputStream(const byte *ptr, uint32 len, bool isUnsigned, bool is16Bit) {
 	if (isUnsigned) {
 		if (is16Bit)
 			return new LinearMemoryStream<stereo, true, true>(ptr, len);
@@ -148,9 +173,34 @@
 }
 
 
-AudioInputStream *makeInputStream(byte _flags, const byte *ptr, uint32 len) {
-	if (_flags & SoundMixer::FLAG_STEREO)
-		return makeInputStream<true>(ptr, len, _flags & SoundMixer::FLAG_UNSIGNED, _flags & SoundMixer::FLAG_16BITS);
-	else
-		return makeInputStream<false>(ptr, len, _flags & SoundMixer::FLAG_UNSIGNED, _flags & SoundMixer::FLAG_16BITS);
+template<bool stereo>
+static WrappedAudioInputStream *makeWrappedInputStream(uint32 len, bool isUnsigned, bool is16Bit) {
+	if (isUnsigned) {
+		if (is16Bit)
+			return new WrappedMemoryStream<stereo, true, true>(len);
+		else
+			return new WrappedMemoryStream<stereo, false, true>(len);
+	} else {
+		if (is16Bit)
+			return new WrappedMemoryStream<stereo, true, false>(len);
+		else
+			return new WrappedMemoryStream<stereo, false, false>(len);
+	}
+}
+
+
+AudioInputStream *makeLinearInputStream(byte _flags, const byte *ptr, uint32 len) {
+	if (_flags & SoundMixer::FLAG_STEREO) {
+		return makeLinearInputStream<true>(ptr, len, _flags & SoundMixer::FLAG_UNSIGNED, _flags & SoundMixer::FLAG_16BITS);
+	} else {
+		return makeLinearInputStream<false>(ptr, len, _flags & SoundMixer::FLAG_UNSIGNED, _flags & SoundMixer::FLAG_16BITS);
+	}
+}
+
+WrappedAudioInputStream *makeWrappedInputStream(byte _flags, uint32 len) {
+	if (_flags & SoundMixer::FLAG_STEREO) {
+		return makeWrappedInputStream<true>(len, _flags & SoundMixer::FLAG_UNSIGNED, _flags & SoundMixer::FLAG_16BITS);
+	} else {
+		return makeWrappedInputStream<false>(len, _flags & SoundMixer::FLAG_UNSIGNED, _flags & SoundMixer::FLAG_16BITS);
+	}
 }

Index: audiostream.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- audiostream.h	28 Jul 2003 17:28:29 -0000	1.8
+++ audiostream.h	28 Jul 2003 18:01:56 -0000	1.9
@@ -36,6 +36,8 @@
  */
 class AudioInputStream {
 public:
+	virtual ~AudioInputStream() {}
+
 	virtual int16 read() = 0;
 	virtual int size() const = 0;
 	virtual bool isStereo() const = 0;
@@ -43,6 +45,11 @@
 	bool eof() const { return size() <= 0; }
 };
 
+class WrappedAudioInputStream : public AudioInputStream {
+public:
+	virtual void append(const byte *data, uint32 len) = 0;
+};
+
 class ZeroInputStream : public AudioInputStream {
 protected:
 	int _len;
@@ -53,24 +60,7 @@
 	bool isStereo() const { return false; }
 };
 
-// Wrapped memory stream, to be used by the ChannelStream class (and possibly others?)
-template<bool stereo, bool is16Bit, bool isUnsigned>
-class WrappedMemoryStream : public AudioInputStream {
-protected:
-	byte *_bufferStart;
-	byte *_bufferEnd;
-	byte *_pos;
-	byte *_end;
-	
-public:
-	WrappedMemoryStream(const byte *buffer, uint bufferSize);
-	int16 read();
-	int size() const;
-
-	void append(const byte *data, uint32 len);
-};
-
-
-AudioInputStream *makeInputStream(byte _flags, const byte *ptr, uint32 len);
+AudioInputStream *makeLinearInputStream(byte _flags, const byte *ptr, uint32 len);
+WrappedAudioInputStream *makeWrappedInputStream(byte _flags, uint32 len);
 
 #endif





More information about the Scummvm-git-logs mailing list