comparison src/portaudio/examples/pa_devs.c @ 4:e13257ea84a4

Add bzip2, zlib, liblo, portaudio sources
author Chris Cannam
date Wed, 20 Mar 2013 13:59:52 +0000
parents
children
comparison
equal deleted inserted replaced
3:6c505a35919a 4:e13257ea84a4
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 1752 2011-09-08 03:21:55Z philburk $
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 #if PA_USE_ASIO
53 #include "pa_asio.h"
54 #endif
55 #endif
56
57 /*******************************************************************/
58 static void PrintSupportedStandardSampleRates(
59 const PaStreamParameters *inputParameters,
60 const PaStreamParameters *outputParameters )
61 {
62 static double standardSampleRates[] = {
63 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0,
64 44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1 /* negative terminated list */
65 };
66 int i, printCount;
67 PaError err;
68
69 printCount = 0;
70 for( i=0; standardSampleRates[i] > 0; i++ )
71 {
72 err = Pa_IsFormatSupported( inputParameters, outputParameters, standardSampleRates[i] );
73 if( err == paFormatIsSupported )
74 {
75 if( printCount == 0 )
76 {
77 printf( "\t%8.2f", standardSampleRates[i] );
78 printCount = 1;
79 }
80 else if( printCount == 4 )
81 {
82 printf( ",\n\t%8.2f", standardSampleRates[i] );
83 printCount = 1;
84 }
85 else
86 {
87 printf( ", %8.2f", standardSampleRates[i] );
88 ++printCount;
89 }
90 }
91 }
92 if( !printCount )
93 printf( "None\n" );
94 else
95 printf( "\n" );
96 }
97
98 /*******************************************************************/
99 int main(void);
100 int main(void)
101 {
102 int i, numDevices, defaultDisplayed;
103 const PaDeviceInfo *deviceInfo;
104 PaStreamParameters inputParameters, outputParameters;
105 PaError err;
106
107
108 Pa_Initialize();
109
110 printf( "PortAudio version number = %d\nPortAudio version text = '%s'\n",
111 Pa_GetVersion(), Pa_GetVersionText() );
112
113
114 numDevices = Pa_GetDeviceCount();
115 if( numDevices < 0 )
116 {
117 printf( "ERROR: Pa_GetDeviceCount returned 0x%x\n", numDevices );
118 err = numDevices;
119 goto error;
120 }
121
122 printf( "Number of devices = %d\n", numDevices );
123 for( i=0; i<numDevices; i++ )
124 {
125 deviceInfo = Pa_GetDeviceInfo( i );
126 printf( "--------------------------------------- device #%d\n", i );
127
128 /* Mark global and API specific default devices */
129 defaultDisplayed = 0;
130 if( i == Pa_GetDefaultInputDevice() )
131 {
132 printf( "[ Default Input" );
133 defaultDisplayed = 1;
134 }
135 else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultInputDevice )
136 {
137 const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
138 printf( "[ Default %s Input", hostInfo->name );
139 defaultDisplayed = 1;
140 }
141
142 if( i == Pa_GetDefaultOutputDevice() )
143 {
144 printf( (defaultDisplayed ? "," : "[") );
145 printf( " Default Output" );
146 defaultDisplayed = 1;
147 }
148 else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultOutputDevice )
149 {
150 const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
151 printf( (defaultDisplayed ? "," : "[") );
152 printf( " Default %s Output", hostInfo->name );
153 defaultDisplayed = 1;
154 }
155
156 if( defaultDisplayed )
157 printf( " ]\n" );
158
159 /* print device info fields */
160 printf( "Name = %s\n", deviceInfo->name );
161 printf( "Host API = %s\n", Pa_GetHostApiInfo( deviceInfo->hostApi )->name );
162 printf( "Max inputs = %d", deviceInfo->maxInputChannels );
163 printf( ", Max outputs = %d\n", deviceInfo->maxOutputChannels );
164
165 printf( "Default low input latency = %8.4f\n", deviceInfo->defaultLowInputLatency );
166 printf( "Default low output latency = %8.4f\n", deviceInfo->defaultLowOutputLatency );
167 printf( "Default high input latency = %8.4f\n", deviceInfo->defaultHighInputLatency );
168 printf( "Default high output latency = %8.4f\n", deviceInfo->defaultHighOutputLatency );
169
170 #ifdef WIN32
171 #if PA_USE_ASIO
172 /* ASIO specific latency information */
173 if( Pa_GetHostApiInfo( deviceInfo->hostApi )->type == paASIO ){
174 long minLatency, maxLatency, preferredLatency, granularity;
175
176 err = PaAsio_GetAvailableLatencyValues( i,
177 &minLatency, &maxLatency, &preferredLatency, &granularity );
178
179 printf( "ASIO minimum buffer size = %ld\n", minLatency );
180 printf( "ASIO maximum buffer size = %ld\n", maxLatency );
181 printf( "ASIO preferred buffer size = %ld\n", preferredLatency );
182
183 if( granularity == -1 )
184 printf( "ASIO buffer granularity = power of 2\n" );
185 else
186 printf( "ASIO buffer granularity = %ld\n", granularity );
187 }
188 #endif /* PA_USE_ASIO */
189 #endif /* WIN32 */
190
191 printf( "Default sample rate = %8.2f\n", deviceInfo->defaultSampleRate );
192
193 /* poll for standard sample rates */
194 inputParameters.device = i;
195 inputParameters.channelCount = deviceInfo->maxInputChannels;
196 inputParameters.sampleFormat = paInt16;
197 inputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
198 inputParameters.hostApiSpecificStreamInfo = NULL;
199
200 outputParameters.device = i;
201 outputParameters.channelCount = deviceInfo->maxOutputChannels;
202 outputParameters.sampleFormat = paInt16;
203 outputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
204 outputParameters.hostApiSpecificStreamInfo = NULL;
205
206 if( inputParameters.channelCount > 0 )
207 {
208 printf("Supported standard sample rates\n for half-duplex 16 bit %d channel input = \n",
209 inputParameters.channelCount );
210 PrintSupportedStandardSampleRates( &inputParameters, NULL );
211 }
212
213 if( outputParameters.channelCount > 0 )
214 {
215 printf("Supported standard sample rates\n for half-duplex 16 bit %d channel output = \n",
216 outputParameters.channelCount );
217 PrintSupportedStandardSampleRates( NULL, &outputParameters );
218 }
219
220 if( inputParameters.channelCount > 0 && outputParameters.channelCount > 0 )
221 {
222 printf("Supported standard sample rates\n for full-duplex 16 bit %d channel input, %d channel output = \n",
223 inputParameters.channelCount, outputParameters.channelCount );
224 PrintSupportedStandardSampleRates( &inputParameters, &outputParameters );
225 }
226 }
227
228 Pa_Terminate();
229
230 printf("----------------------------------------------\n");
231 return 0;
232
233 error:
234 Pa_Terminate();
235 fprintf( stderr, "An error occured while using the portaudio stream\n" );
236 fprintf( stderr, "Error number: %d\n", err );
237 fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
238 return err;
239 }