| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
#include <stdio.h> |
| 40 |
#include <math.h> |
| 41 |
#include "portaudio.h" |
| 42 |
|
| 43 |
#ifdef WIN32 |
| 44 |
#ifndef PA_NO_ASIO |
| 45 |
#include "pa_asio.h" |
| 46 |
#endif |
| 47 |
#endif |
| 48 |
|
| 49 |
|
| 50 |
static void PrintSupportedStandardSampleRates( |
| 51 |
const PaStreamParameters *inputParameters, |
| 52 |
const PaStreamParameters *outputParameters ) |
| 53 |
{ |
| 54 |
static double standardSampleRates[] = { |
| 55 |
8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0, |
| 56 |
44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1 |
| 57 |
}; |
| 58 |
int i, printCount; |
| 59 |
PaError err; |
| 60 |
|
| 61 |
printCount = 0; |
| 62 |
for( i=0; standardSampleRates[i] > 0; i++ ) |
| 63 |
{ |
| 64 |
err = Pa_IsFormatSupported( inputParameters, outputParameters, standardSampleRates[i] ); |
| 65 |
if( err == paFormatIsSupported ) |
| 66 |
{ |
| 67 |
if( printCount == 0 ) |
| 68 |
{ |
| 69 |
printf( "\t%8.2f", standardSampleRates[i] ); |
| 70 |
printCount = 1; |
| 71 |
} |
| 72 |
else if( printCount == 4 ) |
| 73 |
{ |
| 74 |
printf( ",\n\t%8.2f", standardSampleRates[i] ); |
| 75 |
printCount = 1; |
| 76 |
} |
| 77 |
else |
| 78 |
{ |
| 79 |
printf( ", %8.2f", standardSampleRates[i] ); |
| 80 |
++printCount; |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
if( !printCount ) |
| 85 |
printf( "None\n" ); |
| 86 |
else |
| 87 |
printf( "\n" ); |
| 88 |
} |
| 89 |
|
| 90 |
int main(void); |
| 91 |
int main(void) |
| 92 |
{ |
| 93 |
int i, numDevices, defaultDisplayed; |
| 94 |
const PaDeviceInfo *deviceInfo; |
| 95 |
PaStreamParameters inputParameters, outputParameters; |
| 96 |
PaError err; |
| 97 |
|
| 98 |
|
| 99 |
Pa_Initialize(); |
| 100 |
|
| 101 |
printf( "PortAudio version number = %d\nPortAudio version text = '%s'\n", |
| 102 |
Pa_GetVersion(), Pa_GetVersionText() ); |
| 103 |
|
| 104 |
|
| 105 |
numDevices = Pa_GetDeviceCount(); |
| 106 |
if( numDevices < 0 ) |
| 107 |
{ |
| 108 |
printf( "ERROR: Pa_CountDevices returned 0x%x\n", numDevices ); |
| 109 |
err = numDevices; |
| 110 |
goto error; |
| 111 |
} |
| 112 |
|
| 113 |
printf( "Number of devices = %d\n", numDevices ); |
| 114 |
for( i=0; i<numDevices; i++ ) |
| 115 |
{ |
| 116 |
deviceInfo = Pa_GetDeviceInfo( i ); |
| 117 |
printf( "--------------------------------------- device #%d\n", i ); |
| 118 |
|
| 119 |
|
| 120 |
defaultDisplayed = 0; |
| 121 |
if( i == Pa_GetDefaultInputDevice() ) |
| 122 |
{ |
| 123 |
printf( "[ Default Input" ); |
| 124 |
defaultDisplayed = 1; |
| 125 |
} |
| 126 |
else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultInputDevice ) |
| 127 |
{ |
| 128 |
const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); |
| 129 |
printf( "[ Default %s Input", hostInfo->name ); |
| 130 |
defaultDisplayed = 1; |
| 131 |
} |
| 132 |
|
| 133 |
if( i == Pa_GetDefaultOutputDevice() ) |
| 134 |
{ |
| 135 |
printf( (defaultDisplayed ? "," : "[") ); |
| 136 |
printf( " Default Output" ); |
| 137 |
defaultDisplayed = 1; |
| 138 |
} |
| 139 |
else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultOutputDevice ) |
| 140 |
{ |
| 141 |
const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); |
| 142 |
printf( (defaultDisplayed ? "," : "[") ); |
| 143 |
printf( " Default %s Output", hostInfo->name ); |
| 144 |
defaultDisplayed = 1; |
| 145 |
} |
| 146 |
|
| 147 |
if( defaultDisplayed ) |
| 148 |
printf( " ]\n" ); |
| 149 |
|
| 150 |
|
| 151 |
printf( "Name = %s\n", deviceInfo->name ); |
| 152 |
printf( "Host API = %s\n", Pa_GetHostApiInfo( deviceInfo->hostApi )->name ); |
| 153 |
printf( "Max inputs = %d", deviceInfo->maxInputChannels ); |
| 154 |
printf( ", Max outputs = %d\n", deviceInfo->maxOutputChannels ); |
| 155 |
|
| 156 |
printf( "Default low input latency = %8.3f\n", deviceInfo->defaultLowInputLatency ); |
| 157 |
printf( "Default low output latency = %8.3f\n", deviceInfo->defaultLowOutputLatency ); |
| 158 |
printf( "Default high input latency = %8.3f\n", deviceInfo->defaultHighInputLatency ); |
| 159 |
printf( "Default high output latency = %8.3f\n", deviceInfo->defaultHighOutputLatency ); |
| 160 |
|
| 161 |
#ifdef WIN32 |
| 162 |
#ifndef PA_NO_ASIO |
| 163 |
|
| 164 |
if( Pa_GetHostApiInfo( deviceInfo->hostApi )->type == paASIO ){ |
| 165 |
long minLatency, maxLatency, preferredLatency, granularity; |
| 166 |
|
| 167 |
err = PaAsio_GetAvailableLatencyValues( i, |
| 168 |
&minLatency, &maxLatency, &preferredLatency, &granularity ); |
| 169 |
|
| 170 |
printf( "ASIO minimum buffer size = %ld\n", minLatency ); |
| 171 |
printf( "ASIO maximum buffer size = %ld\n", maxLatency ); |
| 172 |
printf( "ASIO preferred buffer size = %ld\n", preferredLatency ); |
| 173 |
|
| 174 |
if( granularity == -1 ) |
| 175 |
printf( "ASIO buffer granularity = power of 2\n" ); |
| 176 |
else |
| 177 |
printf( "ASIO buffer granularity = %ld\n", granularity ); |
| 178 |
} |
| 179 |
#endif |
| 180 |
#endif |
| 181 |
|
| 182 |
printf( "Default sample rate = %8.2f\n", deviceInfo->defaultSampleRate ); |
| 183 |
|
| 184 |
|
| 185 |
inputParameters.device = i; |
| 186 |
inputParameters.channelCount = deviceInfo->maxInputChannels; |
| 187 |
inputParameters.sampleFormat = paInt16; |
| 188 |
inputParameters.suggestedLatency = 0; |
| 189 |
inputParameters.hostApiSpecificStreamInfo = NULL; |
| 190 |
|
| 191 |
outputParameters.device = i; |
| 192 |
outputParameters.channelCount = deviceInfo->maxOutputChannels; |
| 193 |
outputParameters.sampleFormat = paInt16; |
| 194 |
outputParameters.suggestedLatency = 0; |
| 195 |
outputParameters.hostApiSpecificStreamInfo = NULL; |
| 196 |
|
| 197 |
if( inputParameters.channelCount > 0 ) |
| 198 |
{ |
| 199 |
printf("Supported standard sample rates\n for half-duplex 16 bit %d channel input = \n", |
| 200 |
inputParameters.channelCount ); |
| 201 |
PrintSupportedStandardSampleRates( &inputParameters, NULL ); |
| 202 |
} |
| 203 |
|
| 204 |
if( outputParameters.channelCount > 0 ) |
| 205 |
{ |
| 206 |
printf("Supported standard sample rates\n for half-duplex 16 bit %d channel output = \n", |
| 207 |
outputParameters.channelCount ); |
| 208 |
PrintSupportedStandardSampleRates( NULL, &outputParameters ); |
| 209 |
} |
| 210 |
|
| 211 |
if( inputParameters.channelCount > 0 && outputParameters.channelCount > 0 ) |
| 212 |
{ |
| 213 |
printf("Supported standard sample rates\n for full-duplex 16 bit %d channel input, %d channel output = \n", |
| 214 |
inputParameters.channelCount, outputParameters.channelCount ); |
| 215 |
PrintSupportedStandardSampleRates( &inputParameters, &outputParameters ); |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
Pa_Terminate(); |
| 220 |
|
| 221 |
printf("----------------------------------------------\n"); |
| 222 |
return 0; |
| 223 |
|
| 224 |
error: |
| 225 |
Pa_Terminate(); |
| •226 |
fprintf( stderr, "An error occurred while using the portaudio stream\n" ); |
| 227 |
fprintf( stderr, "Error number: %d\n", err ); |
| 228 |
fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); |
| 229 |
return err; |
| 230 |
} |