[Scummvm-cvs-logs] CVS: scummvm/sound mixer.cpp,1.172,1.173 mixer.h,1.84,1.85

Jerome Fisher kingguppy at users.sourceforge.net
Sun Nov 28 14:16:11 CET 2004


Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9969

Modified Files:
	mixer.cpp mixer.h 
Log Message:
Added a "permanent" field to Channels, which simply prevents them from being deleted during stopAll().
I hope this doesn't step on anyone's toes; it was quite urgent, since loading a saved game stopped MT-32 emulation audio forever.


Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.172
retrieving revision 1.173
diff -u -d -r1.172 -r1.173
--- mixer.cpp	28 Nov 2004 13:57:49 -0000	1.172
+++ mixer.cpp	28 Nov 2004 22:15:08 -0000	1.173
@@ -46,6 +46,7 @@
 	PlayingSoundHandle *_handle;
 	bool _autofreeStream;
 	const bool _isMusic;
+	bool _permanent;
 	byte _volume;
 	int8 _balance;
 	bool _paused;
@@ -61,11 +62,14 @@
 public:
 
 	Channel(SoundMixer *mixer, PlayingSoundHandle *handle, bool isMusic, int id = -1);
-	Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioStream *input, bool autofreeStream, bool isMusic, bool reverseStereo = false, int id = -1);
+	Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioStream *input, bool autofreeStream, bool isMusic, bool reverseStereo = false, int id = -1, bool permanent = false);
 	virtual ~Channel();
 
 	void mix(int16 *data, uint len);
 
+	bool isPermanent() const {
+		return _permanent;
+	}
 	bool isFinished() const {
 		return _input->endOfStream();
 	}
@@ -122,7 +126,7 @@
 
 SoundMixer::~SoundMixer() {
 	_syst->clearSoundCallback();
-	stopAll();
+	stopAll(true);
 
 	delete _premixChannel;
 	_premixChannel = 0;
@@ -200,7 +204,7 @@
 	insertChannel(handle, chan);
 }
 
-void SoundMixer::playInputStream(PlayingSoundHandle *handle, AudioStream *input, bool isMusic, byte volume, int8 balance, int id, bool autofreeStream) {
+void SoundMixer::playInputStream(PlayingSoundHandle *handle, AudioStream *input, bool isMusic, byte volume, int8 balance, int id, bool autofreeStream, bool permanent) {
 	Common::StackLock lock(_mutex);
 
 	if (input == 0) {
@@ -219,7 +223,7 @@
 	}
 
 	// Create the channel
-	Channel *chan = new Channel(this, handle, input, autofreeStream, isMusic, false, id);
+	Channel *chan = new Channel(this, handle, input, autofreeStream, isMusic, false, id, permanent);
 	chan->setVolume(volume);
 	chan->setBalance(balance);
 	insertChannel(handle, chan);
@@ -255,12 +259,14 @@
 	((SoundMixer *)s)->mix((int16 *)samples, len >> 2);
 }
 
-void SoundMixer::stopAll() {
+void SoundMixer::stopAll(bool force) {
 	Common::StackLock lock(_mutex);
 	for (int i = 0; i != NUM_CHANNELS; i++)
 		if (_channels[i] != 0) {
-			delete _channels[i];
-			_channels[i] = 0;
+			if (force || !_channels[i]->isPermanent()) {
+				delete _channels[i];
+				_channels[i] = 0;
+			}
 		}
 }
 
@@ -431,10 +437,10 @@
 }
 
 Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioStream *input,
-				bool autofreeStream, bool isMusic, bool reverseStereo, int id)
+				bool autofreeStream, bool isMusic, bool reverseStereo, int id, bool permanent)
 	: _mixer(mixer), _handle(handle), _autofreeStream(autofreeStream), _isMusic(isMusic),
 	  _volume(255), _balance(0), _paused(false), _id(id), _samplesConsumed(0),
-	  _samplesDecoded(0), _mixerTimeStamp(0), _converter(0), _input(input) {
+	  _samplesDecoded(0), _mixerTimeStamp(0), _converter(0), _input(input), _permanent(permanent) {
 	assert(mixer);
 	assert(input);
 

Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- mixer.h	27 Nov 2004 17:09:05 -0000	1.84
+++ mixer.h	28 Nov 2004 22:15:09 -0000	1.85
@@ -131,14 +131,14 @@
 	/**
 	 * Start playing the given audio input stream.
 	 */
-	void playInputStream(PlayingSoundHandle *handle, AudioStream *input, bool isMusic, byte volume = 255, int8 balance = 0, int id = -1, bool autofreeStream = true);
+	void playInputStream(PlayingSoundHandle *handle, AudioStream *input, bool isMusic, byte volume = 255, int8 balance = 0, int id = -1, bool autofreeStream = true, bool permanent = false);
 
 
 
 	/**
 	 * Stop all currently playing sounds.
 	 */
-	void stopAll();
+	void stopAll(bool force = false);
 
 	/**
 	 * Stop playing the sound with given ID.





More information about the Scummvm-git-logs mailing list