Skip to content

Commit

Permalink
Add void restartAudio() to wasapi.c
Browse files Browse the repository at this point in the history
Rule of three
  • Loading branch information
jgraj authored Aug 4, 2024
1 parent a92527e commit f82f652
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Backends/Audio2/WASAPI/Sources/kinc/backend/wasapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();
}
}
}
Expand All @@ -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;
}
Expand Down

0 comments on commit f82f652

Please sign in to comment.