diff options
Diffstat (limited to 'engines/sci/sound/audio32.cpp')
-rw-r--r-- | engines/sci/sound/audio32.cpp | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/engines/sci/sound/audio32.cpp b/engines/sci/sound/audio32.cpp index 4689d13d7d..0cf8e3cb13 100644 --- a/engines/sci/sound/audio32.cpp +++ b/engines/sci/sound/audio32.cpp @@ -124,10 +124,10 @@ Audio32::Audio32(ResourceManager *resMan) : _attenuatedMixing(true), - _monitoredChannelIndex(-1), - _monitoredBuffer(nullptr), - _monitoredBufferSize(0), - _numMonitoredSamples(0) { + _monitoredChannelIndex(-1), + _monitoredBuffer(nullptr), + _monitoredBufferSize(0), + _numMonitoredSamples(0) { if (getSciVersion() < SCI_VERSION_3) { _channels.resize(5); @@ -146,19 +146,13 @@ Audio32::Audio32(ResourceManager *resMan) : default: break; } - } else if (getSciVersion() == SCI_VERSION_2_1_EARLY) { - switch (g_sci->getGameId()) { - // 1.51 uses the non-standard attenuation, but 2.00b + } else if (getSciVersion() == SCI_VERSION_2_1_EARLY && g_sci->getGameId() == GID_KQ7) { + // KQ7 1.51 uses the non-standard attenuation, but 2.00b // does not, which is strange. - case GID_KQ7: - _useModifiedAttenuation = true; - default: - break; - } + _useModifiedAttenuation = true; } _mixer->playStream(Audio::Mixer::kSFXSoundType, &_handle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); - _mixer->pauseHandle(_handle, true); } Audio32::~Audio32() { @@ -240,16 +234,16 @@ int Audio32::writeAudioInternal(Audio::RewindableAudioStream *const sourceStream int Audio32::readBuffer(Audio::st_sample_t *buffer, const int numSamples) { Common::StackLock lock(_mutex); + if (_pausedAtTick != 0 || _numActiveChannels == 0) { + return 0; + } + // ResourceManager is not thread-safe so we need to // avoid calling into it from the audio thread, but at // the same time we need to be able to clear out any // finished channels on a regular basis _inAudioThread = true; - // The system mixer should not try to get data when - // Audio32 is paused - assert(_pausedAtTick == 0 && _numActiveChannels > 0); - freeUnusedChannels(); // The caller of `readBuffer` is a rate converter, @@ -359,6 +353,16 @@ int Audio32::readBuffer(Audio::st_sample_t *buffer, const int numSamples) { maxSamplesWritten = _numMonitoredSamples; } } else if (!channel.stream->endOfStream() || channel.loop) { + if (_monitoredChannelIndex != -1) { + // Audio that is not on the monitored channel is silent + // when the monitored channel is active, but the stream still + // needs to be read in order to ensure that sound effects sync + // up once the monitored channel is turned off. The easiest + // way to guarantee this is to just do the normal channel read, + // but set the channel volume to zero so nothing is mixed in + leftVolume = rightVolume = 0; + } + const int channelSamplesWritten = writeAudioInternal(channel.stream, channel.converter, buffer, numSamples, leftVolume, rightVolume, channel.loop); if (channelSamplesWritten > maxSamplesWritten) { maxSamplesWritten = channelSamplesWritten; @@ -652,7 +656,6 @@ uint16 Audio32::play(int16 channelIndex, const ResourceId resourceId, const bool if (_numActiveChannels == 1) { _startedAtTick = now; - _mixer->pauseHandle(_handle, false); } return channel.duration; @@ -683,7 +686,6 @@ bool Audio32::resume(const int16 channelIndex) { _startedAtTick += now - _pausedAtTick; _pausedAtTick = 0; - _mixer->pauseHandle(_handle, false); return true; } else if (channelIndex == kRobotChannel) { for (int i = 0; i < _numActiveChannels; ++i) { @@ -720,7 +722,6 @@ bool Audio32::pause(const int16 channelIndex) { if (channelIndex == kAllChannels) { if (_pausedAtTick == 0) { _pausedAtTick = now; - _mixer->pauseHandle(_handle, true); didPause = true; } } else if (channelIndex == kRobotChannel) { @@ -773,9 +774,6 @@ int16 Audio32::stop(const int16 channelIndex) { // NOTE: SSCI stops the DSP interrupt and frees the // global decompression buffer here if there are no // more active channels - if (_numActiveChannels == 0) { - _mixer->pauseHandle(_handle, true); - } return oldNumChannels; } @@ -891,17 +889,15 @@ reg_t Audio32::kernelPlay(const bool autoPlay, const int argc, const reg_t *cons #pragma mark Effects int16 Audio32::getVolume(const int16 channelIndex) const { - Common::StackLock lock(_mutex); if (channelIndex < 0 || channelIndex >= _numActiveChannels) { return _mixer->getChannelVolume(_handle) * kMaxVolume / Audio::Mixer::kMaxChannelVolume; } + Common::StackLock lock(_mutex); return getChannel(channelIndex).volume; } void Audio32::setVolume(const int16 channelIndex, int16 volume) { - Common::StackLock lock(_mutex); - volume = MIN((int16)kMaxVolume, volume); if (channelIndex == kAllChannels) { ConfMan.setInt("sfx_volume", volume * Audio::Mixer::kMaxChannelVolume / kMaxVolume); @@ -909,6 +905,7 @@ void Audio32::setVolume(const int16 channelIndex, int16 volume) { _mixer->setChannelVolume(_handle, volume * Audio::Mixer::kMaxChannelVolume / kMaxVolume); g_engine->syncSoundSettings(); } else if (channelIndex != kNoExistingChannel) { + Common::StackLock lock(_mutex); getChannel(channelIndex).volume = volume; } } |