summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-09-08 22:04:45 +0200
committerwm4 <wm4@nowhere>2015-09-08 22:16:30 +0200
commit4eae4a5da77f127f381119a1e54351b7812deed4 (patch)
treeeaecc5886797715831f19fce95e666f65b59a787
parent0eb72d786c2c39e6c53b4f065912e433639b0fb9 (diff)
downloadmpv-4eae4a5da77f127f381119a1e54351b7812deed4.tar.bz2
mpv-4eae4a5da77f127f381119a1e54351b7812deed4.tar.xz
af_lavrresample: add normalize suboption
-rw-r--r--DOCS/man/af.rst7
-rw-r--r--audio/filter/af_lavrresample.c7
2 files changed, 13 insertions, 1 deletions
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=<yes|no>``
+ 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=<string>``
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}
},