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