annotate src/portaudio_20161030/examples/pa_devs.c @ 169:223a55898ab9 tip default

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