|
PortAudio 2.0
|
00001 00009 /* 00010 * $Id$ 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: 0x%08X\n", Pa_GetVersion()); 00118 printf( "Version text: '%s'\n", Pa_GetVersionInfo()->versionText ); 00119 00120 numDevices = Pa_GetDeviceCount(); 00121 if( numDevices < 0 ) 00122 { 00123 printf( "ERROR: Pa_GetDeviceCount returned 0x%x\n", numDevices ); 00124 err = numDevices; 00125 goto error; 00126 } 00127 00128 printf( "Number of devices = %d\n", numDevices ); 00129 for( i=0; i<numDevices; i++ ) 00130 { 00131 deviceInfo = Pa_GetDeviceInfo( i ); 00132 printf( "--------------------------------------- device #%d\n", i ); 00133 00134 /* Mark global and API specific default devices */ 00135 defaultDisplayed = 0; 00136 if( i == Pa_GetDefaultInputDevice() ) 00137 { 00138 printf( "[ Default Input" ); 00139 defaultDisplayed = 1; 00140 } 00141 else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultInputDevice ) 00142 { 00143 const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); 00144 printf( "[ Default %s Input", hostInfo->name ); 00145 defaultDisplayed = 1; 00146 } 00147 00148 if( i == Pa_GetDefaultOutputDevice() ) 00149 { 00150 printf( (defaultDisplayed ? "," : "[") ); 00151 printf( " Default Output" ); 00152 defaultDisplayed = 1; 00153 } 00154 else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultOutputDevice ) 00155 { 00156 const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); 00157 printf( (defaultDisplayed ? "," : "[") ); 00158 printf( " Default %s Output", hostInfo->name ); 00159 defaultDisplayed = 1; 00160 } 00161 00162 if( defaultDisplayed ) 00163 printf( " ]\n" ); 00164 00165 /* print device info fields */ 00166 #ifdef WIN32 00167 { /* Use wide char on windows, so we can show UTF-8 encoded device names */ 00168 wchar_t wideName[MAX_PATH]; 00169 MultiByteToWideChar(CP_UTF8, 0, deviceInfo->name, -1, wideName, MAX_PATH-1); 00170 wprintf( L"Name = %s\n", wideName ); 00171 } 00172 #else 00173 printf( "Name = %s\n", deviceInfo->name ); 00174 #endif 00175 printf( "Host API = %s\n", Pa_GetHostApiInfo( deviceInfo->hostApi )->name ); 00176 printf( "Max inputs = %d", deviceInfo->maxInputChannels ); 00177 printf( ", Max outputs = %d\n", deviceInfo->maxOutputChannels ); 00178 00179 printf( "Default low input latency = %8.4f\n", deviceInfo->defaultLowInputLatency ); 00180 printf( "Default low output latency = %8.4f\n", deviceInfo->defaultLowOutputLatency ); 00181 printf( "Default high input latency = %8.4f\n", deviceInfo->defaultHighInputLatency ); 00182 printf( "Default high output latency = %8.4f\n", deviceInfo->defaultHighOutputLatency ); 00183 00184 #ifdef WIN32 00185 #if PA_USE_ASIO 00186 /* ASIO specific latency information */ 00187 if( Pa_GetHostApiInfo( deviceInfo->hostApi )->type == paASIO ){ 00188 long minLatency, maxLatency, preferredLatency, granularity; 00189 00190 err = PaAsio_GetAvailableLatencyValues( i, 00191 &minLatency, &maxLatency, &preferredLatency, &granularity ); 00192 00193 printf( "ASIO minimum buffer size = %ld\n", minLatency ); 00194 printf( "ASIO maximum buffer size = %ld\n", maxLatency ); 00195 printf( "ASIO preferred buffer size = %ld\n", preferredLatency ); 00196 00197 if( granularity == -1 ) 00198 printf( "ASIO buffer granularity = power of 2\n" ); 00199 else 00200 printf( "ASIO buffer granularity = %ld\n", granularity ); 00201 } 00202 #endif /* PA_USE_ASIO */ 00203 #endif /* WIN32 */ 00204 00205 printf( "Default sample rate = %8.2f\n", deviceInfo->defaultSampleRate ); 00206 00207 /* poll for standard sample rates */ 00208 inputParameters.device = i; 00209 inputParameters.channelCount = deviceInfo->maxInputChannels; 00210 inputParameters.sampleFormat = paInt16; 00211 inputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */ 00212 inputParameters.hostApiSpecificStreamInfo = NULL; 00213 00214 outputParameters.device = i; 00215 outputParameters.channelCount = deviceInfo->maxOutputChannels; 00216 outputParameters.sampleFormat = paInt16; 00217 outputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */ 00218 outputParameters.hostApiSpecificStreamInfo = NULL; 00219 00220 if( inputParameters.channelCount > 0 ) 00221 { 00222 printf("Supported standard sample rates\n for half-duplex 16 bit %d channel input = \n", 00223 inputParameters.channelCount ); 00224 PrintSupportedStandardSampleRates( &inputParameters, NULL ); 00225 } 00226 00227 if( outputParameters.channelCount > 0 ) 00228 { 00229 printf("Supported standard sample rates\n for half-duplex 16 bit %d channel output = \n", 00230 outputParameters.channelCount ); 00231 PrintSupportedStandardSampleRates( NULL, &outputParameters ); 00232 } 00233 00234 if( inputParameters.channelCount > 0 && outputParameters.channelCount > 0 ) 00235 { 00236 printf("Supported standard sample rates\n for full-duplex 16 bit %d channel input, %d channel output = \n", 00237 inputParameters.channelCount, outputParameters.channelCount ); 00238 PrintSupportedStandardSampleRates( &inputParameters, &outputParameters ); 00239 } 00240 } 00241 00242 Pa_Terminate(); 00243 00244 printf("----------------------------------------------\n"); 00245 return 0; 00246 00247 error: 00248 Pa_Terminate(); 00249 fprintf( stderr, "Error number: %d\n", err ); 00250 fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); 00251 return err; 00252 }
1.7.3