annotate src/portaudio_20161030_catalina_patch/examples/pa_devs.c @ 81:7029a4916348

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