shithub: opus-tools

Download patch

ref: a2be3388fb5905efa4652adf859ea3b7e1ceaea6
parent: ec08f7bd88bf6598ad8b666b7c4d2c1162487838
author: Chris Hold <Christoph.Hold@aalto.fi>
date: Mon Jul 24 16:40:01 EDT 2023

opusenc: Implement --channels discrete switch

Resolves https://github.com/xiph/opus-tools/pull/80
Signed-off-by: Mark Harris <mark.hsj@gmail.com>

--- a/man/opusenc.1
+++ b/man/opusenc.1
@@ -312,12 +312,13 @@
 The length will always be ignored when it is implausible (very small or very
 large), but some stdin usage may still need this option to avoid truncation.
 .TP
-.B --channels <ambix>
+.B --channels <ambix, discrete>
 Override the format of the input channels.
 The "ambix" option indicates that the input is ambisonics using ACN channel
 ordering with SN3D normalization. All channels in a full ambisonics order must
 be included. A pair of non-diegetic stereo channels can be optionally placed
-after the ambisonics channels.
+after the ambisonics channels. The option "discrete" forces uncoupled
+channels.
 .SS "Diagnostic options"
 .TP
 .BI --serial " N"
--- a/src/encoder.h
+++ b/src/encoder.h
@@ -18,6 +18,7 @@
 
 #define CHANNELS_FORMAT_DEFAULT  0
 #define CHANNELS_FORMAT_AMBIX    1
+#define CHANNELS_FORMAT_DISCRETE 2
 
 typedef long (*audio_read_func)(void *src, float *buffer, int samples);
 
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -176,7 +176,7 @@
   printf(" --raw-chan n       Set number of channels for raw input (default: 2)\n");
   printf(" --raw-endianness n 1 for big endian, 0 for little (default: 0)\n");
   printf(" --ignorelength     Ignore the data length in Wave headers\n");
-  printf(" --channels <ambix> Override the format of the input channels\n");
+  printf(" --channels         Override the format of the input channels (ambix, discrete)\n");
   printf("\nDiagnostic options:\n");
   printf(" --serial n         Force use of a specific stream serial number\n");
   printf(" --save-range file  Save check values for every frame to a file\n");
@@ -637,9 +637,11 @@
         } else if (strcmp(optname, "channels")==0) {
           if (strcmp(optarg, "ambix")==0) {
             inopt.channels_format=CHANNELS_FORMAT_AMBIX;
+          } else if (strcmp(optarg, "discrete")==0) {
+            inopt.channels_format=CHANNELS_FORMAT_DISCRETE;
           } else {
             fatal("Invalid input format: %s\n"
-              "--channels only supports 'ambix'\n",
+              "--channels only supports 'ambix' or 'discrete'\n",
               optarg);
           }
         } else if (strcmp(optname, "serial")==0) {
@@ -881,6 +883,11 @@
     fatal("Error: downmixing is currently unimplemented for ambisonics input.\n");
   }
 
+  if (downmix>0&&inopt.channels_format==CHANNELS_FORMAT_DISCRETE) {
+    /*Downmix of uncoupled channels not specified.*/
+    fatal("Error: downmixing is currently unimplemented for independent input.\n");
+  }
+
   if (inopt.channels_format==CHANNELS_FORMAT_DEFAULT) {
     if (downmix==0&&inopt.channels>2&&bitrate>0&&bitrate<(16000*inopt.channels)) {
       if (!quiet) fprintf(stderr,"Notice: Surround bitrate less than 16 kbit/s per channel, downmixing.\n");
@@ -904,6 +911,8 @@
       (including the non-diegetic stereo track). For other orders with no
       demixing matrices currently available, use channel mapping 2.*/
     mapping_family=(chan>=4&&chan<=18)?3:2;
+  } else if (inopt.channels_format==CHANNELS_FORMAT_DISCRETE) {
+    mapping_family=255;
   } else {
     mapping_family=chan>8?255:chan>2;
   }