From: Niklas Haas <ffmpeg@haasn.xyz> To: ffmpeg-devel@ffmpeg.org Cc: Niklas Haas <git@haasn.dev> Subject: [FFmpeg-devel] [PATCH v4 05/13] avfilter/f_ebur128: move weights and cache to EBUR128DSPContext Date: Tue, 17 Jun 2025 14:05:58 +0200 Message-ID: <20250617120609.1987435-5-ffmpeg@haasn.xyz> (raw) In-Reply-To: <20250617120609.1987435-1-ffmpeg@haasn.xyz> From: Niklas Haas <git@haasn.dev> --- libavfilter/f_ebur128.c | 53 +++++++++++++++++------------------------ libavfilter/f_ebur128.h | 40 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 31 deletions(-) create mode 100644 libavfilter/f_ebur128.h diff --git a/libavfilter/f_ebur128.c b/libavfilter/f_ebur128.c index 9f7c080750..c3328dc520 100644 --- a/libavfilter/f_ebur128.c +++ b/libavfilter/f_ebur128.c @@ -43,6 +43,8 @@ #include "formats.h" #include "video.h" +#include "f_ebur128.h" + #define ABS_THRES -70 ///< silence gate: we discard anything below this absolute (LUFS) threshold #define ABS_UP_THRES 10 ///< upper loud limit to consider (ABS_THRES being the minimum) #define HIST_GRAIN 100 ///< defines histogram precision @@ -75,13 +77,9 @@ struct integrator { struct rect { int x, y, w, h; }; -struct biquad { - double b0, b1, b2; - double a1, a2; -}; - typedef struct EBUR128Context { const AVClass *class; ///< AVClass context for log and options purpose + EBUR128DSPContext dsp; /* peak metering */ int peak_mode; ///< enabled peak modes @@ -118,13 +116,6 @@ typedef struct EBUR128Context { int idx_insample; ///< current sample position of processed samples in single input frame AVFrame *insamples; ///< input samples reference, updated regularly - /* Filter caches. - * The mult by 3 in the following is for X[i], X[i-1] and X[i-2] */ - double *y; ///< 3 pre-filter samples cache for each channel - double *z; ///< 3 RLB-filter samples cache for each channel - struct biquad pre; - struct biquad rlb; - struct integrator i400; ///< 400ms integrator, used for Momentary loudness (M), and Integrated loudness (I) struct integrator i3000; ///< 3s integrator, used for Short term loudness (S), and Loudness Range (LRA) @@ -408,21 +399,21 @@ static int config_audio_input(AVFilterLink *inlink) double a0 = 1.0 + K / Q + K * K; - ebur128->pre.b0 = (Vh + Vb * K / Q + K * K) / a0; - ebur128->pre.b1 = 2.0 * (K * K - Vh) / a0; - ebur128->pre.b2 = (Vh - Vb * K / Q + K * K) / a0; - ebur128->pre.a1 = 2.0 * (K * K - 1.0) / a0; - ebur128->pre.a2 = (1.0 - K / Q + K * K) / a0; + ebur128->dsp.pre.b0 = (Vh + Vb * K / Q + K * K) / a0; + ebur128->dsp.pre.b1 = 2.0 * (K * K - Vh) / a0; + ebur128->dsp.pre.b2 = (Vh - Vb * K / Q + K * K) / a0; + ebur128->dsp.pre.a1 = 2.0 * (K * K - 1.0) / a0; + ebur128->dsp.pre.a2 = (1.0 - K / Q + K * K) / a0; f0 = 38.13547087602444; Q = 0.5003270373238773; K = tan(M_PI * f0 / (double)inlink->sample_rate); - ebur128->rlb.b0 = 1.0; - ebur128->rlb.b1 = -2.0; - ebur128->rlb.b2 = 1.0; - ebur128->rlb.a1 = 2.0 * (K * K - 1.0) / (1.0 + K / Q + K * K); - ebur128->rlb.a2 = (1.0 - K / Q + K * K) / (1.0 + K / Q + K * K); + ebur128->dsp.rlb.b0 = 1.0; + ebur128->dsp.rlb.b1 = -2.0; + ebur128->dsp.rlb.b2 = 1.0; + ebur128->dsp.rlb.a1 = 2.0 * (K * K - 1.0) / (1.0 + K / Q + K * K); + ebur128->dsp.rlb.a2 = (1.0 - K / Q + K * K) / (1.0 + K / Q + K * K); /* Force 100ms framing in case of metadata injection: the frames must have * a granularity of the window overlap to be accurately exploited. @@ -448,10 +439,10 @@ static int config_audio_output(AVFilterLink *outlink) AV_CH_SURROUND_DIRECT_LEFT |AV_CH_SURROUND_DIRECT_RIGHT) ebur128->nb_channels = nb_channels; - ebur128->y = av_calloc(nb_channels, 3 * sizeof(*ebur128->y)); - ebur128->z = av_calloc(nb_channels, 3 * sizeof(*ebur128->z)); + ebur128->dsp.y = av_calloc(nb_channels, 3 * sizeof(*ebur128->dsp.y)); + ebur128->dsp.z = av_calloc(nb_channels, 3 * sizeof(*ebur128->dsp.z)); ebur128->ch_weighting = av_calloc(nb_channels, sizeof(*ebur128->ch_weighting)); - if (!ebur128->ch_weighting || !ebur128->y || !ebur128->z) + if (!ebur128->ch_weighting || !ebur128->dsp.y || !ebur128->dsp.z) return AVERROR(ENOMEM); #define I400_BINS(x) ((x) * 4 / 10) @@ -648,8 +639,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) } #endif - const struct biquad pre = ebur128->pre; - const struct biquad rlb = ebur128->rlb; + const EBUR128Biquad pre = ebur128->dsp.pre; + const EBUR128Biquad rlb = ebur128->dsp.rlb; for (idx_insample = ebur128->idx_insample; idx_insample < nb_samples; idx_insample++) { const int bin_id_400 = ebur128->i400.cache_pos; @@ -684,8 +675,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) } while (0) const double x = samples[idx_insample * nb_channels + ch]; - double *restrict y = &ebur128->y[3 * ch]; - double *restrict z = &ebur128->z[3 * ch]; + double *restrict y = &ebur128->dsp.y[3 * ch]; + double *restrict z = &ebur128->dsp.z[3 * ch]; // TODO: merge both filters in one? FILTER(y, x, pre); // apply pre-filter @@ -1063,8 +1054,8 @@ static av_cold void uninit(AVFilterContext *ctx) } av_freep(&ebur128->y_line_ref); - av_freep(&ebur128->y); - av_freep(&ebur128->z); + av_freep(&ebur128->dsp.y); + av_freep(&ebur128->dsp.z); av_freep(&ebur128->ch_weighting); av_freep(&ebur128->true_peaks); av_freep(&ebur128->sample_peaks); diff --git a/libavfilter/f_ebur128.h b/libavfilter/f_ebur128.h new file mode 100644 index 0000000000..42cce9a5e4 --- /dev/null +++ b/libavfilter/f_ebur128.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2012 Clément Bœsch + * Copyright (c) 2025 Niklas Haas + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVFILTER_F_EBUR128_H +#define AVFILTER_F_EBUR128_H + +typedef struct EBUR128Biquad { + double b0, b1, b2; + double a1, a2; +} EBUR128Biquad; + +typedef struct EBUR128DSPContext { + /* Filter data */ + EBUR128Biquad pre; + EBUR128Biquad rlb; + + /* Cache of 3 samples for each channel */ + double *y; /* after pre-filter */ + double *z; /* after RLB-filter */ +} EBUR128DSPContext; + +#endif /* AVFILTER_F_EBUR128_H */ -- 2.49.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2025-06-17 12:07 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-06-17 12:05 [FFmpeg-devel] [PATCH v4 01/13] avfilter/f_ebur128: use transformed direct form II Niklas Haas 2025-06-17 12:05 ` [FFmpeg-devel] [PATCH v4 02/13] avfilter/f_ebur128: simplify sample cache array Niklas Haas 2025-06-17 12:05 ` [FFmpeg-devel] [PATCH v4 03/13] avfilter/f_ebur128: use structs for biquad weights Niklas Haas 2025-06-17 12:05 ` [FFmpeg-devel] [PATCH v4 04/13] avfilter/f_ebur128: use a single packed array for the integrator cache Niklas Haas 2025-06-17 12:05 ` Niklas Haas [this message] 2025-06-17 12:05 ` [FFmpeg-devel] [PATCH v4 06/13] avfilter/f_ebur128: split off C implementation to separate function Niklas Haas 2025-06-17 12:06 ` [FFmpeg-devel] [PATCH v4 07/13] avfilter/x86/f_ebur128: add x86 AVX implementation Niklas Haas 2025-06-17 12:06 ` [FFmpeg-devel] [PATCH v4 08/13] avfilter/f_ebur128: remove pointless macro Niklas Haas 2025-06-17 12:06 ` [FFmpeg-devel] [PATCH v4 09/13] avfilter/f_ebur128: move true peak calculation out of main loop Niklas Haas 2025-06-17 12:06 ` [FFmpeg-devel] [PATCH v4 10/13] avfilter/f_ebur128: lift sample " Niklas Haas 2025-06-17 12:06 ` [FFmpeg-devel] [PATCH v4 11/13] avfilter/f_ebur128: move variable declarations to usage site Niklas Haas 2025-06-17 12:06 ` [FFmpeg-devel] [PATCH v4 12/13] avfilter/f_ebur128: move true peak calculation to DSP function Niklas Haas 2025-06-17 12:06 ` [FFmpeg-devel] [PATCH v4 13/13] avfilter/x86/f_ebur128: implement AVX true peak calculation Niklas Haas 2025-06-17 13:48 ` Niklas Haas
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20250617120609.1987435-5-ffmpeg@haasn.xyz \ --to=ffmpeg@haasn.xyz \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=git@haasn.dev \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git