annotate src/portaudio_20140130/qa/paqa_latency.c @ 39:7ddb4fc30dac

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