]> Repos - portaudio/commitdiff
qa-latency: use defaultSampleRate; fix crash on single loops; change latency check...
authorgineera <gineera@0f58301d-fd10-0410-b4af-bbb618454e57>
Tue, 5 Jun 2012 16:36:54 +0000 (16:36 +0000)
committergineera <gineera@0f58301d-fd10-0410-b4af-bbb618454e57>
Tue, 5 Jun 2012 16:36:54 +0000 (16:36 +0000)
qa/paqa_latency.c

index e7db42edd4cfc2699c6ccf5b0348bfc2589b1186..2e7544016848f0fb9ccd1459d3f5626cc6b76dc5 100644 (file)
@@ -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; 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 );
     
@@ -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;
@@ -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;
@@ -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; i<TABLE_SIZE; i++ )
     {
@@ -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");