2
@brief List available devices, including device information.
3
@author Phil Burk http://www.softsynth.com
5
@note Define PA_NO_ASIO to compile this code on Windows without
9
* $Id: pa_devs.c,v 1.1 2006/06/10 21:30:56 dmazzoni Exp $
11
* This program uses the PortAudio Portable Audio Library.
12
* For more information see: http://www.portaudio.com
13
* Copyright (c) 1999-2000 Ross Bencina and Phil Burk
15
* Permission is hereby granted, free of charge, to any person obtaining
16
* a copy of this software and associated documentation files
17
* (the "Software"), to deal in the Software without restriction,
18
* including without limitation the rights to use, copy, modify, merge,
19
* publish, distribute, sublicense, and/or sell copies of the Software,
20
* and to permit persons to whom the Software is furnished to do so,
21
* subject to the following conditions:
23
* The above copyright notice and this permission notice shall be
24
* included in all copies or substantial portions of the Software.
26
* Any person wishing to distribute modifications to the Software is
27
* requested to send the modifications to the original developer so that
28
* they can be incorporated into the canonical version.
30
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
34
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
35
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41
#include "portaudio.h"
49
/*******************************************************************/
50
static void PrintSupportedStandardSampleRates(
51
const PaStreamParameters *inputParameters,
52
const PaStreamParameters *outputParameters )
54
static double standardSampleRates[] = {
55
8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0,
56
44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1 /* negative terminated list */
62
for( i=0; standardSampleRates[i] > 0; i++ )
64
err = Pa_IsFormatSupported( inputParameters, outputParameters, standardSampleRates[i] );
65
if( err == paFormatIsSupported )
69
printf( "\t%8.2f", standardSampleRates[i] );
72
else if( printCount == 4 )
74
printf( ",\n\t%8.2f", standardSampleRates[i] );
79
printf( ", %8.2f", standardSampleRates[i] );
89
/*******************************************************************/
93
int i, numDevices, defaultDisplayed;
94
const PaDeviceInfo *deviceInfo;
95
PaStreamParameters inputParameters, outputParameters;
101
printf( "PortAudio version number = %d\nPortAudio version text = '%s'\n",
102
Pa_GetVersion(), Pa_GetVersionText() );
105
numDevices = Pa_GetDeviceCount();
108
printf( "ERROR: Pa_CountDevices returned 0x%x\n", numDevices );
113
printf( "Number of devices = %d\n", numDevices );
114
for( i=0; i<numDevices; i++ )
116
deviceInfo = Pa_GetDeviceInfo( i );
117
printf( "--------------------------------------- device #%d\n", i );
119
/* Mark global and API specific default devices */
120
defaultDisplayed = 0;
121
if( i == Pa_GetDefaultInputDevice() )
123
printf( "[ Default Input" );
124
defaultDisplayed = 1;
126
else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultInputDevice )
128
const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
129
printf( "[ Default %s Input", hostInfo->name );
130
defaultDisplayed = 1;
133
if( i == Pa_GetDefaultOutputDevice() )
135
printf( (defaultDisplayed ? "," : "[") );
136
printf( " Default Output" );
137
defaultDisplayed = 1;
139
else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultOutputDevice )
141
const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
142
printf( (defaultDisplayed ? "," : "[") );
143
printf( " Default %s Output", hostInfo->name );
144
defaultDisplayed = 1;
147
if( defaultDisplayed )
150
/* print device info fields */
151
printf( "Name = %s\n", deviceInfo->name );
152
printf( "Host API = %s\n", Pa_GetHostApiInfo( deviceInfo->hostApi )->name );
153
printf( "Max inputs = %d", deviceInfo->maxInputChannels );
154
printf( ", Max outputs = %d\n", deviceInfo->maxOutputChannels );
156
printf( "Default low input latency = %8.3f\n", deviceInfo->defaultLowInputLatency );
157
printf( "Default low output latency = %8.3f\n", deviceInfo->defaultLowOutputLatency );
158
printf( "Default high input latency = %8.3f\n", deviceInfo->defaultHighInputLatency );
159
printf( "Default high output latency = %8.3f\n", deviceInfo->defaultHighOutputLatency );
163
/* ASIO specific latency information */
164
if( Pa_GetHostApiInfo( deviceInfo->hostApi )->type == paASIO ){
165
long minLatency, maxLatency, preferredLatency, granularity;
167
err = PaAsio_GetAvailableLatencyValues( i,
168
&minLatency, &maxLatency, &preferredLatency, &granularity );
170
printf( "ASIO minimum buffer size = %ld\n", minLatency );
171
printf( "ASIO maximum buffer size = %ld\n", maxLatency );
172
printf( "ASIO preferred buffer size = %ld\n", preferredLatency );
174
if( granularity == -1 )
175
printf( "ASIO buffer granularity = power of 2\n" );
177
printf( "ASIO buffer granularity = %ld\n", granularity );
179
#endif /* !PA_NO_ASIO */
182
printf( "Default sample rate = %8.2f\n", deviceInfo->defaultSampleRate );
184
/* poll for standard sample rates */
185
inputParameters.device = i;
186
inputParameters.channelCount = deviceInfo->maxInputChannels;
187
inputParameters.sampleFormat = paInt16;
188
inputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
189
inputParameters.hostApiSpecificStreamInfo = NULL;
191
outputParameters.device = i;
192
outputParameters.channelCount = deviceInfo->maxOutputChannels;
193
outputParameters.sampleFormat = paInt16;
194
outputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
195
outputParameters.hostApiSpecificStreamInfo = NULL;
197
if( inputParameters.channelCount > 0 )
199
printf("Supported standard sample rates\n for half-duplex 16 bit %d channel input = \n",
200
inputParameters.channelCount );
201
PrintSupportedStandardSampleRates( &inputParameters, NULL );
204
if( outputParameters.channelCount > 0 )
206
printf("Supported standard sample rates\n for half-duplex 16 bit %d channel output = \n",
207
outputParameters.channelCount );
208
PrintSupportedStandardSampleRates( NULL, &outputParameters );
211
if( inputParameters.channelCount > 0 && outputParameters.channelCount > 0 )
213
printf("Supported standard sample rates\n for full-duplex 16 bit %d channel input, %d channel output = \n",
214
inputParameters.channelCount, outputParameters.channelCount );
215
PrintSupportedStandardSampleRates( &inputParameters, &outputParameters );
221
printf("----------------------------------------------\n");
226
fprintf( stderr, "An error occured while using the portaudio stream\n" );
227
fprintf( stderr, "Error number: %d\n", err );
228
fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );