diff mbox series

[FFmpeg-devel] avfilter/af_loudnorm: Don't mix dB and linear values when calculating linear offset with inputs <3s

Message ID 20200426194855.618952-1-slomo@coaxion.net
State Accepted
Commit ed3da72583298ed04a488e363bd3fa6d69ade165
Headers show
Series [FFmpeg-devel] avfilter/af_loudnorm: Don't mix dB and linear values when calculating linear offset with inputs <3s | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Sebastian Dröge April 26, 2020, 7:48 p.m. UTC
From: Sebastian Dröge <sebastian@centricular.com>

s->target_i and global are in dB but s->target_tp and true_peak are
linear. Instead of mixing these in the calculations, convert the former
first to have all following calculations in the same unit.
---
 libavfilter/af_loudnorm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Paul B Mahol April 28, 2020, 7:58 a.m. UTC | #1
On 4/26/20, Sebastian Dröge <slomo@coaxion.net> wrote:
> From: Sebastian Dröge <sebastian@centricular.com>
>
> s->target_i and global are in dB but s->target_tp and true_peak are
> linear. Instead of mixing these in the calculations, convert the former
> first to have all following calculations in the same unit.
> ---
>  libavfilter/af_loudnorm.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>

LGTM, but better ask and CC maintainer directly.
Kyle Swanson May 2, 2020, 4:50 a.m. UTC | #2
Hi,

On Tue, Apr 28, 2020 at 12:58 AM Paul B Mahol <onemda@gmail.com> wrote:
>
> On 4/26/20, Sebastian Dröge <slomo@coaxion.net> wrote:
> > From: Sebastian Dröge <sebastian@centricular.com>
> >
> > s->target_i and global are in dB but s->target_tp and true_peak are
> > linear. Instead of mixing these in the calculations, convert the former
> > first to have all following calculations in the same unit.
> > ---
> >  libavfilter/af_loudnorm.c | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> >
>
> LGTM, but better ask and CC maintainer directly.

Tested and pushed. Thank you.

Thanks,
Kyle
diff mbox series

Patch

diff --git a/libavfilter/af_loudnorm.c b/libavfilter/af_loudnorm.c
index 314b25fa39..8e3cdc36db 100644
--- a/libavfilter/af_loudnorm.c
+++ b/libavfilter/af_loudnorm.c
@@ -453,10 +453,9 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *in)
                 true_peak = tmp;
         }
 
-        offset    = s->target_i - global;
-        offset_tp = true_peak + offset;
+        offset    = pow(10., (s->target_i - global) / 20.);
+        offset_tp = true_peak * offset;
         s->offset = offset_tp < s->target_tp ? offset : s->target_tp - true_peak;
-        s->offset = pow(10., s->offset / 20.);
         s->frame_type = LINEAR_MODE;
     }