comparison src/portaudio_20140130/examples/pa_devs.c @ 124:e3d5853d5918

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