diff --git a/examples/pa_devs.c b/examples/pa_devs.c index 27acfd53b..0e5eddf6d 100644 --- a/examples/pa_devs.c +++ b/examples/pa_devs.c @@ -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 ); @@ -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 ); @@ -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, ¤tSampleRate ); + printf( "ASIO current sample rate = %8.2f\n", currentSampleRate); } #endif /* PA_USE_ASIO */ #endif /* WIN32 */ diff --git a/include/pa_asio.h b/include/pa_asio.h index 27cbd3b81..4c8df06d7 100644 --- a/include/pa_asio.h +++ b/include/pa_asio.h @@ -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. diff --git a/src/hostapi/asio/pa_asio.cpp b/src/hostapi/asio/pa_asio.cpp index dfa052915..7c0e49844 100644 --- a/src/hostapi/asio/pa_asio.cpp +++ b/src/hostapi/asio/pa_asio.cpp @@ -266,6 +266,7 @@ typedef struct PaAsioDriverInfo ASIODriverInfo asioDriverInfo; long inputChannelCount, outputChannelCount; long bufferMinSize, bufferMaxSize, bufferPreferredSize, bufferGranularity; + ASIOSampleRate sampleRate; bool postOutput; } PaAsioDriverInfo; @@ -894,6 +895,7 @@ typedef struct PaAsioDeviceInfo long maxBufferSize; long preferredBufferSize; long bufferGranularity; + ASIOSampleRate sampleRate; ASIOChannelInfo *asioChannelInfos; } @@ -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 ) @@ -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 @@ -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 ) @@ -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,