From 3849080ed771c0b9849d274775513b7c3fb91f6f Mon Sep 17 00:00:00 2001 From: Nicolas Bacca Date: Wed, 1 May 2002 22:22:22 +0000 Subject: [PATCH] Pause and start of volume support svn-id: r4165 --- sound/mixer.cpp | 14 ++++++++++++-- sound/mixer.h | 5 +++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/sound/mixer.cpp b/sound/mixer.cpp index c8502685da0..5b0be93ee46 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++; } diff --git a/sound/mixer.h b/sound/mixer.h index 6107d98ece6..319c6e69796 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -108,6 +108,8 @@ public: int16 *_volume_table; + bool _paused; + enum { NUM_CHANNELS = 16, }; @@ -157,6 +159,9 @@ public: /* set the volume, 0-256 */ void set_volume(int volume); + /* pause - unpause */ + void pause(bool paused); + };