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