[Scummvm-cvs-logs] CVS: scummvm/sound mixer.cpp,1.3,1.4 mixer.h,1.2,1.3

Lionel Ulmer bbrox at users.sourceforge.net
Tue Apr 16 13:02:18 CEST 2002


Update of /cvsroot/scummvm/scummvm/sound
In directory usw-pr-cvs1:/tmp/cvs-serv32765/sound

Modified Files:
	mixer.cpp mixer.h 
Log Message:
Proper commit now for MP3 sound support....


Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** mixer.cpp	16 Apr 2002 12:18:50 -0000	1.3
--- mixer.cpp	16 Apr 2002 18:33:04 -0000	1.4
***************
*** 37,40 ****
--- 37,46 ----
  }
  
+ #ifdef COMPRESSED_SOUND_FILE
+ void SoundMixer::play_mp3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags) {
+ 	insert(handle, new Channel_MP3(this, sound, size, flags));
+ }
+ #endif
+ 
  void SoundMixer::mix(int16 *buf, uint len) {
  	if (_premix_proc) {
***************
*** 183,221 ****
  
  /* MP3 mixer goes here */
- 
- #if 0
- 
  #ifdef COMPRESSED_SOUND_FILE
! void Scumm::playSfxSound_MP3(void *sound, uint32 size)
! {
! 	MixerChannel *mc = allocateMixer();
! 
! 	if (!mc) {
! 		warning("No mixer channel available");
! 		return;
! 	}
! 
! 	mc->type = MIXER_MP3;
! 	mc->_sfx_sound = sound;
! 
! 	mad_stream_init(&mc->sound_data.mp3.stream);
! 
! 
! 
  #ifdef _WIN32_WCE
- 
  	// 11 kHz on WinCE
! 
! 	mad_stream_options((mad_stream *) & mc->sound_data.mp3.stream,
! 										 MAD_OPTION_HALFSAMPLERATE);
! 
  #endif
! 
! 
! 	mad_frame_init(&mc->sound_data.mp3.frame);
! 	mad_synth_init(&mc->sound_data.mp3.synth);
! 	mc->sound_data.mp3.position = 0;
! 	mc->sound_data.mp3.pos_in_frame = 0xFFFFFFFF;
! 	mc->sound_data.mp3.size = size;
  	/* 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
--- 189,208 ----
  
  /* MP3 mixer goes here */
  #ifdef COMPRESSED_SOUND_FILE
! SoundMixer::Channel_MP3::Channel_MP3(SoundMixer *mixer, void *sound, uint size, byte flags) {
! 	_mixer = mixer;
! 	_flags = flags;
! 	_pos_in_frame = 0xFFFFFFFF;
! 	_position = 0;
! 	_size = size;
! 	_ptr = sound;
! 	
! 	mad_stream_init(&_stream);
  #ifdef _WIN32_WCE
  	// 11 kHz on WinCE
! 	mad_stream_options(&_stream, MAD_OPTION_HALFSAMPLERATE);
  #endif
! 	mad_frame_init(&_frame);
! 	mad_synth_init(&_synth);
  	/* 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
***************
*** 230,238 ****
  	   from the start of the sound => we skip about 1024 samples.
  	 */
! 	mc->sound_data.mp3.silence_cut = 1024;
  }
- #endif
  
- #ifdef COMPRESSED_SOUND_FILE
  static inline int scale_sample(mad_fixed_t sample)
  {
--- 217,223 ----
  	   from the start of the sound => we skip about 1024 samples.
  	 */
! 	_silence_cut = 1024;
  }
  
  static inline int scale_sample(mad_fixed_t sample)
  {
***************
*** 249,333 ****
  	return sample >> (MAD_F_FRACBITS + 2 - 16);
  }
- #endif
- 
- void MixerChannel::mix(int16 * data, uint32 len)
- {
- 	if (!_sfx_sound)
- 		return;
  
! #ifdef COMPRESSED_SOUND_FILE
! 	if (type == MIXER_STANDARD) {
! #endif
! 		int8 *s;
! 		uint32 fp_pos, fp_speed;
! 
! 		if (len > sound_data.standard._sfx_size)
! 			len = sound_data.standard._sfx_size;
! 		sound_data.standard._sfx_size -= len;
! 
! 		s = (int8 *) _sfx_sound + sound_data.standard._sfx_pos;
! 		fp_pos = sound_data.standard._sfx_fp_pos;
! 		fp_speed = sound_data.standard._sfx_fp_speed;
  
! 		do {
! 			fp_pos += fp_speed;
! 			*data++ += (*s << 6);
! 			s += fp_pos >> 16;
! 			fp_pos &= 0x0000FFFF;
! 		} while (--len);
  
! 		sound_data.standard._sfx_pos = s - (int8 *) _sfx_sound;
! 		sound_data.standard._sfx_fp_speed = fp_speed;
! 		sound_data.standard._sfx_fp_pos = fp_pos;
  
! 		if (!sound_data.standard._sfx_size)
! 			clear();
! #ifdef COMPRESSED_SOUND_FILE
! 	} else {
! 		if (type == MIXER_MP3) {
! 			mad_fixed_t const *ch;
! 			while (1) {
! 				ch =
! 					sound_data.mp3.synth.pcm.samples[0] + sound_data.mp3.pos_in_frame;
! 				while ((sound_data.mp3.pos_in_frame < sound_data.mp3.synth.pcm.length)
! 							 && (len > 0)) {
! 					if (sound_data.mp3.silence_cut > 0) {
! 						sound_data.mp3.silence_cut--;
! 					} else {
! 						*data++ += scale_sample(*ch++);
! 						len--;
! 					}
! 					sound_data.mp3.pos_in_frame++;
! 				}
! 				if (len == 0)
! 					return;
  
! 				if (sound_data.mp3.position >= sound_data.mp3.size) {
! 					clear();
! 					return;
! 				}
  
! 				mad_stream_buffer(&sound_data.mp3.stream,
! 													((unsigned char *)_sfx_sound) +
! 													sound_data.mp3.position,
! 													sound_data.mp3.size + MAD_BUFFER_GUARD -
! 													sound_data.mp3.position);
  
! 				if (mad_frame_decode(&sound_data.mp3.frame, &sound_data.mp3.stream) ==
! 						-1) {
! 					/* End of audio... */
! 					if (sound_data.mp3.stream.error == MAD_ERROR_BUFLEN) {
! 						clear();
! 						return;
! 					} else if (!MAD_RECOVERABLE(sound_data.mp3.stream.error)) {
! 						error("MAD frame decode error !");
! 					}
! 				}
! 				mad_synth_frame(&sound_data.mp3.synth, &sound_data.mp3.frame);
! 				sound_data.mp3.pos_in_frame = 0;
! 				sound_data.mp3.position =
! 					(unsigned char *)sound_data.mp3.stream.next_frame -
! 					(unsigned char *)_sfx_sound;
! 			}
  		} else if (type == MIXER_MP3_CDMUSIC) {
  			mad_fixed_t const *ch;
--- 234,290 ----
  	return sample >> (MAD_F_FRACBITS + 2 - 16);
  }
  
! void SoundMixer::Channel_MP3::mix(int16 *data, uint len) {
! 	mad_fixed_t const *ch;
! 	while (1) {
! 		ch = _synth.pcm.samples[0] + _pos_in_frame;
! 		while ((_pos_in_frame < _synth.pcm.length) && (len > 0)) {
! 			if (_silence_cut > 0) {
! 				_silence_cut--;
! 			} else {
! 				*data++ += scale_sample(*ch++);
! 				len--;
! 			}
! 			_pos_in_frame++;
! 		}
! 		if (len == 0)
! 			return;
! 		
! 		if (_position >= _size) {
! 			return; /* TODO : add equivalent to 'clear' */
! 		}
  
! 		mad_stream_buffer(&_stream, ((unsigned char *)_ptr) + _position, _size + MAD_BUFFER_GUARD - _position);
  
! 		if (mad_frame_decode(&_frame, &_stream) == -1) {
! 			/* End of audio... */
! 			if (_stream.error == MAD_ERROR_BUFLEN) {
! 				return; /* TODO : add equivalent to 'clear' */
! 			} else if (!MAD_RECOVERABLE(_stream.error)) {
! 				error("MAD frame decode error !");
! 			}
! 		}
! 		mad_synth_frame(&_synth, &_frame);
! 		_pos_in_frame = 0;
! 		_position = (unsigned char *)_stream.next_frame - (unsigned char *)_ptr;
! 	}
! }
  
! void SoundMixer::Channel_MP3::destroy() {
! 	if (_flags & FLAG_AUTOFREE)
! 		free(_ptr);
! 	_mixer->uninsert(this);
! 	mad_synth_finish(&_synth);
! 	mad_frame_finish(&_frame);
! 	mad_stream_finish(&_stream);
  
! 	delete this;
! }
! #endif
  
! #if 0
  
! void MixerChannel::mix(int16 * data, uint32 len)
! {
  		} else if (type == MIXER_MP3_CDMUSIC) {
  			mad_fixed_t const *ch;
***************
*** 469,487 ****
  		}
  	}
- #endif
- }
- 
- void MixerChannel::clear()
- {
- 	free(_sfx_sound);
- 	_sfx_sound = NULL;
- 
- #ifdef COMPRESSED_SOUND_FILE
- 	if (type == MIXER_MP3) {
- 		mad_synth_finish(&sound_data.mp3.synth);
- 		mad_frame_finish(&sound_data.mp3.frame);
- 		mad_stream_finish(&sound_data.mp3.stream);
- 	}
- #endif
  }
  
--- 426,429 ----

Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** mixer.h	16 Apr 2002 12:07:19 -0000	1.2
--- mixer.h	16 Apr 2002 18:33:04 -0000	1.3
***************
*** 2,5 ****
--- 2,9 ----
  #define _mixer_h_included
  
+ #ifdef COMPRESSED_SOUND_FILE
+ #include <mad.h>
+ #endif
+ 
  typedef uint32 PlayingSoundHandle;
  
***************
*** 31,36 ****
  #ifdef COMPRESSED_SOUND_FILE
  
! 	class Channel_RAW : public Channel {
  		SoundMixer *_mixer;
  
  	public:
--- 35,49 ----
  #ifdef COMPRESSED_SOUND_FILE
  
! 	class Channel_MP3 : public Channel {
  		SoundMixer *_mixer;
+ 		void *_ptr;
+ 		struct mad_stream _stream;
+ 		struct mad_frame _frame;
+ 		struct mad_synth _synth;
+ 		uint32 _silence_cut;
+ 		uint32 _pos_in_frame;
+ 		uint32 _position;
+ 		uint32 _size;
+ 		byte _flags;
  
  	public:
***************
*** 38,42 ****
  		void destroy();
  
! 		Channel_MP3(SoundMixer *mixer, void *sound, uint rate);
  	};
  
--- 51,55 ----
  		void destroy();
  
! 		Channel_MP3(SoundMixer *mixer, void *sound, uint size, byte flags);
  	};
  
***************
*** 72,75 ****
--- 85,91 ----
  	};
  	void play_raw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags);
+ #ifdef COMPRESSED_SOUND_FILE
+ 	void play_mp3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags);
+ #endif
  
  	/* Premix procedure, useful when using fmopl adlib */





More information about the Scummvm-git-logs mailing list