cannam@124: /** @file pa_devs.c cannam@124: @ingroup examples_src cannam@124: @brief List available devices, including device information. cannam@124: @author Phil Burk http://www.softsynth.com cannam@124: cannam@124: @note Define PA_USE_ASIO=0 to compile this code on Windows without cannam@124: ASIO support. cannam@124: */ cannam@124: /* cannam@124: * $Id: pa_devs.c 1891 2013-05-05 14:00:02Z rbencina $ cannam@124: * cannam@124: * This program uses the PortAudio Portable Audio Library. cannam@124: * For more information see: http://www.portaudio.com cannam@124: * Copyright (c) 1999-2000 Ross Bencina and Phil Burk cannam@124: * cannam@124: * Permission is hereby granted, free of charge, to any person obtaining cannam@124: * a copy of this software and associated documentation files cannam@124: * (the "Software"), to deal in the Software without restriction, cannam@124: * including without limitation the rights to use, copy, modify, merge, cannam@124: * publish, distribute, sublicense, and/or sell copies of the Software, cannam@124: * and to permit persons to whom the Software is furnished to do so, cannam@124: * subject to the following conditions: cannam@124: * cannam@124: * The above copyright notice and this permission notice shall be cannam@124: * included in all copies or substantial portions of the Software. cannam@124: * cannam@124: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, cannam@124: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF cannam@124: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. cannam@124: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR cannam@124: * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF cannam@124: * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION cannam@124: * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. cannam@124: */ cannam@124: cannam@124: /* cannam@124: * The text above constitutes the entire PortAudio license; however, cannam@124: * the PortAudio community also makes the following non-binding requests: cannam@124: * cannam@124: * Any person wishing to distribute modifications to the Software is cannam@124: * requested to send the modifications to the original developer so that cannam@124: * they can be incorporated into the canonical version. It is also cannam@124: * requested that these non-binding requests be included along with the cannam@124: * license above. cannam@124: */ cannam@124: cannam@124: #include cannam@124: #include cannam@124: #include "portaudio.h" cannam@124: cannam@124: #ifdef WIN32 cannam@124: #include cannam@124: cannam@124: #if PA_USE_ASIO cannam@124: #include "pa_asio.h" cannam@124: #endif cannam@124: #endif cannam@124: cannam@124: /*******************************************************************/ cannam@124: static void PrintSupportedStandardSampleRates( cannam@124: const PaStreamParameters *inputParameters, cannam@124: const PaStreamParameters *outputParameters ) cannam@124: { cannam@124: static double standardSampleRates[] = { cannam@124: 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0, cannam@124: 44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1 /* negative terminated list */ cannam@124: }; cannam@124: int i, printCount; cannam@124: PaError err; cannam@124: cannam@124: printCount = 0; cannam@124: for( i=0; standardSampleRates[i] > 0; i++ ) cannam@124: { cannam@124: err = Pa_IsFormatSupported( inputParameters, outputParameters, standardSampleRates[i] ); cannam@124: if( err == paFormatIsSupported ) cannam@124: { cannam@124: if( printCount == 0 ) cannam@124: { cannam@124: printf( "\t%8.2f", standardSampleRates[i] ); cannam@124: printCount = 1; cannam@124: } cannam@124: else if( printCount == 4 ) cannam@124: { cannam@124: printf( ",\n\t%8.2f", standardSampleRates[i] ); cannam@124: printCount = 1; cannam@124: } cannam@124: else cannam@124: { cannam@124: printf( ", %8.2f", standardSampleRates[i] ); cannam@124: ++printCount; cannam@124: } cannam@124: } cannam@124: } cannam@124: if( !printCount ) cannam@124: printf( "None\n" ); cannam@124: else cannam@124: printf( "\n" ); cannam@124: } cannam@124: cannam@124: /*******************************************************************/ cannam@124: int main(void); cannam@124: int main(void) cannam@124: { cannam@124: int i, numDevices, defaultDisplayed; cannam@124: const PaDeviceInfo *deviceInfo; cannam@124: PaStreamParameters inputParameters, outputParameters; cannam@124: PaError err; cannam@124: cannam@124: cannam@124: err = Pa_Initialize(); cannam@124: if( err != paNoError ) cannam@124: { cannam@124: printf( "ERROR: Pa_Initialize returned 0x%x\n", err ); cannam@124: goto error; cannam@124: } cannam@124: cannam@124: printf( "PortAudio version number = %d\nPortAudio version text = '%s'\n", cannam@124: Pa_GetVersion(), Pa_GetVersionText() ); cannam@124: cannam@124: cannam@124: numDevices = Pa_GetDeviceCount(); cannam@124: if( numDevices < 0 ) cannam@124: { cannam@124: printf( "ERROR: Pa_GetDeviceCount returned 0x%x\n", numDevices ); cannam@124: err = numDevices; cannam@124: goto error; cannam@124: } cannam@124: cannam@124: printf( "Number of devices = %d\n", numDevices ); cannam@124: for( i=0; ihostApi )->defaultInputDevice ) cannam@124: { cannam@124: const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); cannam@124: printf( "[ Default %s Input", hostInfo->name ); cannam@124: defaultDisplayed = 1; cannam@124: } cannam@124: cannam@124: if( i == Pa_GetDefaultOutputDevice() ) cannam@124: { cannam@124: printf( (defaultDisplayed ? "," : "[") ); cannam@124: printf( " Default Output" ); cannam@124: defaultDisplayed = 1; cannam@124: } cannam@124: else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultOutputDevice ) cannam@124: { cannam@124: const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); cannam@124: printf( (defaultDisplayed ? "," : "[") ); cannam@124: printf( " Default %s Output", hostInfo->name ); cannam@124: defaultDisplayed = 1; cannam@124: } cannam@124: cannam@124: if( defaultDisplayed ) cannam@124: printf( " ]\n" ); cannam@124: cannam@124: /* print device info fields */ cannam@124: #ifdef WIN32 cannam@124: { /* Use wide char on windows, so we can show UTF-8 encoded device names */ cannam@124: wchar_t wideName[MAX_PATH]; cannam@124: MultiByteToWideChar(CP_UTF8, 0, deviceInfo->name, -1, wideName, MAX_PATH-1); cannam@124: wprintf( L"Name = %s\n", wideName ); cannam@124: } cannam@124: #else cannam@124: printf( "Name = %s\n", deviceInfo->name ); cannam@124: #endif cannam@124: printf( "Host API = %s\n", Pa_GetHostApiInfo( deviceInfo->hostApi )->name ); cannam@124: printf( "Max inputs = %d", deviceInfo->maxInputChannels ); cannam@124: printf( ", Max outputs = %d\n", deviceInfo->maxOutputChannels ); cannam@124: cannam@124: printf( "Default low input latency = %8.4f\n", deviceInfo->defaultLowInputLatency ); cannam@124: printf( "Default low output latency = %8.4f\n", deviceInfo->defaultLowOutputLatency ); cannam@124: printf( "Default high input latency = %8.4f\n", deviceInfo->defaultHighInputLatency ); cannam@124: printf( "Default high output latency = %8.4f\n", deviceInfo->defaultHighOutputLatency ); cannam@124: cannam@124: #ifdef WIN32 cannam@124: #if PA_USE_ASIO cannam@124: /* ASIO specific latency information */ cannam@124: if( Pa_GetHostApiInfo( deviceInfo->hostApi )->type == paASIO ){ cannam@124: long minLatency, maxLatency, preferredLatency, granularity; cannam@124: cannam@124: err = PaAsio_GetAvailableLatencyValues( i, cannam@124: &minLatency, &maxLatency, &preferredLatency, &granularity ); cannam@124: cannam@124: printf( "ASIO minimum buffer size = %ld\n", minLatency ); cannam@124: printf( "ASIO maximum buffer size = %ld\n", maxLatency ); cannam@124: printf( "ASIO preferred buffer size = %ld\n", preferredLatency ); cannam@124: cannam@124: if( granularity == -1 ) cannam@124: printf( "ASIO buffer granularity = power of 2\n" ); cannam@124: else cannam@124: printf( "ASIO buffer granularity = %ld\n", granularity ); cannam@124: } cannam@124: #endif /* PA_USE_ASIO */ cannam@124: #endif /* WIN32 */ cannam@124: cannam@124: printf( "Default sample rate = %8.2f\n", deviceInfo->defaultSampleRate ); cannam@124: cannam@124: /* poll for standard sample rates */ cannam@124: inputParameters.device = i; cannam@124: inputParameters.channelCount = deviceInfo->maxInputChannels; cannam@124: inputParameters.sampleFormat = paInt16; cannam@124: inputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */ cannam@124: inputParameters.hostApiSpecificStreamInfo = NULL; cannam@124: cannam@124: outputParameters.device = i; cannam@124: outputParameters.channelCount = deviceInfo->maxOutputChannels; cannam@124: outputParameters.sampleFormat = paInt16; cannam@124: outputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */ cannam@124: outputParameters.hostApiSpecificStreamInfo = NULL; cannam@124: cannam@124: if( inputParameters.channelCount > 0 ) cannam@124: { cannam@124: printf("Supported standard sample rates\n for half-duplex 16 bit %d channel input = \n", cannam@124: inputParameters.channelCount ); cannam@124: PrintSupportedStandardSampleRates( &inputParameters, NULL ); cannam@124: } cannam@124: cannam@124: if( outputParameters.channelCount > 0 ) cannam@124: { cannam@124: printf("Supported standard sample rates\n for half-duplex 16 bit %d channel output = \n", cannam@124: outputParameters.channelCount ); cannam@124: PrintSupportedStandardSampleRates( NULL, &outputParameters ); cannam@124: } cannam@124: cannam@124: if( inputParameters.channelCount > 0 && outputParameters.channelCount > 0 ) cannam@124: { cannam@124: printf("Supported standard sample rates\n for full-duplex 16 bit %d channel input, %d channel output = \n", cannam@124: inputParameters.channelCount, outputParameters.channelCount ); cannam@124: PrintSupportedStandardSampleRates( &inputParameters, &outputParameters ); cannam@124: } cannam@124: } cannam@124: cannam@124: Pa_Terminate(); cannam@124: cannam@124: printf("----------------------------------------------\n"); cannam@124: return 0; cannam@124: cannam@124: error: cannam@124: Pa_Terminate(); cannam@124: fprintf( stderr, "Error number: %d\n", err ); cannam@124: fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); cannam@124: return err; cannam@124: }