patest_out_underflow: cleanup
Replace some tabs. Print overflow under stress. Prevent accidental overrange of phases array.
This commit is contained in:
parent
3d4139cb00
commit
13b2159821
1 changed files with 33 additions and 24 deletions
|
|
@ -85,8 +85,9 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
|
|||
|
||||
|
||||
if( data->countUnderflows && (statusFlags & paOutputUnderflow) )
|
||||
{
|
||||
data->outputUnderflowCount++;
|
||||
|
||||
}
|
||||
for( i=0; i<framesPerBuffer; i++ )
|
||||
{
|
||||
float output = 0.0;
|
||||
|
|
@ -121,9 +122,11 @@ int main(void)
|
|||
PaStream *stream;
|
||||
PaError err;
|
||||
int safeSineCount, stressedSineCount;
|
||||
int sineCount;
|
||||
int safeUnderflowCount, stressedUnderflowCount;
|
||||
paTestData data = {0};
|
||||
double load;
|
||||
double suggestedLatency;
|
||||
|
||||
|
||||
printf("PortAudio Test: output sine waves, count underflows. SR = %d, BufSize = %d. MAX_LOAD = %f\n",
|
||||
|
|
@ -139,7 +142,8 @@ int main(void)
|
|||
}
|
||||
outputParameters.channelCount = 1; /* mono output */
|
||||
outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
|
||||
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
|
||||
suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
|
||||
outputParameters.suggestedLatency = suggestedLatency;
|
||||
outputParameters.hostApiSpecificStreamInfo = NULL;
|
||||
|
||||
err = Pa_OpenStream(
|
||||
|
|
@ -160,24 +164,23 @@ int main(void)
|
|||
/* Determine number of sines required to get to 50% */
|
||||
do
|
||||
{
|
||||
Pa_Sleep( 100 );
|
||||
Pa_Sleep( 100 );
|
||||
|
||||
load = Pa_GetStreamCpuLoad( stream );
|
||||
printf("sineCount = %d, CPU load = %f\n", data.sineCount, load );
|
||||
|
||||
if( load < 0.3 )
|
||||
{
|
||||
data.sineCount += 10;
|
||||
}
|
||||
else if( load < 0.4 )
|
||||
{
|
||||
data.sineCount += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
data.sineCount += 1;
|
||||
}
|
||||
|
||||
if( load < 0.3 )
|
||||
{
|
||||
data.sineCount += 10;
|
||||
}
|
||||
else if( load < 0.4 )
|
||||
{
|
||||
data.sineCount += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
data.sineCount += 1;
|
||||
}
|
||||
}
|
||||
while( load < 0.5 && data.sineCount < (MAX_SINES-1));
|
||||
|
||||
|
|
@ -187,16 +190,18 @@ int main(void)
|
|||
stressedSineCount = (int) (2.0 * data.sineCount * MAX_LOAD );
|
||||
if( stressedSineCount > MAX_SINES )
|
||||
stressedSineCount = MAX_SINES;
|
||||
for( ; data.sineCount < stressedSineCount; data.sineCount+=4 )
|
||||
sineCount = data.sineCount;
|
||||
for( ; sineCount < stressedSineCount; sineCount+=4 )
|
||||
{
|
||||
data.sineCount = sineCount;
|
||||
Pa_Sleep( 100 );
|
||||
load = Pa_GetStreamCpuLoad( stream );
|
||||
printf("STRESSING: sineCount = %d, CPU load = %f\n", data.sineCount, load );
|
||||
printf("STRESSING: sineCount = %d, CPU load = %f\n", sineCount, load );
|
||||
}
|
||||
|
||||
printf("Counting underflows for 5 seconds.\n");
|
||||
printf("Counting underflows for 2 seconds.\n");
|
||||
data.countUnderflows = 1;
|
||||
Pa_Sleep( 5000 );
|
||||
Pa_Sleep( 2000 );
|
||||
|
||||
stressedUnderflowCount = data.outputUnderflowCount;
|
||||
|
||||
|
|
@ -225,12 +230,16 @@ int main(void)
|
|||
|
||||
Pa_Terminate();
|
||||
|
||||
printf("suggestedLatency = %f\n", suggestedLatency);
|
||||
|
||||
// Report pass or fail
|
||||
if( stressedUnderflowCount == 0 )
|
||||
printf("Test failed, no output underflows detected under stress.\n");
|
||||
else if( safeUnderflowCount != 0 )
|
||||
printf("Test failed, %d unexpected underflows detected under safe load.\n", safeUnderflowCount);
|
||||
printf("Test FAILED, no output underflows detected under stress.\n");
|
||||
else
|
||||
printf("Test passed, %d expected output underflows detected under stress, 0 unexpected underflows detected under safe load.\n", stressedUnderflowCount );
|
||||
printf("Test %s, %d expected output underflows detected under stress, "
|
||||
"%d unexpected underflows detected under safe load.\n",
|
||||
(safeUnderflowCount == 0) ? "PASSED" : "FAILED",
|
||||
stressedUnderflowCount, safeUnderflowCount );
|
||||
|
||||
return err;
|
||||
error:
|
||||
|
|
|
|||
Loading…
Reference in a new issue