[Scummvm-cvs-logs] CVS: scummvm/sound mixer.cpp,1.144,1.145 mixer.h,1.65,1.66 vorbis.cpp,1.4,1.5 vorbis.h,1.3,1.4

Max Horn fingolfin at users.sourceforge.net
Tue Dec 23 11:16:01 CET 2003


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

Modified Files:
	mixer.cpp mixer.h vorbis.cpp vorbis.h 
Log Message:
Allow sound ID for MP3/Vorbis sounds, too; cleaned up Vorbis playback code a bit

Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.144
retrieving revision 1.145
diff -u -d -r1.144 -r1.145
--- mixer.cpp	22 Dec 2003 19:19:04 -0000	1.144
+++ mixer.cpp	23 Dec 2003 19:14:57 -0000	1.145
@@ -256,34 +256,50 @@
 }
 
 #ifdef USE_MAD
-void SoundMixer::playMP3(PlayingSoundHandle *handle, File *file, uint32 size, byte volume, int8 pan) {
+void SoundMixer::playMP3(PlayingSoundHandle *handle, File *file, uint32 size, byte volume, int8 pan, int id) {
 	// Create the input stream
 	AudioInputStream *input = makeMP3Stream(file, mad_timer_zero, size);
-	playInputStream(handle, input, false, volume, pan);
+	playInputStream(handle, input, false, volume, pan, id);
 }
-void SoundMixer::playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan) {
+void SoundMixer::playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan, int id) {
 	// Create the input stream
 	AudioInputStream *input = makeMP3Stream(file, duration, 0);
-	playInputStream(handle, input, true, volume, pan);
+	playInputStream(handle, input, true, volume, pan, id);
 }
 #endif
 
 #ifdef USE_VORBIS
-void SoundMixer::playVorbis(PlayingSoundHandle *handle, File *file, uint32 size) {
-	playSfxSound_Vorbis(this, file, size, handle);
+void SoundMixer::playVorbis(PlayingSoundHandle *handle, File *file, uint32 size, byte volume, int8 pan, int id) {
+	// Create the input stream
+	AudioInputStream *input = makeVorbisStream(file, size);
+	playInputStream(handle, input, false, volume, pan, id);
 }
-void SoundMixer::playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume, int8 pan) {
+void SoundMixer::playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume, int8 pan, int id) {
 	// Create the input stream
 	AudioInputStream *input = makeVorbisStream(ov_file, duration);
-	playInputStream(handle, input, is_cd_track, volume, pan);
+	playInputStream(handle, input, is_cd_track, volume, pan, id);
 }
 #endif
 
-void SoundMixer::playInputStream(PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume, int8 pan) {
+void SoundMixer::playInputStream(PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume, int8 pan, int id) {
 	Common::StackLock lock(_mutex);
 
+	if (input == 0) {
+		warning("input stream is 0");
+		return;
+	}
+
+	// Prevent duplicate sounds
+	if (id != -1) {
+		for (int i = 0; i != NUM_CHANNELS; i++)
+			if (_channels[i] != 0 && _channels[i]->getId() == id) {
+				delete input;
+				return;
+			}
+	}
+
 	// Create the channel
-	Channel *chan = new Channel(this, handle, input, isMusic, volume, pan);
+	Channel *chan = new Channel(this, handle, input, isMusic, volume, pan, false, id);
 	insertChannel(handle, chan);
 }
 

Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- mixer.h	22 Dec 2003 19:08:19 -0000	1.65
+++ mixer.h	23 Dec 2003 19:14:57 -0000	1.66
@@ -99,15 +99,15 @@
 	void playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags,
 				int id = -1, byte volume = 255, int8 pan = 0, uint32 loopStart = 0, uint32 loopEnd = 0);
 #ifdef USE_MAD
-	void playMP3(PlayingSoundHandle *handle, File *file, uint32 size, byte volume = 255, int8 pan = 0);
-	void playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume = 255, int8 pan = 0);
+	void playMP3(PlayingSoundHandle *handle, File *file, uint32 size, byte volume = 255, int8 pan = 0, int id = -1);
+	void playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume = 255, int8 pan = 0, int id = -1);
 #endif
 #ifdef USE_VORBIS
-	void playVorbis(PlayingSoundHandle *handle, File *file, uint32 size);
-	void playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume = 255, int8 pan = 0);
+	void playVorbis(PlayingSoundHandle *handle, File *file, uint32 size, byte volume = 255, int8 pan = 0, int id = -1);
+	void playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume = 255, int8 pan = 0, int id = -1);
 #endif
 
-	void playInputStream(PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume = 255, int8 pan = 0);
+	void playInputStream(PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume = 255, int8 pan = 0, int id = -1);
 
 
 	/** Start a new stream. */
@@ -116,7 +116,12 @@
 	/** Append to an existing stream. */
 	void appendStream(PlayingSoundHandle handle, void *sound, uint32 size);
 
-	/** Mark a stream as finished - it will play all its remaining data, then stop. */
+	/**
+	 * Mark a stream as finished.
+	 * Where stopHandle() would stop the sound immediately, when using this
+	 * method, the stream will first finish playing all its data before it
+	 * finally stops.
+	 */
 	void endStream(PlayingSoundHandle handle);
 
 	/** stop all currently playing sounds */

Index: vorbis.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/vorbis.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- vorbis.cpp	21 Dec 2003 00:44:31 -0000	1.4
+++ vorbis.cpp	23 Dec 2003 19:14:57 -0000	1.5
@@ -128,24 +128,6 @@
 	}
 }
 
-void playSfxSound_Vorbis(SoundMixer *mixer, File *file, uint32 size, PlayingSoundHandle *handle) {
-	OggVorbis_File *ov_file = new OggVorbis_File;
-	file_info *f = new file_info;
-
-	f->file = file;
-	f->start = file->pos();
-	f->len = size;
-	f->curr_pos = 0;
-
-	if (ov_open_callbacks((void *) f, ov_file, NULL, 0, g_File_wrap) < 0) {
-		warning("Invalid file format");
-		delete ov_file;
-		delete f;
-	} else
-		mixer->playVorbis(handle, ov_file, 0, false);
-}
-
-
 #pragma mark -
 #pragma mark --- Ogg Vorbis stream ---
 #pragma mark -
@@ -264,5 +246,22 @@
 	return new VorbisInputStream(file, duration);
 }
 
+AudioInputStream *makeVorbisStream(File *file, uint32 size) {
+	OggVorbis_File *ov_file = new OggVorbis_File;
+	file_info *f = new file_info;
+
+	f->file = file;
+	f->start = file->pos();
+	f->len = size;
+	f->curr_pos = 0;
+
+	if (ov_open_callbacks((void *) f, ov_file, NULL, 0, g_File_wrap) < 0) {
+		warning("Invalid file format");
+		delete ov_file;
+		delete f;
+		return 0;
+	} else
+		return new VorbisInputStream(ov_file, 0);
+}
 
 #endif

Index: vorbis.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/vorbis.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- vorbis.h	21 Dec 2003 00:44:31 -0000	1.3
+++ vorbis.h	23 Dec 2003 19:14:57 -0000	1.4
@@ -47,9 +47,8 @@
 };
 
 
-void playSfxSound_Vorbis(SoundMixer *mixer, File *file, uint32 size, PlayingSoundHandle *handle);
-
 AudioInputStream *makeVorbisStream(OggVorbis_File *file, int duration);
+AudioInputStream *makeVorbisStream(File *file, uint32 size);
 
 #endif
 





More information about the Scummvm-git-logs mailing list