[Scummvm-cvs-logs] CVS: scummvm/sound mixer.cpp,1.47,1.48 mixer.h,1.26,1.27

Max Horn fingolfin at users.sourceforge.net
Sun Jun 22 04:47:11 CEST 2003


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

Modified Files:
	mixer.cpp mixer.h 
Log Message:
Change names of the stream API in the mixer; added endStream method (stop() halts stream immediately; endStream() lets it first finish playing)

Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- mixer.cpp	22 Jun 2003 03:54:43 -0000	1.47
+++ mixer.cpp	22 Jun 2003 11:46:58 -0000	1.48
@@ -73,6 +73,7 @@
 	uint32 _bufferSize;
 	uint32 _rate;
 	byte _flags;
+	bool _finished;
 
 public:
 	ChannelStream(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags, int32 buffer_size);
@@ -83,6 +84,7 @@
 	bool isMusicChannel() {
 		return true;
 	}
+	void finish() { _finished = true; }
 };
 
 #ifdef USE_MAD
@@ -170,18 +172,30 @@
 	_syst->delete_mutex(_mutex);
 }
 
-int SoundMixer::append(int index, void *sound, uint32 size) {
+void SoundMixer::appendStream(int index, void *sound, uint32 size) {
 	_syst->lock_mutex(_mutex);
 
-	Channel *chan = _channels[index];
+	ChannelStream *chan = dynamic_cast<ChannelStream *>(_channels[index]);
 	if (!chan) {
-		error("Trying to stream to a nonexistant streamer : %d", index);
+		error("Trying to append to a nonexistant stream %d", index);
 	} else {
-		dynamic_cast<ChannelStream *>(chan)->append(sound, size);
+		chan->append(sound, size);
+	}
+
+	_syst->unlock_mutex(_mutex);
+}
+
+void SoundMixer::endStream(int index) {
+	_syst->lock_mutex(_mutex);
+
+	ChannelStream *chan = dynamic_cast<ChannelStream *>(_channels[index]);
+	if (!chan) {
+		error("Trying to end a nonexistant streamer : %d", index);
+	} else {
+		chan->finish();
 	}
 
 	_syst->unlock_mutex(_mutex);
-	return 1;
 }
 
 int SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) {
@@ -209,7 +223,7 @@
 	return insertChannel(handle, new ChannelRaw(this, sound, size, rate, flags, id));
 }
 
-int SoundMixer::playStream(void *sound, uint32 size, uint rate, byte flags, int32 buffer_size) {
+int SoundMixer::newStream(void *sound, uint32 size, uint rate, byte flags, int32 buffer_size) {
 	return insertChannel(NULL, new ChannelStream(this, sound, size, rate, flags, buffer_size));
 }
 
@@ -717,6 +731,7 @@
 	_pos = _ptr;
 	_fpPos = 0;
 	_fpSpeed = (1 << 16) * rate / mixer->_outputRate;
+	_finished = false;
 
 	// adjust the magnitude to prevent division error
 	while (size & 0xFFFF0000)
@@ -757,6 +772,13 @@
 	const int16 *vol_tab = _mixer->_volumeTable;
 
 	if (_pos == _endOfData) {
+		// 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();
 		return;
 	}
 

Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- mixer.h	22 Jun 2003 01:55:51 -0000	1.26
+++ mixer.h	22 Jun 2003 11:46:58 -0000	1.27
@@ -86,7 +86,6 @@
 		FLAG_LOOP = 1 << 5              // loop the audio
 	};
 	int playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id = -1);
-	int playStream(void *sound, uint32 size, uint rate, byte flags, int32 buffer_size);
 #ifdef USE_MAD
 	int playMP3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags);
 	int playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration);
@@ -110,8 +109,14 @@
 	/** stop playing a specific sound */
 	void stopID(int id);
 
-	/** append to existing sound */
-	int append(int index, void * sound, uint32 size);
+	/** Start a new stream. */
+	int newStream(void *sound, uint32 size, uint rate, byte flags, int32 buffer_size);
+
+	/** Append to an existing stream. */
+	void appendStream(int index, void * sound, uint32 size);
+
+	/** Mark a stream as finished - it will play all its remaining data, then stop. */
+	void endStream(int index);
 
 	/** Check whether any SFX channel is active.*/
 	bool hasActiveSFXChannel();





More information about the Scummvm-git-logs mailing list