[Scummvm-cvs-logs] SF.net SVN: scummvm:[47189] scummvm/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Jan 9 01:19:13 CET 2010


Revision: 47189
          http://scummvm.svn.sourceforge.net/scummvm/?rev=47189&view=rev
Author:   fingolfin
Date:     2010-01-09 00:19:13 +0000 (Sat, 09 Jan 2010)

Log Message:
-----------
Replace AppendableAudioStream by QueuingAudioStream

Modified Paths:
--------------
    scummvm/trunk/engines/groovie/player.h
    scummvm/trunk/engines/groovie/roq.cpp
    scummvm/trunk/engines/groovie/vdx.cpp
    scummvm/trunk/engines/kyra/vqa.cpp
    scummvm/trunk/engines/kyra/vqa.h
    scummvm/trunk/engines/kyra/wsamovie.h
    scummvm/trunk/sound/audiostream.cpp
    scummvm/trunk/sound/audiostream.h

Modified: scummvm/trunk/engines/groovie/player.h
===================================================================
--- scummvm/trunk/engines/groovie/player.h	2010-01-08 23:09:30 UTC (rev 47188)
+++ scummvm/trunk/engines/groovie/player.h	2010-01-09 00:19:13 UTC (rev 47189)
@@ -52,7 +52,7 @@
 	OSystem *_syst;
 	Common::SeekableReadStream *_file;
 	uint16 _flags;
-	Audio::AppendableAudioStream *_audioStream;
+	Audio::QueuingAudioStream *_audioStream;
 
 private:
 	// Synchronization stuff

Modified: scummvm/trunk/engines/groovie/roq.cpp
===================================================================
--- scummvm/trunk/engines/groovie/roq.cpp	2010-01-08 23:09:30 UTC (rev 47188)
+++ scummvm/trunk/engines/groovie/roq.cpp	2010-01-09 00:19:13 UTC (rev 47189)
@@ -516,11 +516,7 @@
 
 	// Initialize the audio stream if needed
 	if (!_audioStream) {
-		byte flags = Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_AUTOFREE;
-#ifdef SCUMM_LITTLE_ENDIAN
-		flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN;
-#endif
-		_audioStream = Audio::makeAppendableAudioStream(22050, flags);
+		_audioStream = Audio::makeQueuingAudioStream(22050, false);
 		Audio::SoundHandle sound_handle;
 		g_system->getMixer()->playInputStream(Audio::Mixer::kPlainSoundType, &sound_handle, _audioStream);
 	}
@@ -544,7 +540,11 @@
 	}
 
 	// Queue the read buffer
-	_audioStream->queueBuffer((byte *)buffer, blockHeader.size * 2);
+	byte flags = Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_AUTOFREE;
+#ifdef SCUMM_LITTLE_ENDIAN
+	flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN;
+#endif
+	_audioStream->queueBuffer((byte *)buffer, blockHeader.size * 2, flags);
 
 	return true;
 }
@@ -559,11 +559,7 @@
 
 	// Initialize the audio stream if needed
 	if (!_audioStream) {
-		byte flags = Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_AUTOFREE | Audio::Mixer::FLAG_STEREO;
-#ifdef SCUMM_LITTLE_ENDIAN
-		flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN;
-#endif
-		_audioStream = Audio::makeAppendableAudioStream(22050, flags);
+		_audioStream = Audio::makeQueuingAudioStream(22050, true);
 		Audio::SoundHandle sound_handle;
 		g_system->getMixer()->playInputStream(Audio::Mixer::kPlainSoundType, &sound_handle, _audioStream);
 	}
@@ -600,7 +596,11 @@
 	}
 
 	// Queue the read buffer
-	_audioStream->queueBuffer((byte *)buffer, blockHeader.size * 2);
+	byte flags = Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_AUTOFREE | Audio::Mixer::FLAG_STEREO;
+#ifdef SCUMM_LITTLE_ENDIAN
+	flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN;
+#endif
+	_audioStream->queueBuffer((byte *)buffer, blockHeader.size * 2, flags);
 
 	return true;
 }

Modified: scummvm/trunk/engines/groovie/vdx.cpp
===================================================================
--- scummvm/trunk/engines/groovie/vdx.cpp	2010-01-08 23:09:30 UTC (rev 47188)
+++ scummvm/trunk/engines/groovie/vdx.cpp	2010-01-09 00:19:13 UTC (rev 47189)
@@ -498,7 +498,7 @@
 
 void VDXPlayer::chunkSound(Common::ReadStream *in) {
 	if (!_audioStream) {
-		_audioStream = Audio::makeAppendableAudioStream(22050, Audio::Mixer::FLAG_UNSIGNED | Audio::Mixer::FLAG_AUTOFREE);
+		_audioStream = Audio::makeQueuingAudioStream(22050, false);
 		Audio::SoundHandle sound_handle;
 		g_system->getMixer()->playInputStream(Audio::Mixer::kPlainSoundType, &sound_handle, _audioStream);
 	}
@@ -506,7 +506,7 @@
 	byte *data = new byte[60000];
 	int chunksize = in->read(data, 60000);
 	if (!Common::isDebugChannelEnabled(kGroovieDebugFast)) {
-		_audioStream->queueBuffer(data, chunksize);
+		_audioStream->queueBuffer(data, chunksize, Audio::Mixer::FLAG_UNSIGNED | Audio::Mixer::FLAG_AUTOFREE);
 	}
 }
 

