diff --git a/README.md b/README.md index 86f0732..7370d7c 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,13 @@ Help screen of the program is reproduced below. Usage: ./dcadec [-26bcfhlmnPqSx] [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. diff --git a/dcadec.c b/dcadec.c index d87201f..f3946c0 100644 --- a/dcadec.c +++ b/dcadec.c @@ -46,10 +46,13 @@ static void print_help(char *name) "Usage: %s [-26bcfhlmnPqSx] [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" diff --git a/libdcadec/dca_context.c b/libdcadec/dca_context.c index 9a40499..5509131 100644 --- a/libdcadec/dca_context.c +++ b/libdcadec/dca_context.c @@ -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; diff --git a/libdcadec/dca_context.h b/libdcadec/dca_context.h index bc9b879..826d4cf 100644 --- a/libdcadec/dca_context.h +++ b/libdcadec/dca_context.h @@ -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