aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorMax Horn2010-01-09 00:19:13 +0000
committerMax Horn2010-01-09 00:19:13 +0000
commitbe8371fb07936f27934909c4c0eb5184547a2656 (patch)
tree9edc668e3306f3ae87a8b9ed3a4a26a05eea0bdc /sound
parent41eaeaa61d968442bf2055d07e30b0dd4d31d606 (diff)
downloadscummvm-rg350-be8371fb07936f27934909c4c0eb5184547a2656.tar.gz
scummvm-rg350-be8371fb07936f27934909c4c0eb5184547a2656.tar.bz2
scummvm-rg350-be8371fb07936f27934909c4c0eb5184547a2656.zip
Replace AppendableAudioStream by QueuingAudioStream
svn-id: r47189
Diffstat (limited to 'sound')
-rw-r--r--sound/audiostream.cpp165
-rw-r--r--sound/audiostream.h31
2 files changed, 1 insertions, 195 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp
index 6d7ee24738..72f01b35d1 100644
--- a/sound/audiostream.cpp
+++ b/sound/audiostream.cpp
@@ -26,7 +26,6 @@
#include "common/debug.h"
#include "common/endian.h"
#include "common/file.h"
-#include "common/list.h"
#include "common/queue.h"
#include "common/util.h"
@@ -604,171 +603,9 @@ SeekableAudioStream *makeLinearDiskStream(Common::SeekableReadStream *stream, Li
}
-#pragma mark -
-#pragma mark --- Appendable audio stream ---
-#pragma mark -
-
-struct Buffer {
- byte *start;
- byte *end;
-};
-
-/**
- * Wrapped memory stream.
- */
-class BaseAppendableMemoryStream : public AppendableAudioStream {
-protected:
-
- /**
- * A mutex to avoid access problems (causing e.g. corruption of
- * the linked list) in thread aware environments.
- */
- Common::Mutex _mutex;
-
- // List of all queued buffers
- Common::List<Buffer> _bufferQueue;
-
- bool _finalized;
- const int _rate;
- // Position in the front buffer, if any
- byte *_pos;
-
- inline bool eosIntern() const { return _bufferQueue.empty(); };
-public:
- BaseAppendableMemoryStream(int rate);
- ~BaseAppendableMemoryStream();
-
- bool endOfStream() const { return _finalized && eosIntern(); }
- bool endOfData() const { return eosIntern(); }
-
- int getRate() const { return _rate; }
-
- void finish() { _finalized = true; }
-
- void queueBuffer(byte *data, uint32 size);
-};
-
-/**
- * Wrapped memory stream.
- */
-template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
-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) {
-
-}
-
-BaseAppendableMemoryStream::~BaseAppendableMemoryStream() {
- // Clear the queue
- Common::List<Buffer>::iterator iter;
- for (iter = _bufferQueue.begin(); iter != _bufferQueue.end(); ++iter)
- delete[] iter->start;
-}
-
-template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
-int AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buffer, const int numSamples) {
- Common::StackLock lock(_mutex);
- int samples = numSamples;
- while (samples > 0 && !eosIntern()) {
- Buffer buf = *_bufferQueue.begin();
- if (_pos == 0)
- _pos = buf.start;
-
- assert(buf.start <= _pos && _pos <= buf.end);
- const int samplesLeftInCurBuffer = buf.end - _pos;
- if (samplesLeftInCurBuffer == 0) {
- delete[] buf.start;
- _bufferQueue.erase(_bufferQueue.begin());
- _pos = 0;
- continue;
- }
-
- int len = MIN(samples, samplesLeftInCurBuffer / (is16Bit ? 2 : 1));
- samples -= len;
- do {
- *buffer++ = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _pos, isLE);
- _pos += (is16Bit ? 2 : 1);
- } while (--len);
- }
-
- return numSamples - samples;
-}
-
-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);
-
- // Queue the buffer
- Buffer buf = {data, data+size};
- _bufferQueue.push_back(buf);
-
-
-#if 0
- // Output some stats
- uint totalSize = 0;
- Common::List<Buffer>::iterator iter;
- for (iter = _bufferQueue.begin(); iter != _bufferQueue.end(); ++iter)
- totalSize += iter->end - iter->start;
- printf("AppendableMemoryStream::queueBuffer: added a %d byte buf, a total of %d bytes are queued\n",
- size, totalSize);
-#endif
-}
-
-
-#define MAKE_WRAPPED(STEREO, UNSIGNED) \
- if (is16Bit) { \
- if (isLE) \
- return new AppendableMemoryStream<STEREO, true, UNSIGNED, true>(rate); \
- else \
- return new AppendableMemoryStream<STEREO, true, UNSIGNED, false>(rate); \
- } else \
- return new AppendableMemoryStream<STEREO, false, UNSIGNED, false>(rate)
-
-AppendableAudioStream *makeAppendableAudioStream(int rate, byte _flags) {
- const bool isStereo = (_flags & Mixer::FLAG_STEREO) != 0;
- const bool is16Bit = (_flags & Mixer::FLAG_16BITS) != 0;
- const bool isUnsigned = (_flags & Mixer::FLAG_UNSIGNED) != 0;
- const bool isLE = (_flags & Mixer::FLAG_LITTLE_ENDIAN) != 0;
-
- if (isStereo) {
- if (isUnsigned) {
- MAKE_WRAPPED(true, true);
- } else {
- MAKE_WRAPPED(true, false);
- }
- } else {
- if (isUnsigned) {
- MAKE_WRAPPED(false, true);
- } else {
- MAKE_WRAPPED(false, false);
- }
- }
-}
-
-
-
-
#pragma mark -
-#pragma mark --- Appendable audio stream ---
+#pragma mark --- Queueing audio stream ---
#pragma mark -
diff --git a/sound/audiostream.h b/sound/audiostream.h
index 192dc249bf..817cd36f95 100644
--- a/sound/audiostream.h
+++ b/sound/audiostream.h
@@ -289,37 +289,6 @@ struct LinearDiskStreamAudioBlock {
SeekableAudioStream *makeLinearDiskStream(Common::SeekableReadStream *stream, LinearDiskStreamAudioBlock *block,
int numBlocks, int rate, byte flags, bool disposeStream, uint loopStart, uint loopEnd);
-/**
- * An audio stream to which additional data can be appended on-the-fly.
- * Used by SMUSH, iMuseDigital, the Kyrandia 3 VQA player, etc.
- */
-class AppendableAudioStream : public Audio::AudioStream {
-public:
-
- /**
- * Queue another audio data buffer for playback. The stream
- * will playback all queued buffers, in the order they were
- * queued. After all data contained in them has been played,
- * the buffer will be delete[]'d (so make sure to allocate them
- * with new[], not with malloc).
- */
- virtual void queueBuffer(byte *data, uint32 size) = 0;
-
- /**
- * Mark the stream as finished, that is, signal that no further data
- * will be appended to it. Only after this has been done can the
- * AppendableAudioStream ever 'end'
- */
- virtual void finish() = 0;
-};
-
-/**
- * Factory function for an AppendableAudioStream. The rate and flags
- * parameters are analog to those used in makeLinearInputStream.
- */
-AppendableAudioStream *makeAppendableAudioStream(int rate, byte flags);
-
-
class QueuingAudioStream : public Audio::AudioStream {
public: