1
0
Fork 0

Merge pull request #4601 from FearlessTobi/fix-0-percent-issue

dsp_interface: fix sound being played while volume is 0
This commit is contained in:
Weiyi Wang 2019-01-26 14:24:01 -05:00 committed by GitHub
commit bad2e084e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -77,7 +77,8 @@ void DspInterface::OutputCallback(s16* buffer, std::size_t num_frames) {
// Implementation of the hardware volume slider with a dynamic range of 60 dB // Implementation of the hardware volume slider with a dynamic range of 60 dB
const float linear_volume = std::clamp(Settings::values.volume, 0.0f, 1.0f); const float linear_volume = std::clamp(Settings::values.volume, 0.0f, 1.0f);
if (linear_volume != 1.0) { if (linear_volume != 1.0) {
const float volume_scale_factor = std::exp(6.90775f * linear_volume) * 0.001f; const float volume_scale_factor =
linear_volume == 0 ? 0 : std::exp(6.90775f * linear_volume) * 0.001f;
for (std::size_t i = 0; i < num_frames; i++) { for (std::size_t i = 0; i < num_frames; i++) {
buffer[i * 2 + 0] = static_cast<s16>(buffer[i * 2 + 0] * volume_scale_factor); buffer[i * 2 + 0] = static_cast<s16>(buffer[i * 2 + 0] * volume_scale_factor);
buffer[i * 2 + 1] = static_cast<s16>(buffer[i * 2 + 1] * volume_scale_factor); buffer[i * 2 + 1] = static_cast<s16>(buffer[i * 2 + 1] * volume_scale_factor);