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