[Scummvm-cvs-logs] CVS: scummvm/sound mixer.cpp,1.82,1.83 mixer.h,1.34,1.35 audiostream.cpp,1.8,1.9

Max Horn fingolfin at users.sourceforge.net
Tue Jul 29 05:40:08 CEST 2003


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

Modified Files:
	mixer.cpp mixer.h audiostream.cpp 
Log Message:
cleanup

Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- mixer.cpp	29 Jul 2003 02:48:38 -0000	1.82
+++ mixer.cpp	29 Jul 2003 12:39:41 -0000	1.83
@@ -122,7 +122,6 @@
 class ChannelMP3Common : public Channel {
 protected:
 	byte *_ptr;
-	bool _releasePtr;
 	struct mad_stream _stream;
 	struct mad_frame _frame;
 	struct mad_synth _synth;
@@ -139,7 +138,7 @@
 	uint32 _position;
 
 public:
-	ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint size, byte flags);
+	ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, uint size);
 
 	void mix(int16 *data, uint len);
 	bool isMusicChannel() { return false; }
@@ -283,9 +282,9 @@
 }
 
 #ifdef USE_MAD
-int SoundMixer::playMP3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags) {
+int SoundMixer::playMP3(PlayingSoundHandle *handle, File *file, uint32 size) {
 	StackLock lock(_mutex);
-	return insertChannel(handle, new ChannelMP3(this, handle, sound, size, flags));
+	return insertChannel(handle, new ChannelMP3(this, handle, file, size));
 }
 int SoundMixer::playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration) {
 	StackLock lock(_mutex);
@@ -924,8 +923,7 @@
 }
 
 ChannelMP3Common::~ChannelMP3Common() {
-	if (_releasePtr)
-		free(_ptr);
+	free(_ptr);
 	mad_synth_finish(&_synth);
 	mad_frame_finish(&_frame);
 	mad_stream_finish(&_stream);
@@ -945,18 +943,24 @@
 	return sample >> (MAD_F_FRACBITS + 1 - 16);
 }
 
-ChannelMP3::ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint size, byte flags)
+ChannelMP3::ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, uint size)
 	: ChannelMP3Common(mixer, handle) {
 	_posInFrame = 0xFFFFFFFF;
 	_position = 0;
-	_size = size;
-	_ptr = (byte *)sound;
-	_releasePtr = (flags & SoundMixer::FLAG_AUTOFREE) != 0;
+	_ptr = (byte *)malloc(size + MAD_BUFFER_GUARD);
+
+	_size = file->read(_ptr, size);
 }
 
 void ChannelMP3::mix(int16 *data, uint len) {
 	const int volume = _mixer->getVolume();
 
+	// Exit if all data is used up (this also covers the case were reading from the file failed).
+	if (_position >= _size) {
+		destroy();
+		return;
+	}
+
 	while (1) {
 
 		int16 sample;
@@ -1003,7 +1007,6 @@
 	_duration = duration;
 	_bufferSize = MP3CD_BUFFERING_SIZE;
 	_ptr = (byte *)malloc(MP3CD_BUFFERING_SIZE);
-	_releasePtr = true;
 }
 
 void ChannelMP3CDMusic::mix(int16 *data, uint len) {

Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- mixer.h	25 Jul 2003 01:19:14 -0000	1.34
+++ mixer.h	29 Jul 2003 12:39:41 -0000	1.35
@@ -84,7 +84,7 @@
 	// start playing a raw sound
 	int playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id = -1);
 #ifdef USE_MAD
-	int playMP3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags);
+	int playMP3(PlayingSoundHandle *handle, File *file, uint32 size);
 	int playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration);
 #endif
 #ifdef USE_VORBIS

Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- audiostream.cpp	29 Jul 2003 03:02:25 -0000	1.8
+++ audiostream.cpp	29 Jul 2003 12:39:41 -0000	1.9
@@ -166,7 +166,11 @@
 	uint32 _posInFrame;
 public:
 	// TODO
+	MP3InputStream();
 };
+
+MP3InputStream::MP3InputStream() {
+}
 #endif
 
 





More information about the Scummvm-git-logs mailing list