diff options
Diffstat (limited to 'sound')
-rw-r--r-- | sound/flac.cpp | 2 | ||||
-rw-r--r-- | sound/mixer.cpp | 59 | ||||
-rw-r--r-- | sound/mixer.h | 48 | ||||
-rw-r--r-- | sound/mp3.cpp | 2 | ||||
-rw-r--r-- | sound/softsynth/mt32.cpp | 2 | ||||
-rw-r--r-- | sound/vorbis.cpp | 2 |
6 files changed, 54 insertions, 61 deletions
diff --git a/sound/flac.cpp b/sound/flac.cpp index 15e04f34f6..b0306967e0 100644 --- a/sound/flac.cpp +++ b/sound/flac.cpp @@ -783,7 +783,7 @@ void FlacTrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int star flac->setLastSample(0); if (flac->seekAbsolute(static_cast<FLAC__uint64>(startFrame) * (info.sample_rate / 75))) { - mixer->playInputStream(handle, flac, true); + mixer->playInputStream(SoundMixer::kMusicAudioDataType, handle, flac); return; } // startSample is beyond the existing Samples diff --git a/sound/mixer.cpp b/sound/mixer.cpp index 6e8f514c1f..76d2697586 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -41,11 +41,12 @@ * Channels used by the sound mixer. */ class Channel { +public: + const SoundMixer::SoundType _type; private: SoundMixer *_mixer; PlayingSoundHandle *_handle; bool _autofreeStream; - const bool _isMusic; bool _permanent; byte _volume; int8 _balance; @@ -61,8 +62,8 @@ protected: public: - Channel(SoundMixer *mixer, PlayingSoundHandle *handle, bool isMusic, int id = -1); - Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioStream *input, bool autofreeStream, bool isMusic, bool reverseStereo = false, int id = -1, bool permanent = false); + 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); virtual ~Channel(); void mix(int16 *data, uint len); @@ -73,9 +74,6 @@ public: bool isFinished() const { return _input->endOfStream(); } - bool isMusicChannel() const { - return _isMusic; - } void pause(bool paused) { _paused = paused; } @@ -107,8 +105,8 @@ SoundMixer::SoundMixer() { _premixChannel = 0; int i = 0; - _globalVolume = 0; - _musicVolume = 0; + for (i = 0; i < ARRAYSIZE(_volumeForSoundType); i++) + _volumeForSoundType[i] = 256; _paused = false; @@ -148,7 +146,7 @@ void SoundMixer::setupPremix(AudioStream *stream) { return; // Create the channel - _premixChannel = new Channel(this, 0, stream, false, true); + _premixChannel = new Channel(this, 0, kPlainAudioDataType, stream, false); } void SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) { @@ -172,7 +170,7 @@ void SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) { } void SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, - int id, byte volume, int8 balance, uint32 loopStart, uint32 loopEnd) { + int id, byte volume, int8 balance, uint32 loopStart, uint32 loopEnd, SoundType type) { Common::StackLock lock(_mutex); // Prevent duplicate sounds @@ -199,13 +197,13 @@ void SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, u } // Create the channel - Channel *chan = new Channel(this, handle, input, true, false, (flags & SoundMixer::FLAG_REVERSE_STEREO) != 0, id); + Channel *chan = new Channel(this, handle, type, input, true, (flags & SoundMixer::FLAG_REVERSE_STEREO) != 0, id); chan->setVolume(volume); chan->setBalance(balance); insertChannel(handle, chan); } -void SoundMixer::playInputStream(PlayingSoundHandle *handle, AudioStream *input, bool isMusic, +void SoundMixer::playInputStream(SoundType type, PlayingSoundHandle *handle, AudioStream *input, int id, byte volume, int8 balance, bool autofreeStream, bool permanent) { Common::StackLock lock(_mutex); @@ -225,7 +223,7 @@ void SoundMixer::playInputStream(PlayingSoundHandle *handle, AudioStream *input, } // Create the channel - Channel *chan = new Channel(this, handle, input, autofreeStream, isMusic, false, id, permanent); + Channel *chan = new Channel(this, handle, type, input, autofreeStream, false, id, permanent); chan->setVolume(volume); chan->setBalance(balance); insertChannel(handle, chan); @@ -396,16 +394,17 @@ bool SoundMixer::isSoundIDActive(int id) { return false; } -bool SoundMixer::hasActiveSFXChannel() { - // FIXME/TODO: We need to distinguish between SFX and music channels +bool SoundMixer::hasActiveChannelOfType(SoundType type) { Common::StackLock lock(_mutex); for (int i = 0; i != NUM_CHANNELS; i++) - if (_channels[i] && !_channels[i]->isMusicChannel()) + if (_channels[i] && !_channels[i]->_type == type) return true; return false; } -void SoundMixer::setVolume(int volume) { +void SoundMixer::setVolumeForSoundType(SoundType type, int volume) { + assert(0 <= type && type < ARRAYSIZE(_volumeForSoundType)); + // Check range if (volume > 256) volume = 256; @@ -415,17 +414,13 @@ void SoundMixer::setVolume(int volume) { // TODO: Maybe we should do logarithmic (not linear) volume // scaling? See also Player_V2::setMasterVolume - _globalVolume = volume; + _volumeForSoundType[type] = volume; } -void SoundMixer::setMusicVolume(int volume) { - // Check range - if (volume > 256) - volume = 256; - else if (volume < 0) - volume = 0; - - _musicVolume = volume; +int SoundMixer::getVolumeForSoundType(SoundType type) const { + assert(0 <= type && type < ARRAYSIZE(_volumeForSoundType)); + + return _volumeForSoundType[type]; } @@ -434,16 +429,16 @@ void SoundMixer::setMusicVolume(int volume) { #pragma mark - -Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, bool isMusic, int id) - : _mixer(mixer), _handle(handle), _autofreeStream(true), _isMusic(isMusic), +Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, int id) + : _type(type), _mixer(mixer), _handle(handle), _autofreeStream(true), _volume(255), _balance(0), _paused(false), _id(id), _samplesConsumed(0), _samplesDecoded(0), _mixerTimeStamp(0), _converter(0), _input(0) { assert(mixer); } -Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioStream *input, - bool autofreeStream, bool isMusic, bool reverseStereo, int id, bool permanent) - : _mixer(mixer), _handle(handle), _autofreeStream(autofreeStream), _isMusic(isMusic), +Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, AudioStream *input, + bool autofreeStream, bool reverseStereo, int id, bool permanent) + : _type(type), _mixer(mixer), _handle(handle), _autofreeStream(autofreeStream), _volume(255), _balance(0), _paused(false), _id(id), _samplesConsumed(0), _samplesDecoded(0), _mixerTimeStamp(0), _converter(0), _input(input), _permanent(permanent) { assert(mixer); @@ -481,7 +476,7 @@ void Channel::mix(int16 *data, uint len) { // volume is in the range 0 - 256. // Hence, the vol_l/vol_r values will be in that range, too - int vol = (isMusicChannel() ? _mixer->getMusicVolume() : _mixer->getVolume()) * _volume; + int vol = _mixer->getVolumeForSoundType(_type) * _volume; st_volume_t vol_l, vol_r; if (_balance == 0) { diff --git a/sound/mixer.h b/sound/mixer.h index b70c3b8692..268e66296f 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -68,6 +68,14 @@ public: /** loop the audio */ FLAG_LOOP = 1 << 6 }; + + enum SoundType { + kPlainAudioDataType = 0, + + kMusicAudioDataType = 1, + kSFXAudioDataType = 2 + // kSpeechAudioDataType = 3 TODO: Add this type later... + }; private: enum { @@ -81,8 +89,7 @@ private: uint _outputRate; - int _globalVolume; - int _musicVolume; + int _volumeForSoundType[4]; bool _paused; @@ -123,14 +130,16 @@ public: * (using the makeLinearInputStream factory function), which is then * passed on to playInputStream. */ - void playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, + void playRaw(PlayingSoundHandle *handle, + void *sound, uint32 size, uint rate, byte flags, int id = -1, byte volume = 255, int8 balance = 0, - uint32 loopStart = 0, uint32 loopEnd = 0); + uint32 loopStart = 0, uint32 loopEnd = 0, + SoundType type = kSFXAudioDataType); /** * Start playing the given audio input stream. */ - void playInputStream(PlayingSoundHandle *handle, AudioStream *input, bool isMusic, + void playInputStream(SoundType type, PlayingSoundHandle *handle, AudioStream *input, int id = -1, byte volume = 255, int8 balance = 0, bool autofreeStream = true, bool permanent = false); @@ -223,39 +232,28 @@ public: uint32 getSoundElapsedTime(PlayingSoundHandle handle); /** - * Check whether any SFX channel is active. + * Check whether any channel of the given sound type is active. + * For example, this can be used to check whether any SFX sound + * is currently playing, by checking for type kSFXAudioDataType. * - * @return true if any SFX (= non-music) channels are active. + * @param type the sound type to look for + * @return true if any channels of the specified type are active. */ - bool hasActiveSFXChannel(); + bool hasActiveChannelOfType(SoundType type); /** - * Set the global volume. + * Set the volume for the given sound type. * * @param volume the new global volume, 0-256 */ - void setVolume(int volume); + void setVolumeForSoundType(SoundType type, int volume); /** * Query the global volume. * * @return the global music volume, 0-256 */ - int getVolume() const { return _globalVolume; } - - /** - * Set the music volume. - * - * @param volume the new music volume, 0-256 - */ - void setMusicVolume(int volume); - - /** - * Query the music volume. - * - * @return the current music volume, 0-256 - */ - int getMusicVolume() const { return _musicVolume; } + int getVolumeForSoundType(SoundType type) const; /** * Query the system's audio output sample rate. This returns diff --git a/sound/mp3.cpp b/sound/mp3.cpp index a81f2171e3..51f444aa1c 100644 --- a/sound/mp3.cpp +++ b/sound/mp3.cpp @@ -380,7 +380,7 @@ void MP3TrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int start // Play it AudioStream *input = new MP3InputStream(_file, durationTime); - mixer->playInputStream(handle, input, true); + mixer->playInputStream(SoundMixer::kMusicAudioDataType, handle, input); } MP3TrackInfo::~MP3TrackInfo() { diff --git a/sound/softsynth/mt32.cpp b/sound/softsynth/mt32.cpp index 4789e46fc7..3244e0bb42 100644 --- a/sound/softsynth/mt32.cpp +++ b/sound/softsynth/mt32.cpp @@ -267,7 +267,7 @@ int MidiDriver_MT32::open() { _initialising = false; g_system->clearScreen(); g_system->updateScreen(); - _mixer->playInputStream(&_handle, this, false, -1, 255, 0, false, true); + _mixer->playInputStream(SoundMixer::kSFXAudioDataType, &_handle, this, -1, 255, 0, false, true); return 0; } diff --git a/sound/vorbis.cpp b/sound/vorbis.cpp index 2b3b416fb3..0ddf423439 100644 --- a/sound/vorbis.cpp +++ b/sound/vorbis.cpp @@ -178,7 +178,7 @@ void VorbisTrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int st #endif AudioStream *input = makeVorbisStream(&_ov_file, duration * ov_info(&_ov_file, -1)->rate / 75); - mixer->playInputStream(handle, input, true); + mixer->playInputStream(SoundMixer::kMusicAudioDataType, handle, input); } DigitalTrackInfo *getVorbisTrack(int track) { |