From 4eae4a5da77f127f381119a1e54351b7812deed4 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 8 Sep 2015 22:04:45 +0200 Subject: af_lavrresample: add normalize suboption --- DOCS/man/af.rst | 7 +++++++ audio/filter/af_lavrresample.c | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/DOCS/man/af.rst b/DOCS/man/af.rst index 9baaca664b..f839770247 100644 --- a/DOCS/man/af.rst +++ b/DOCS/man/af.rst @@ -59,6 +59,13 @@ Available filters are: (If you just want to set defaults for this filter that will be used even by automatically inserted lavrresample instances, you should prefer setting them with ``--af-defaults=lavrresample:...``.) + ``normalize=`` + Whether to normalize when remixing channel layouts (default: yes). This + is e.g. applied when downmixing surround audio to stereo. The advantage + is that this guarantees that no clipping can happen. Unfortunately, + this can also lead to too low volume levels. Whether you enable or + disable this is essentially a matter of taste, but the default uses + the safer choice. ``o=`` Set AVOptions on the SwrContext or AVAudioResampleContext. These should be documented by FFmpeg or Libav. diff --git a/audio/filter/af_lavrresample.c b/audio/filter/af_lavrresample.c index 706ed87eb7..f4669af343 100644 --- a/audio/filter/af_lavrresample.c +++ b/audio/filter/af_lavrresample.c @@ -65,6 +65,7 @@ struct af_resample_opts { int phase_shift; int linear; double cutoff; + int normalize; int in_rate_af; // filter input sample rate int in_rate; // actual rate (used by lavr), adjusted for playback speed @@ -234,7 +235,9 @@ static int configure_lavrr(struct af_instance *af, struct mp_audio *in, av_opt_set_double(s->avrctx, "cutoff", s->ctx.cutoff, 0); #if HAVE_LIBSWRESAMPLE - av_opt_set_double(s->avrctx, "rematrix_maxval", 1.0, 0); + av_opt_set_double(s->avrctx, "rematrix_maxval", s->opts.normalize ? 1 : 1000, 0); +#else + av_opt_set_int(s->avrctx, "normalize_mix_level", s->opts.normalize, 0); #endif if (mp_set_avopts(af->log, s->avrctx, s->avopts) < 0) @@ -546,6 +549,7 @@ const struct af_info af_info_lavrresample = { .filter_size = 16, .cutoff = 0.0, .phase_shift = 10, + .normalize = 1, }, .playback_speed = 1.0, .allow_detach = 1, @@ -556,6 +560,7 @@ const struct af_info af_info_lavrresample = { OPT_FLAG("linear", opts.linear, 0), OPT_DOUBLE("cutoff", opts.cutoff, M_OPT_RANGE, .min = 0, .max = 1), OPT_FLAG("detach", allow_detach, 0), + OPT_FLAG("normalize", opts.normalize, 0), OPT_KEYVALUELIST("o", avopts, 0), {0} }, -- cgit v1.2.3