annotate src/portaudio_20161030/qa/paqa_latency.c @ 148:b4bfdf10c4b3

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