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