From 6d881ec6dc5466a918d5f30ecf5031cd1ccad7f1 Mon Sep 17 00:00:00 2001 From: gineera Date: Tue, 5 Jun 2012 16:36:54 +0000 Subject: [PATCH] qa-latency: use defaultSampleRate; fix crash on single loops; change latency check limits; continue after a failed test; some alterations to printed messages. --- qa/paqa_latency.c | 55 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/qa/paqa_latency.c b/qa/paqa_latency.c index e7db42e..2e75440 100644 --- a/qa/paqa_latency.c +++ b/qa/paqa_latency.c @@ -220,11 +220,12 @@ static int paqaCheckMultipleSuggested( PaDeviceIndex deviceIndex, int isInput ) double lowLatency; double highLatency; double finalLatency; - double sampleRate = 44100.0; + double sampleRate = SAMPLE_RATE; const PaDeviceInfo *pdi = Pa_GetDeviceInfo( deviceIndex ); double previousLatency = 0.0; int numChannels = 1; - + float toleranceRatio = 1.0; + printf("------------------------ paqaCheckMultipleSuggested - %s\n", (isInput ? "INPUT" : "OUTPUT") ); if( isInput ) @@ -243,10 +244,12 @@ static int paqaCheckMultipleSuggested( PaDeviceIndex deviceIndex, int isInput ) streamParameters.device = deviceIndex; streamParameters.hostApiSpecificStreamInfo = NULL; streamParameters.sampleFormat = paFloat32; + sampleRate = pdi->defaultSampleRate; printf(" lowLatency = %g\n", lowLatency ); printf(" highLatency = %g\n", highLatency ); printf(" numChannels = %d\n", numChannels ); + printf(" sampleRate = %g\n", sampleRate ); if( (highLatency - lowLatency) < 0.001 ) { @@ -255,7 +258,10 @@ static int paqaCheckMultipleSuggested( PaDeviceIndex deviceIndex, int isInput ) for( i=0; ioutputLatency; } printf(" finalLatency = %6.4f\n", finalLatency ); - QA_ASSERT_CLOSE( "final latency should be close to suggested latency", - streamParameters.suggestedLatency, finalLatency, (streamParameters.suggestedLatency * 0.3) ); - - QA_ASSERT_TRUE( " final latency should increase with suggested latency", (finalLatency > previousLatency) ); - previousLatency = finalLatency; + /* For the default low & high latency values, expect quite close; for other requested + * values, at worst the next power-of-2 may result (eg 513 -> 1024) */ + if( i == 0 | i == ( numLoops - 1 )) + toleranceRatio = 0.1; + else + toleranceRatio = 1.0; + QA_ASSERT_CLOSE( "final latency should be close to suggested latency", + streamParameters.suggestedLatency, finalLatency, (streamParameters.suggestedLatency * toleranceRatio) ); + if( i == 0 ) + previousLatency = finalLatency; } - + if( numLoops > 1 ) + QA_ASSERT_TRUE( " final latency should increase with suggested latency", (finalLatency > previousLatency) ); + return 0; error: return -1; @@ -307,14 +320,16 @@ static int paqaVerifySuggestedLatency( void ) for( id=0; idname, Pa_GetHostApiInfo(pdi->hostApi)->name); + printf("\nUsing device #%d: '%s' (%s)\n", id, pdi->name, Pa_GetHostApiInfo(pdi->hostApi)->name); if( pdi->maxOutputChannels > 0 ) { - if( (result = paqaCheckMultipleSuggested( id, 0 )) != 0 ) goto error; + if( (result = paqaCheckMultipleSuggested( id, 0 )) != 0 ) + printf("OUTPUT CHECK FAILED !!! #%d: '%s'\n", id, pdi->name); } if( pdi->maxInputChannels > 0 ) { - if( (result = paqaCheckMultipleSuggested( id, 1 )) != 0 ) goto error; + if( (result = paqaCheckMultipleSuggested( id, 1 )) != 0 ) + printf("INPUT CHECK FAILED !!! #%d: '%s'\n", id, pdi->name); } } return 0; @@ -337,7 +352,7 @@ static int paqaVerifyDeviceInfoLatency( void ) if( pdi->maxOutputChannels > 0 ) { printf(" Output defaultLowOutputLatency = %f seconds\n", pdi->defaultLowOutputLatency); - printf(" Output info: defaultHighOutputLatency = %f seconds\n", pdi->defaultHighOutputLatency); + printf(" Output defaultHighOutputLatency = %f seconds\n", pdi->defaultHighOutputLatency); QA_ASSERT_TRUE( "defaultLowOutputLatency should be > 0", (pdi->defaultLowOutputLatency > 0.0) ); QA_ASSERT_TRUE( "defaultHighOutputLatency should be > 0", (pdi->defaultHighOutputLatency > 0.0) ); //QA_ASSERT_TRUE( "defaultHighOutputLatency should be > Low", (pdi->defaultHighOutputLatency > pdi->defaultLowOutputLatency) ); @@ -368,10 +383,10 @@ int main(void) const PaDeviceInfo *deviceInfo; int i; int framesPerBuffer; - double sampleRate = 44100; - - printf("PortAudio QA: investigate output latency. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER); + double sampleRate = SAMPLE_RATE; + printf("\nPortAudio QA: investigate output latency.\n"); + /* initialise sinusoidal wavetable */ for( i=0; iname, Pa_GetHostApiInfo(deviceInfo->hostApi)->name); printf("Device info: defaultLowOutputLatency = %f seconds\n", deviceInfo->defaultLowOutputLatency); printf("Device info: defaultHighOutputLatency = %f seconds\n", deviceInfo->defaultHighOutputLatency); + sampleRate = deviceInfo->defaultSampleRate; + printf("Sample Rate for following tests: %g\n", sampleRate); outputParameters.hostApiSpecificStreamInfo = NULL; - + printf("-------------------------------------\n"); + // Try to use a small buffer that is smaller than we think the device can handle. // Try to force combining multiple user buffers into a host buffer. printf("------------- Try a very small buffer.\n"); -- 2.43.0