PortAudio
2.0
|
00001 00009 /* 00010 * $Id: pa_devs.c 1752 2011-09-08 03:21:55Z philburk $ 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 #if PA_USE_ASIO 00053 #include "pa_asio.h" 00054 #endif 00055 #endif 00056 00057 /*******************************************************************/ 00058 static void PrintSupportedStandardSampleRates( 00059 const PaStreamParameters *inputParameters, 00060 const PaStreamParameters *outputParameters ) 00061 { 00062 static double standardSampleRates[] = { 00063 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0, 00064 44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1 /* negative terminated list */ 00065 }; 00066 int i, printCount; 00067 PaError err; 00068 00069 printCount = 0; 00070 for( i=0; standardSampleRates[i] > 0; i++ ) 00071 { 00072 err = Pa_IsFormatSupported( inputParameters, outputParameters, standardSampleRates[i] ); 00073 if( err == paFormatIsSupported ) 00074 { 00075 if( printCount == 0 ) 00076 { 00077 printf( "\t%8.2f", standardSampleRates[i] ); 00078 printCount = 1; 00079 } 00080 else if( printCount == 4 ) 00081 { 00082 printf( ",\n\t%8.2f", standardSampleRates[i] ); 00083 printCount = 1; 00084 } 00085 else 00086 { 00087 printf( ", %8.2f", standardSampleRates[i] ); 00088 ++printCount; 00089 } 00090 } 00091 } 00092 if( !printCount ) 00093 printf( "None\n" ); 00094 else 00095 printf( "\n" ); 00096 } 00097 00098 /*******************************************************************/ 00099 int main(void); 00100 int main(void) 00101 { 00102 int i, numDevices, defaultDisplayed; 00103 const PaDeviceInfo *deviceInfo; 00104 PaStreamParameters inputParameters, outputParameters; 00105 PaError err; 00106 00107 00108 Pa_Initialize(); 00109 00110 printf( "PortAudio version number = %d\nPortAudio version text = '%s'\n", 00111 Pa_GetVersion(), Pa_GetVersionText() ); 00112 00113 00114 numDevices = Pa_GetDeviceCount(); 00115 if( numDevices < 0 ) 00116 { 00117 printf( "ERROR: Pa_GetDeviceCount returned 0x%x\n", numDevices ); 00118 err = numDevices; 00119 goto error; 00120 } 00121 00122 printf( "Number of devices = %d\n", numDevices ); 00123 for( i=0; i<numDevices; i++ ) 00124 { 00125 deviceInfo = Pa_GetDeviceInfo( i ); 00126 printf( "--------------------------------------- device #%d\n", i ); 00127 00128 /* Mark global and API specific default devices */ 00129 defaultDisplayed = 0; 00130 if( i == Pa_GetDefaultInputDevice() ) 00131 { 00132 printf( "[ Default Input" ); 00133 defaultDisplayed = 1; 00134 } 00135 else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultInputDevice ) 00136 { 00137 const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); 00138 printf( "[ Default %s Input", hostInfo->name ); 00139 defaultDisplayed = 1; 00140 } 00141 00142 if( i == Pa_GetDefaultOutputDevice() ) 00143 { 00144 printf( (defaultDisplayed ? "," : "[") ); 00145 printf( " Default Output" ); 00146 defaultDisplayed = 1; 00147 } 00148 else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultOutputDevice ) 00149 { 00150 const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); 00151 printf( (defaultDisplayed ? "," : "[") ); 00152 printf( " Default %s Output", hostInfo->name ); 00153 defaultDisplayed = 1; 00154 } 00155 00156 if( defaultDisplayed ) 00157 printf( " ]\n" ); 00158 00159 /* print device info fields */ 00160 printf( "Name = %s\n", deviceInfo->name ); 00161 printf( "Host API = %s\n", Pa_GetHostApiInfo( deviceInfo->hostApi )->name ); 00162 printf( "Max inputs = %d", deviceInfo->maxInputChannels ); 00163 printf( ", Max outputs = %d\n", deviceInfo->maxOutputChannels ); 00164 00165 printf( "Default low input latency = %8.4f\n", deviceInfo->defaultLowInputLatency ); 00166 printf( "Default low output latency = %8.4f\n", deviceInfo->defaultLowOutputLatency ); 00167 printf( "Default high input latency = %8.4f\n", deviceInfo->defaultHighInputLatency ); 00168 printf( "Default high output latency = %8.4f\n", deviceInfo->defaultHighOutputLatency ); 00169 00170 #ifdef WIN32 00171 #if PA_USE_ASIO 00172 /* ASIO specific latency information */ 00173 if( Pa_GetHostApiInfo( deviceInfo->hostApi )->type == paASIO ){ 00174 long minLatency, maxLatency, preferredLatency, granularity; 00175 00176 err = PaAsio_GetAvailableLatencyValues( i, 00177 &minLatency, &maxLatency, &preferredLatency, &granularity ); 00178 00179 printf( "ASIO minimum buffer size = %ld\n", minLatency ); 00180 printf( "ASIO maximum buffer size = %ld\n", maxLatency ); 00181 printf( "ASIO preferred buffer size = %ld\n", preferredLatency ); 00182 00183 if( granularity == -1 ) 00184 printf( "ASIO buffer granularity = power of 2\n" ); 00185 else 00186 printf( "ASIO buffer granularity = %ld\n", granularity ); 00187 } 00188 #endif /* PA_USE_ASIO */ 00189 #endif /* WIN32 */ 00190 00191 printf( "Default sample rate = %8.2f\n", deviceInfo->defaultSampleRate ); 00192 00193 /* poll for standard sample rates */ 00194 inputParameters.device = i; 00195 inputParameters.channelCount = deviceInfo->maxInputChannels; 00196 inputParameters.sampleFormat = paInt16; 00197 inputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */ 00198 inputParameters.hostApiSpecificStreamInfo = NULL; 00199 00200 outputParameters.device = i; 00201 outputParameters.channelCount = deviceInfo->maxOutputChannels; 00202 outputParameters.sampleFormat = paInt16; 00203 outputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */ 00204 outputParameters.hostApiSpecificStreamInfo = NULL; 00205 00206 if( inputParameters.channelCount > 0 ) 00207 { 00208 printf("Supported standard sample rates\n for half-duplex 16 bit %d channel input = \n", 00209 inputParameters.channelCount ); 00210 PrintSupportedStandardSampleRates( &inputParameters, NULL ); 00211 } 00212 00213 if( outputParameters.channelCount > 0 ) 00214 { 00215 printf("Supported standard sample rates\n for half-duplex 16 bit %d channel output = \n", 00216 outputParameters.channelCount ); 00217 PrintSupportedStandardSampleRates( NULL, &outputParameters ); 00218 } 00219 00220 if( inputParameters.channelCount > 0 && outputParameters.channelCount > 0 ) 00221 { 00222 printf("Supported standard sample rates\n for full-duplex 16 bit %d channel input, %d channel output = \n", 00223 inputParameters.channelCount, outputParameters.channelCount ); 00224 PrintSupportedStandardSampleRates( &inputParameters, &outputParameters ); 00225 } 00226 } 00227 00228 Pa_Terminate(); 00229 00230 printf("----------------------------------------------\n"); 00231 return 0; 00232 00233 error: 00234 Pa_Terminate(); 00235 fprintf( stderr, "An error occured while using the portaudio stream\n" ); 00236 fprintf( stderr, "Error number: %d\n", err ); 00237 fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); 00238 return err; 00239 }