annotate src/portaudio_20161030_catalina_patch/examples/pa_devs.c @ 162:d43aab368df9

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