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