Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASIO: add PaAsio_GetSampleRate() function #971

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/pa_devs.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ int main(void)
{ /* Use wide char on windows, so we can show UTF-8 encoded device names */
wchar_t wideName[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, deviceInfo->name, -1, wideName, MAX_PATH-1);
#if __USE_MINGW_ANSI_STDIO
wprintf( L"Name = %S\n", wideName );
#else
wprintf( L"Name = %s\n", wideName );
#endif
}
#else
printf( "Name = %s\n", deviceInfo->name );
Expand All @@ -186,6 +190,7 @@ int main(void)
/* ASIO specific latency information */
if( Pa_GetHostApiInfo( deviceInfo->hostApi )->type == paASIO ){
long minLatency, maxLatency, preferredLatency, granularity;
double currentSampleRate;

err = PaAsio_GetAvailableLatencyValues( i,
&minLatency, &maxLatency, &preferredLatency, &granularity );
Expand All @@ -198,6 +203,9 @@ int main(void)
printf( "ASIO buffer granularity = power of 2\n" );
else
printf( "ASIO buffer granularity = %ld\n", granularity );

err = PaAsio_GetSampleRate( i, &currentSampleRate );
printf( "ASIO current sample rate = %8.2f\n", currentSampleRate);
}
#endif /* PA_USE_ASIO */
#endif /* WIN32 */
Expand Down
12 changes: 12 additions & 0 deletions include/pa_asio.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ PaError PaAsio_GetAvailableBufferSizes( PaDeviceIndex device,
#define PaAsio_GetAvailableLatencyValues PaAsio_GetAvailableBufferSizes


/** Get the current sample rate of the specified device (at the time of PortAudio initialization).

@param device The global index of the device about which the query is being made.
@param sampleRate A pointer to the location which will receive the current sample rate.

If the current sample rate is unknown, sampleRate will be set to 0.

@see ASIOGetSampleRate in the ASIO SDK.
*/
PaError PaAsio_GetSampleRate( PaDeviceIndex device, double* sampleRate );


/** Display the ASIO control panel for the specified device.

@param device The global index of the device whose control panel is to be displayed.
Expand Down
43 changes: 42 additions & 1 deletion src/hostapi/asio/pa_asio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ typedef struct PaAsioDriverInfo
ASIODriverInfo asioDriverInfo;
long inputChannelCount, outputChannelCount;
long bufferMinSize, bufferMaxSize, bufferPreferredSize, bufferGranularity;
ASIOSampleRate sampleRate;
bool postOutput;
}
PaAsioDriverInfo;
Expand Down Expand Up @@ -894,6 +895,7 @@ typedef struct PaAsioDeviceInfo
long maxBufferSize;
long preferredBufferSize;
long bufferGranularity;
ASIOSampleRate sampleRate;

ASIOChannelInfo *asioChannelInfos;
}
Expand Down Expand Up @@ -928,6 +930,32 @@ PaError PaAsio_GetAvailableBufferSizes( PaDeviceIndex device,
return result;
}


PaError PaAsio_GetSampleRate( PaDeviceIndex device, double* sampleRate )
{
PaError result;
PaUtilHostApiRepresentation *hostApi;
PaDeviceIndex hostApiDevice;

result = PaUtil_GetHostApiRepresentation( &hostApi, paASIO );

if( result == paNoError )
{
result = PaUtil_DeviceIndexToHostApiDeviceIndex( &hostApiDevice, device, hostApi );

if( result == paNoError )
{
PaAsioDeviceInfo *asioDeviceInfo =
(PaAsioDeviceInfo*)hostApi->deviceInfos[hostApiDevice];

*sampleRate = asioDeviceInfo->sampleRate;
}
}

return result;
}


/* Unload whatever we loaded in LoadAsioDriver().
*/
static void UnloadAsioDriver( void )
Expand Down Expand Up @@ -986,6 +1014,17 @@ static PaError LoadAsioDriver( PaAsioHostApiRepresentation *asioHostApi, const c
goto error;
}

if( (asioError = ASIOGetSampleRate(&driverInfo->sampleRate)) != ASE_OK )
{
#if 1
driverInfo->sampleRate = 0;
#else
result = paUnanticipatedHostError;
PA_ASIO_SET_LAST_ASIO_ERROR( asioError );
goto error;
#endif
}

if( ASIOOutputReady() == ASE_OK )
driverInfo->postOutput = true;
else
Expand Down Expand Up @@ -1034,10 +1073,12 @@ static PaError InitPaDeviceInfoFromAsioDriver( PaAsioHostApiRepresentation *asio
PA_DEBUG(("PaAsio_Initialize: drv:%d bufferMaxSize = %d\n", driverIndex, paAsioDriver.info.bufferMaxSize));
PA_DEBUG(("PaAsio_Initialize: drv:%d bufferPreferredSize = %d\n", driverIndex, paAsioDriver.info.bufferPreferredSize));
PA_DEBUG(("PaAsio_Initialize: drv:%d bufferGranularity = %d\n", driverIndex, paAsioDriver.info.bufferGranularity));
PA_DEBUG(("PaAsio_Initialize: drv:%d sampleRate = %d\n", driverIndex, paAsioDriver.info.sampleRate));

deviceInfo->maxInputChannels = paAsioDriver.info.inputChannelCount;
deviceInfo->maxOutputChannels = paAsioDriver.info.outputChannelCount;


deviceInfo->defaultSampleRate = 0.;
bool foundDefaultSampleRate = false;
for( int j=0; j < PA_DEFAULTSAMPLERATESEARCHORDER_COUNT_; ++j )
Expand Down Expand Up @@ -1095,7 +1136,7 @@ static PaError InitPaDeviceInfoFromAsioDriver( PaAsioHostApiRepresentation *asio
asioDeviceInfo->maxBufferSize = paAsioDriver.info.bufferMaxSize;
asioDeviceInfo->preferredBufferSize = paAsioDriver.info.bufferPreferredSize;
asioDeviceInfo->bufferGranularity = paAsioDriver.info.bufferGranularity;

asioDeviceInfo->sampleRate = paAsioDriver.info.sampleRate;

asioDeviceInfo->asioChannelInfos = (ASIOChannelInfo*)PaUtil_GroupAllocateZeroInitializedMemory(
asioHostApi->allocations,
Expand Down
Loading