Commit bb512a8f authored by David Reid's avatar David Reid

WASAPI: Fix a bug introduced in the previous commit.

This was resulting in a loop consuming 100% of the CPU.
parent ee2e7694
...@@ -15668,34 +15668,32 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice) ...@@ -15668,34 +15668,32 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice)
break; break;
} }
if (framesAvailablePlayback < pDevice->wasapi.periodSizeInFramesPlayback) { if (framesAvailablePlayback >= pDevice->wasapi.periodSizeInFramesPlayback) {
continue; /* No space available. */ /* Map a the data buffer in preparation for the callback. */
} hr = ma_IAudioRenderClient_GetBuffer((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient, framesAvailablePlayback, &pMappedDeviceBufferPlayback);
if (FAILED(hr)) {
ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve internal buffer from playback device in preparation for writing to the device.", ma_result_from_HRESULT(hr));
exitLoop = MA_TRUE;
break;
}
/* Map a the data buffer in preparation for the callback. */ /* We should have a buffer at this point. */
hr = ma_IAudioRenderClient_GetBuffer((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient, framesAvailablePlayback, &pMappedDeviceBufferPlayback); ma_device__read_frames_from_client(pDevice, framesAvailablePlayback, pMappedDeviceBufferPlayback);
if (FAILED(hr)) {
ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve internal buffer from playback device in preparation for writing to the device.", ma_result_from_HRESULT(hr));
exitLoop = MA_TRUE;
break;
}
/* We should have a buffer at this point. */ /* At this point we're done writing to the device and we just need to release the buffer. */
ma_device__read_frames_from_client(pDevice, framesAvailablePlayback, pMappedDeviceBufferPlayback); hr = ma_IAudioRenderClient_ReleaseBuffer((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient, framesAvailablePlayback, 0);
pMappedDeviceBufferPlayback = NULL; /* <-- Important. Not doing this can result in an error once we leave this loop because it will use this to know whether or not a final ReleaseBuffer() needs to be called. */
mappedDeviceBufferSizeInFramesPlayback = 0;
/* At this point we're done writing to the device and we just need to release the buffer. */ if (FAILED(hr)) {
hr = ma_IAudioRenderClient_ReleaseBuffer((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient, framesAvailablePlayback, 0); ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to release internal buffer from playback device after writing to the device.", ma_result_from_HRESULT(hr));
pMappedDeviceBufferPlayback = NULL; /* <-- Important. Not doing this can result in an error once we leave this loop because it will use this to know whether or not a final ReleaseBuffer() needs to be called. */ exitLoop = MA_TRUE;
mappedDeviceBufferSizeInFramesPlayback = 0; break;
}
if (FAILED(hr)) { framesWrittenToPlaybackDevice += framesAvailablePlayback;
ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to release internal buffer from playback device after writing to the device.", ma_result_from_HRESULT(hr));
exitLoop = MA_TRUE;
break;
} }
framesWrittenToPlaybackDevice += framesAvailablePlayback;
if (!c89atomic_load_8(&pDevice->wasapi.isStartedPlayback)) { if (!c89atomic_load_8(&pDevice->wasapi.isStartedPlayback)) {
hr = ma_IAudioClient_Start((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); hr = ma_IAudioClient_Start((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback);
if (FAILED(hr)) { if (FAILED(hr)) {
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment