[Scummvm-cvs-logs] CVS: scummvm/sound audiostream.cpp,1.26,1.27

Max Horn fingolfin at users.sourceforge.net
Mon Aug 4 18:15:02 CEST 2003


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

Modified Files:
	audiostream.cpp 
Log Message:
optimized MP3InputStream::readBuffer (once more, I won't gurantee for correctness although it seems to work fine over here)

Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- audiostream.cpp	5 Aug 2003 00:53:25 -0000	1.26
+++ audiostream.cpp	5 Aug 2003 01:14:27 -0000	1.27
@@ -68,28 +68,33 @@
 		if (stereo)	// Stereo requires even sized data
 			assert(len % 2 == 0);
 	}
-	int readBuffer(int16 *buffer, int numSamples) {
-		int samples = 0;
-		while (samples < numSamples && !eosIntern()) {
-			const int len = MIN(numSamples, (_end - _ptr) / (is16Bit ? 2 : 1));
-			while (samples < len) {
-				*buffer++ = readSample<is16Bit, isUnsigned>(_ptr);
-				_ptr += (is16Bit ? 2 : 1);
-				samples++;
-			}
-			if (_loopPtr && _ptr == _end) {
-				_ptr = _loopPtr;
-				_end = _loopEnd;
-			}
-		}
-		return samples;
-	}
+	int readBuffer(int16 *buffer, int numSamples);
 
 	int16 read()				{ return readIntern(); }
 	bool eos() const			{ return eosIntern(); }
 	bool isStereo() const		{ return stereo; }
 };
 
+template<bool stereo, bool is16Bit, bool isUnsigned>
+int LinearMemoryStream<stereo, is16Bit, isUnsigned>::readBuffer(int16 *buffer, int numSamples) {
+	int samples = 0;
+	while (samples < numSamples && !eosIntern()) {
+		const int len = MIN(numSamples, (_end - _ptr) / (is16Bit ? 2 : 1));
+		while (samples < len) {
+			*buffer++ = readSample<is16Bit, isUnsigned>(_ptr);
+			_ptr += (is16Bit ? 2 : 1);
+			samples++;
+		}
+		// Loop, if looping was specified
+		if (_loopPtr && _ptr == _end) {
+			_ptr = _loopPtr;
+			_end = _loopEnd;
+		}
+	}
+	return samples;
+}
+
+
 
 #pragma mark -
 #pragma mark --- WrappedMemoryStream ---
@@ -149,7 +154,6 @@
 	while (samples < numSamples && !eosIntern()) {
 		const byte *endMarker = (_pos > _end) ? _bufferEnd : _end;
 		const int len = MIN(numSamples, (endMarker - _pos) / (is16Bit ? 2 : 1));
-
 		while (samples < len) {
 			*buffer++ = readSample<is16Bit, isUnsigned>(_pos);
 			_pos += (is16Bit ? 2 : 1);
@@ -386,9 +390,7 @@
 }
 
 inline int16 MP3InputStream::readIntern() {
-	if (_size < 0 || _posInFrame >= _synth.pcm.length) {	// EOF
-		return 0;
-	}
+	assert(!eosIntern());
 
 	int16 sample;
 	if (_isStereo) {
@@ -412,10 +414,30 @@
 }
 
 int MP3InputStream::readBuffer(int16 *buffer, int numSamples) {
-	int samples;
+	int samples = 0;
+#if 1
+	if (_isStereo)
+		assert(_curChannel == 0);
+	while (samples < numSamples && !eosIntern()) {
+		const int len = MIN(numSamples, (int)(_synth.pcm.length - _posInFrame) * (_isStereo ? 2 : 1));
+		while (samples < len) {
+			*buffer++ = (int16)scale_sample(_synth.pcm.samples[0][_posInFrame]);
+			samples++;
+			if (_isStereo) {
+				*buffer++ = (int16)scale_sample(_synth.pcm.samples[1][_posInFrame]);
+				samples++;
+			}
+			_posInFrame++;
+		}
+		if (_posInFrame >= _synth.pcm.length) {
+			refill();
+		}
+	}
+#else
 	for (samples = 0; samples < numSamples && !eosIntern(); samples++) {
 		*buffer++ = readIntern();
 	}
+#endif
 	return samples;
 }
 





More information about the Scummvm-git-logs mailing list