[Scummvm-cvs-logs] CVS: scummvm/sound mixer.cpp,1.32,1.33 mixer.h,1.17,1.18

Max Horn fingolfin at users.sourceforge.net
Tue Mar 18 13:47:12 CET 2003


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

Modified Files:
	mixer.cpp mixer.h 
Log Message:
cleanup; add stopID method to stop a currently playing sound via its ID

Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- mixer.cpp	6 Mar 2003 21:46:55 -0000	1.32
+++ mixer.cpp	18 Mar 2003 21:46:36 -0000	1.33
@@ -88,17 +88,6 @@
 	return index;
 }
 
-int SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags) {
-	for (int i = _beginSlots; i != NUM_CHANNELS; i++) {
-		if (_channels[i] == NULL) {
-			return insertAt(handle, i, new ChannelRaw(this, sound, size, rate, flags, -1));
-		}
-	}
-
-	warning("SoundMixer::out of mixer slots");
-	return -1;
-}
-
 int SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id) {
 	for (int i = _beginSlots; i != NUM_CHANNELS; i++) {
 		if (_channels[i] == NULL) {
@@ -217,6 +206,16 @@
 		_channels[index]->destroy();
 }
 
+void SoundMixer::stopID(int id) {
+
+	for (int i = _beginSlots; i != NUM_CHANNELS; i++) {
+		if (_channels[i] != NULL && _channels[i]->_id == id) {
+			_channels[i]->destroy();
+			return;
+		}
+	}
+}
+
 void SoundMixer::pause(bool paused) {
 	_paused = paused;
 }
@@ -578,9 +577,7 @@
 };
 
 void SoundMixer::ChannelRaw::mix(int16 *data, uint len) {
-	byte *s, *s_org = NULL;
-	uint32 fp_pos;
-	byte *end;
+	byte *s, *end;
 
 	if (_toBeDestroyed) {
 		realDestroy();
@@ -591,41 +588,15 @@
 		len = _size;
 	_size -= len;
 
-	/* 
-	 * simple support for fread() reading of samples
-	 */
-	if (_flags & FLAG_FILE) {
-		/* determine how many samples to read from the file */
-		uint num = len * _fpSpeed >> 16;
-
-		s_org = (byte *)malloc(num);
-		if (s_org == NULL)
-			error("ChannelRaw::mix out of memory");
-
-		uint num_read = ((File *)_ptr)->read(s_org, num);
-		if (num - num_read != 0)
-			memset(s_org + num_read, 0x80, num - num_read);
-
-		s = s_org;
-		fp_pos = 0;
-		end = s_org + num;
-	} else {
-		s = (byte *)_ptr + _pos;
-		fp_pos = _fpPos;
-		end = (byte *)_ptr + _realSize;
-	}
+	s = (byte *)_ptr + _pos;
+	end = (byte *)_ptr + _realSize;
 
 	const uint32 fp_speed = _fpSpeed;
 	const int16 *vol_tab = _mixer->_volumeTable;
 
-	mixer_helper_table[_flags & 0x07] (data, &len, &s, &fp_pos, fp_speed, vol_tab, end, (_flags & FLAG_REVERSE_STEREO) ? true : false);
+	mixer_helper_table[_flags & 0x07] (data, &len, &s, &_fpPos, fp_speed, vol_tab, end, (_flags & FLAG_REVERSE_STEREO) ? true : false);
 
 	_pos = s - (byte *)_ptr;
-	_fpPos = fp_pos;
-
-	if (_flags & FLAG_FILE) {
-		free(s_org);
-	}
 
 	if (_size < 1) {
 		if (_flags & FLAG_LOOP) {

Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- mixer.h	6 Mar 2003 21:46:56 -0000	1.17
+++ mixer.h	18 Mar 2003 21:46:44 -0000	1.18
@@ -46,6 +46,7 @@
 	public:
 		bool _toBeDestroyed;
 		int _id;
+		Channel() : _id(-1) {}
 		virtual void mix(int16 *data, uint len) = 0;
 		void destroy() {
 			_toBeDestroyed = true;
@@ -196,16 +197,14 @@
 	// start playing a raw sound
 	enum {
 		// Do *NOT* change any of these flags without looking at the code in mixer.cpp
-		FLAG_UNSIGNED = 1,          // unsigned samples
-		FLAG_STEREO = 2,            // sound is in stereo
-		FLAG_16BITS = 4,            // sound is 16 bits wide
-		FLAG_AUTOFREE = 8,          // sound buffer is freed automagically at the end of playing
-		FLAG_FILE = 16,             // sound is a FILE * that's read from
-		FLAG_REVERSE_STEREO = 32,   // sound should be reverse stereo
-		FLAG_LOOP = 64              // loop the audio
+		FLAG_UNSIGNED = 1 << 0,         // unsigned samples
+		FLAG_STEREO = 1 << 1,           // sound is in stereo
+		FLAG_16BITS = 1 << 2,           // sound is 16 bits wide
+		FLAG_AUTOFREE = 1 << 3,         // sound buffer is freed automagically at the end of playing
+		FLAG_REVERSE_STEREO = 1 << 4,   // sound should be reverse stereo
+		FLAG_LOOP = 1 << 5              // loop the audio
 	};
-	int playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags);
-	int playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id);
+	int playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id = -1);
 	int playStream(PlayingSoundHandle *handle, int index, void *sound, uint32 size, uint rate,
 									byte flags, int32 timeout = 3, int32 buffer_size = 2000000);
 #ifdef USE_MAD
@@ -227,6 +226,9 @@
 
 	/* stop playing a specific sound */
 	void stop(int index);
+
+	/* stop playing a specific sound */
+	void stopID(int id);
 
 	/* append to existing sound */
 	int append(int index, void * sound, uint32 size, uint rate, byte flags);





More information about the Scummvm-git-logs mailing list