annotate src/portaudio_20140130/qa/paqa_latency.c @ 124:e3d5853d5918

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