Skip to content

Commit

Permalink
Don't force 2.0 downmix with KEEP_DMIX_2CH flag alone.
Browse files Browse the repository at this point in the history
Previously setting KEEP_DMIX_2CH flag alone forced the 2.0 downmix using
default coefficients if none are embedded, while combining it with
KEEP_DMIX_6CH performed the 2.0 downmix only when custom coefficients
are present.

Inverse the meaning of combination of these flags: make KEEP_DMIX_2CH
flag extract embedded downmix when used alone. Add special
FORCE_DMIX_2CH constant (both flags set) to force downmix.

Forcing downmix with a single KEEP_DMIX_2CH flag is a bad idea as it
might result in clipping for streams that were not prepared for 2.0
downmix. Make this caveat explicit.
  • Loading branch information
foo86 committed May 15, 2015
1 parent 396e756 commit bc08f9e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ Help screen of the program is reproduced below.
Usage: ./dcadec [-26bcfhlmnPqSx] <input.dts> [output.wav]
dcadec is a free DTS Coherent Acoustics decoder. Supported options:
-2 Extract embedded 2.0 downmix.
-2 Extract embedded 2.0 downmix if present, otherwise extract 5.1 downmix.
-6 Extract embedded 5.1 downmix.
-26 Extract embedded 2.0 downmix if present, otherwise force 2.0 downmix using
default coefficients. Might result in clipping.
-b Force fixed point DTS core interpolation. Developer option, degrades sound
quality.
Expand Down
5 changes: 4 additions & 1 deletion dcadec.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ static void print_help(char *name)
"Usage: %s [-26bcfhlmnPqSx] <input.dts> [output.wav]\n"
"dcadec is a free DTS Coherent Acoustics decoder. Supported options:\n"
"\n"
"-2 Extract embedded 2.0 downmix.\n"
"-2 Extract embedded 2.0 downmix if present, otherwise extract 5.1 downmix.\n"
"\n"
"-6 Extract embedded 5.1 downmix.\n"
"\n"
"-26 Extract embedded 2.0 downmix if present, otherwise force 2.0 downmix using\n"
" default coefficients. Might result in clipping.\n"
"\n"
"-b Force fixed point DTS core interpolation. Developer option, degrades sound\n"
" quality.\n"
"\n"
Expand Down
10 changes: 5 additions & 5 deletions libdcadec/dca_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,17 @@ static void clip_samples(struct dcadec_context *dca, int nchannels)
static int down_mix_prim_chset(struct dcadec_context *dca, int **samples,
int nsamples, int *ch_mask, int *dmix_coeff)
{
// With both KEEP_DMIX flags set, perfrom 2.0 downmix only when custom
// matrix is present
if (!dmix_coeff && (dca->flags & DCADEC_FLAG_KEEP_DMIX_6CH))
return 0;

// No action if already 2.0. Remove LFE channel if 2.1.
if ((*ch_mask & ~SPEAKER_MASK_LFE1) == (SPEAKER_MASK_L | SPEAKER_MASK_R)) {
*ch_mask = SPEAKER_MASK_L | SPEAKER_MASK_R;
return 0;
}

// Unless both KEEP_DMIX flags are set, perform 2.0 downmix only when
// custom matrix is present
if (!dmix_coeff && !(dca->flags & DCADEC_FLAG_KEEP_DMIX_6CH))
return 0;

// Reallocate downmix sample buffer
if (ta_alloc_fast(dca, &dca->dmix_sample_buffer, 2 * nsamples, sizeof(int)) < 0)
return -DCADEC_ENOMEM;
Expand Down
8 changes: 7 additions & 1 deletion libdcadec/dca_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,18 @@
/* Use FIR filter for floating point DTS core LFE channel interpolation */
#define DCADEC_FLAG_CORE_LFE_FIR 0x10

/** Extract embedded 2.0 downmix */
/** Extract embedded 2.0 downmix if present, otherwise extract 5.1 downmix */
#define DCADEC_FLAG_KEEP_DMIX_2CH 0x20

/** Extract embedded 5.1 downmix */
#define DCADEC_FLAG_KEEP_DMIX_6CH 0x40

/**
* Extract embedded 2.0 downmix if present, otherwise force 2.0 downmix using
* default coefficients. Might result in clipping.
*/
#define DCADEC_FLAG_FORCE_DMIX_2CH 0x60

/** Output native DTS channel layout, not WAVEFORMATEXTENSIBLE layout */
#define DCADEC_FLAG_NATIVE_LAYOUT 0x80

Expand Down

0 comments on commit bc08f9e

Please sign in to comment.