From 78b812760d313fb818e5f376bb7215a3a912c801 Mon Sep 17 00:00:00 2001 From: Chris Hold Date: Mon, 24 Jul 2023 20:40:01 +0300 Subject: [PATCH 1/2] Implement --channels individual switch --- man/opusenc.1 | 5 +++-- src/encoder.h | 1 + src/opusenc.c | 13 +++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/man/opusenc.1 b/man/opusenc.1 index 27f652b..8c3209d 100644 --- a/man/opusenc.1 +++ b/man/opusenc.1 @@ -312,12 +312,13 @@ Ignore the data length in Wave headers. 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 +.B --channels 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 "individual" forces uncoupled +channels. .SS "Diagnostic options" .TP .BI --serial " N" diff --git a/src/encoder.h b/src/encoder.h index 4cc99aa..108e0aa 100644 --- 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_INDIVIDUAL 2 typedef long (*audio_read_func)(void *src, float *buffer, int samples); diff --git a/src/opusenc.c b/src/opusenc.c index 06838e5..9c6e91e 100644 --- a/src/opusenc.c +++ b/src/opusenc.c @@ -176,7 +176,7 @@ static void usage(void) 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 Override the format of the input channels\n"); + printf(" --channels Override the format of the input channels (ambix, individual)\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 @@ int main(int argc, char **argv) } else if (strcmp(optname, "channels")==0) { if (strcmp(optarg, "ambix")==0) { inopt.channels_format=CHANNELS_FORMAT_AMBIX; + } else if (strcmp(optarg, "individual")==0) { + inopt.channels_format=CHANNELS_FORMAT_INDIVIDUAL; } else { fatal("Invalid input format: %s\n" - "--channels only supports 'ambix'\n", + "--channels only supports 'ambix' or 'individual'\n", optarg); } } else if (strcmp(optname, "serial")==0) { @@ -881,6 +883,11 @@ int main(int argc, char **argv) fatal("Error: downmixing is currently unimplemented for ambisonics input.\n"); } + if (downmix>0&&inopt.channels_format==CHANNELS_FORMAT_INDIVIDUAL) { + /*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 @@ int main(int argc, char **argv) (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_INDIVIDUAL) { + mapping_family=255; } else { mapping_family=chan>8?255:chan>2; } From bda3650f73e703691ff2b073f16bab991d3b0e1e Mon Sep 17 00:00:00 2001 From: Chris Hold Date: Tue, 31 Oct 2023 19:47:35 +0200 Subject: [PATCH 2/2] Rename option "individual" to "discrete" --- man/opusenc.1 | 4 ++-- src/encoder.h | 2 +- src/opusenc.c | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/man/opusenc.1 b/man/opusenc.1 index 8c3209d..ca9e79f 100644 --- a/man/opusenc.1 +++ b/man/opusenc.1 @@ -312,12 +312,12 @@ Ignore the data length in Wave headers. 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 +.B --channels 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. The option "individual" forces uncoupled +after the ambisonics channels. The option "discrete" forces uncoupled channels. .SS "Diagnostic options" .TP diff --git a/src/encoder.h b/src/encoder.h index 108e0aa..ffec1ed 100644 --- a/src/encoder.h +++ b/src/encoder.h @@ -18,7 +18,7 @@ #define CHANNELS_FORMAT_DEFAULT 0 #define CHANNELS_FORMAT_AMBIX 1 -#define CHANNELS_FORMAT_INDIVIDUAL 2 +#define CHANNELS_FORMAT_DISCRETE 2 typedef long (*audio_read_func)(void *src, float *buffer, int samples); diff --git a/src/opusenc.c b/src/opusenc.c index 9c6e91e..c7aa108 100644 --- a/src/opusenc.c +++ b/src/opusenc.c @@ -176,7 +176,7 @@ static void usage(void) 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 Override the format of the input channels (ambix, individual)\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,11 +637,11 @@ int main(int argc, char **argv) } else if (strcmp(optname, "channels")==0) { if (strcmp(optarg, "ambix")==0) { inopt.channels_format=CHANNELS_FORMAT_AMBIX; - } else if (strcmp(optarg, "individual")==0) { - inopt.channels_format=CHANNELS_FORMAT_INDIVIDUAL; + } else if (strcmp(optarg, "discrete")==0) { + inopt.channels_format=CHANNELS_FORMAT_DISCRETE; } else { fatal("Invalid input format: %s\n" - "--channels only supports 'ambix' or 'individual'\n", + "--channels only supports 'ambix' or 'discrete'\n", optarg); } } else if (strcmp(optname, "serial")==0) { @@ -883,7 +883,7 @@ int main(int argc, char **argv) fatal("Error: downmixing is currently unimplemented for ambisonics input.\n"); } - if (downmix>0&&inopt.channels_format==CHANNELS_FORMAT_INDIVIDUAL) { + 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"); } @@ -911,7 +911,7 @@ int main(int argc, char **argv) (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_INDIVIDUAL) { + } else if (inopt.channels_format==CHANNELS_FORMAT_DISCRETE) { mapping_family=255; } else { mapping_family=chan>8?255:chan>2;