Skip to content

Commit

Permalink
Don't try to keep the buffer size info updated
Browse files Browse the repository at this point in the history
It raises threading synchronization issues, and not all
kAsioResetRequest events will be about that anyway.  For example,
ASIO4ALL can have changes in input channels; Portaudio's current API
can't have chanel names change without reinitializing the library.
  • Loading branch information
npostavs committed Feb 26, 2021
1 parent f7beca8 commit f8da4ee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 45 deletions.
5 changes: 3 additions & 2 deletions include/pa_asio.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ typedef void (*PaAsioResetRequestCallback)();
@param callback The function to call on ASIO reset request. This is called
when the driver's buffer size has changed or it needs a reset, usually in
response to a user changing the configuration. Pass NULL to unregister a
callback.
response to a user changing the configuration. Call Pa_Terminate followed by
Pa_Initialize to have the changes reflected in Portaudio's API. Pass NULL to
unregister a callback.
*/
void PaAsio_RegisterResetRequestCallback( PaAsioResetRequestCallback callback );

Expand Down
44 changes: 1 addition & 43 deletions src/hostapi/asio/pa_asio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ typedef struct PaAsioDriverInfo
ASIODriverInfo asioDriverInfo;
long inputChannelCount, outputChannelCount;
long bufferMinSize, bufferMaxSize, bufferPreferredSize, bufferGranularity;
bool postOutput, bufferSizeOutdated;
bool postOutput;
}
PaAsioDriverInfo;

Expand Down Expand Up @@ -928,30 +928,6 @@ PaError PaAsio_GetAvailableBufferSizes( PaDeviceIndex device,
PaAsioDeviceInfo *asioDeviceInfo =
(PaAsioDeviceInfo*)hostApi->deviceInfos[hostApiDevice];

PaAsioHostApiRepresentation *asioApi = (PaAsioHostApiRepresentation*) hostApi;
if ( hostApiDevice == asioApi->openAsioDeviceIndex &&
asioApi->openAsioDriverInfo.bufferSizeOutdated )
{
ASIOError asioError;
PaAsioDriverInfo &driverInfo = asioApi->openAsioDriverInfo;
if( (asioError = ASIOGetBufferSize(&driverInfo.bufferMinSize,
&driverInfo.bufferMaxSize, &driverInfo.bufferPreferredSize,
&driverInfo.bufferGranularity)) != ASE_OK )
{
PA_ASIO_SET_LAST_ASIO_ERROR( asioError );
return paUnanticipatedHostError;
}
else
{
asioDeviceInfo->minBufferSize = driverInfo.bufferMinSize;
asioDeviceInfo->maxBufferSize = driverInfo.bufferMaxSize;
asioDeviceInfo->preferredBufferSize = driverInfo.bufferPreferredSize;
asioDeviceInfo->bufferGranularity = driverInfo.bufferGranularity;

driverInfo.bufferSizeOutdated = false;
}
}

*minBufferSizeFrames = asioDeviceInfo->minBufferSize;
*maxBufferSizeFrames = asioDeviceInfo->maxBufferSize;
*preferredBufferSizeFrames = asioDeviceInfo->preferredBufferSize;
Expand Down Expand Up @@ -1019,7 +995,6 @@ static PaError LoadAsioDriver( PaAsioHostApiRepresentation *asioHostApi, const c
PA_ASIO_SET_LAST_ASIO_ERROR( asioError );
goto error;
}
driverInfo->bufferSizeOutdated = false;

if( ASIOOutputReady() == ASE_OK )
driverInfo->postOutput = true;
Expand Down Expand Up @@ -3231,21 +3206,6 @@ void PaAsio_RegisterResetRequestCallback( PaAsioResetRequestCallback callback )
resetRequestCallback_ = callback;
}

static void setBufferSizesOutdated()
{
PaUtilHostApiRepresentation *hostApi;
PaAsioHostApiRepresentation *asioApi;

PaError result = PaUtil_GetHostApiRepresentation( &hostApi, paASIO );
if( result != paNoError )
return;
asioApi = (PaAsioHostApiRepresentation*) hostApi;
if ( asioApi->openAsioDeviceIndex == paNoDevice )
return;

asioApi->openAsioDriverInfo.bufferSizeOutdated = true;
}

static long asioMessages(long selector, long value, void* message, double* opt)
{
// TAKEN FROM THE ASIO SDK
Expand Down Expand Up @@ -3273,7 +3233,6 @@ static long asioMessages(long selector, long value, void* message, double* opt)

case kAsioBufferSizeChange:
//printf("kAsioBufferSizeChange \n");
setBufferSizesOutdated();
if (resetRequestCallback_) {
resetRequestCallback_();
ret = 1L;
Expand All @@ -3292,7 +3251,6 @@ static long asioMessages(long selector, long value, void* message, double* opt)
http://www.portaudio.com/trac/ticket/108
*/
//asioDriverInfo.stopped; // In this sample the processing will just stop
setBufferSizesOutdated();
if (resetRequestCallback_) {
resetRequestCallback_();
}
Expand Down

0 comments on commit f8da4ee

Please sign in to comment.