shithub: opus-tools

Download patch

ref: 8c9ee43e3e24c4006884846312c72fa125cebac4
parent: 7b1ce31a95068ca8c2458dc3201e889fec71a4ac
author: Gregory Maxwell <greg@xiph.org>
date: Mon Jun 11 13:55:24 EDT 2012

Add an --ignorelength option to opusenc.

--- a/man/opusenc.1
+++ b/man/opusenc.1
@@ -72,6 +72,8 @@
 ] [
 .B --raw-endianness
 .I flag
+] [
+.B --ignorelength
 ]
 .I input.wav
 .I output.opus
@@ -152,6 +154,10 @@
 Set number of channels for raw input (default: 2)
 .IP "--raw-endianness [0/1]"
 Set the endianness for raw input: 1 for bigendian, 0 for little (defaults to 0)
+.IP "--ignorelength"
+Always ignore the datalength in Wave headers. Opusenc automatically ignores
+the length when its implausible (very small or very large) but some STDIN
+usage may still need this option to avoid truncation.
 
 .SH EXAMPLES
 
--- a/src/audio-in.c
+++ b/src/audio-in.c
@@ -584,7 +584,7 @@
                                             of trying to abstract stuff. */
         wav->samplesize = format.samplesize;
 
-        if(len>(format.channels*samplesize*4U) && len<((1U<<31)-65536)) /*Length provided is plausible.*/
+        if(len>(format.channels*samplesize*4U) && len<((1U<<31)-65536) && opt->ignorelength!=1) /*Length provided is plausible.*/
         {
             opt->total_samples_per_channel = len/(format.channels*samplesize);
         }
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -151,6 +151,7 @@
   printf(" --raw-rate n       Set sampling rate for raw input (default: 48000)\n");
   printf(" --raw-chan n       Set number of channels for raw input (default: 2)\n");
   printf(" --raw-endianness n 1 for bigendian, 0 for little (defaults to 0)\n");
+  printf(" --ignorelength     Always ignore the datalength in Wave headers\n");
 }
 
 static inline void print_time(double seconds)
@@ -194,6 +195,7 @@
     {"raw-rate", required_argument, NULL, 0},
     {"raw-chan", required_argument, NULL, 0},
     {"raw-endianness", required_argument, NULL, 0},
+    {"ignorelength", no_argument, NULL, 0},
     {"rate", required_argument, NULL, 0},
     {"music", no_argument, NULL, 0},
     {"speech", no_argument, NULL, 0},
@@ -276,6 +278,7 @@
   inopt.samplesize=16;
   inopt.endianness=0;
   inopt.rawmode=0;
+  inopt.ignorelength=0;
 
   for(i=0;i<256;i++)mapping[i]=i;
 
@@ -318,6 +321,8 @@
         }else if(strcmp(long_options[option_index].name,"version-short")==0){
           opustoolsversion_short(opus_version);
           exit(0);
+        }else if(strcmp(long_options[option_index].name,"ignorelength")==0){
+          inopt.ignorelength=1;
         }else if(strcmp(long_options[option_index].name,"raw")==0){
           inopt.rawmode=1;
         }else if(strcmp(long_options[option_index].name,"raw-bits")==0){