Merge pull request #362 from PortAudio/winrt

wasapi: Fixed underruns in the Exclusive mode on UWP platform.
This commit is contained in:
Dmitry Kostjuchenko 2020-12-11 15:33:26 +02:00 committed by GitHub
commit 37a97ac470
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -825,7 +825,7 @@ static inline UINT32 ThreadIdleScheduler_NextSleep(ThreadIdleScheduler *sched)
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
typedef struct _SystemTimer typedef struct _SystemTimer
{ {
UINT32 granularity; INT32 granularity;
} SystemTimer; } SystemTimer;
static LARGE_INTEGER g_SystemTimerFrequency; static LARGE_INTEGER g_SystemTimerFrequency;
@ -849,12 +849,15 @@ static BOOL SystemTimer_SetGranularity(SystemTimer *timer, UINT32 granularity)
{ {
PRINT(("SetSystemTimer: timeBeginPeriod(1) failed!\n")); PRINT(("SetSystemTimer: timeBeginPeriod(1) failed!\n"));
timer->granularity = 0; timer->granularity = 10;
return FALSE; return FALSE;
} }
#else #else
(void)timer;
(void)granularity; (void)granularity;
// UWP does not support increase of the timer precision change and thus calling WaitForSingleObject with anything
// below 10 milliseconds will cause underruns for input and output stream.
timer->granularity = 10;
#endif #endif
return TRUE; return TRUE;
@ -6113,8 +6116,11 @@ static inline INT32 GetNextSleepTime(SystemTimer *timer, ThreadIdleScheduler *sc
// //
INT32 procTime = (INT32)(SystemTimer_GetTime(timer) - startTime); INT32 procTime = (INT32)(SystemTimer_GetTime(timer) - startTime);
nextSleepTime -= procTime; nextSleepTime -= procTime;
if (nextSleepTime < 0) if (nextSleepTime < timer->granularity)
nextSleepTime = 0; nextSleepTime = 0;
else
if (timer->granularity > 1)
nextSleepTime = ALIGN_BWD(nextSleepTime, timer->granularity);
#ifdef PA_WASAPI_LOG_TIME_SLOTS #ifdef PA_WASAPI_LOG_TIME_SLOTS
printf("{%d},", procTime); printf("{%d},", procTime);