[Scummvm-cvs-logs] CVS: scummvm/sound audiostream.cpp,1.43,1.44 audiostream.h,1.21,1.22 mixer.cpp,1.133,1.134

Max Horn fingolfin at users.sourceforge.net
Tue Dec 16 17:51:04 CET 2003


Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1:/tmp/cvs-serv25708

Modified Files:
	audiostream.cpp audiostream.h mixer.cpp 
Log Message:
changed the way 'streams' are handled: the finalization logic is now in the WrappedAudioInputStream; this allows further streamlining of the channel/mixer code (can you already guess what I am working towards? :-)

Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.cpp,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- audiostream.cpp	17 Dec 2003 01:32:00 -0000	1.43
+++ audiostream.cpp	17 Dec 2003 01:50:50 -0000	1.44
@@ -118,6 +118,7 @@
 	byte *_bufferEnd;
 	byte *_pos;
 	byte *_end;
+	bool _finalized;
 
 	inline bool eosIntern() const { return _end == _pos; };
 public:
@@ -126,10 +127,11 @@
 	int readBuffer(int16 *buffer, const int numSamples);
 
 	int16 read();
-	bool eos() const			{ return eosIntern(); }
+	bool eos() const			{ return _finalized; }
 	bool isStereo() const		{ return stereo; }
 
 	void append(const byte *data, uint32 len);
+	void finish()				{ _finalized = true; }
 };
 
 
@@ -145,6 +147,8 @@
 	_bufferStart = (byte *)malloc(bufferSize);
 	_pos = _end = _bufferStart;
 	_bufferEnd = _bufferStart + bufferSize;
+	
+	_finalized = false;
 }
 
 template<bool stereo, bool is16Bit, bool isUnsigned>
@@ -189,6 +193,9 @@
 		assert((len & 3) == 0);
 	else if (is16Bit || stereo)
 		assert((len & 1) == 0);
+	
+	// Verify the stream has not been finalized (by a call to finish()) yet
+	assert(!_finalized);
 
 	if (_end + len > _bufferEnd) {
 		// Wrap-around case

Index: audiostream.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- audiostream.h	7 Nov 2003 09:38:06 -0000	1.21
+++ audiostream.h	17 Dec 2003 01:50:50 -0000	1.22
@@ -83,6 +83,7 @@
 class WrappedAudioInputStream : public AudioInputStream {
 public:
 	virtual void append(const byte *data, uint32 len) = 0;
+	virtual void finish() = 0;
 };
 
 class ZeroInputStream : public AudioInputStream {

Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.133
retrieving revision 1.134
diff -u -d -r1.133 -r1.134
--- mixer.cpp	17 Dec 2003 01:32:00 -0000	1.133
+++ mixer.cpp	17 Dec 2003 01:50:50 -0000	1.134
@@ -88,13 +88,12 @@
 };
 
 class ChannelStream : public Channel {
-	bool _finished;
 public:
 	ChannelStream(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, uint32 buffer_size, byte volume, int8 pan);
-	void mix(int16 *data, uint len);
 	void append(void *sound, uint32 size);
 	bool isMusicChannel() const		{ return true; }
-	void finish()					{ _finished = true; }
+
+	void finish();
 };
 
 #ifdef USE_MAD
@@ -523,11 +522,11 @@
 		_input = makeLinearInputStream(flags, _ptr, size, 0, 0);
 	}
 
-	// Get a rate converter instance
-	_converter = makeRateConverter(rate, mixer->getOutputRate(), _input->isStereo(), (flags & SoundMixer::FLAG_REVERSE_STEREO) != 0);
-
 	if (!(flags & SoundMixer::FLAG_AUTOFREE))
 		_ptr = 0;
+
+	// Get a rate converter instance
+	_converter = makeRateConverter(rate, mixer->getOutputRate(), _input->isStereo(), (flags & SoundMixer::FLAG_REVERSE_STEREO) != 0);
 }
 
 ChannelRaw::~ChannelRaw() {
@@ -544,35 +543,18 @@
 	_input = makeWrappedInputStream(flags, buffer_size);
 	
 	// Append the initial data
-	((WrappedAudioInputStream *)_input)->append((const byte *)sound, size);
+	append(sound, size);
 
 	// Get a rate converter instance
 	_converter = makeRateConverter(rate, mixer->getOutputRate(), _input->isStereo(), (flags & SoundMixer::FLAG_REVERSE_STEREO) != 0);
+}
 
-	_finished = false;
+void ChannelStream::finish() {
+	((WrappedAudioInputStream *)_input)->finish();
 }
 
 void ChannelStream::append(void *data, uint32 len) {
 	((WrappedAudioInputStream *)_input)->append((const byte *)data, len);
-}
-
-void ChannelStream::mix(int16 *data, uint len) {
-	assert(_input);
-	if (_input->eos()) {
-		// TODO: call drain method
-
-		// Normally, the stream stays around even if all its data is used up.
-		// This is in case more data is streamed into it. To make the stream
-		// go away, one can either stop() it (which takes effect immediately,
-		// ignoring any remaining sound data), or finish() it, which means
-		// it will finish playing before it terminates itself.
-		if (_finished) {
-			destroy();
-		}
-	} else {
-		// Invoke the parent implementation.
-		Channel::mix(data, len);
-	}
 }
 
 #ifdef USE_MAD





More information about the Scummvm-git-logs mailing list