diff options
author | wm4 <wm4@nowhere> | 2015-11-25 22:07:18 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-11-25 22:07:18 +0100 |
commit | 04257417542212c72e74a26d3b96c4fead51578f (patch) | |
tree | cef97eac4b1b5991abab1ad96f52aaeb04365d6e /audio | |
parent | 19c1a208ece76ccd7662a21685c08706b279f2a8 (diff) | |
download | mpv-04257417542212c72e74a26d3b96c4fead51578f.tar.bz2 mpv-04257417542212c72e74a26d3b96c4fead51578f.tar.xz |
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.
Diffstat (limited to 'audio')
-rw-r--r-- | audio/filter/af_lavrresample.c | 12 |
1 files changed, 12 insertions, 0 deletions
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. |