00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
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
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
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
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
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
00189 #endif
00190
00191 printf( "Default sample rate = %8.2f\n", deviceInfo->defaultSampleRate );
00192
00193
00194 inputParameters.device = i;
00195 inputParameters.channelCount = deviceInfo->maxInputChannels;
00196 inputParameters.sampleFormat = paInt16;
00197 inputParameters.suggestedLatency = 0;
00198 inputParameters.hostApiSpecificStreamInfo = NULL;
00199
00200 outputParameters.device = i;
00201 outputParameters.channelCount = deviceInfo->maxOutputChannels;
00202 outputParameters.sampleFormat = paInt16;
00203 outputParameters.suggestedLatency = 0;
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 }