diff options
author | Torbjörn Andersson | 2003-09-02 13:48:20 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2003-09-02 13:48:20 +0000 |
commit | f486997822e2340dfe36efd828b669aedf59c332 (patch) | |
tree | d03eeb4769250c8c02a900836076e979066a9755 /sound/mixer.cpp | |
parent | 8c61a29c29abfb3501dcde5ba6bcca2416ba00a4 (diff) | |
download | scummvm-rg350-f486997822e2340dfe36efd828b669aedf59c332.tar.gz scummvm-rg350-f486997822e2340dfe36efd828b669aedf59c332.tar.bz2 scummvm-rg350-f486997822e2340dfe36efd828b669aedf59c332.zip |
Added per-channel pausing. Maybe I should have named the pauseChannel()
function simply pause() to be consistent with stop(), but there already is
a pause() function and I don't want to have two functions with the same
name doing different things. (The current pause() function pauses all
channels.)
svn-id: r9968
Diffstat (limited to 'sound/mixer.cpp')
-rw-r--r-- | sound/mixer.cpp | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/sound/mixer.cpp b/sound/mixer.cpp index 7315f59ca4..b5444937ca 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -46,17 +46,24 @@ protected: AudioInputStream *_input; byte _volume; int8 _pan; + bool _paused; public: int _id; Channel(SoundMixer *mixer, PlayingSoundHandle *handle) - : _mixer(mixer), _handle(handle), _converter(0), _input(0), _id(-1) { + : _mixer(mixer), _handle(handle), _converter(0), _input(0), _id(-1), _paused(false) { assert(mixer); } virtual ~Channel(); void destroy(); virtual void mix(int16 *data, uint len); + virtual void pause(bool paused) { + _paused = paused; + } + virtual bool isPaused() { + return _paused; + } virtual void setChannelVolume(const byte volume) { _volume = volume; } @@ -271,7 +278,7 @@ void SoundMixer::mix(int16 *buf, uint len) { if (!_paused && !_channelsPaused) { // now mix all channels for (int i = 0; i != NUM_CHANNELS; i++) - if (_channels[i]) + if (_channels[i] && !_channels[i]->isPaused()) _channels[i]->mix(buf, len); } } @@ -383,6 +390,45 @@ void SoundMixer::pauseChannels(bool paused) { _channelsPaused = paused; } +void SoundMixer::pauseChannel(int index, bool paused) { + if ((index < 0) || (index >= NUM_CHANNELS)) { + warning("soundMixer::pauseChannel has invalid index %d", index); + return; + } + + StackLock lock(_mutex); + if (_channels[index]) + _channels[index]->pause(paused); +} + +void SoundMixer::pauseID(int id, bool paused) { + StackLock lock(_mutex); + for (int i = 0; i != NUM_CHANNELS; i++) { + if (_channels[i] != NULL && _channels[i]->_id == id) { + _channels[i]->pause(paused); + return; + } + } +} + +void SoundMixer::pauseHandle(PlayingSoundHandle handle, bool pause) { + StackLock lock(_mutex); + + // Simply ignore pause/unpause requests for handles of sound that alreayd terminated + if (handle == 0) + return; + + int index = handle - 1; + + if ((index < 0) || (index >= NUM_CHANNELS)) { + warning("soundMixer::pauseHandle has invalid index %d", index); + return; + } + + if (_channels[index]) + _channels[index]->pause(pause); +} + bool SoundMixer::hasActiveSFXChannel() { // FIXME/TODO: We need to distinguish between SFX and music channels // (and maybe also voice) here to work properly in iMuseDigital |