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