Modified: scummvm/trunk/engines/kyra/vqa.cpp
===================================================================
--- scummvm/trunk/engines/kyra/vqa.cpp	2010-01-08 23:09:30 UTC (rev 47188)
+++ scummvm/trunk/engines/kyra/vqa.cpp	2010-01-09 00:19:13 UTC (rev 47189)
@@ -292,7 +292,7 @@
 				assert(_header.bits == 8);
 				assert(_header.channels == 1);
 
-				_stream = Audio::makeAppendableAudioStream(_header.freq, Audio::Mixer::FLAG_UNSIGNED);
+				_stream = Audio::makeQueuingAudioStream(_header.freq, false);
 			} else {
 				_stream = NULL;
 			}
@@ -422,7 +422,7 @@
 			inbuf = new byte[size];
 			_file->read(inbuf, size);
 			assert(_stream);
-			_stream->queueBuffer(inbuf, size);
+			_stream->queueBuffer(inbuf, size, Audio::Mixer::FLAG_UNSIGNED);
 			break;
 
 		case MKID_BE('SND1'):	// Compressed sound, almost like AUD
@@ -435,12 +435,12 @@
 
 			if (insize == outsize) {
 				assert(_stream);
-				_stream->queueBuffer(inbuf, insize);
+				_stream->queueBuffer(inbuf, insize, Audio::Mixer::FLAG_UNSIGNED);
 			} else {
 				outbuf = new byte[outsize];
 				decodeSND1(inbuf, insize, outbuf, outsize);
 				assert(_stream);
-				_stream->queueBuffer(outbuf, outsize);
+				_stream->queueBuffer(outbuf, outsize, Audio::Mixer::FLAG_UNSIGNED);
 				delete[] inbuf;
 			}
 			break;
@@ -612,7 +612,7 @@
 			case MKID_BE('SND0'):	// Uncompressed sound
 				inbuf = new byte[size];
 				_file->read(inbuf, size);
-				_stream->queueBuffer(inbuf, size);
+				_stream->queueBuffer(inbuf, size, Audio::Mixer::FLAG_UNSIGNED);
 				break;
 
 			case MKID_BE('SND1'):	// Compressed sound
@@ -623,11 +623,11 @@
 				_file->read(inbuf, insize);
 
 				if (insize == outsize) {
-					_stream->queueBuffer(inbuf, insize);
+					_stream->queueBuffer(inbuf, insize, Audio::Mixer::FLAG_UNSIGNED);
 				} else {
 					outbuf = new byte[outsize];
 					decodeSND1(inbuf, insize, outbuf, outsize);
-					_stream->queueBuffer(outbuf, outsize);
+					_stream->queueBuffer(outbuf, outsize, Audio::Mixer::FLAG_UNSIGNED);
 					delete[] inbuf;
 				}
 				break;

Modified: scummvm/trunk/engines/kyra/vqa.h
===================================================================
--- scummvm/trunk/engines/kyra/vqa.h	2010-01-08 23:09:30 UTC (rev 47188)
+++ scummvm/trunk/engines/kyra/vqa.h	2010-01-09 00:19:13 UTC (rev 47189)
@@ -33,7 +33,7 @@
 class OSystem;
 
 namespace Audio {
-class AppendableAudioStream;
+class QueuingAudioStream;
 } // End of namespace Audio
 
 namespace Common {
@@ -127,7 +127,7 @@
 
 	byte *_frame;
 
-	Audio::AppendableAudioStream *_stream;
+	Audio::QueuingAudioStream *_stream;
 	Audio::SoundHandle _sound;
 
 	uint32 readTag();

Modified: scummvm/trunk/engines/kyra/wsamovie.h
===================================================================
--- scummvm/trunk/engines/kyra/wsamovie.h	2010-01-08 23:09:30 UTC (rev 47188)
+++ scummvm/trunk/engines/kyra/wsamovie.h	2010-01-09 00:19:13 UTC (rev 47189)
@@ -26,12 +26,8 @@
 #ifndef KYRA_WSAMOVIE_H
 #define KYRA_WSAMOVIE_H
 
-namespace Audio {
-class AppendableAudioStream;
-class SoundHandle;
-} // End of namespace Audio
-
 namespace Kyra {
+
 class KyraEngine_v1;
 class Screen_v2;
 class Palette;

Modified: scummvm/trunk/sound/audiostream.cpp
===================================================================
--- scummvm/trunk/sound/audiostream.cpp	2010-01-08 23:09:30 UTC (rev 47188)
+++ scummvm/trunk/sound/audiostream.cpp	2010-01-09 00:19:13 UTC (rev 47189)
@@ -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 @@
 }
 
 
-#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 -
 
 

Modified: scummvm/trunk/sound/audiostream.h
===================================================================
--- scummvm/trunk/sound/audiostream.h	2010-01-08 23:09:30 UTC (rev 47188)
+++ scummvm/trunk/sound/audiostream.h	2010-01-09 00:19:13 UTC (rev 47189)
@@ -289,37 +289,6 @@
 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:
 


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