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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Mon Nov 17 12:09:23 CET 2008


Revision: 35104
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35104&view=rev
Author:   fingolfin
Date:     2008-11-17 11:09:23 +0000 (Mon, 17 Nov 2008)

Log Message:
-----------
Factoring shared code of template classes into a shared base class saves another 4-7kb code size

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

Modified: scummvm/trunk/sound/audiostream.cpp
===================================================================
--- scummvm/trunk/sound/audiostream.cpp	2008-11-17 11:07:04 UTC (rev 35103)
+++ scummvm/trunk/sound/audiostream.cpp	2008-11-17 11:09:23 UTC (rev 35104)
@@ -247,8 +247,7 @@
 /**
  * Wrapped memory stream.
  */
-template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
-class AppendableMemoryStream : public AppendableAudioStream {
+class BaseAppendableMemoryStream : public AppendableAudioStream {
 protected:
 
 	// A mutex to avoid access problems (causing e.g. corruption of
@@ -269,30 +268,40 @@
 
 	inline bool eosIntern() const { return _bufferQueue.empty(); };
 public:
-	AppendableMemoryStream(int rate);
-	~AppendableMemoryStream();
-	int readBuffer(int16 *buffer, const int numSamples);
+	BaseAppendableMemoryStream(int rate);
+	~BaseAppendableMemoryStream();
 
-	bool isStereo() const		{ return stereo; }
 	bool endOfStream() const	{ return _finalized && eosIntern(); }
 	bool endOfData() const		{ return eosIntern(); }
 
 	int getRate() const			{ return _rate; }
 
+	void finish()				{ _finalized = true; }
+
 	int32 getTotalPlayTime() const { return _playTime; }
 
 	void queueBuffer(byte *data, uint32 size);
-	void finish()				{ _finalized = true; }
 };
 
+/**
+ * Wrapped memory stream.
+ */
 template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
-AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::AppendableMemoryStream(int rate)
+class AppendableMemoryStream : public BaseAppendableMemoryStream {
+public:
+	AppendableMemoryStream(int rate) : BaseAppendableMemoryStream(rate) {}
+
+	bool isStereo() const		{ return stereo; }
+
+	int readBuffer(int16 *buffer, const int numSamples);
+};
+
+BaseAppendableMemoryStream::BaseAppendableMemoryStream(int rate)
  : _finalized(false), _rate(rate), _pos(0), _playTime(0), _playSamp(0) {
 
 }
 
-template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
-AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::~AppendableMemoryStream() {
+BaseAppendableMemoryStream::~BaseAppendableMemoryStream() {
 	// Clear the queue
 	Common::List<Buffer>::iterator iter;
 	for (iter = _bufferQueue.begin(); iter != _bufferQueue.end(); ++iter)
@@ -336,17 +345,17 @@
 	return written;
 }
 
-template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
-void AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::queueBuffer(byte *data, uint32 size) {
+void BaseAppendableMemoryStream::queueBuffer(byte *data, uint32 size) {
 	Common::StackLock lock(_mutex);
 
+/*
 	// Verify the buffer size is sane
 	if (is16Bit && stereo) {
 		assert((size & 3) == 0);
 	} else if (is16Bit || stereo) {
 		assert((size & 1) == 0);
 	}
-
+*/
 	// Verify that the stream has not yet been finalized (by a call to finish())
 	assert(!_finalized);
 


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