From: dmitrykos Date: Fri, 6 Aug 2010 20:25:07 +0000 (+0000) Subject: wasapi: X-Git-Tag: pa_stable_v19_20110326_r1647~95 X-Git-Url: https://andrewgundersen.net/repos?a=commitdiff_plain;h=9c7974c76c372de394588b75aee6e1f01f283706;p=portaudio wasapi: - fixed alignment missing for host buffer if overall buffer size was set to less than 3ms that results in device timeout - advanced Event driven mode and extended the range of host buffer size which can operate in this mode up up to 20.66 ms, e.g. your device buffer size will vary in range 3 - 20.66 ms, if goes above then Poll driven mode is switched on automatically --- diff --git a/include/pa_win_wasapi.h b/include/pa_win_wasapi.h index e949dfe..64eb49b 100644 --- a/include/pa_win_wasapi.h +++ b/include/pa_win_wasapi.h @@ -346,8 +346,8 @@ PaError PaWasapi_GetJackDescription(PaDeviceIndex nDevice, int jindex, PaWasapiJ 1) Event-Driven: This is the most powerful WASAPI implementation which provides glitch-free audio at around 3ms latency in Exclusive mode. Lowest possible latency for this mode is - usually - 1.4(Vista only)-3ms(Windows 7+) for HD Audio class audio chips. For the - Shared mode latency can not be lower than 20ms. + 3 ms for HD Audio class audio chips. For the Shared mode latency can not be + lower than 20 ms. 2) Poll-Driven: Polling is another 2-nd method to operate with WASAPI. It is less efficient than Event-Driven diff --git a/src/hostapi/wasapi/pa_win_wasapi.c b/src/hostapi/wasapi/pa_win_wasapi.c index 5177bc4..2db509e 100644 --- a/src/hostapi/wasapi/pa_win_wasapi.c +++ b/src/hostapi/wasapi/pa_win_wasapi.c @@ -2094,7 +2094,7 @@ static HRESULT CreateAudioClient(PaWasapiStream *pStream, PaWasapiSubStream *pSu // Use Polling if overall latency is > 5ms as it allows to use 100% CPU in a callback, // or user specified latency parameter overall = MakeHnsPeriod(framesPerLatency, pSub->wavex.Format.nSamplesPerSec); - if ((overall > 50000) || (params->suggestedLatency > 0)) + if ((overall >= (106667*2)/*21.33ms*/) || ((INT32)(params->suggestedLatency*100000.0) != 0/*0.01 msec granularity*/)) { framesPerLatency = PaUtil_GetFramesPerHostBuffer(userFramesPerBuffer, params->suggestedLatency, pSub->wavex.Format.nSamplesPerSec, 0/*, @@ -2124,12 +2124,22 @@ static HRESULT CreateAudioClient(PaWasapiStream *pStream, PaWasapiSubStream *pSu if (pSub->shareMode == AUDCLNT_SHAREMODE_SHARED) { if (pSub->period < pInfo->DefaultDevicePeriod) + { pSub->period = pInfo->DefaultDevicePeriod; + // Recalculate aligned period + framesPerLatency = MakeFramesFromHns(pSub->period, pSub->wavex.Format.nSamplesPerSec); + _CalculateAlignedPeriod(pSub, &framesPerLatency, ALIGN_BWD); + } } else { if (pSub->period < pInfo->MinimumDevicePeriod) + { pSub->period = pInfo->MinimumDevicePeriod; + // Recalculate aligned period + framesPerLatency = MakeFramesFromHns(pSub->period, pSub->wavex.Format.nSamplesPerSec); + _CalculateAlignedPeriod(pSub, &framesPerLatency, ALIGN_BWD); + } } /*! Windows 7 does not allow to set latency lower than minimal device period and will @@ -2152,7 +2162,6 @@ static HRESULT CreateAudioClient(PaWasapiStream *pStream, PaWasapiSubStream *pSu if (pSub->period > MAX_BUFFER_EVENT_DURATION) { pSub->period = MAX_BUFFER_EVENT_DURATION; - // Recalculate aligned period framesPerLatency = MakeFramesFromHns(pSub->period, pSub->wavex.Format.nSamplesPerSec); _CalculateAlignedPeriod(pSub, &framesPerLatency, ALIGN_BWD); @@ -2163,7 +2172,6 @@ static HRESULT CreateAudioClient(PaWasapiStream *pStream, PaWasapiSubStream *pSu if (pSub->period > MAX_BUFFER_POLL_DURATION) { pSub->period = MAX_BUFFER_POLL_DURATION; - // Recalculate aligned period framesPerLatency = MakeFramesFromHns(pSub->period, pSub->wavex.Format.nSamplesPerSec); _CalculateAlignedPeriod(pSub, &framesPerLatency, ALIGN_BWD);