diff options
Diffstat (limited to 'sound')
-rw-r--r-- | sound/audiocd.cpp | 2 | ||||
-rw-r--r-- | sound/audiocd.h | 4 | ||||
-rw-r--r-- | sound/flac.cpp | 4 | ||||
-rw-r--r-- | sound/mixer.cpp | 26 | ||||
-rw-r--r-- | sound/mixer.h | 32 | ||||
-rw-r--r-- | sound/mp3.cpp | 4 | ||||
-rw-r--r-- | sound/softsynth/mt32.cpp | 2 | ||||
-rw-r--r-- | sound/vorbis.cpp | 4 |
8 files changed, 44 insertions, 34 deletions
diff --git a/sound/audiocd.cpp b/sound/audiocd.cpp index e8a74d062c..3188d03cee 100644 --- a/sound/audiocd.cpp +++ b/sound/audiocd.cpp @@ -105,7 +105,7 @@ bool AudioCDManager::isPlaying() const { void AudioCDManager::updateCD() { if (_cd.playing) { // If the sound handle is 0, then playback stopped. - if (!_cd.handle.isActive()) { + if (!g_engine->_mixer->isSoundHandleActive(_cd.handle)) { // 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. diff --git a/sound/audiocd.h b/sound/audiocd.h index d523bc5a46..8d2ffdc364 100644 --- a/sound/audiocd.h +++ b/sound/audiocd.h @@ -30,7 +30,7 @@ class DigitalTrackInfo { public: virtual bool error() = 0; - virtual void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) = 0; + virtual void play(SoundMixer *mixer, SoundHandle *handle, int startFrame, int duration) = 0; virtual ~DigitalTrackInfo() { } }; @@ -62,7 +62,7 @@ private: private: /* used for emulated CD music */ struct ExtStatus : Status { - PlayingSoundHandle handle; + SoundHandle handle; }; ExtStatus _cd; diff --git a/sound/flac.cpp b/sound/flac.cpp index eb8e0a1bec..409bb293a1 100644 --- a/sound/flac.cpp +++ b/sound/flac.cpp @@ -746,7 +746,7 @@ public: FlacTrackInfo(File *file); ~FlacTrackInfo(); bool error() { return _file == NULL; } - void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration); + void play(SoundMixer *mixer, SoundHandle *handle, int startFrame, int duration); }; FlacTrackInfo::FlacTrackInfo(File *file) : _file(NULL), _firstStream(NULL) @@ -760,7 +760,7 @@ FlacTrackInfo::FlacTrackInfo(File *file) : _file(NULL), _firstStream(NULL) delete tempStream; } -void FlacTrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) { +void FlacTrackInfo::play(SoundMixer *mixer, SoundHandle *handle, int startFrame, int duration) { if (error()) { debug(1, "FlacTrackInfo::play: invalid state, method should not been called"); } diff --git a/sound/mixer.cpp b/sound/mixer.cpp index 78a2e9f7dd..0ea88373a1 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -47,7 +47,7 @@ public: const SoundMixer::SoundType _type; private: SoundMixer *_mixer; - PlayingSoundHandle *_handle; + SoundHandle *_handle; bool _autofreeStream; bool _permanent; byte _volume; @@ -64,8 +64,8 @@ protected: public: - Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, int id = -1); - Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, AudioStream *input, bool autofreeStream, bool reverseStereo = false, int id = -1, bool permanent = false); + Channel(SoundMixer *mixer, SoundHandle *handle, SoundMixer::SoundType type, int id = -1); + Channel(SoundMixer *mixer, SoundHandle *handle, SoundMixer::SoundType type, AudioStream *input, bool autofreeStream, bool reverseStereo = false, int id = -1, bool permanent = false); virtual ~Channel(); void mix(int16 *data, uint len); @@ -148,7 +148,7 @@ void SoundMixer::setupPremix(AudioStream *stream, SoundType type) { _premixChannel = new Channel(this, 0, type, stream, false); } -void SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) { +void SoundMixer::insertChannel(SoundHandle *handle, Channel *chan) { int index = -1; for (int i = 0; i != NUM_CHANNELS; i++) { @@ -168,7 +168,7 @@ void SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) { handle->setIndex(index); } -void SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, +void SoundMixer::playRaw(SoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id, byte volume, int8 balance, uint32 loopStart, uint32 loopEnd, SoundType type) { Common::StackLock lock(_mutex); @@ -202,7 +202,7 @@ void SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, u insertChannel(handle, chan); } -void SoundMixer::playInputStream(SoundType type, PlayingSoundHandle *handle, AudioStream *input, +void SoundMixer::playInputStream(SoundType type, SoundHandle *handle, AudioStream *input, int id, byte volume, int8 balance, bool autofreeStream, bool permanent) { Common::StackLock lock(_mutex); @@ -279,7 +279,7 @@ void SoundMixer::stopID(int id) { } } -void SoundMixer::stopHandle(PlayingSoundHandle handle) { +void SoundMixer::stopHandle(SoundHandle handle) { Common::StackLock lock(_mutex); // Simply ignore stop requests for handles of sounds that already terminated @@ -299,7 +299,7 @@ void SoundMixer::stopHandle(PlayingSoundHandle handle) { } } -void SoundMixer::setChannelVolume(PlayingSoundHandle handle, byte volume) { +void SoundMixer::setChannelVolume(SoundHandle handle, byte volume) { Common::StackLock lock(_mutex); if (!handle.isActive()) @@ -316,7 +316,7 @@ void SoundMixer::setChannelVolume(PlayingSoundHandle handle, byte volume) { _channels[index]->setVolume(volume); } -void SoundMixer::setChannelBalance(PlayingSoundHandle handle, int8 balance) { +void SoundMixer::setChannelBalance(SoundHandle handle, int8 balance) { Common::StackLock lock(_mutex); if (!handle.isActive()) @@ -341,7 +341,7 @@ uint32 SoundMixer::getSoundElapsedTimeOfSoundID(int id) { return 0; } -uint32 SoundMixer::getSoundElapsedTime(PlayingSoundHandle handle) { +uint32 SoundMixer::getSoundElapsedTime(SoundHandle handle) { Common::StackLock lock(_mutex); if (!handle.isActive()) @@ -375,7 +375,7 @@ void SoundMixer::pauseID(int id, bool paused) { } } -void SoundMixer::pauseHandle(PlayingSoundHandle handle, bool paused) { +void SoundMixer::pauseHandle(SoundHandle handle, bool paused) { Common::StackLock lock(_mutex); // Simply ignore pause/unpause requests for handles of sound that alreayd terminated @@ -436,14 +436,14 @@ int SoundMixer::getVolumeForSoundType(SoundType type) const { #pragma mark - -Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, int id) +Channel::Channel(SoundMixer *mixer, SoundHandle *handle, SoundMixer::SoundType type, int id) : _type(type), _mixer(mixer), _handle(handle), _autofreeStream(true), _volume(SoundMixer::kMaxChannelVolume), _balance(0), _paused(false), _id(id), _samplesConsumed(0), _samplesDecoded(0), _mixerTimeStamp(0), _converter(0), _input(0) { assert(mixer); } -Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, AudioStream *input, +Channel::Channel(SoundMixer *mixer, SoundHandle *handle, SoundMixer::SoundType type, AudioStream *input, bool autofreeStream, bool reverseStereo, int id, bool permanent) : _type(type), _mixer(mixer), _handle(handle), _autofreeStream(autofreeStream), _volume(SoundMixer::kMaxChannelVolume), _balance(0), _paused(false), _id(id), _samplesConsumed(0), diff --git a/sound/mixer.h b/sound/mixer.h index aef5602c03..8121cee08c 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -33,16 +33,16 @@ class Channel; class File; class OSystem; -class PlayingSoundHandle { +class SoundHandle { 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; } +public: + SoundHandle() { resetIndex(); } }; class SoundMixer { @@ -136,7 +136,7 @@ public: * (using the makeLinearInputStream factory function), which is then * passed on to playInputStream. */ - void playRaw(PlayingSoundHandle *handle, + void playRaw(SoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id = -1, byte volume = 255, int8 balance = 0, uint32 loopStart = 0, uint32 loopEnd = 0, @@ -145,7 +145,7 @@ public: /** * Start playing the given audio input stream. */ - void playInputStream(SoundType type, PlayingSoundHandle *handle, AudioStream *input, + void playInputStream(SoundType type, SoundHandle *handle, AudioStream *input, int id = -1, byte volume = 255, int8 balance = 0, bool autofreeStream = true, bool permanent = false); @@ -168,7 +168,7 @@ public: * * @param handle the sound to affect */ - void stopHandle(PlayingSoundHandle handle); + void stopHandle(SoundHandle handle); @@ -194,7 +194,7 @@ public: * @param handle the sound to affect * @param paused true to pause the sound, false to unpause it */ - void pauseHandle(PlayingSoundHandle handle, bool paused); + void pauseHandle(SoundHandle handle, bool paused); @@ -207,6 +207,16 @@ public: bool isSoundIDActive(int id); /** + * Check if a sound with the given hANDLE is active. + * + * @param handle the sound to query + * @return true if the sound is active + */ + bool isSoundHandleActive(SoundHandle handle) { + return handle.isActive(); + } + + /** * Check if the mixer is paused (using pauseAll). * * @return true if the mixer is paused @@ -221,7 +231,7 @@ public: * @param handle the sound to affect * @param volume the new channel volume (0 - 255) */ - void setChannelVolume(PlayingSoundHandle handle, byte volume); + void setChannelVolume(SoundHandle handle, byte volume); /** * Set the channel balance for the given handle. @@ -230,7 +240,7 @@ public: * @param balance the new channel balance: * (-127 ... 0 ... 127) corresponds to (left ... center ... right) */ - void setChannelBalance(PlayingSoundHandle handle, int8 balance); + void setChannelBalance(SoundHandle handle, int8 balance); /** * Get approximation of for how long the Sound ID has been playing. @@ -240,7 +250,7 @@ public: /** * Get approximation of for how long the channel has been playing. */ - uint32 getSoundElapsedTime(PlayingSoundHandle handle); + uint32 getSoundElapsedTime(SoundHandle handle); /** * Check whether any channel of the given sound type is active. @@ -275,7 +285,7 @@ public: uint getOutputRate() const { return _outputRate; } private: - void insertChannel(PlayingSoundHandle *handle, Channel *chan); + void insertChannel(SoundHandle *handle, Channel *chan); /** * Internal main method -- all the actual mixing work is done from here. diff --git a/sound/mp3.cpp b/sound/mp3.cpp index 708d3396b9..79a4635be1 100644 --- a/sound/mp3.cpp +++ b/sound/mp3.cpp @@ -285,7 +285,7 @@ public: MP3TrackInfo(File *file); ~MP3TrackInfo(); bool error() { return _error_flag; } - void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration); + void play(SoundMixer *mixer, SoundHandle *handle, int startFrame, int duration); }; @@ -360,7 +360,7 @@ error: delete file; } -void MP3TrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) { +void MP3TrackInfo::play(SoundMixer *mixer, SoundHandle *handle, int startFrame, int duration) { unsigned int offset; mad_timer_t durationTime; diff --git a/sound/softsynth/mt32.cpp b/sound/softsynth/mt32.cpp index ad3f41af6d..a62b2459f5 100644 --- a/sound/softsynth/mt32.cpp +++ b/sound/softsynth/mt32.cpp @@ -43,7 +43,7 @@ class MidiChannel_MT32 : public MidiChannel_MPU401 { class MidiDriver_MT32 : public MidiDriver_Emulated { private: - PlayingSoundHandle _handle; + SoundHandle _handle; MidiChannel_MT32 _midiChannels[16]; uint16 _channelMask; MT32Emu::Synth *_synth; diff --git a/sound/vorbis.cpp b/sound/vorbis.cpp index 8886a63a05..deca2c62c3 100644 --- a/sound/vorbis.cpp +++ b/sound/vorbis.cpp @@ -50,7 +50,7 @@ public: ~VorbisTrackInfo(); bool openTrack(); bool error() { return _error_flag; } - void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration); + void play(SoundMixer *mixer, SoundHandle *handle, int startFrame, int duration); }; @@ -166,7 +166,7 @@ VorbisTrackInfo::~VorbisTrackInfo() { #define VORBIS_TREMOR #endif -void VorbisTrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) { +void VorbisTrackInfo::play(SoundMixer *mixer, SoundHandle *handle, int startFrame, int duration) { bool err = openTrack(); assert(!err); |