[Scummvm-cvs-logs] CVS: scummvm/sound mixer.cpp,1.114,1.115 mixer.h,1.46,1.47

Torbj?rn Andersson eriktorbjorn at users.sourceforge.net
Tue Sep 2 06:49:17 CEST 2003


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

Modified Files:
	mixer.cpp mixer.h 
Log Message:
Added per-channel pausing. Maybe I should have named the pauseChannel()
function simply pause() to be consistent with stop(), but there already is
a pause() function and I don't want to have two functions with the same
name doing different things. (The current pause() function pauses all
channels.)


Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.114
retrieving revision 1.115
diff -u -d -r1.114 -r1.115
--- mixer.cpp	1 Sep 2003 14:02:45 -0000	1.114
+++ mixer.cpp	2 Sep 2003 13:48:20 -0000	1.115
@@ -46,17 +46,24 @@
 	AudioInputStream *_input;
 	byte _volume;
 	int8 _pan;
+	bool _paused;
 
 public:
 	int _id;
 
 	Channel(SoundMixer *mixer, PlayingSoundHandle *handle)
-		: _mixer(mixer), _handle(handle), _converter(0), _input(0), _id(-1) {
+		: _mixer(mixer), _handle(handle), _converter(0), _input(0), _id(-1), _paused(false) {
 		assert(mixer);
 	}
 	virtual ~Channel();
 	void destroy();
 	virtual void mix(int16 *data, uint len);
+	virtual void pause(bool paused) {
+		_paused = paused;
+	}
+	virtual bool isPaused() {
+		return _paused;
+	}
 	virtual void setChannelVolume(const byte volume) {
 		_volume = volume;
 	}
@@ -271,7 +278,7 @@
 	if (!_paused && !_channelsPaused) {
 		// now mix all channels
 		for (int i = 0; i != NUM_CHANNELS; i++)
-			if (_channels[i])
+			if (_channels[i] && !_channels[i]->isPaused())
 				_channels[i]->mix(buf, len);
 	}
 }
@@ -381,6 +388,45 @@
 
 void SoundMixer::pauseChannels(bool paused) {
 	_channelsPaused = paused;
+}
+
+void SoundMixer::pauseChannel(int index, bool paused) {
+	if ((index < 0) || (index >= NUM_CHANNELS)) {
+		warning("soundMixer::pauseChannel has invalid index %d", index);
+		return;
+	}
+
+	StackLock lock(_mutex);
+	if (_channels[index])
+		_channels[index]->pause(paused);
+}
+
+void SoundMixer::pauseID(int id, bool paused) {
+	StackLock lock(_mutex);
+	for (int i = 0; i != NUM_CHANNELS; i++) {
+		if (_channels[i] != NULL && _channels[i]->_id == id) {
+			_channels[i]->pause(paused);
+			return;
+		}
+	}
+}
+
+void SoundMixer::pauseHandle(PlayingSoundHandle handle, bool pause) {
+	StackLock lock(_mutex);
+
+	// Simply ignore pause/unpause requests for handles of sound that alreayd terminated
+	if (handle == 0)
+		return;
+
+	int index = handle - 1;
+
+	if ((index < 0) || (index >= NUM_CHANNELS)) {
+		warning("soundMixer::pauseHandle has invalid index %d", index);
+		return;
+	}
+
+	if (_channels[index])
+		_channels[index]->pause(pause);
 }
 
 bool SoundMixer::hasActiveSFXChannel() {

Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- mixer.h	1 Sep 2003 14:02:45 -0000	1.46
+++ mixer.h	2 Sep 2003 13:48:20 -0000	1.47
@@ -107,6 +107,15 @@
 	/** stop playing the channel for the given handle */
 	void stopHandle(PlayingSoundHandle handle);
 
+	/** pause/unpause the given channel */
+	void pauseChannel(int index, bool paused);
+
+	/** pause/unpause the sound with the given ID */
+	void pauseID(int id, bool paused);
+
+	/** pause/unpause the channel for the given handle */
+	void pauseHandle(PlayingSoundHandle handle, bool paused);
+
 	/** changing the channel volume for the given handle (0 - 255) */
 	void setChannelVolume(PlayingSoundHandle handle, byte volume);
 





More information about the Scummvm-git-logs mailing list