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