[Scummvm-cvs-logs] CVS: scummvm/sound audiostream.cpp,1.56,1.57 audiostream.h,1.32,1.33

Pawel Kolodziejski aquadran at users.sourceforge.net
Mon Apr 12 23:12:01 CEST 2004


Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11488

Modified Files:
	audiostream.cpp audiostream.h 
Log Message:
added CustomProcInputStream

Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.cpp,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- audiostream.cpp	22 Feb 2004 14:11:10 -0000	1.56
+++ audiostream.cpp	13 Apr 2004 05:57:52 -0000	1.57
@@ -336,6 +336,34 @@
 };
 #endif
 
+CustomProcInputStream::CustomProcInputStream(int rate, byte flags, CustomInputProc proc, void *refCon) {
+	_refCon = refCon;
+	_refStream = this;
+	_rate = rate;
+	_proc = proc;
+	_finished = false;
+	_isStereo   = (flags & SoundMixer::FLAG_STEREO) != 0;
+	_is16Bit    = (flags & SoundMixer::FLAG_16BITS) != 0;
+	_isUnsigned = (flags & SoundMixer::FLAG_UNSIGNED) != 0;
+	assert(!(flags & SoundMixer::FLAG_LITTLE_ENDIAN));
+	assert(!(flags & SoundMixer::FLAG_AUTOFREE));
+}
+
+int CustomProcInputStream::readBuffer(int16 *buffer, const int numSamples) {
+	int numBytes = numSamples;
+	numBytes *= (_is16Bit ? 2 : 1);
+	byte *tmpBuffer = (byte *)malloc(numBytes);
+	int gotSamples = (_proc)(_refCon, _refStream, tmpBuffer, numBytes) / (_is16Bit ? 2 : 1);
+
+	const byte *ptr = tmpBuffer;
+	for (int samples = 0; samples < gotSamples; samples++) {
+		*buffer++ = READSAMPLE(_is16Bit, _isUnsigned, ptr);
+		ptr += (_is16Bit ? 2 : 1);
+	}
+
+	free(tmpBuffer);
+	return gotSamples;
+}
 
 #pragma mark -
 #pragma mark --- Input stream factories ---

Index: audiostream.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- audiostream.h	22 Feb 2004 14:11:11 -0000	1.32
+++ audiostream.h	13 Apr 2004 05:57:52 -0000	1.33
@@ -113,6 +113,31 @@
 	int getRate() const { return -1; }
 };
 
+class CustomProcInputStream : public AudioStream {
+public:
+	typedef int (*CustomInputProc)(void *refCon, CustomProcInputStream *stream, byte *data, uint len);
+
+private:
+	bool _isStereo;
+	bool _is16Bit;
+	bool _isUnsigned;
+	int _rate;
+	CustomInputProc _proc;
+	CustomProcInputStream *_refStream;
+	void *_refCon;
+	bool _finished;
+
+public:
+
+	CustomProcInputStream(int rate, byte flags, CustomInputProc proc, void *refCon);
+
+	int readBuffer(int16 *buffer, const int numSamples);
+	bool isStereo() const { return _isStereo; }
+	bool endOfData() const { return _finished; }
+	void finish() { _finished = true; }
+	int getRate() const { return _rate; }
+};
+
 AudioStream *makeLinearInputStream(int rate, byte _flags, const byte *ptr, uint32 len, uint loopOffset, uint loopLen);
 AppendableAudioStream *makeAppendableAudioStream(int rate, byte _flags, uint32 len);
 





More information about the Scummvm-git-logs mailing list