[Scummvm-cvs-logs] SF.net SVN: scummvm: [25832] scummvm/trunk/sound/flac.cpp

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Feb 24 22:25:47 CET 2007


Revision: 25832
          http://scummvm.svn.sourceforge.net/scummvm/?rev=25832&view=rev
Author:   fingolfin
Date:     2007-02-24 13:25:46 -0800 (Sat, 24 Feb 2007)

Log Message:
-----------
Replaced variable buffer in the FLAC code by a fixed on

Modified Paths:
--------------
    scummvm/trunk/sound/flac.cpp

Modified: scummvm/trunk/sound/flac.cpp
===================================================================
--- scummvm/trunk/sound/flac.cpp	2007-02-24 21:13:30 UTC (rev 25831)
+++ scummvm/trunk/sound/flac.cpp	2007-02-24 21:25:46 UTC (rev 25832)
@@ -105,10 +105,15 @@
 	typedef int16 SampleType;
 	enum { BUFTYPE_BITS = 16 };
 
+	enum {
+		// Maximal buffer size. According to the FLAC format specification, the  block size is
+		// a 16 bit value (in fact it seems the maximal block size is 32768, but we play it safe).
+		BUFFER_SIZE = 65536
+	};
+	
 	struct {
-		SampleType *bufData;
+		SampleType bufData[BUFFER_SIZE];
 		SampleType *bufReadPos;
-		uint bufSize;
 		uint bufFill;
 	} _sampleCache;
 
@@ -191,10 +196,8 @@
 
 // TODO: Implement looping support
 
-	_sampleCache.bufData = NULL;
 	_sampleCache.bufReadPos = NULL;
 	_sampleCache.bufFill = 0;
-	_sampleCache.bufSize = 0;
 
 	_methodConvertBuffers = &FlacInputStream::convertBuffersGeneric;
 
@@ -250,8 +253,6 @@
 		::FLAC__stream_decoder_delete(_decoder);
 #endif
 	}
-	delete[] _sampleCache.bufData;
-
 	if (_disposeAfterUse)
 		delete _inStream;
 }
@@ -316,7 +317,6 @@
 	// If there is still data in our buffer from the last time around,
 	// copy that first.
 	if (_sampleCache.bufFill > 0) {
-		assert(_sampleCache.bufData != NULL && _sampleCache.bufReadPos != NULL && _sampleCache.bufSize > 0);
 		assert(_sampleCache.bufReadPos >= _sampleCache.bufData);
 		assert(_sampleCache.bufFill % numChannels == 0);
 
@@ -390,26 +390,6 @@
 #endif
 }
 
-bool FlacInputStream::allocateBuffer(uint minSamples) {
-	uint allocateSize = minSamples / getChannels();
-	// TODO: insert funky algorithm for optimum buffersize here
-	allocateSize = MIN(_streaminfo.max_blocksize, MAX(_streaminfo.min_blocksize, allocateSize));
-	allocateSize += 8 - (allocateSize % 8); // make sure it's a nice even amount
-	allocateSize *= getChannels();
-
-	_lastSampleWritten = _lastSampleWritten && _sampleCache.bufFill == 0;
-	_sampleCache.bufFill = 0;
-	_sampleCache.bufSize = 0;
-	delete[] _sampleCache.bufData;
-
-	_sampleCache.bufData = new SampleType[allocateSize];
-	if (_sampleCache.bufData != NULL) {
-		_sampleCache.bufSize = allocateSize;
-		return true;
-	}
-	return false;
-}
-
 void FlacInputStream::setBestConvertBufferMethod() {
 	PFCONVERTBUFFERS tempMethod = &FlacInputStream::convertBuffersGeneric;
 
@@ -624,11 +604,11 @@
 		_outBuffer += copySamples;
 	}
 
-	// checking if Buffer fits
-	if (_sampleCache.bufSize < numSamples) {
-		if (!allocateBuffer(numSamples))
-			return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
-	} // optional check if buffer is wasting too much memory ?
+	// verify that the buffer fits
+	if (numSamples > BUFFER_SIZE) {
+		warning("FlacInputStream: write buffer is too small: %d bytes available, %d bytes needed", BUFFER_SIZE,numSamples); 
+		return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
+	}
 
 	(*_methodConvertBuffers)(_sampleCache.bufData, inChannels, numSamples, numChannels, numBits);
 


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