annotate src/portaudio_20161030_catalina_patch/qa/paqa_latency.c @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents d43aab368df9
children
rev   line source
cannam@162 1 /** @file paqa_latency.c
cannam@162 2 @ingroup qa_src
cannam@162 3 @brief Test latency estimates.
cannam@162 4 @author Ross Bencina <rossb@audiomulch.com>
cannam@162 5 @author Phil Burk <philburk@softsynth.com>
cannam@162 6 */
cannam@162 7 /*
cannam@162 8 * $Id: patest_sine.c 1368 2008-03-01 00:38:27Z rossb $
cannam@162 9 *
cannam@162 10 * This program uses the PortAudio Portable Audio Library.
cannam@162 11 * For more information see: http://www.portaudio.com/
cannam@162 12 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
cannam@162 13 *
cannam@162 14 * Permission is hereby granted, free of charge, to any person obtaining
cannam@162 15 * a copy of this software and associated documentation files
cannam@162 16 * (the "Software"), to deal in the Software without restriction,
cannam@162 17 * including without limitation the rights to use, copy, modify, merge,
cannam@162 18 * publish, distribute, sublicense, and/or sell copies of the Software,
cannam@162 19 * and to permit persons to whom the Software is furnished to do so,
cannam@162 20 * subject to the following conditions:
cannam@162 21 *
cannam@162 22 * The above copyright notice and this permission notice shall be
cannam@162 23 * included in all copies or substantial portions of the Software.
cannam@162 24 *
cannam@162 25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@162 26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@162 27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
cannam@162 28 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
cannam@162 29 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@162 30 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@162 31 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@162 32 */
cannam@162 33
cannam@162 34 /*
cannam@162 35 * The text above constitutes the entire PortAudio license; however,
cannam@162 36 * the PortAudio community also makes the following non-binding requests:
cannam@162 37 *
cannam@162 38 * Any person wishing to distribute modifications to the Software is
cannam@162 39 * requested to send the modifications to the original developer so that
cannam@162 40 * they can be incorporated into the canonical version. It is also
cannam@162 41 * requested that these non-binding requests be included along with the
cannam@162 42 * license above.
cannam@162 43 */
cannam@162 44 #include <stdio.h>
cannam@162 45 #include <math.h>
cannam@162 46 #include "portaudio.h"
cannam@162 47 #include "loopback/src/qa_tools.h"
cannam@162 48
cannam@162 49 #define NUM_SECONDS (5)
cannam@162 50 #define SAMPLE_RATE (44100)
cannam@162 51 #define FRAMES_PER_BUFFER (64)
cannam@162 52
cannam@162 53 #ifndef M_PI
cannam@162 54 #define M_PI (3.14159265)
cannam@162 55 #endif
cannam@162 56
cannam@162 57 #define TABLE_SIZE (200)
cannam@162 58 typedef struct
cannam@162 59 {
cannam@162 60 float sine[TABLE_SIZE];
cannam@162 61 int left_phase;
cannam@162 62 int right_phase;
cannam@162 63 char message[20];
cannam@162 64 int minFramesPerBuffer;
cannam@162 65 int maxFramesPerBuffer;
cannam@162 66 int callbackCount;
cannam@162 67 PaTime minDeltaDacTime;
cannam@162 68 PaTime maxDeltaDacTime;
cannam@162 69 PaStreamCallbackTimeInfo previousTimeInfo;
cannam@162 70 }
cannam@162 71 paTestData;
cannam@162 72
cannam@162 73 /* Used to tally the results of the QA tests. */
cannam@162 74 int g_testsPassed = 0;
cannam@162 75 int g_testsFailed = 0;
cannam@162 76
cannam@162 77 /* This routine will be called by the PortAudio engine when audio is needed.
cannam@162 78 ** It may called at interrupt level on some machines so don't do anything
cannam@162 79 ** that could mess up the system like calling malloc() or free().
cannam@162 80 */
cannam@162 81 static int patestCallback( const void *inputBuffer, void *outputBuffer,
cannam@162 82 unsigned long framesPerBuffer,
cannam@162 83 const PaStreamCallbackTimeInfo* timeInfo,
cannam@162 84 PaStreamCallbackFlags statusFlags,
cannam@162 85 void *userData )
cannam@162 86 {
cannam@162 87 paTestData *data = (paTestData*)userData;
cannam@162 88 float *out = (float*)outputBuffer;
cannam@162 89 unsigned long i;
cannam@162 90
cannam@162 91 (void) timeInfo; /* Prevent unused variable warnings. */
cannam@162 92 (void) statusFlags;
cannam@162 93 (void) inputBuffer;
cannam@162 94
cannam@162 95 if( data->minFramesPerBuffer > framesPerBuffer )
cannam@162 96 {
cannam@162 97 data->minFramesPerBuffer = framesPerBuffer;
cannam@162 98 }
cannam@162 99 if( data->maxFramesPerBuffer < framesPerBuffer )
cannam@162 100 {
cannam@162 101 data->maxFramesPerBuffer = framesPerBuffer;
cannam@162 102 }
cannam@162 103
cannam@162 104 /* Measure min and max output time stamp delta. */
cannam@162 105 if( data->callbackCount > 0 )
cannam@162 106 {
cannam@162 107 PaTime delta = timeInfo->outputBufferDacTime - data->previousTimeInfo.outputBufferDacTime;
cannam@162 108 if( data->minDeltaDacTime > delta )
cannam@162 109 {
cannam@162 110 data->minDeltaDacTime = delta;
cannam@162 111 }
cannam@162 112 if( data->maxDeltaDacTime < delta )
cannam@162 113 {
cannam@162 114 data->maxDeltaDacTime = delta;
cannam@162 115 }
cannam@162 116 }
cannam@162 117 data->previousTimeInfo = *timeInfo;
cannam@162 118
cannam@162 119 for( i=0; i<framesPerBuffer; i++ )
cannam@162 120 {
cannam@162 121 *out++ = data->sine[data->left_phase]; /* left */
cannam@162 122 *out++ = data->sine[data->right_phase]; /* right */
cannam@162 123 data->left_phase += 1;
cannam@162 124 if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE;
cannam@162 125 data->right_phase += 3; /* higher pitch so we can distinguish left and right. */
cannam@162 126 if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE;
cannam@162 127 }
cannam@162 128
cannam@162 129 data->callbackCount += 1;
cannam@162 130 return paContinue;
cannam@162 131 }
cannam@162 132
cannam@162 133 PaError paqaCheckLatency( PaStreamParameters *outputParamsPtr,
cannam@162 134 paTestData *dataPtr, double sampleRate, unsigned long framesPerBuffer )
cannam@162 135 {
cannam@162 136 PaError err;
cannam@162 137 PaStream *stream;
cannam@162 138 const PaStreamInfo* streamInfo;
cannam@162 139
cannam@162 140 dataPtr->minFramesPerBuffer = 9999999;
cannam@162 141 dataPtr->maxFramesPerBuffer = 0;
cannam@162 142 dataPtr->minDeltaDacTime = 9999999.0;
cannam@162 143 dataPtr->maxDeltaDacTime = 0.0;
cannam@162 144 dataPtr->callbackCount = 0;
cannam@162 145
cannam@162 146 printf("Stream parameter: suggestedOutputLatency = %g\n", outputParamsPtr->suggestedLatency );
cannam@162 147 if( framesPerBuffer == paFramesPerBufferUnspecified ){
cannam@162 148 printf("Stream parameter: user framesPerBuffer = paFramesPerBufferUnspecified\n" );
cannam@162 149 }else{
cannam@162 150 printf("Stream parameter: user framesPerBuffer = %lu\n", framesPerBuffer );
cannam@162 151 }
cannam@162 152 err = Pa_OpenStream(
cannam@162 153 &stream,
cannam@162 154 NULL, /* no input */
cannam@162 155 outputParamsPtr,
cannam@162 156 sampleRate,
cannam@162 157 framesPerBuffer,
cannam@162 158 paClipOff, /* we won't output out of range samples so don't bother clipping them */
cannam@162 159 patestCallback,
cannam@162 160 dataPtr );
cannam@162 161 if( err != paNoError ) goto error1;
cannam@162 162
cannam@162 163 streamInfo = Pa_GetStreamInfo( stream );
cannam@162 164 printf("Stream info: inputLatency = %g\n", streamInfo->inputLatency );
cannam@162 165 printf("Stream info: outputLatency = %g\n", streamInfo->outputLatency );
cannam@162 166
cannam@162 167 err = Pa_StartStream( stream );
cannam@162 168 if( err != paNoError ) goto error2;
cannam@162 169
cannam@162 170 printf("Play for %d seconds.\n", NUM_SECONDS );
cannam@162 171 Pa_Sleep( NUM_SECONDS * 1000 );
cannam@162 172
cannam@162 173 printf(" minFramesPerBuffer = %4d\n", dataPtr->minFramesPerBuffer );
cannam@162 174 printf(" maxFramesPerBuffer = %4d\n", dataPtr->maxFramesPerBuffer );
cannam@162 175 printf(" minDeltaDacTime = %f\n", dataPtr->minDeltaDacTime );
cannam@162 176 printf(" maxDeltaDacTime = %f\n", dataPtr->maxDeltaDacTime );
cannam@162 177
cannam@162 178 err = Pa_StopStream( stream );
cannam@162 179 if( err != paNoError ) goto error2;
cannam@162 180
cannam@162 181 err = Pa_CloseStream( stream );
cannam@162 182 Pa_Sleep( 1 * 1000 );
cannam@162 183
cannam@162 184
cannam@162 185 printf("-------------------------------------\n");
cannam@162 186 return err;
cannam@162 187 error2:
cannam@162 188 Pa_CloseStream( stream );
cannam@162 189 error1:
cannam@162 190 printf("-------------------------------------\n");
cannam@162 191 return err;
cannam@162 192 }
cannam@162 193
cannam@162 194
cannam@162 195 /*******************************************************************/
cannam@162 196 static int paqaNoopCallback( const void *inputBuffer, void *outputBuffer,
cannam@162 197 unsigned long framesPerBuffer,
cannam@162 198 const PaStreamCallbackTimeInfo* timeInfo,
cannam@162 199 PaStreamCallbackFlags statusFlags,
cannam@162 200 void *userData )
cannam@162 201 {
cannam@162 202 (void)inputBuffer;
cannam@162 203 (void)outputBuffer;
cannam@162 204 (void)framesPerBuffer;
cannam@162 205 (void)timeInfo;
cannam@162 206 (void)statusFlags;
cannam@162 207 (void)userData;
cannam@162 208 return paContinue;
cannam@162 209 }
cannam@162 210
cannam@162 211 /*******************************************************************/
cannam@162 212 static int paqaCheckMultipleSuggested( PaDeviceIndex deviceIndex, int isInput )
cannam@162 213 {
cannam@162 214 int i;
cannam@162 215 int numLoops = 10;
cannam@162 216 PaError err;
cannam@162 217 PaStream *stream;
cannam@162 218 PaStreamParameters streamParameters;
cannam@162 219 const PaStreamInfo* streamInfo;
cannam@162 220 double lowLatency;
cannam@162 221 double highLatency;
cannam@162 222 double finalLatency;
cannam@162 223 double sampleRate = SAMPLE_RATE;
cannam@162 224 const PaDeviceInfo *pdi = Pa_GetDeviceInfo( deviceIndex );
cannam@162 225 double previousLatency = 0.0;
cannam@162 226 int numChannels = 1;
cannam@162 227 float toleranceRatio = 1.0;
cannam@162 228
cannam@162 229 printf("------------------------ paqaCheckMultipleSuggested - %s\n",
cannam@162 230 (isInput ? "INPUT" : "OUTPUT") );
cannam@162 231 if( isInput )
cannam@162 232 {
cannam@162 233 lowLatency = pdi->defaultLowInputLatency;
cannam@162 234 highLatency = pdi->defaultHighInputLatency;
cannam@162 235 numChannels = (pdi->maxInputChannels < 2) ? 1 : 2;
cannam@162 236 }
cannam@162 237 else
cannam@162 238 {
cannam@162 239 lowLatency = pdi->defaultLowOutputLatency;
cannam@162 240 highLatency = pdi->defaultHighOutputLatency;
cannam@162 241 numChannels = (pdi->maxOutputChannels < 2) ? 1 : 2;
cannam@162 242 }
cannam@162 243 streamParameters.channelCount = numChannels;
cannam@162 244 streamParameters.device = deviceIndex;
cannam@162 245 streamParameters.hostApiSpecificStreamInfo = NULL;
cannam@162 246 streamParameters.sampleFormat = paFloat32;
cannam@162 247 sampleRate = pdi->defaultSampleRate;
cannam@162 248
cannam@162 249 printf(" lowLatency = %g\n", lowLatency );
cannam@162 250 printf(" highLatency = %g\n", highLatency );
cannam@162 251 printf(" numChannels = %d\n", numChannels );
cannam@162 252 printf(" sampleRate = %g\n", sampleRate );
cannam@162 253
cannam@162 254 if( (highLatency - lowLatency) < 0.001 )
cannam@162 255 {
cannam@162 256 numLoops = 1;
cannam@162 257 }
cannam@162 258
cannam@162 259 for( i=0; i<numLoops; i++ )
cannam@162 260 {
cannam@162 261 if( numLoops == 1 )
cannam@162 262 streamParameters.suggestedLatency = lowLatency;
cannam@162 263 else
cannam@162 264 streamParameters.suggestedLatency = lowLatency + ((highLatency - lowLatency) * i /(numLoops - 1));
cannam@162 265
cannam@162 266 printf(" suggestedLatency[%d] = %6.4f\n", i, streamParameters.suggestedLatency );
cannam@162 267
cannam@162 268 err = Pa_OpenStream(
cannam@162 269 &stream,
cannam@162 270 (isInput ? &streamParameters : NULL),
cannam@162 271 (isInput ? NULL : &streamParameters),
cannam@162 272 sampleRate,
cannam@162 273 paFramesPerBufferUnspecified,
cannam@162 274 paClipOff, /* we won't output out of range samples so don't bother clipping them */
cannam@162 275 paqaNoopCallback,
cannam@162 276 NULL );
cannam@162 277 if( err != paNoError ) goto error;
cannam@162 278
cannam@162 279 streamInfo = Pa_GetStreamInfo( stream );
cannam@162 280
cannam@162 281 err = Pa_CloseStream( stream );
cannam@162 282
cannam@162 283 if( isInput )
cannam@162 284 {
cannam@162 285 finalLatency = streamInfo->inputLatency;
cannam@162 286 }
cannam@162 287 else
cannam@162 288 {
cannam@162 289 finalLatency = streamInfo->outputLatency;
cannam@162 290 }
cannam@162 291 printf(" finalLatency = %6.4f\n", finalLatency );
cannam@162 292 /* For the default low & high latency values, expect quite close; for other requested
cannam@162 293 * values, at worst the next power-of-2 may result (eg 513 -> 1024) */
cannam@162 294 toleranceRatio = ( (i == 0) || (i == ( numLoops - 1 )) ) ? 0.1 : 1.0;
cannam@162 295 QA_ASSERT_CLOSE( "final latency should be close to suggested latency",
cannam@162 296 streamParameters.suggestedLatency, finalLatency, (streamParameters.suggestedLatency * toleranceRatio) );
cannam@162 297 if( i == 0 )
cannam@162 298 {
cannam@162 299 previousLatency = finalLatency;
cannam@162 300 }
cannam@162 301 }
cannam@162 302
cannam@162 303 if( numLoops > 1 )
cannam@162 304 {
cannam@162 305 QA_ASSERT_TRUE( " final latency should increase with suggested latency", (finalLatency > previousLatency) );
cannam@162 306 }
cannam@162 307
cannam@162 308 return 0;
cannam@162 309 error:
cannam@162 310 return -1;
cannam@162 311 }
cannam@162 312
cannam@162 313 /*******************************************************************/
cannam@162 314 static int paqaVerifySuggestedLatency( void )
cannam@162 315 {
cannam@162 316 PaDeviceIndex id;
cannam@162 317 int result = 0;
cannam@162 318 const PaDeviceInfo *pdi;
cannam@162 319 int numDevices = Pa_GetDeviceCount();
cannam@162 320
cannam@162 321 printf("\n ------------------------ paqaVerifySuggestedLatency\n");
cannam@162 322 for( id=0; id<numDevices; id++ ) /* Iterate through all devices. */
cannam@162 323 {
cannam@162 324 pdi = Pa_GetDeviceInfo( id );
cannam@162 325 printf("\nUsing device #%d: '%s' (%s)\n", id, pdi->name, Pa_GetHostApiInfo(pdi->hostApi)->name);
cannam@162 326 if( pdi->maxOutputChannels > 0 )
cannam@162 327 {
cannam@162 328 if( paqaCheckMultipleSuggested( id, 0 ) < 0 )
cannam@162 329 {
cannam@162 330 printf("OUTPUT CHECK FAILED !!! #%d: '%s'\n", id, pdi->name);
cannam@162 331 result -= 1;
cannam@162 332 }
cannam@162 333 }
cannam@162 334 if( pdi->maxInputChannels > 0 )
cannam@162 335 {
cannam@162 336 if( paqaCheckMultipleSuggested( id, 1 ) < 0 )
cannam@162 337 {
cannam@162 338 printf("INPUT CHECK FAILED !!! #%d: '%s'\n", id, pdi->name);
cannam@162 339 result -= 1;
cannam@162 340 }
cannam@162 341 }
cannam@162 342 }
cannam@162 343 return result;
cannam@162 344 }
cannam@162 345
cannam@162 346 /*******************************************************************/
cannam@162 347 static int paqaVerifyDeviceInfoLatency( void )
cannam@162 348 {
cannam@162 349 PaDeviceIndex id;
cannam@162 350 const PaDeviceInfo *pdi;
cannam@162 351 int numDevices = Pa_GetDeviceCount();
cannam@162 352
cannam@162 353 printf("\n ------------------------ paqaVerifyDeviceInfoLatency\n");
cannam@162 354 for( id=0; id<numDevices; id++ ) /* Iterate through all devices. */
cannam@162 355 {
cannam@162 356 pdi = Pa_GetDeviceInfo( id );
cannam@162 357 printf("Using device #%d: '%s' (%s)\n", id, pdi->name, Pa_GetHostApiInfo(pdi->hostApi)->name);
cannam@162 358 if( pdi->maxOutputChannels > 0 )
cannam@162 359 {
cannam@162 360 printf(" Output defaultLowOutputLatency = %f seconds\n", pdi->defaultLowOutputLatency);
cannam@162 361 printf(" Output defaultHighOutputLatency = %f seconds\n", pdi->defaultHighOutputLatency);
cannam@162 362 QA_ASSERT_TRUE( "defaultLowOutputLatency should be > 0", (pdi->defaultLowOutputLatency > 0.0) );
cannam@162 363 QA_ASSERT_TRUE( "defaultHighOutputLatency should be > 0", (pdi->defaultHighOutputLatency > 0.0) );
cannam@162 364 QA_ASSERT_TRUE( "defaultHighOutputLatency should be >= Low", (pdi->defaultHighOutputLatency >= pdi->defaultLowOutputLatency) );
cannam@162 365 }
cannam@162 366 if( pdi->maxInputChannels > 0 )
cannam@162 367 {
cannam@162 368 printf(" Input defaultLowInputLatency = %f seconds\n", pdi->defaultLowInputLatency);
cannam@162 369 printf(" Input defaultHighInputLatency = %f seconds\n", pdi->defaultHighInputLatency);
cannam@162 370 QA_ASSERT_TRUE( "defaultLowInputLatency should be > 0", (pdi->defaultLowInputLatency > 0.0) );
cannam@162 371 QA_ASSERT_TRUE( "defaultHighInputLatency should be > 0", (pdi->defaultHighInputLatency > 0.0) );
cannam@162 372 QA_ASSERT_TRUE( "defaultHighInputLatency should be >= Low", (pdi->defaultHighInputLatency >= pdi->defaultLowInputLatency) );
cannam@162 373 }
cannam@162 374 }
cannam@162 375 return 0;
cannam@162 376 error:
cannam@162 377 return -1;
cannam@162 378 }
cannam@162 379
cannam@162 380
cannam@162 381
cannam@162 382 /*******************************************************************/
cannam@162 383 int main(void);
cannam@162 384 int main(void)
cannam@162 385 {
cannam@162 386 PaStreamParameters outputParameters;
cannam@162 387 PaError err;
cannam@162 388 paTestData data;
cannam@162 389 const PaDeviceInfo *deviceInfo;
cannam@162 390 int i;
cannam@162 391 int framesPerBuffer;
cannam@162 392 double sampleRate = SAMPLE_RATE;
cannam@162 393
cannam@162 394 printf("\nPortAudio QA: investigate output latency.\n");
cannam@162 395
cannam@162 396 /* initialise sinusoidal wavetable */
cannam@162 397 for( i=0; i<TABLE_SIZE; i++ )
cannam@162 398 {
cannam@162 399 data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );
cannam@162 400 }
cannam@162 401 data.left_phase = data.right_phase = 0;
cannam@162 402
cannam@162 403 err = Pa_Initialize();
cannam@162 404 if( err != paNoError ) goto error;
cannam@162 405
cannam@162 406 /* Run self tests. */
cannam@162 407 if( paqaVerifyDeviceInfoLatency() < 0 ) goto error;
cannam@162 408
cannam@162 409 if( paqaVerifySuggestedLatency() < 0 ) goto error;
cannam@162 410
cannam@162 411 outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
cannam@162 412 if (outputParameters.device == paNoDevice) {
cannam@162 413 fprintf(stderr,"Error: No default output device.\n");
cannam@162 414 goto error;
cannam@162 415 }
cannam@162 416
cannam@162 417 printf("\n\nNow running Audio Output Tests...\n");
cannam@162 418 printf("-------------------------------------\n");
cannam@162 419
cannam@162 420 outputParameters.channelCount = 2; /* stereo output */
cannam@162 421 outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
cannam@162 422 deviceInfo = Pa_GetDeviceInfo( outputParameters.device );
cannam@162 423 printf("Using device #%d: '%s' (%s)\n", outputParameters.device, deviceInfo->name, Pa_GetHostApiInfo(deviceInfo->hostApi)->name);
cannam@162 424 printf("Device info: defaultLowOutputLatency = %f seconds\n", deviceInfo->defaultLowOutputLatency);
cannam@162 425 printf("Device info: defaultHighOutputLatency = %f seconds\n", deviceInfo->defaultHighOutputLatency);
cannam@162 426 sampleRate = deviceInfo->defaultSampleRate;
cannam@162 427 printf("Sample Rate for following tests: %g\n", sampleRate);
cannam@162 428 outputParameters.hostApiSpecificStreamInfo = NULL;
cannam@162 429 printf("-------------------------------------\n");
cannam@162 430
cannam@162 431 // Try to use a small buffer that is smaller than we think the device can handle.
cannam@162 432 // Try to force combining multiple user buffers into a host buffer.
cannam@162 433 printf("------------- Try a very small buffer.\n");
cannam@162 434 framesPerBuffer = 9;
cannam@162 435 outputParameters.suggestedLatency = deviceInfo->defaultLowOutputLatency;
cannam@162 436 err = paqaCheckLatency( &outputParameters, &data, sampleRate, framesPerBuffer );
cannam@162 437 if( err != paNoError ) goto error;
cannam@162 438
cannam@162 439 printf("------------- 64 frame buffer with 1.1 * defaultLow latency.\n");
cannam@162 440 framesPerBuffer = 64;
cannam@162 441 outputParameters.suggestedLatency = deviceInfo->defaultLowOutputLatency * 1.1;
cannam@162 442 err = paqaCheckLatency( &outputParameters, &data, sampleRate, framesPerBuffer );
cannam@162 443 if( err != paNoError ) goto error;
cannam@162 444
cannam@162 445 // Try to create a huge buffer that is bigger than the allowed device maximum.
cannam@162 446 printf("------------- Try a huge buffer.\n");
cannam@162 447 framesPerBuffer = 16*1024;
cannam@162 448 outputParameters.suggestedLatency = ((double)framesPerBuffer) / sampleRate; // approximate
cannam@162 449 err = paqaCheckLatency( &outputParameters, &data, sampleRate, framesPerBuffer );
cannam@162 450 if( err != paNoError ) goto error;
cannam@162 451
cannam@162 452 printf("------------- Try suggestedLatency = 0.0\n");
cannam@162 453 outputParameters.suggestedLatency = 0.0;
cannam@162 454 err = paqaCheckLatency( &outputParameters, &data, sampleRate, paFramesPerBufferUnspecified );
cannam@162 455 if( err != paNoError ) goto error;
cannam@162 456
cannam@162 457 printf("------------- Try suggestedLatency = defaultLowOutputLatency\n");
cannam@162 458 outputParameters.suggestedLatency = deviceInfo->defaultLowOutputLatency;
cannam@162 459 err = paqaCheckLatency( &outputParameters, &data, sampleRate, paFramesPerBufferUnspecified );
cannam@162 460 if( err != paNoError ) goto error;
cannam@162 461
cannam@162 462 printf("------------- Try suggestedLatency = defaultHighOutputLatency\n");
cannam@162 463 outputParameters.suggestedLatency = deviceInfo->defaultHighOutputLatency;
cannam@162 464 err = paqaCheckLatency( &outputParameters, &data, sampleRate, paFramesPerBufferUnspecified );
cannam@162 465 if( err != paNoError ) goto error;
cannam@162 466
cannam@162 467 printf("------------- Try suggestedLatency = defaultHighOutputLatency * 4\n");
cannam@162 468 outputParameters.suggestedLatency = deviceInfo->defaultHighOutputLatency * 4;
cannam@162 469 err = paqaCheckLatency( &outputParameters, &data, sampleRate, paFramesPerBufferUnspecified );
cannam@162 470 if( err != paNoError ) goto error;
cannam@162 471
cannam@162 472 Pa_Terminate();
cannam@162 473 printf("SUCCESS - test finished.\n");
cannam@162 474 return err;
cannam@162 475
cannam@162 476 error:
cannam@162 477 Pa_Terminate();
cannam@162 478 fprintf( stderr, "ERROR - test failed.\n" );
cannam@162 479 fprintf( stderr, "Error number: %d\n", err );
cannam@162 480 fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
cannam@162 481 return err;
cannam@162 482 }