From 3849080ed771c0b9849d274775513b7c3fb91f6f Mon Sep 17 00:00:00 2001 From: Nicolas Bacca Date: Wed, 1 May 2002 22:22:22 +0000 Subject: Pause and start of volume support svn-id: r4165 --- sound/mixer.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'sound/mixer.cpp') diff --git a/sound/mixer.cpp b/sound/mixer.cpp index c8502685da..5b0be93ee4 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -71,6 +71,10 @@ int SoundMixer::play_mp3_cdtrack(PlayingSoundHandle *handle, FILE* file, mad_tim #endif void SoundMixer::mix(int16 *buf, uint len) { + + if (_paused) + return; + if (_premix_proc) { _premix_proc(_premix_param, buf, len); } else { @@ -117,6 +121,10 @@ void SoundMixer::stop(int index) { _channels[index]->destroy(); } +void SoundMixer::pause(bool paused) { + _paused = paused; +} + bool SoundMixer::has_active_channel() { for(int i=0; i!=NUM_CHANNELS; i++) if (_channels[i]) @@ -282,6 +290,7 @@ static inline int scale_sample(mad_fixed_t sample) void SoundMixer::Channel_MP3::mix(int16 *data, uint len) { mad_fixed_t const *ch; + const int16 *vol_tab = _mixer->_volume_table; if (_to_be_destroyed) { real_destroy(); @@ -294,7 +303,7 @@ void SoundMixer::Channel_MP3::mix(int16 *data, uint len) { if (_silence_cut > 0) { _silence_cut--; } else { - *data++ += scale_sample(*ch++); + *data++ += (int16)((float)scale_sample(*ch++) * ((float)vol_tab[1] / (float)128)); len--; } _pos_in_frame++; @@ -359,6 +368,7 @@ SoundMixer::Channel_MP3_CDMUSIC::Channel_MP3_CDMUSIC(SoundMixer *mixer, FILE* fi void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len) { mad_fixed_t const *ch; mad_timer_t frame_duration; + const int16 *vol_tab = _mixer->_volume_table; if (_to_be_destroyed) { real_destroy(); @@ -410,7 +420,7 @@ void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len) { // Get samples, play samples ... ch = _synth.pcm.samples[0] + _pos_in_frame; while ((_pos_in_frame < _synth.pcm.length) && (len > 0)) { - *data++ += scale_sample(*ch++); + *data++ += (int16)((float)scale_sample(*ch++) * ((float)vol_tab[1] / (float)128)); len--; _pos_in_frame++; } -- cgit v1.2.3