From: Toni Wilen Date: Sun, 14 Jan 2024 17:12:13 +0000 (+0200) Subject: UAE AHI ignored AHI sound volume and master volume was converted incorrectly X-Git-Tag: 5200~58 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=7c89049bdd71d3ad1b3f2905bccafb4c6ad6fd26;p=francis%2Fwinuae.git UAE AHI ignored AHI sound volume and master volume was converted incorrectly --- diff --git a/od-win32/ahidsound_dsonly.cpp b/od-win32/ahidsound_dsonly.cpp index f89aebf8..155bfa2a 100644 --- a/od-win32/ahidsound_dsonly.cpp +++ b/od-win32/ahidsound_dsonly.cpp @@ -298,14 +298,21 @@ static int ahi_init_record_win32 (void) return 1; } -void setvolume_ahi (LONG vol) +void setvolume_ahi(LONG volume) { HRESULT hr; + if (!lpDS2) return; - hr = IDirectSoundBuffer_SetVolume (lpDSB2, vol); - if (FAILED (hr)) - write_log (_T("AHI: SetVolume(%d) failed: %s\n"), vol, DXError (hr)); + + float adjvol = (100.0f - currprefs.sound_volume_board) * (100.0f - volume) / 100.0f; + LONG vol = DSBVOLUME_MIN; + if (adjvol > 0) { + vol = (LONG)((DSBVOLUME_MIN / 2) + (-DSBVOLUME_MIN / 2) * log(1 + (2.718281828 - 1) * (adjvol / 100.0))); + } + hr = IDirectSoundBuffer_SetVolume(lpDSB2, vol); + if (FAILED(hr)) + write_log(_T("AHI: SetVolume(%d) failed: %s\n"), vol, DXError (hr)); } static int ahi_init_sound_win32 (void)