Allow specifying frames per call to resample()

Bug: 13073201
Change-Id: Id2f0fcd7562d9ba5a58c128d71bbba42dfea86cc
diff --git a/services/audioflinger/test-resample.cpp b/services/audioflinger/test-resample.cpp
index 66fcd90..74d5702 100644
--- a/services/audioflinger/test-resample.cpp
+++ b/services/audioflinger/test-resample.cpp
@@ -34,7 +34,7 @@
 
 static int usage(const char* name) {
     fprintf(stderr,"Usage: %s [-p] [-h] [-v] [-s] [-q {dq|lq|mq|hq|vhq|dlq|dmq|dhq}]"
-                   " [-i input-sample-rate] [-o output-sample-rate] [<input-file>]"
+                   " [-i input-sample-rate] [-o output-sample-rate] [-O #] [<input-file>]"
                    " <output-file>\n", name);
     fprintf(stderr,"    -p    enable profiling\n");
     fprintf(stderr,"    -h    create wav file\n");
@@ -51,6 +51,7 @@
     fprintf(stderr,"              dhq : dynamic high quality\n");
     fprintf(stderr,"    -i    input file sample rate (ignored if input file is specified)\n");
     fprintf(stderr,"    -o    output file sample rate\n");
+    fprintf(stderr,"    -O    # frames output per call to resample()\n");
     return -1;
 }
 
@@ -64,9 +65,10 @@
     int input_freq = 0;
     int output_freq = 0;
     AudioResampler::src_quality quality = AudioResampler::DEFAULT_QUALITY;
+    size_t framesPerCall = 0;
 
     int ch;
-    while ((ch = getopt(argc, argv, "pfhvsq:i:o:")) != -1) {
+    while ((ch = getopt(argc, argv, "pfhvsq:i:o:O:")) != -1) {
         switch (ch) {
         case 'p':
             profileResample = true;
@@ -111,6 +113,9 @@
         case 'o':
             output_freq = atoi(optarg);
             break;
+        case 'O':
+            framesPerCall = atoi(optarg);
+            break;
         case '?':
         default:
             usage(progname);
@@ -343,7 +348,14 @@
     if (gVerbose) {
         printf("resample() %u output frames\n", out_frames);
     }
-    resampler->resample((int*) output_vaddr, out_frames, &provider);
+    if (framesPerCall == 0 || framesPerCall > out_frames) {
+        framesPerCall = out_frames;
+    }
+    for (size_t i = 0; i < out_frames; ) {
+        size_t thisFrames = framesPerCall <= out_frames - i ? framesPerCall : out_frames - i;
+        resampler->resample((int*) output_vaddr + 2*i, thisFrames, &provider);
+        i += thisFrames;
+    }
     if (gVerbose) {
         printf("resample() complete\n");
     }