diff options
author | Max Horn | 2008-11-17 11:09:23 +0000 |
---|---|---|
committer | Max Horn | 2008-11-17 11:09:23 +0000 |
commit | 1067a2ec7786a61ad9cc1f69ec1d368a53ed75fa (patch) | |
tree | 06cb2ff9a9b218e62747c786d3b41f8e71a456fe /sound | |
parent | be0f709be952bbae25d4cca98ab5cf218647b1a7 (diff) | |
download | scummvm-rg350-1067a2ec7786a61ad9cc1f69ec1d368a53ed75fa.tar.gz scummvm-rg350-1067a2ec7786a61ad9cc1f69ec1d368a53ed75fa.tar.bz2 scummvm-rg350-1067a2ec7786a61ad9cc1f69ec1d368a53ed75fa.zip |
Factoring shared code of template classes into a shared base class saves another 4-7kb code size
svn-id: r35104
Diffstat (limited to 'sound')
-rw-r--r-- | sound/audiostream.cpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp index 6bc978e575..4c10bfe1a3 100644 --- a/sound/audiostream.cpp +++ b/sound/audiostream.cpp @@ -247,8 +247,7 @@ struct Buffer { /** * 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 @@ protected: 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 @@ int AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 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); |