diff options
Diffstat (limited to 'sound')
-rw-r--r-- | sound/audiocd.cpp | 4 | ||||
-rw-r--r-- | sound/mixer.cpp | 28 | ||||
-rw-r--r-- | sound/mixer.h | 14 |
3 files changed, 28 insertions, 18 deletions
diff --git a/sound/audiocd.cpp b/sound/audiocd.cpp index ca4216b6c6..f2b243b843 100644 --- a/sound/audiocd.cpp +++ b/sound/audiocd.cpp @@ -74,7 +74,7 @@ bool AudioCDManager::isPlaying() const { void AudioCDManager::updateCD() { if (_cd.playing) { // If the sound handle is 0, then playback stopped. - if (!_cd.handle) { + if (!_cd.handle.isActive()) { // If playback just stopped, check if the current track is supposed // to be repeated, and if that's the case, play it again. Else, stop // the CD explicitly. @@ -94,7 +94,7 @@ void AudioCDManager::updateCD() { AudioCDManager::Status AudioCDManager::getStatus() const { // TODO: This could be improved for "real" CD playback. - // But to do that, we have to extend the OSystem interface. + // But to do that, we would have to extend the OSystem interface. Status info = _cd; info.playing = isPlaying(); return info; diff --git a/sound/mixer.cpp b/sound/mixer.cpp index 7fbd030f6f..1d0e13a0c1 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -152,10 +152,10 @@ void SoundMixer::newStream(PlayingSoundHandle *handle, uint rate, byte flags, ui void SoundMixer::appendStream(PlayingSoundHandle handle, void *sound, uint32 size) { Common::StackLock lock(_mutex); - if (handle == 0) + if (!handle.isActive()) return; - int index = handle - 1; + int index = handle.getIndex(); if ((index < 0) || (index >= NUM_CHANNELS)) { warning("soundMixer::appendStream has invalid index %d", index); @@ -179,10 +179,10 @@ void SoundMixer::endStream(PlayingSoundHandle handle) { Common::StackLock lock(_mutex); // Simply ignore stop requests for handles of sounds that already terminated - if (handle == 0) + if (!handle.isActive()) return; - int index = handle - 1; + int index = handle.getIndex(); if ((index < 0) || (index >= NUM_CHANNELS)) { warning("soundMixer::endStream has invalid index %d", index); @@ -219,7 +219,7 @@ void SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) { _channels[index] = chan; if (handle) - *handle = index + 1; + handle->setIndex(index); } void SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id, byte volume, int8 pan, uint32 loopStart, uint32 loopEnd) { @@ -358,10 +358,10 @@ void SoundMixer::stopHandle(PlayingSoundHandle handle) { Common::StackLock lock(_mutex); // Simply ignore stop requests for handles of sounds that already terminated - if (handle == 0) + if (!handle.isActive()) return; - int index = handle - 1; + int index = handle.getIndex(); if ((index < 0) || (index >= NUM_CHANNELS)) { warning("soundMixer::stopHandle has invalid index %d", index); @@ -377,10 +377,10 @@ void SoundMixer::stopHandle(PlayingSoundHandle handle) { void SoundMixer::setChannelVolume(PlayingSoundHandle handle, byte volume) { Common::StackLock lock(_mutex); - if (handle == 0) + if (!handle.isActive()) return; - int index = handle - 1; + int index = handle.getIndex(); if ((index < 0) || (index >= NUM_CHANNELS)) { warning("soundMixer::setChannelVolume has invalid index %d", index); @@ -394,10 +394,10 @@ void SoundMixer::setChannelVolume(PlayingSoundHandle handle, byte volume) { void SoundMixer::setChannelPan(PlayingSoundHandle handle, int8 pan) { Common::StackLock lock(_mutex); - if (handle == 0) + if (!handle.isActive()) return; - int index = handle - 1; + int index = handle.getIndex(); if ((index < 0) || (index >= NUM_CHANNELS)) { warning("soundMixer::setChannelVolume has invalid index %d", index); @@ -426,10 +426,10 @@ void SoundMixer::pauseHandle(PlayingSoundHandle handle, bool paused) { Common::StackLock lock(_mutex); // Simply ignore pause/unpause requests for handles of sound that alreayd terminated - if (handle == 0) + if (!handle.isActive()) return; - int index = handle - 1; + int index = handle.getIndex(); if ((index < 0) || (index >= NUM_CHANNELS)) { warning("soundMixer::pauseHandle has invalid index %d", index); @@ -496,7 +496,7 @@ Channel::~Channel() { delete _converter; delete _input; if (_handle) - *_handle = 0; + _handle->resetIndex(); } /* len indicates the number of sample *pairs*. So a value of diff --git a/sound/mixer.h b/sound/mixer.h index 3ed2cd798f..d1bd379408 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -35,12 +35,22 @@ #endif -typedef uint32 PlayingSoundHandle; - class AudioInputStream; class Channel; class File; +class PlayingSoundHandle { + friend class Channel; + friend class SoundMixer; + int val; + int getIndex() const { return val - 1; } + void setIndex(int i) { val = i + 1; } + void resetIndex() { val = 0; } +public: + PlayingSoundHandle() { resetIndex(); } + bool isActive() const { return val > 0; } +}; + class SoundMixer { public: typedef void PremixProc (void *param, int16 *data, uint len); |