]> Repos - portaudio/commitdiff
fixed some warnings and minor bugs in patest_suggested_vs_streaminfo_latency.c
authorrossb <rossb@0f58301d-fd10-0410-b4af-bbb618454e57>
Thu, 25 Aug 2011 14:40:00 +0000 (14:40 +0000)
committerrossb <rossb@0f58301d-fd10-0410-b4af-bbb618454e57>
Thu, 25 Aug 2011 14:40:00 +0000 (14:40 +0000)
test/patest_suggested_vs_streaminfo_latency.c

index fff14814e47e03b38894cfff1bf8b4810f6da52d..12996cc192dd8c35c5331ab651767f5f5a3fd5fa 100644 (file)
  */\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
+#include <string.h>\r
 #include <math.h>\r
 #include "portaudio.h"\r
 \r
 #define SAMPLE_RATE             (44100)\r
-#define FRAMES_PER_BUFFER       (128)\r
+#define FRAMES_PER_BUFFER       2//(128)\r
 #define NUM_CHANNELS            (2)\r
 \r
 #define SUGGESTED_LATENCY_START_SECONDS     (0.0)\r
@@ -67,6 +68,7 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
                             PaStreamCallbackFlags statusFlags,\r
                             void *userData )\r
 {\r
+    return paContinue;\r
 }\r
 \r
 /*******************************************************************/\r
@@ -97,12 +99,12 @@ static void usage()
 int main( int argc, const char* argv[] );\r
 int main( int argc, const char* argv[] )\r
 {\r
-    PaStreamParameters outputParameters, inputParameters;\r
+    PaStreamParameters inputParameters, outputParameters;\r
     PaStream *stream;\r
     PaError err;\r
     PaTime suggestedLatency;\r
-    PaStreamInfo *streamInfo;\r
-    PaDeviceInfo *deviceInfo;\r
+    const PaStreamInfo *streamInfo;\r
+    const PaDeviceInfo *deviceInfo;\r
     float sampleRate = SAMPLE_RATE;\r
     int framesPerBuffer = FRAMES_PER_BUFFER;\r
     err = Pa_Initialize();\r
@@ -121,37 +123,8 @@ int main( int argc, const char* argv[] )
 \r
     printf("# sample rate=%f, frames per buffer=%d\n", (float)sampleRate, framesPerBuffer );\r
 \r
-    outputParameters.device = -1;\r
-    if( argc > 1 )\r
-        outputParameters.device = atoi(argv[1]);\r
-    if( outputParameters.device == -1 ){\r
-        outputParameters.device = Pa_GetDefaultOutputDevice();\r
-        if (outputParameters.device == paNoDevice) {\r
-          fprintf(stderr,"Error: No default output device available.\n");\r
-          goto error;\r
-        }\r
-    }else{\r
-        deviceInfo = Pa_GetDeviceInfo(outputParameters.device);\r
-        if( !deviceInfo ){\r
-            fprintf(stderr,"Error: Invalid output device index.\n");\r
-            usage();\r
-        }\r
-        if( deviceInfo->maxOutputChannels == 0 ){\r
-            fprintf(stderr,"Error: Specified output device has no output channels (an input only device?).\n");\r
-            usage();\r
-        }\r
-    }\r
-    \r
-    outputParameters.channelCount = NUM_CHANNELS;\r
-    outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */\r
-    outputParameters.hostApiSpecificStreamInfo = NULL;\r
-\r
-    deviceInfo = Pa_GetDeviceInfo(outputParameters.device);\r
-    printf( "# using output device id %d (%s, %s)\n", outputParameters.device, deviceInfo->name, Pa_GetHostApiInfo(deviceInfo->hostApi)->name );\r
-\r
-\r
     inputParameters.device = -1;\r
-    if( argc > 2 )\r
+    if( argc > 1 )\r
         inputParameters.device = atoi(argv[1]);\r
     if( inputParameters.device == -1 ){\r
         inputParameters.device = Pa_GetDefaultInputDevice();\r
@@ -170,7 +143,6 @@ int main( int argc, const char* argv[] )
             usage();\r
         }\r
     }\r
-\r
     \r
     inputParameters.channelCount = NUM_CHANNELS;\r
     inputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */\r
@@ -180,7 +152,36 @@ int main( int argc, const char* argv[] )
     printf( "# using input device id %d (%s, %s)\n", inputParameters.device, deviceInfo->name, Pa_GetHostApiInfo(deviceInfo->hostApi)->name );\r
 \r
 \r
-    printf( "# suggested latency, half duplex PaStreamInfo::outputLatency, half duplex PaStreamInfo::inputLatency, half duplex PaStreamInfo::outputLatency, half duplex PaStreamInfo::inputLatency\n" );\r
+    outputParameters.device = -1;\r
+    if( argc > 2 )\r
+        outputParameters.device = atoi(argv[2]);\r
+    if( outputParameters.device == -1 ){\r
+        outputParameters.device = Pa_GetDefaultOutputDevice();\r
+        if (outputParameters.device == paNoDevice) {\r
+          fprintf(stderr,"Error: No default output device available.\n");\r
+          goto error;\r
+        }\r
+    }else{\r
+        deviceInfo = Pa_GetDeviceInfo(outputParameters.device);\r
+        if( !deviceInfo ){\r
+            fprintf(stderr,"Error: Invalid output device index.\n");\r
+            usage();\r
+        }\r
+        if( deviceInfo->maxOutputChannels == 0 ){\r
+            fprintf(stderr,"Error: Specified output device has no output channels (an input only device?).\n");\r
+            usage();\r
+        }\r
+    }\r
+\r
+    outputParameters.channelCount = NUM_CHANNELS;\r
+    outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */\r
+    outputParameters.hostApiSpecificStreamInfo = NULL;\r
+\r
+    deviceInfo = Pa_GetDeviceInfo(outputParameters.device);\r
+    printf( "# using output device id %d (%s, %s)\n", outputParameters.device, deviceInfo->name, Pa_GetHostApiInfo(deviceInfo->hostApi)->name );\r
+\r
+\r
+    printf( "# suggested latency, half duplex PaStreamInfo::outputLatency, half duplex PaStreamInfo::inputLatency, full duplex PaStreamInfo::outputLatency, full duplex PaStreamInfo::inputLatency\n" );\r
     suggestedLatency = SUGGESTED_LATENCY_START_SECONDS;\r
     while( suggestedLatency <= SUGGESTED_LATENCY_END_SECONDS ){\r
 \r