Skip to content

Commit

Permalink
Merge pull request #879 from jgraj/patch-1
Browse files Browse the repository at this point in the history
Add `void restartAudio()` to `wasapi.c`
  • Loading branch information
RobDangerous authored Aug 4, 2024
2 parents a92527e + f82f652 commit 8b8eec7
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 8b8eec7

Please sign in to comment.