shithub: opus

Download patch

ref: 356c9c48b009d5b641dd9b49f5034c07fc901c81
parent: 2c8cfd06f66c1b4740e9da813b2dd3a4c62c4b9a
author: Jean-Marc Valin <[email protected]>
date: Thu Feb 3 20:09:54 EST 2011

Frame size optional, defaults to 20 ms

--- a/src/test_opus.c
+++ b/src/test_opus.c
@@ -46,12 +46,13 @@
 
 void print_usage( char* argv[] ) 
 {
-    fprintf(stderr, "Usage: %s <mode (0/1/2)> <sampling rate (Hz)> <channels> <frame size (samples)> "
+    fprintf(stderr, "Usage: %s <mode (0/1/2)> <sampling rate (Hz)> <channels> "
         "<bits per second>  [options] <input> <output>\n\n", argv[0]);
     fprintf(stderr, "mode: 0 for SILK, 1 for hybrid, 2 for CELT:\n" );
     fprintf(stderr, "options:\n" );
-    fprintf(stderr, "-cbr                 : enable constant bitrate (default is VBR)\n" );
-    fprintf(stderr, "-bandwidth <NB|MB|WB|SWB|FB>  : audio bandwidth (from narrowband to fullband)\n" );
+    fprintf(stderr, "-cbr                 : enable constant bitrate; default: VBR\n" );
+    fprintf(stderr, "-bandwidth <NB|MB|WB|SWB|FB>  : audio bandwidth (from narrowband to fullband); default: sampling rate\n" );
+    fprintf(stderr, "-framesize <2.5|5|10|20|40|60>  : frame size in ms; default: 20 \n" );
     fprintf(stderr, "-max_payload <bytes> : maximum payload size in bytes, default: 1024\n" );
     fprintf(stderr, "-complexity <comp>   : complexity, 0 (lowest) ... 10 (highest); default: 10\n" );
     fprintf(stderr, "-inbandfec           : enable SILK inband FEC\n" );
@@ -105,9 +106,10 @@
    mode = atoi(argv[1]) + MODE_SILK_ONLY;
    sampling_rate = atoi(argv[2]);
    channels = atoi(argv[3]);
-   frame_size = atoi(argv[4]);
-   bitrate_bps = atoi(argv[5]);
+   bitrate_bps = atoi(argv[4]);
 
+   frame_size = sampling_rate/50;
+
    /* defaults: */
    use_vbr = 1;
    bandwidth=-1;
@@ -136,7 +138,7 @@
 	   bandwidth = BANDWIDTH_FULLBAND;
 	   break;
    }
-   args = 6;
+   args = 5;
    while( args < argc - 2 ) {
        /* process command line options */
         if( STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-cbr" ) == 0 ) {
@@ -158,6 +160,24 @@
                 return 1;
             }
             args += 2;
+        } else if( STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-framesize" ) == 0 ) {
+            if (strcmp(argv[ args + 1 ], "2.5")==0)
+                frame_size = sampling_rate/400;
+            else if (strcmp(argv[ args + 1 ], "5")==0)
+                frame_size = sampling_rate/400;
+            else if (strcmp(argv[ args + 1 ], "10")==0)
+                frame_size = sampling_rate/100;
+            else if (strcmp(argv[ args + 1 ], "20")==0)
+                frame_size = sampling_rate/50;
+            else if (strcmp(argv[ args + 1 ], "40")==0)
+                frame_size = sampling_rate/25;
+            else if (strcmp(argv[ args + 1 ], "60")==0)
+                frame_size = 3*sampling_rate/50;
+            else {
+                fprintf(stderr, "Unsupported frame size: %s ms. Supported are 2.5, 5, 10, 20, 40, 60.\n", argv[ args + 1 ]);
+                return 1;
+            }
+            args += 2;
         } else if( STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-max_payload" ) == 0 ) {
             max_payload_bytes = atoi( argv[ args + 1 ] );
             args += 2;
@@ -282,7 +302,7 @@
 	   bandwidth_string = "unknown";
    }
 
-   printf("Encoding %d Hz input at %.3f kb/s in %s mode.\n", sampling_rate, bitrate_bps*0.001, bandwidth_string);
+   printf("Encoding %d Hz input at %.3f kb/s in %s mode with %d-sample frames.\n", sampling_rate, bitrate_bps*0.001, bandwidth_string, frame_size);
 
    in = (short*)malloc(frame_size*channels*sizeof(short));
    out = (short*)malloc(frame_size*channels*sizeof(short));