diff options
Diffstat (limited to 'engines/bladerunner/audio_mixer.cpp')
-rw-r--r-- | engines/bladerunner/audio_mixer.cpp | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/engines/bladerunner/audio_mixer.cpp b/engines/bladerunner/audio_mixer.cpp index 0bd7b04b89..d9d04e65d9 100644 --- a/engines/bladerunner/audio_mixer.cpp +++ b/engines/bladerunner/audio_mixer.cpp @@ -30,29 +30,30 @@ #include "common/timer.h" namespace BladeRunner { + AudioMixer::AudioMixer(BladeRunnerEngine *vm): _vm(vm) { - for (int i = 0; i < kAudioMixerChannels; i++) { + for (int i = 0; i < kChannels; i++) { _channels[i].isPresent = false; } - _vm->getTimerManager()->installTimerProc(timerCallback, 25 * 1000 , this, "BladeRunnerAudioMixerTimer"); + _vm->getTimerManager()->installTimerProc(timerCallback, (1000 / kUpdatesPerSecond) * 1000 , this, "BladeRunnerAudioMixerTimer"); } AudioMixer::~AudioMixer() { - for (int i = 0; i < kAudioMixerChannels; i++) { + for (int i = 0; i < kChannels; i++) { stop(i, 0); } _vm->getTimerManager()->removeTimerProc(timerCallback); } -int AudioMixer::playStream(Audio::Mixer::SoundType type, Audio::RewindableAudioStream *stream, int priority, bool loop, int volume, int pan, void (*endCallback)(int, void*), void *callbackData) { +int AudioMixer::play(Audio::Mixer::SoundType type, Audio::RewindableAudioStream *stream, int priority, bool loop, int volume, int pan, void (*endCallback)(int, void*), void *callbackData) { Common::StackLock lock(_mutex); int channel = -1; int lowestPriority = 1000000; int lowestPriorityChannel = -1; - for (int i = 0; i < kAudioMixerChannels; i++) { + for (int i = 0; i < kUsableChannels; i++) { if (!_channels[i].isPresent) { channel = i; break; @@ -70,6 +71,32 @@ int AudioMixer::playStream(Audio::Mixer::SoundType type, Audio::RewindableAudioS channel = lowestPriorityChannel; } + return playInChannel(channel, type, stream, priority, loop, volume, pan, endCallback, callbackData); +} + +int AudioMixer::playMusic(Audio::RewindableAudioStream *stream, int volume, void(*endCallback)(int, void *), void *callbackData) { + Common::StackLock lock(_mutex); + + return playInChannel(kMusicChannel, Audio::Mixer::kMusicSoundType, stream, 100, false, volume, 0, endCallback, callbackData); +} + +void AudioMixer::stop(int channel, int time) { + Common::StackLock lock(_mutex); + + if (_channels[channel].isPresent) { + if (time) { + adjustVolume(channel, 0, time); + } else { + _channels[channel].isPresent = false; + _vm->_mixer->stopHandle(_channels[channel].handle); + if (_channels[channel].endCallback != nullptr) { + _channels[channel].endCallback(channel, _channels[channel].callbackData); + } + } + } +} + +int AudioMixer::playInChannel(int channel, Audio::Mixer::SoundType type, Audio::RewindableAudioStream *stream, int priority, bool loop, int volume, int pan, void(*endCallback)(int, void *), void *callbackData) { _channels[channel].isPresent = true; _channels[channel].stream = stream; _channels[channel].priority = priority; @@ -83,7 +110,6 @@ int AudioMixer::playStream(Audio::Mixer::SoundType type, Audio::RewindableAudioS _channels[channel].endCallback = endCallback; _channels[channel].callbackData = callbackData; - Audio::AudioStream* audioStream = stream; if (loop) { @@ -101,22 +127,6 @@ int AudioMixer::playStream(Audio::Mixer::SoundType type, Audio::RewindableAudioS return channel; } -void AudioMixer::stop(int channel, int time) { - Common::StackLock lock(_mutex); - - if (_channels[channel].isPresent) { - if (time) { - adjustVolume(channel, 0, time); - } else { - _channels[channel].isPresent = false; - _vm->_mixer->stopHandle(_channels[channel].handle); - if (_channels[channel].endCallback != nullptr) { - _channels[channel].endCallback(channel, _channels[channel].callbackData); - } - } - } -} - bool AudioMixer::isActive(int channel) { Common::StackLock lock(_mutex); @@ -133,7 +143,7 @@ void AudioMixer::adjustVolume(int channel, int newVolume, int time) if (_channels[channel].isPresent) { _channels[channel].volumeTarget = newVolume; - _channels[channel].volumeDelta = ((newVolume - _channels[channel].volume) / (time / 60.0f)) / 40.0f; + _channels[channel].volumeDelta = ((newVolume - _channels[channel].volume) / (time / 60.0f)) / (float)kUpdatesPerSecond; } } @@ -144,7 +154,7 @@ void AudioMixer::adjustPan(int channel, int newPan, int time) if (_channels[channel].isPresent) { newPan = CLIP(newPan, -100, 100); _channels[channel].panTarget = newPan; - _channels[channel].panDelta = ((newPan - _channels[channel].pan) / (time / 60.0f)) / 40.0f; + _channels[channel].panDelta = ((newPan - _channels[channel].pan) / (time / 60.0f)) / (float)kUpdatesPerSecond; } } @@ -152,7 +162,7 @@ void AudioMixer::tick() { Common::StackLock lock(_mutex); - for (int i = 0; i < kAudioMixerChannels; i++) { + for (int i = 0; i < kChannels; i++) { Channel *channel = &_channels[i]; if (!channel->isPresent) { continue; |