From f82f65202ab66006f74ce85f4ec49b79ec78e5bb Mon Sep 17 00:00:00 2001 From: Julian <31388661+jgraj@users.noreply.github.com> Date: Sun, 4 Aug 2024 03:07:10 +0200 Subject: [PATCH] Add `void restartAudio()` to `wasapi.c` Rule of three --- .../WASAPI/Sources/kinc/backend/wasapi.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Backends/Audio2/WASAPI/Sources/kinc/backend/wasapi.c b/Backends/Audio2/WASAPI/Sources/kinc/backend/wasapi.c index f730ac361..8a62ae4ec 100644 --- a/Backends/Audio2/WASAPI/Sources/kinc/backend/wasapi.c +++ b/Backends/Audio2/WASAPI/Sources/kinc/backend/wasapi.c @@ -163,6 +163,12 @@ static bool initDefaultDevice() { } } +static void restartAudio() { + initDefaultDevice(); + submitEmptyBuffer(bufferFrames); + audioClient->lpVtbl->Start(audioClient); +} + static void copyS16Sample(int16_t *left, int16_t *right) { float left_value = *(float *)&a2_buffer.channels[0][a2_buffer.read_location]; float right_value = *(float *)&a2_buffer.channels[1][a2_buffer.read_location]; @@ -202,9 +208,7 @@ static void submitBuffer(unsigned frames) { HRESULT result = renderClient->lpVtbl->GetBuffer(renderClient, frames, &buffer); if (FAILED(result)) { if (result == AUDCLNT_E_DEVICE_INVALIDATED) { - initDefaultDevice(); - submitEmptyBuffer(bufferFrames); - audioClient->lpVtbl->Start(audioClient); + restartAudio(); } return; } @@ -228,9 +232,7 @@ static void submitBuffer(unsigned frames) { result = renderClient->lpVtbl->ReleaseBuffer(renderClient, frames, 0); if (FAILED(result)) { if (result == AUDCLNT_E_DEVICE_INVALIDATED) { - initDefaultDevice(); - submitEmptyBuffer(bufferFrames); - audioClient->lpVtbl->Start(audioClient); + restartAudio(); } } } @@ -244,9 +246,7 @@ static DWORD WINAPI audioThread(LPVOID ignored) { HRESULT result = audioClient->lpVtbl->GetCurrentPadding(audioClient, &padding); if (FAILED(result)) { if (result == AUDCLNT_E_DEVICE_INVALIDATED) { - initDefaultDevice(); - submitEmptyBuffer(bufferFrames); - audioClient->lpVtbl->Start(audioClient); + restartAudio(); } continue; }