shithub: opus-tools

Download patch

ref: d1a0b0d116f2fd4d528b59754b31c49252960e9f
parent: 11fe5419b018ef54ee505fc5cb6ccbcbf86464c8
author: Gregory Maxwell <greg@xiph.org>
date: Thu Sep 27 04:34:35 EDT 2012

Opusdec don't add wav header on non-.wav output. Offer --force-wav.

--- a/man/opusdec.1
+++ b/man/opusdec.1
@@ -17,6 +17,8 @@
 ] [
 .B --no-dither
 ] [
+.B --force-wav
+] [
 .B --packet-loss pct
 ] [
 .B --save-range file
@@ -59,6 +61,8 @@
 Adjust the output volume n dB, negative values make the signal quieter.
 .IP "--no-dither"
 Do not dither 16-bit output
+.IP "--force-wav"
+Force including a wav header on output (e.g. for non-wav extensions and stdout)
 .IP "--packet-loss"
 Simulate n % random Opus packet loss
 .IP "--save-range"
@@ -85,7 +89,7 @@
 
 Re-encode a high bitrate Opus file to a lower rate
 .RS
-opusdec input.opus - | opusenc --bitrate 64 - output.opus
+opusdec --force-wav input.opus - | opusenc --bitrate 64 - output.opus
 .RE
 
 Play an http stream
--- a/src/opusdec.c
+++ b/src/opusdec.c
@@ -430,14 +430,14 @@
             perror(outFile);
             quit(1);
          }
-         if (*wav_format)
+      }
+      if (*wav_format)
+      {
+         *wav_format = write_wav_header(fout, rate, mapping_family, *channels);
+         if (*wav_format < 0)
          {
-            *wav_format = write_wav_header(fout, rate, mapping_family, *channels);
-            if (*wav_format < 0)
-            {
-               fprintf (stderr, "Error writing WAV header.\n");
-               quit(1);
-            }
+            fprintf (stderr, "Error writing WAV header.\n");
+            quit(1);
          }
       }
    }
@@ -457,7 +457,7 @@
    printf ("output_file can be:\n");
    printf ("  filename.wav         Wav file\n");
    printf ("  filename.*           Raw PCM file (any extension other than .wav)\n");
-   printf ("  -                    stdout\n");
+   printf ("  -                    stdout (raw; unless --force-wav)\n");
    printf ("  (nothing)            Will be played to soundcard\n");
    printf ("\n");
    printf ("Options:\n");
@@ -464,6 +464,7 @@
    printf (" --rate n              Force decoding at sampling rate n Hz\n");
    printf (" --gain n              Manually adjust gain by n.nn dB (0 default)\n");
    printf (" --no-dither           Do not dither 16-bit output\n");
+   printf (" --force-wav           Force wav header on output\n");
    printf (" --packet-loss n       Simulate n %% random packet loss\n");
    printf (" --save-range file     Saves check values for every frame to a file\n");
    printf (" -h, --help            This help\n");
@@ -642,6 +643,7 @@
    int total_links=0;
    int stream_init = 0;
    int quiet = 0;
+   int forcewav = 0;
    ogg_int64_t page_granule=0;
    ogg_int64_t link_out=0;
    struct option long_options[] =
@@ -653,6 +655,7 @@
       {"rate", required_argument, NULL, 0},
       {"gain", required_argument, NULL, 0},
       {"no-dither", no_argument, NULL, 0},
+      {"force-wav", no_argument, NULL, 0},
       {"packet-loss", required_argument, NULL, 0},
       {"save-range", required_argument, NULL, 0},
       {0, 0, 0, 0}
@@ -734,6 +737,9 @@
          } else if (strcmp(long_options[option_index].name,"no-dither")==0)
          {
             dither=0;
+         } else if (strcmp(long_options[option_index].name,"force-wav")==0)
+         {
+            forcewav=1;
          } else if (strcmp(long_options[option_index].name,"rate")==0)
          {
             rate=atoi (optarg);
@@ -786,6 +792,7 @@
      while(wav_format&&ext&&outFile[i]) {
        wav_format&=tolower(outFile[i++])==*ext++;
      }
+     wav_format|=forcewav;
    }else {
      outFile="";
      wav_format=0;
@@ -1035,7 +1042,7 @@
    }
 
    /*If we were writing wav, go set the duration.*/
-   if (strlen(outFile)!=0 && fout && wav_format>=0 && audio_size<0x7FFFFFFF)
+   if (strlen(outFile)!=0 && fout && wav_format>0 && audio_size<0x7FFFFFFF)
    {
       if (fseek(fout,4,SEEK_SET)==0)
       {
@@ -1051,7 +1058,7 @@
             fprintf (stderr, "First seek worked, second didn't\n");
          }
       } else {
-         fprintf (stderr, "Cannot seek on wave file, size will be incorrect\n");
+         fprintf (stderr, "Cannot seek on wav file output, wav size chunk will be incorrect\n");
       }
    }