diff --git a/src/contrib/directsoundout/DirectSoundOut.cpp b/src/contrib/directsoundout/DirectSoundOut.cpp index ca1b48d07..e6f4a292c 100644 --- a/src/contrib/directsoundout/DirectSoundOut.cpp +++ b/src/contrib/directsoundout/DirectSoundOut.cpp @@ -158,14 +158,21 @@ void DirectSoundOut::SetVolume(double volume) { if (this->state != StateStopped) { if (this->secondaryBuffer) { - double db = (volume < 0.0001f) - ? DSBVOLUME_MIN - : log10(this->volume) * 6000.f; + /* normalize between 1 and 10000 (DSBVOLUME_MIN) */ + double scaled = fabs(volume * 10000); + scaled = scaled < 0 ? 1 : scaled; + + /* found on experts-exchange (20181717) */ + double db = ((log10(scaled) / 4) * 10000) - 10000; if (db > DSBVOLUME_MAX) { db = DSBVOLUME_MAX; } + if (db < DSBVOLUME_MIN) { + db = DSBVOLUME_MIN; + } + this->secondaryBuffer->SetVolume((LONG) db); } }