Skip to content

Commit

Permalink
qa-latency: use defaultSampleRate; fix crash on single loops; change …
Browse files Browse the repository at this point in the history
…latency check limits; continue after a failed test; some alterations to printed messages.

git-svn-id: https://subversion.assembla.com/svn/portaudio/portaudio/trunk@1839 0f58301d-fd10-0410-b4af-bbb618454e57
  • Loading branch information
gineera committed Jun 5, 2012
1 parent acf9922 commit 54d41e1
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions qa/paqa_latency.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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 )
{
Expand All @@ -255,7 +258,10 @@ static int paqaCheckMultipleSuggested( PaDeviceIndex deviceIndex, int isInput )

for( i=0; i<numLoops; i++ )
{
streamParameters.suggestedLatency = lowLatency + ((highLatency - lowLatency) * i /(numLoops - 1.0));
if( numLoops == 1 )
streamParameters.suggestedLatency = lowLatency;
else
streamParameters.suggestedLatency = lowLatency + ((highLatency - lowLatency) * i /(numLoops - 1));

printf(" suggestedLatency[%d] = %6.4f\n", i, streamParameters.suggestedLatency );

Expand Down Expand Up @@ -283,13 +289,20 @@ static int paqaCheckMultipleSuggested( PaDeviceIndex deviceIndex, int isInput )
finalLatency = streamInfo->outputLatency;
}
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;
Expand All @@ -307,14 +320,16 @@ static int paqaVerifySuggestedLatency( void )
for( id=0; id<numDevices; id++ ) /* Iterate through all devices. */
{
pdi = Pa_GetDeviceInfo( id );
printf("Using device #%d: '%s' (%s)\n", id, pdi->name, 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;
Expand All @@ -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) );
Expand Down Expand Up @@ -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; i<TABLE_SIZE; i++ )
{
Expand All @@ -393,14 +408,20 @@ int main(void)
goto error;
}

printf("\n\nNow running Audio Output Tests...\n");
printf("-------------------------------------\n");

outputParameters.channelCount = 2; /* stereo output */
outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
deviceInfo = Pa_GetDeviceInfo( outputParameters.device );
printf("Using device #%d: '%s' (%s)\n", outputParameters.device, deviceInfo->name, 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");
Expand Down

0 comments on commit 54d41e1

Please sign in to comment.