Skip to content

Commit

Permalink
opusenc: Implement --channels discrete switch
Browse files Browse the repository at this point in the history
Resolves #80
Signed-off-by: Mark Harris <mark.hsj@gmail.com>
  • Loading branch information
chris-hld authored and mark4o committed Nov 12, 2023
1 parent ec08f7b commit a2be338
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions man/opusenc.1
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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"
Expand Down
1 change: 1 addition & 0 deletions src/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 11 additions & 2 deletions src/opusenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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");
Expand Down Expand Up @@ -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, "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) {
Expand Down Expand Up @@ -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_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");
Expand All @@ -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_DISCRETE) {
mapping_family=255;
} else {
mapping_family=chan>8?255:chan>2;
}
Expand Down

0 comments on commit a2be338

Please sign in to comment.