annotate src/portaudio_20140130/examples/pa_devs.c @ 39:7ddb4fc30dac

Current stable PortAudio source
author Chris Cannam
date Tue, 18 Oct 2016 13:11:05 +0100
parents
children
rev   line source
Chris@39 1 /** @file pa_devs.c
Chris@39 2 @ingroup examples_src
Chris@39 3 @brief List available devices, including device information.
Chris@39 4 @author Phil Burk http://www.softsynth.com
Chris@39 5
Chris@39 6 @note Define PA_USE_ASIO=0 to compile this code on Windows without
Chris@39 7 ASIO support.
Chris@39 8 */
Chris@39 9 /*
Chris@39 10 * $Id: pa_devs.c 1891 2013-05-05 14:00:02Z rbencina $
Chris@39 11 *
Chris@39 12 * This program uses the PortAudio Portable Audio Library.
Chris@39 13 * For more information see: http://www.portaudio.com
Chris@39 14 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
Chris@39 15 *
Chris@39 16 * Permission is hereby granted, free of charge, to any person obtaining
Chris@39 17 * a copy of this software and associated documentation files
Chris@39 18 * (the "Software"), to deal in the Software without restriction,
Chris@39 19 * including without limitation the rights to use, copy, modify, merge,
Chris@39 20 * publish, distribute, sublicense, and/or sell copies of the Software,
Chris@39 21 * and to permit persons to whom the Software is furnished to do so,
Chris@39 22 * subject to the following conditions:
Chris@39 23 *
Chris@39 24 * The above copyright notice and this permission notice shall be
Chris@39 25 * included in all copies or substantial portions of the Software.
Chris@39 26 *
Chris@39 27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@39 28 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@39 29 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Chris@39 30 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
Chris@39 31 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@39 32 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@39 33 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@39 34 */
Chris@39 35
Chris@39 36 /*
Chris@39 37 * The text above constitutes the entire PortAudio license; however,
Chris@39 38 * the PortAudio community also makes the following non-binding requests:
Chris@39 39 *
Chris@39 40 * Any person wishing to distribute modifications to the Software is
Chris@39 41 * requested to send the modifications to the original developer so that
Chris@39 42 * they can be incorporated into the canonical version. It is also
Chris@39 43 * requested that these non-binding requests be included along with the
Chris@39 44 * license above.
Chris@39 45 */
Chris@39 46
Chris@39 47 #include <stdio.h>
Chris@39 48 #include <math.h>
Chris@39 49 #include "portaudio.h"
Chris@39 50
Chris@39 51 #ifdef WIN32
Chris@39 52 #include <windows.h>
Chris@39 53
Chris@39 54 #if PA_USE_ASIO
Chris@39 55 #include "pa_asio.h"
Chris@39 56 #endif
Chris@39 57 #endif
Chris@39 58
Chris@39 59 /*******************************************************************/
Chris@39 60 static void PrintSupportedStandardSampleRates(
Chris@39 61 const PaStreamParameters *inputParameters,
Chris@39 62 const PaStreamParameters *outputParameters )
Chris@39 63 {
Chris@39 64 static double standardSampleRates[] = {
Chris@39 65 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0,
Chris@39 66 44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1 /* negative terminated list */
Chris@39 67 };
Chris@39 68 int i, printCount;
Chris@39 69 PaError err;
Chris@39 70
Chris@39 71 printCount = 0;
Chris@39 72 for( i=0; standardSampleRates[i] > 0; i++ )
Chris@39 73 {
Chris@39 74 err = Pa_IsFormatSupported( inputParameters, outputParameters, standardSampleRates[i] );
Chris@39 75 if( err == paFormatIsSupported )
Chris@39 76 {
Chris@39 77 if( printCount == 0 )
Chris@39 78 {
Chris@39 79 printf( "\t%8.2f", standardSampleRates[i] );
Chris@39 80 printCount = 1;
Chris@39 81 }
Chris@39 82 else if( printCount == 4 )
Chris@39 83 {
Chris@39 84 printf( ",\n\t%8.2f", standardSampleRates[i] );
Chris@39 85 printCount = 1;
Chris@39 86 }
Chris@39 87 else
Chris@39 88 {
Chris@39 89 printf( ", %8.2f", standardSampleRates[i] );
Chris@39 90 ++printCount;
Chris@39 91 }
Chris@39 92 }
Chris@39 93 }
Chris@39 94 if( !printCount )
Chris@39 95 printf( "None\n" );
Chris@39 96 else
Chris@39 97 printf( "\n" );
Chris@39 98 }
Chris@39 99
Chris@39 100 /*******************************************************************/
Chris@39 101 int main(void);
Chris@39 102 int main(void)
Chris@39 103 {
Chris@39 104 int i, numDevices, defaultDisplayed;
Chris@39 105 const PaDeviceInfo *deviceInfo;
Chris@39 106 PaStreamParameters inputParameters, outputParameters;
Chris@39 107 PaError err;
Chris@39 108
Chris@39 109
Chris@39 110 err = Pa_Initialize();
Chris@39 111 if( err != paNoError )
Chris@39 112 {
Chris@39 113 printf( "ERROR: Pa_Initialize returned 0x%x\n", err );
Chris@39 114 goto error;
Chris@39 115 }
Chris@39 116
Chris@39 117 printf( "PortAudio version number = %d\nPortAudio version text = '%s'\n",
Chris@39 118 Pa_GetVersion(), Pa_GetVersionText() );
Chris@39 119
Chris@39 120
Chris@39 121 numDevices = Pa_GetDeviceCount();
Chris@39 122 if( numDevices < 0 )
Chris@39 123 {
Chris@39 124 printf( "ERROR: Pa_GetDeviceCount returned 0x%x\n", numDevices );
Chris@39 125 err = numDevices;
Chris@39 126 goto error;
Chris@39 127 }
Chris@39 128
Chris@39 129 printf( "Number of devices = %d\n", numDevices );
Chris@39 130 for( i=0; i<numDevices; i++ )
Chris@39 131 {
Chris@39 132 deviceInfo = Pa_GetDeviceInfo( i );
Chris@39 133 printf( "--------------------------------------- device #%d\n", i );
Chris@39 134
Chris@39 135 /* Mark global and API specific default devices */
Chris@39 136 defaultDisplayed = 0;
Chris@39 137 if( i == Pa_GetDefaultInputDevice() )
Chris@39 138 {
Chris@39 139 printf( "[ Default Input" );
Chris@39 140 defaultDisplayed = 1;
Chris@39 141 }
Chris@39 142 else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultInputDevice )
Chris@39 143 {
Chris@39 144 const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
Chris@39 145 printf( "[ Default %s Input", hostInfo->name );
Chris@39 146 defaultDisplayed = 1;
Chris@39 147 }
Chris@39 148
Chris@39 149 if( i == Pa_GetDefaultOutputDevice() )
Chris@39 150 {
Chris@39 151 printf( (defaultDisplayed ? "," : "[") );
Chris@39 152 printf( " Default Output" );
Chris@39 153 defaultDisplayed = 1;
Chris@39 154 }
Chris@39 155 else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultOutputDevice )
Chris@39 156 {
Chris@39 157 const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
Chris@39 158 printf( (defaultDisplayed ? "," : "[") );
Chris@39 159 printf( " Default %s Output", hostInfo->name );
Chris@39 160 defaultDisplayed = 1;
Chris@39 161 }
Chris@39 162
Chris@39 163 if( defaultDisplayed )
Chris@39 164 printf( " ]\n" );
Chris@39 165
Chris@39 166 /* print device info fields */
Chris@39 167 #ifdef WIN32
Chris@39 168 { /* Use wide char on windows, so we can show UTF-8 encoded device names */
Chris@39 169 wchar_t wideName[MAX_PATH];
Chris@39 170 MultiByteToWideChar(CP_UTF8, 0, deviceInfo->name, -1, wideName, MAX_PATH-1);
Chris@39 171 wprintf( L"Name = %s\n", wideName );
Chris@39 172 }
Chris@39 173 #else
Chris@39 174 printf( "Name = %s\n", deviceInfo->name );
Chris@39 175 #endif
Chris@39 176 printf( "Host API = %s\n", Pa_GetHostApiInfo( deviceInfo->hostApi )->name );
Chris@39 177 printf( "Max inputs = %d", deviceInfo->maxInputChannels );
Chris@39 178 printf( ", Max outputs = %d\n", deviceInfo->maxOutputChannels );
Chris@39 179
Chris@39 180 printf( "Default low input latency = %8.4f\n", deviceInfo->defaultLowInputLatency );
Chris@39 181 printf( "Default low output latency = %8.4f\n", deviceInfo->defaultLowOutputLatency );
Chris@39 182 printf( "Default high input latency = %8.4f\n", deviceInfo->defaultHighInputLatency );
Chris@39 183 printf( "Default high output latency = %8.4f\n", deviceInfo->defaultHighOutputLatency );
Chris@39 184
Chris@39 185 #ifdef WIN32
Chris@39 186 #if PA_USE_ASIO
Chris@39 187 /* ASIO specific latency information */
Chris@39 188 if( Pa_GetHostApiInfo( deviceInfo->hostApi )->type == paASIO ){
Chris@39 189 long minLatency, maxLatency, preferredLatency, granularity;
Chris@39 190
Chris@39 191 err = PaAsio_GetAvailableLatencyValues( i,
Chris@39 192 &minLatency, &maxLatency, &preferredLatency, &granularity );
Chris@39 193
Chris@39 194 printf( "ASIO minimum buffer size = %ld\n", minLatency );
Chris@39 195 printf( "ASIO maximum buffer size = %ld\n", maxLatency );
Chris@39 196 printf( "ASIO preferred buffer size = %ld\n", preferredLatency );
Chris@39 197
Chris@39 198 if( granularity == -1 )
Chris@39 199 printf( "ASIO buffer granularity = power of 2\n" );
Chris@39 200 else
Chris@39 201 printf( "ASIO buffer granularity = %ld\n", granularity );
Chris@39 202 }
Chris@39 203 #endif /* PA_USE_ASIO */
Chris@39 204 #endif /* WIN32 */
Chris@39 205
Chris@39 206 printf( "Default sample rate = %8.2f\n", deviceInfo->defaultSampleRate );
Chris@39 207
Chris@39 208 /* poll for standard sample rates */
Chris@39 209 inputParameters.device = i;
Chris@39 210 inputParameters.channelCount = deviceInfo->maxInputChannels;
Chris@39 211 inputParameters.sampleFormat = paInt16;
Chris@39 212 inputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
Chris@39 213 inputParameters.hostApiSpecificStreamInfo = NULL;
Chris@39 214
Chris@39 215 outputParameters.device = i;
Chris@39 216 outputParameters.channelCount = deviceInfo->maxOutputChannels;
Chris@39 217 outputParameters.sampleFormat = paInt16;
Chris@39 218 outputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
Chris@39 219 outputParameters.hostApiSpecificStreamInfo = NULL;
Chris@39 220
Chris@39 221 if( inputParameters.channelCount > 0 )
Chris@39 222 {
Chris@39 223 printf("Supported standard sample rates\n for half-duplex 16 bit %d channel input = \n",
Chris@39 224 inputParameters.channelCount );
Chris@39 225 PrintSupportedStandardSampleRates( &inputParameters, NULL );
Chris@39 226 }
Chris@39 227
Chris@39 228 if( outputParameters.channelCount > 0 )
Chris@39 229 {
Chris@39 230 printf("Supported standard sample rates\n for half-duplex 16 bit %d channel output = \n",
Chris@39 231 outputParameters.channelCount );
Chris@39 232 PrintSupportedStandardSampleRates( NULL, &outputParameters );
Chris@39 233 }
Chris@39 234
Chris@39 235 if( inputParameters.channelCount > 0 && outputParameters.channelCount > 0 )
Chris@39 236 {
Chris@39 237 printf("Supported standard sample rates\n for full-duplex 16 bit %d channel input, %d channel output = \n",
Chris@39 238 inputParameters.channelCount, outputParameters.channelCount );
Chris@39 239 PrintSupportedStandardSampleRates( &inputParameters, &outputParameters );
Chris@39 240 }
Chris@39 241 }
Chris@39 242
Chris@39 243 Pa_Terminate();
Chris@39 244
Chris@39 245 printf("----------------------------------------------\n");
Chris@39 246 return 0;
Chris@39 247
Chris@39 248 error:
Chris@39 249 Pa_Terminate();
Chris@39 250 fprintf( stderr, "Error number: %d\n", err );
Chris@39 251 fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
Chris@39 252 return err;
Chris@39 253 }