From 04257417542212c72e74a26d3b96c4fead51578f Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 25 Nov 2015 22:07:18 +0100 Subject: af_lavrresample: clamp float output to range libswresample doesn't do it - although it should, but the patch is stuck in limbo. Probably reduces problems with artifacts on downmixing in some cases. --- audio/filter/af_lavrresample.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'audio') diff --git a/audio/filter/af_lavrresample.c b/audio/filter/af_lavrresample.c index 8f2efec858..21f31af8f9 100644 --- a/audio/filter/af_lavrresample.c +++ b/audio/filter/af_lavrresample.c @@ -423,6 +423,18 @@ static void extra_output_conversion(struct af_instance *af, struct mp_audio *mpa } mp_audio_set_format(mpa, AF_FORMAT_S24); } + + for (int p = 0; p < mpa->num_planes; p++) { + void *ptr = mpa->planes[p]; + int total = mpa->samples * mpa->spf; + if (af_fmt_from_planar(mpa->format) == AF_FORMAT_FLOAT) { + for (int s = 0; s < total; s++) + ((float *)ptr)[s] = av_clipf(((float *)ptr)[s], -1.0f, 1.0f); + } else if (af_fmt_from_planar(mpa->format) == AF_FORMAT_DOUBLE) { + for (int s = 0; s < total; s++) + ((double *)ptr)[s] = av_clipd(((double *)ptr)[s], -1.0, 1.0); + } + } } // This relies on the tricky way mpa was allocated. -- cgit v1.2.3