add stdin/stdout and fractional resampling support
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 11 Oct 2016 02:08:29 +0000 (02:08 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 11 Oct 2016 02:08:29 +0000 (02:08 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2887 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/unittest/tsrc.c

index ebdca3d1fb5428303f3e4d6a96911ce7fc85ae97..90e695bfe7145790371cdd464ceb65e06c2de6de 100644 (file)
@@ -16,6 +16,7 @@
 #include <samplerate.h>
 
 #define N8   160                     /* processing buffer size at 8 kHz       */
+#define FS   8000                    /* nominal input sample rate             */
 #define N48  ((int)N8*(48000/8000))  /* buf size assuming 48k max sample rate */
 
 int main(int argc, char *argv[]) {
@@ -29,14 +30,20 @@ int main(int argc, char *argv[]) {
     int         error;
 
     if (argc != 4) {
-       printf("usage %s inputRawFile OutputRawFile OutputSamplerate\n", argv[0]);
+       printf("usage %s inputRawFile OutputRawFile OutSampleRatio\n", argv[0]);
        exit(0);
     }
 
-    f8k = fopen(argv[1], "rb");
+    if (strcmp(argv[1], "-") == 0) 
+        f8k = stdin;
+    else
+        f8k = fopen(argv[1], "rb");
     assert(f8k != NULL);
 
-    fout = fopen(argv[2], "wb");
+    if (strcmp(argv[2], "-") == 0) 
+        fout = stdout;
+    else
+        fout = fopen(argv[2], "wb");
     assert(fout != NULL);
 
     src = src_new(SRC_SINC_FASTEST, 1, &error);
@@ -47,17 +54,18 @@ int main(int argc, char *argv[]) {
     data.input_frames = N8;
     data.output_frames = N48;
     data.end_of_input = 0;
-    data.src_ratio = atof(argv[3])/8000;
-    printf("%f\n", data.src_ratio);
+    data.src_ratio = atof(argv[3]);
 
     while(fread(in8k_short, sizeof(short), N8, f8k) == N8) {
        src_short_to_float_array(in8k_short, in8k, N8);
        src_process(src, &data);
-       printf("%d %d\n", (int)data.output_frames , (int)data.output_frames_gen);
+       //fprintf(stderr, "%d %d\n", (int)data.output_frames , (int)data.output_frames_gen);
        assert(data.output_frames_gen <= N48);
        src_float_to_short_array(out, out_short, data.output_frames_gen);
        fwrite(out_short, sizeof(short), data.output_frames_gen, fout);
-    }
+        if (fout == stdout) fflush(stdout);
+        if (f8k == stdin) fflush(stdin);
+   }
 
     fclose(fout);
     fclose(f8k);