diff options
author | AlexOtsuka <eldaflash@gmail.com> | 2024-03-08 13:59:23 +0100 |
---|---|---|
committer | AlexOtsuka <eldaflash@gmail.com> | 2024-03-08 14:05:39 +0100 |
commit | 179b0786c6fa3a432dba9e8fc023a620c11a8a5d (patch) | |
tree | fdd7c469027ef9b8e78b7b2c07fc994d05733d90 /drivers/wasapi | |
parent | ffc41fb76df5922321cdd98cce12715a039629b0 (diff) | |
download | redot-engine-179b0786c6fa3a432dba9e8fc023a620c11a8a5d.tar.gz |
Fix audio crackling issues due to incorrect WASAPI buffer size
Diffstat (limited to 'drivers/wasapi')
-rw-r--r-- | drivers/wasapi/audio_driver_wasapi.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/wasapi/audio_driver_wasapi.cpp b/drivers/wasapi/audio_driver_wasapi.cpp index 64f2d1f203..8ea1f52d15 100644 --- a/drivers/wasapi/audio_driver_wasapi.cpp +++ b/drivers/wasapi/audio_driver_wasapi.cpp @@ -737,12 +737,17 @@ void AudioDriverWASAPI::thread_func(void *p_udata) { ad->start_counting_ticks(); if (avail_frames > 0 && ad->audio_output.audio_client) { + UINT32 buffer_size; UINT32 cur_frames; bool invalidated = false; - HRESULT hr = ad->audio_output.audio_client->GetCurrentPadding(&cur_frames); + HRESULT hr = ad->audio_output.audio_client->GetBufferSize(&buffer_size); + if (hr != S_OK) { + ERR_PRINT("WASAPI: GetBufferSize error"); + } + hr = ad->audio_output.audio_client->GetCurrentPadding(&cur_frames); if (hr == S_OK) { // Check how much frames are available on the WASAPI buffer - UINT32 write_frames = MIN(ad->buffer_frames - cur_frames, avail_frames); + UINT32 write_frames = MIN(buffer_size - cur_frames, avail_frames); if (write_frames > 0) { BYTE *buffer = nullptr; hr = ad->audio_output.render_client->GetBuffer(write_frames, &buffer); |