mirror of https://github.com/libsdl-org/SDL
WASAPI_WaitDevice: Check current padding before waiting on event
During playback, don't queue another buffer unless there are none in the queue. During capture, there may be multiple buffers of audio available. WASAPI_CaptureFromDevice only processes one buffer, and if we always wait on the next event, we will never catch up if it falls behind.
This commit is contained in:
parent
d3d7c04bf8
commit
09fbb2a07d
|
@ -463,20 +463,22 @@ static int WASAPI_WaitDevice(SDL_AudioDevice *device)
|
||||||
{
|
{
|
||||||
// WaitDevice does not hold the device lock, so check for recovery/disconnect details here.
|
// WaitDevice does not hold the device lock, so check for recovery/disconnect details here.
|
||||||
while (RecoverWasapiIfLost(device) && device->hidden->client && device->hidden->event) {
|
while (RecoverWasapiIfLost(device) && device->hidden->client && device->hidden->event) {
|
||||||
DWORD waitResult = WaitForSingleObjectEx(device->hidden->event, 200, FALSE);
|
UINT32 padding = 0;
|
||||||
if (waitResult == WAIT_OBJECT_0) {
|
if (!WasapiFailed(device, IAudioClient_GetCurrentPadding(device->hidden->client, &padding))) {
|
||||||
const UINT32 maxpadding = device->sample_frames;
|
const UINT32 maxpadding = device->sample_frames;
|
||||||
UINT32 padding = 0;
|
//SDL_Log("WASAPI %s EVENT! padding=%u maxpadding=%u", device->iscapture ? "CAPTURE" : "PLAYBACK", (unsigned int)padding, (unsigned int)maxpadding);
|
||||||
if (!WasapiFailed(device, IAudioClient_GetCurrentPadding(device->hidden->client, &padding))) {
|
if (device->iscapture ? (padding > 0) : (padding < maxpadding)) {
|
||||||
//SDL_Log("WASAPI EVENT! padding=%u maxpadding=%u", (unsigned int)padding, (unsigned int)maxpadding);*/
|
break;
|
||||||
if (device->iscapture && (padding > 0)) {
|
|
||||||
break;
|
|
||||||
} else if (!device->iscapture && (padding <= maxpadding)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (waitResult != WAIT_TIMEOUT) {
|
}
|
||||||
//SDL_Log("WASAPI FAILED EVENT!");*/
|
|
||||||
|
switch (WaitForSingleObjectEx(device->hidden->event, 200, FALSE)) {
|
||||||
|
case WAIT_OBJECT_0:
|
||||||
|
case WAIT_TIMEOUT:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
//SDL_Log("WASAPI FAILED EVENT!");
|
||||||
IAudioClient_Stop(device->hidden->client);
|
IAudioClient_Stop(device->hidden->client);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue