[Scummvm-cvs-logs] CVS: scummvm/sound mixer.cpp,1.53,1.54

Max Horn fingolfin at users.sourceforge.net
Tue Jun 24 16:37:02 CEST 2003


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

Modified Files:
	mixer.cpp 
Log Message:
cleanup

Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- mixer.cpp	22 Jun 2003 14:30:32 -0000	1.53
+++ mixer.cpp	24 Jun 2003 23:36:05 -0000	1.54
@@ -32,7 +32,7 @@
 public:
 	bool _toBeDestroyed;
 	int _id;
-	Channel() : _mixer(0), _toBeDestroyed(false), _id(-1) {}
+	Channel(SoundMixer *mixer) : _mixer(mixer), _toBeDestroyed(false), _id(-1) {}
 	virtual ~Channel() {}
 	virtual void mix(int16 *data, uint len) = 0;
 	void destroy() {
@@ -89,34 +89,33 @@
 
 #ifdef USE_MAD
 
-class ChannelMP3 : public Channel {
+class ChannelMP3Common : public Channel {
+protected:
 	byte *_ptr;
+	bool _releasePtr;
 	struct mad_stream _stream;
 	struct mad_frame _frame;
 	struct mad_synth _synth;
-	uint32 _silenceCut;
 	uint32 _posInFrame;
-	uint32 _position;
 	uint32 _size;
-	byte _flags;
+
+public:
+	ChannelMP3Common(SoundMixer *mixer);
+	~ChannelMP3Common();
+};
+
+class ChannelMP3 : public ChannelMP3Common {
+	uint32 _silenceCut;
+	uint32 _position;
 
 public:
 	ChannelMP3(SoundMixer *mixer, void *sound, uint size, byte flags);
-	~ChannelMP3();
 
 	void mix(int16 *data, uint len);
-	bool isMusicChannel() {
-		return false;
-	}
+	bool isMusicChannel() { return false; }
 };
 
-class ChannelMP3CDMusic : public Channel {
-	byte *_ptr;
-	struct mad_stream _stream;
-	struct mad_frame _frame;
-	struct mad_synth _synth;
-	uint32 _posInFrame;
-	uint32 _size;
+class ChannelMP3CDMusic : public ChannelMP3Common {
 	uint32 _bufferSize;
 	mad_timer_t _duration;
 	File *_file;
@@ -125,13 +124,10 @@
 
 public:
 	ChannelMP3CDMusic(SoundMixer *mixer, File *file, mad_timer_t duration);
-	~ChannelMP3CDMusic();
 
 	void mix(int16 *data, uint len);
 	bool isActive();
-	bool isMusicChannel() {
-		return true;
-	}
+	bool isMusicChannel() { return true; }
 };
 
 #endif
@@ -670,9 +666,9 @@
 }
 
 /* RAW mixer */
-ChannelRaw::ChannelRaw(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags, int id) {
+ChannelRaw::ChannelRaw(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags, int id)
+	: Channel(mixer) {
 	_id = id;
-	_mixer = mixer;
 	_flags = flags;
 	_ptr = (byte *)sound;
 	_pos = 0;
@@ -733,8 +729,8 @@
 #define WARP_WORKAROUND 50000
 
 ChannelStream::ChannelStream(SoundMixer *mixer, void *sound, uint32 size, uint rate,
-										 byte flags, int32 buffer_size) {
-	_mixer = mixer;
+										 byte flags, int32 buffer_size)
+	: Channel(mixer) {
 	_flags = flags;
 	_bufferSize = buffer_size;
 	_ptr = (byte *)malloc(_bufferSize + WARP_WORKAROUND);
@@ -825,14 +821,9 @@
 }
 
 #ifdef USE_MAD
-ChannelMP3::ChannelMP3(SoundMixer *mixer, void *sound, uint size, byte flags) {
-	_mixer = mixer;
-	_flags = flags;
-	_posInFrame = 0xFFFFFFFF;
-	_position = 0;
-	_size = size;
-	_ptr = (byte *)sound;
 
+ChannelMP3Common::ChannelMP3Common(SoundMixer *mixer)
+	: Channel(mixer) {
 	mad_stream_init(&_stream);
 #ifdef _WIN32_WCE
 	// 11 kHz on WinCE if necessary
@@ -841,6 +832,24 @@
 #endif
 	mad_frame_init(&_frame);
 	mad_synth_init(&_synth);
+}
+
+ChannelMP3Common::~ChannelMP3Common() {
+	if (_releasePtr)
+		free(_ptr);
+	mad_synth_finish(&_synth);
+	mad_frame_finish(&_frame);
+	mad_stream_finish(&_stream);
+}
+
+ChannelMP3::ChannelMP3(SoundMixer *mixer, void *sound, uint size, byte flags) 
+	: ChannelMP3Common(mixer) {
+	_posInFrame = 0xFFFFFFFF;
+	_position = 0;
+	_size = size;
+	_ptr = (byte *)sound;
+	_releasePtr = (flags & SoundMixer::FLAG_AUTOFREE);
+
 	/* This variable is the number of samples to cut at the start of the MP3
 	   file. This is needed to have lip-sync as the MP3 file have some miliseconds
 	   of blank at the start (as, I suppose, the MP3 compression algorithm need to
@@ -856,14 +865,6 @@
 	_silenceCut = 576 * 2;
 }
 
-ChannelMP3::~ChannelMP3() {
-	if (_flags & SoundMixer::FLAG_AUTOFREE)
-		free(_ptr);
-	mad_synth_finish(&_synth);
-	mad_frame_finish(&_frame);
-	mad_stream_finish(&_stream);
-}
-
 static inline int scale_sample(mad_fixed_t sample) {
 	/* round */
 	sample += (1L << (MAD_F_FRACBITS - 16));
@@ -934,30 +935,14 @@
 
 #define MP3CD_BUFFERING_SIZE 131072
 
-ChannelMP3CDMusic::ChannelMP3CDMusic(SoundMixer *mixer, File *file,
-														 mad_timer_t duration){
-	_mixer = mixer;
+ChannelMP3CDMusic::ChannelMP3CDMusic(SoundMixer *mixer, File *file, mad_timer_t duration)
+	: ChannelMP3Common(mixer) {
 	_file = file;
 	_duration = duration;
 	_initialized = false;
 	_bufferSize = MP3CD_BUFFERING_SIZE;
 	_ptr = (byte *)malloc(MP3CD_BUFFERING_SIZE);
-
-	mad_stream_init(&_stream);
-#ifdef _WIN32_WCE
-	// 11 kHz on WinCE if necessary
-	if ((uint)_mixer->_syst->property(OSystem::PROP_GET_SAMPLE_RATE, 0) != 22050)
-		mad_stream_options(&_stream, MAD_OPTION_HALFSAMPLERATE);
-#endif
-	mad_frame_init(&_frame);
-	mad_synth_init(&_synth);
-}
-
-ChannelMP3CDMusic::~ChannelMP3CDMusic() {
-	free(_ptr);
-	mad_synth_finish(&_synth);
-	mad_frame_finish(&_frame);
-	mad_stream_finish(&_stream);
+	_releasePtr = true;
 }
 
 void ChannelMP3CDMusic::mix(int16 *data, uint len) {
@@ -1062,8 +1047,8 @@
 #endif
 
 #ifdef USE_VORBIS
-ChannelVorbis::ChannelVorbis(SoundMixer *mixer, OggVorbis_File *ov_file, int duration, bool is_cd_track) {
-	_mixer = mixer;
+ChannelVorbis::ChannelVorbis(SoundMixer *mixer, OggVorbis_File *ov_file, int duration, bool is_cd_track)
+	: Channel(mixer) {
 	_ov_file = ov_file;
 
 	if (duration)





More information about the Scummvm-git-logs mailing list