PortAudio 2.0
|
00001 00009 /* 00010 * $Id: pa_devs.c 1891 2013-05-05 14:00:02Z rbencina $ 00011 * 00012 * This program uses the PortAudio Portable Audio Library. 00013 * For more information see: http://www.portaudio.com 00014 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk 00015 * 00016 * Permission is hereby granted, free of charge, to any person obtaining 00017 * a copy of this software and associated documentation files 00018 * (the "Software"), to deal in the Software without restriction, 00019 * including without limitation the rights to use, copy, modify, merge, 00020 * publish, distribute, sublicense, and/or sell copies of the Software, 00021 * and to permit persons to whom the Software is furnished to do so, 00022 * subject to the following conditions: 00023 * 00024 * The above copyright notice and this permission notice shall be 00025 * included in all copies or substantial portions of the Software. 00026 * 00027 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00028 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00029 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00030 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 00031 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 00032 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00033 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00034 */ 00035 00036 /* 00037 * The text above constitutes the entire PortAudio license; however, 00038 * the PortAudio community also makes the following non-binding requests: 00039 * 00040 * Any person wishing to distribute modifications to the Software is 00041 * requested to send the modifications to the original developer so that 00042 * they can be incorporated into the canonical version. It is also 00043 * requested that these non-binding requests be included along with the 00044 * license above. 00045 */ 00046 00047 #include <stdio.h> 00048 #include <math.h> 00049 #include "portaudio.h" 00050 00051 #ifdef WIN32 00052 #include <windows.h> 00053 00054 #if PA_USE_ASIO 00055 #include "pa_asio.h" 00056 #endif 00057 #endif 00058 00059 /*******************************************************************/ 00060 static void PrintSupportedStandardSampleRates( 00061 const PaStreamParameters *inputParameters, 00062 const PaStreamParameters *outputParameters ) 00063 { 00064 static double standardSampleRates[] = { 00065 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0, 00066 44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1 /* negative terminated list */ 00067 }; 00068 int i, printCount; 00069 PaError err; 00070 00071 printCount = 0; 00072 for( i=0; standardSampleRates[i] > 0; i++ ) 00073 { 00074 err = Pa_IsFormatSupported( inputParameters, outputParameters, standardSampleRates[i] ); 00075 if( err == paFormatIsSupported ) 00076 { 00077 if( printCount == 0 ) 00078 { 00079 printf( "\t%8.2f", standardSampleRates[i] ); 00080 printCount = 1; 00081 } 00082 else if( printCount == 4 ) 00083 { 00084 printf( ",\n\t%8.2f", standardSampleRates[i] ); 00085 printCount = 1; 00086 } 00087 else 00088 { 00089 printf( ", %8.2f", standardSampleRates[i] ); 00090 ++printCount; 00091 } 00092 } 00093 } 00094 if( !printCount ) 00095 printf( "None\n" ); 00096 else 00097 printf( "\n" ); 00098 } 00099 00100 /*******************************************************************/ 00101 int main(void); 00102 int main(void) 00103 { 00104 int i, numDevices, defaultDisplayed; 00105 const PaDeviceInfo *deviceInfo; 00106 PaStreamParameters inputParameters, outputParameters; 00107 PaError err; 00108 00109 00110 err = Pa_Initialize(); 00111 if( err != paNoError ) 00112 { 00113 printf( "ERROR: Pa_Initialize returned 0x%x\n", err ); 00114 goto error; 00115 } 00116 00117 printf( "PortAudio version number = %d\nPortAudio version text = '%s'\n", 00118 Pa_GetVersion(), Pa_GetVersionText() ); 00119 00120 00121 numDevices = Pa_GetDeviceCount(); 00122 if( numDevices < 0 ) 00123 { 00124 printf( "ERROR: Pa_GetDeviceCount returned 0x%x\n", numDevices ); 00125 err = numDevices; 00126 goto error; 00127 } 00128 00129 printf( "Number of devices = %d\n", numDevices ); 00130 for( i=0; i<numDevices; i++ ) 00131 { 00132 deviceInfo = Pa_GetDeviceInfo( i ); 00133 printf( "--------------------------------------- device #%d\n", i ); 00134 00135 /* Mark global and API specific default devices */ 00136 defaultDisplayed = 0; 00137 if( i == Pa_GetDefaultInputDevice() ) 00138 { 00139 printf( "[ Default Input" ); 00140 defaultDisplayed = 1; 00141 } 00142 else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultInputDevice ) 00143 { 00144 const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); 00145 printf( "[ Default %s Input", hostInfo->name ); 00146 defaultDisplayed = 1; 00147 } 00148 00149 if( i == Pa_GetDefaultOutputDevice() ) 00150 { 00151 printf( (defaultDisplayed ? "," : "[") ); 00152 printf( " Default Output" ); 00153 defaultDisplayed = 1; 00154 } 00155 else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultOutputDevice ) 00156 { 00157 const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); 00158 printf( (defaultDisplayed ? "," : "[") ); 00159 printf( " Default %s Output", hostInfo->name ); 00160 defaultDisplayed = 1; 00161 } 00162 00163 if( defaultDisplayed ) 00164 printf( " ]\n" ); 00165 00166 /* print device info fields */ 00167 #ifdef WIN32 00168 { /* Use wide char on windows, so we can show UTF-8 encoded device names */ 00169 wchar_t wideName[MAX_PATH]; 00170 MultiByteToWideChar(CP_UTF8, 0, deviceInfo->name, -1, wideName, MAX_PATH-1); 00171 wprintf( L"Name = %s\n", wideName ); 00172 } 00173 #else 00174 printf( "Name = %s\n", deviceInfo->name ); 00175 #endif 00176 printf( "Host API = %s\n", Pa_GetHostApiInfo( deviceInfo->hostApi )->name ); 00177 printf( "Max inputs = %d", deviceInfo->maxInputChannels ); 00178 printf( ", Max outputs = %d\n", deviceInfo->maxOutputChannels ); 00179 00180 printf( "Default low input latency = %8.4f\n", deviceInfo->defaultLowInputLatency ); 00181 printf( "Default low output latency = %8.4f\n", deviceInfo->defaultLowOutputLatency ); 00182 printf( "Default high input latency = %8.4f\n", deviceInfo->defaultHighInputLatency ); 00183 printf( "Default high output latency = %8.4f\n", deviceInfo->defaultHighOutputLatency ); 00184 00185 #ifdef WIN32 00186 #if PA_USE_ASIO 00187 /* ASIO specific latency information */ 00188 if( Pa_GetHostApiInfo( deviceInfo->hostApi )->type == paASIO ){ 00189 long minLatency, maxLatency, preferredLatency, granularity; 00190 00191 err = PaAsio_GetAvailableLatencyValues( i, 00192 &minLatency, &maxLatency, &preferredLatency, &granularity ); 00193 00194 printf( "ASIO minimum buffer size = %ld\n", minLatency ); 00195 printf( "ASIO maximum buffer size = %ld\n", maxLatency ); 00196 printf( "ASIO preferred buffer size = %ld\n", preferredLatency ); 00197 00198 if( granularity == -1 ) 00199 printf( "ASIO buffer granularity = power of 2\n" ); 00200 else 00201 printf( "ASIO buffer granularity = %ld\n", granularity ); 00202 } 00203 #endif /* PA_USE_ASIO */ 00204 #endif /* WIN32 */ 00205 00206 printf( "Default sample rate = %8.2f\n", deviceInfo->defaultSampleRate ); 00207 00208 /* poll for standard sample rates */ 00209 inputParameters.device = i; 00210 inputParameters.channelCount = deviceInfo->maxInputChannels; 00211 inputParameters.sampleFormat = paInt16; 00212 inputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */ 00213 inputParameters.hostApiSpecificStreamInfo = NULL; 00214 00215 outputParameters.device = i; 00216 outputParameters.channelCount = deviceInfo->maxOutputChannels; 00217 outputParameters.sampleFormat = paInt16; 00218 outputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */ 00219 outputParameters.hostApiSpecificStreamInfo = NULL; 00220 00221 if( inputParameters.channelCount > 0 ) 00222 { 00223 printf("Supported standard sample rates\n for half-duplex 16 bit %d channel input = \n", 00224 inputParameters.channelCount ); 00225 PrintSupportedStandardSampleRates( &inputParameters, NULL ); 00226 } 00227 00228 if( outputParameters.channelCount > 0 ) 00229 { 00230 printf("Supported standard sample rates\n for half-duplex 16 bit %d channel output = \n", 00231 outputParameters.channelCount ); 00232 PrintSupportedStandardSampleRates( NULL, &outputParameters ); 00233 } 00234 00235 if( inputParameters.channelCount > 0 && outputParameters.channelCount > 0 ) 00236 { 00237 printf("Supported standard sample rates\n for full-duplex 16 bit %d channel input, %d channel output = \n", 00238 inputParameters.channelCount, outputParameters.channelCount ); 00239 PrintSupportedStandardSampleRates( &inputParameters, &outputParameters ); 00240 } 00241 } 00242 00243 Pa_Terminate(); 00244 00245 printf("----------------------------------------------\n"); 00246 return 0; 00247 00248 error: 00249 Pa_Terminate(); 00250 fprintf( stderr, "Error number: %d\n", err ); 00251 fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); 00252 return err; 00253 }