]> Repos - portaudio/commitdiff
patest_out_underflow: cleanup
authorphilburk <philburk@0f58301d-fd10-0410-b4af-bbb618454e57>
Sun, 10 Apr 2016 18:12:03 +0000 (18:12 +0000)
committerphilburk <philburk@0f58301d-fd10-0410-b4af-bbb618454e57>
Sun, 10 Apr 2016 18:12:03 +0000 (18:12 +0000)
Replace some tabs.
Print overflow under stress.
Prevent accidental overrange of phases array.

test/patest_out_underflow.c

index e69def3a370fe104f032d33c180d1230210cf99a..dee90f8fdc27d06c064c84029aea08658239f991 100644 (file)
@@ -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: