PortAudio  2.0
pa_devs.c
Go to the documentation of this file.
1 
9 /*
10  * $Id: pa_devs.c 1817 2012-02-22 12:44:10Z robiwan $
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  Pa_Initialize();
111 
112  printf( "PortAudio version number = %d\nPortAudio version text = '%s'\n",
114 
115 
116  numDevices = Pa_GetDeviceCount();
117  if( numDevices < 0 )
118  {
119  printf( "ERROR: Pa_GetDeviceCount returned 0x%x\n", numDevices );
120  err = numDevices;
121  goto error;
122  }
123 
124  printf( "Number of devices = %d\n", numDevices );
125  for( i=0; i<numDevices; i++ )
126  {
127  deviceInfo = Pa_GetDeviceInfo( i );
128  printf( "--------------------------------------- device #%d\n", i );
129 
130  /* Mark global and API specific default devices */
131  defaultDisplayed = 0;
132  if( i == Pa_GetDefaultInputDevice() )
133  {
134  printf( "[ Default Input" );
135  defaultDisplayed = 1;
136  }
137  else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultInputDevice )
138  {
139  const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
140  printf( "[ Default %s Input", hostInfo->name );
141  defaultDisplayed = 1;
142  }
143 
144  if( i == Pa_GetDefaultOutputDevice() )
145  {
146  printf( (defaultDisplayed ? "," : "[") );
147  printf( " Default Output" );
148  defaultDisplayed = 1;
149  }
150  else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultOutputDevice )
151  {
152  const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
153  printf( (defaultDisplayed ? "," : "[") );
154  printf( " Default %s Output", hostInfo->name );
155  defaultDisplayed = 1;
156  }
157 
158  if( defaultDisplayed )
159  printf( " ]\n" );
160 
161  /* print device info fields */
162 #ifdef WIN32
163  { /* Use wide char on windows, so we can show UTF-8 encoded device names */
164  wchar_t wideName[MAX_PATH];
165  MultiByteToWideChar(CP_UTF8, 0, deviceInfo->name, -1, wideName, MAX_PATH-1);
166  wprintf( L"Name = %s\n", wideName );
167  }
168 #else
169  printf( "Name = %s\n", deviceInfo->name );
170 #endif
171  printf( "Host API = %s\n", Pa_GetHostApiInfo( deviceInfo->hostApi )->name );
172  printf( "Max inputs = %d", deviceInfo->maxInputChannels );
173  printf( ", Max outputs = %d\n", deviceInfo->maxOutputChannels );
174 
175  printf( "Default low input latency = %8.4f\n", deviceInfo->defaultLowInputLatency );
176  printf( "Default low output latency = %8.4f\n", deviceInfo->defaultLowOutputLatency );
177  printf( "Default high input latency = %8.4f\n", deviceInfo->defaultHighInputLatency );
178  printf( "Default high output latency = %8.4f\n", deviceInfo->defaultHighOutputLatency );
179 
180 #ifdef WIN32
181 #if PA_USE_ASIO
182 /* ASIO specific latency information */
183  if( Pa_GetHostApiInfo( deviceInfo->hostApi )->type == paASIO ){
184  long minLatency, maxLatency, preferredLatency, granularity;
185 
187  &minLatency, &maxLatency, &preferredLatency, &granularity );
188 
189  printf( "ASIO minimum buffer size = %ld\n", minLatency );
190  printf( "ASIO maximum buffer size = %ld\n", maxLatency );
191  printf( "ASIO preferred buffer size = %ld\n", preferredLatency );
192 
193  if( granularity == -1 )
194  printf( "ASIO buffer granularity = power of 2\n" );
195  else
196  printf( "ASIO buffer granularity = %ld\n", granularity );
197  }
198 #endif /* PA_USE_ASIO */
199 #endif /* WIN32 */
200 
201  printf( "Default sample rate = %8.2f\n", deviceInfo->defaultSampleRate );
202 
203  /* poll for standard sample rates */
204  inputParameters.device = i;
205  inputParameters.channelCount = deviceInfo->maxInputChannels;
206  inputParameters.sampleFormat = paInt16;
207  inputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
208  inputParameters.hostApiSpecificStreamInfo = NULL;
209 
210  outputParameters.device = i;
211  outputParameters.channelCount = deviceInfo->maxOutputChannels;
212  outputParameters.sampleFormat = paInt16;
213  outputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
214  outputParameters.hostApiSpecificStreamInfo = NULL;
215 
216  if( inputParameters.channelCount > 0 )
217  {
218  printf("Supported standard sample rates\n for half-duplex 16 bit %d channel input = \n",
219  inputParameters.channelCount );
220  PrintSupportedStandardSampleRates( &inputParameters, NULL );
221  }
222 
223  if( outputParameters.channelCount > 0 )
224  {
225  printf("Supported standard sample rates\n for half-duplex 16 bit %d channel output = \n",
226  outputParameters.channelCount );
227  PrintSupportedStandardSampleRates( NULL, &outputParameters );
228  }
229 
230  if( inputParameters.channelCount > 0 && outputParameters.channelCount > 0 )
231  {
232  printf("Supported standard sample rates\n for full-duplex 16 bit %d channel input, %d channel output = \n",
233  inputParameters.channelCount, outputParameters.channelCount );
234  PrintSupportedStandardSampleRates( &inputParameters, &outputParameters );
235  }
236  }
237 
238  Pa_Terminate();
239 
240  printf("----------------------------------------------\n");
241  return 0;
242 
243 error:
244  Pa_Terminate();
245  fprintf( stderr, "An error occured while using the portaudio stream\n" );
246  fprintf( stderr, "Error number: %d\n", err );
247  fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
248  return err;
249 }

Generated for PortAudio by  doxygen1.8.3.1