From: Niklas Haas <ffmpeg@haasn.xyz> To: ffmpeg-devel@ffmpeg.org Cc: Niklas Haas <git@haasn.dev> Subject: [FFmpeg-devel] [PATCH v2 02/13] avfilter/f_ebur128: simplify sample cache array Date: Fri, 13 Jun 2025 18:37:45 +0200 Message-ID: <20250613163801.197737-2-ffmpeg@haasn.xyz> (raw) In-Reply-To: <20250613163801.197737-1-ffmpeg@haasn.xyz> From: Niklas Haas <git@haasn.dev> We don't need an X sample cache anymore, and we also can simplify the access macro slightly. --- libavfilter/f_ebur128.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/libavfilter/f_ebur128.c b/libavfilter/f_ebur128.c index 173a4f75ca..d0707e9ef9 100644 --- a/libavfilter/f_ebur128.c +++ b/libavfilter/f_ebur128.c @@ -115,7 +115,6 @@ typedef struct EBUR128Context { /* Filter caches. * The mult by 3 in the following is for X[i], X[i-1] and X[i-2] */ - double *x; ///< 3 input samples cache for each channel double *y; ///< 3 pre-filter samples cache for each channel double *z; ///< 3 RLB-filter samples cache for each channel double pre_b[3]; ///< pre-filter numerator coefficients @@ -446,11 +445,10 @@ static int config_audio_output(AVFilterLink *outlink) AV_CH_SURROUND_DIRECT_LEFT |AV_CH_SURROUND_DIRECT_RIGHT) ebur128->nb_channels = nb_channels; - ebur128->x = av_calloc(nb_channels, 3 * sizeof(*ebur128->x)); ebur128->y = av_calloc(nb_channels, 3 * sizeof(*ebur128->y)); ebur128->z = av_calloc(nb_channels, 3 * sizeof(*ebur128->z)); ebur128->ch_weighting = av_calloc(nb_channels, sizeof(*ebur128->ch_weighting)); - if (!ebur128->ch_weighting || !ebur128->x || !ebur128->y || !ebur128->z) + if (!ebur128->ch_weighting || !ebur128->y || !ebur128->z) return AVERROR(ENOMEM); #define I400_BINS(x) ((x) * 4 / 10) @@ -673,34 +671,30 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) MOVE_TO_NEXT_CACHED_ENTRY(3000); for (ch = 0; ch < nb_channels; ch++) { - double bin; - if (ebur128->peak_mode & PEAK_MODE_SAMPLES_PEAKS) ebur128->sample_peaks[ch] = FFMAX(ebur128->sample_peaks[ch], fabs(samples[idx_insample * nb_channels + ch])); - ebur128->x[ch * 3] = samples[idx_insample * nb_channels + ch]; // set X[i] - if (!ebur128->ch_weighting[ch]) continue; /* Y[i] = X[i]*b0 + X[i-1]*b1 + X[i-2]*b2 - Y[i-1]*a1 - Y[i-2]*a2 */ -#define FILTER(Y, X, NUM, DEN) do { \ - double *dst = ebur128->Y + ch*3; \ - double src = ebur128->X[ch*3] ; \ - double dst0 = NUM[0] * src + dst[1]; \ - dst[1] = NUM[1] * src + dst[2] - DEN[1] * dst0; \ - dst[2] = NUM[2] * src - DEN[2] * dst0; \ - dst[0] = dst0; \ +#define FILTER(DST, SRC, NUM, DEN) do { \ + const double tmp = DST[0] = NUM[0] * SRC + DST[1]; \ + DST[1] = NUM[1] * SRC + DST[2] - DEN[1] * tmp; \ + DST[2] = NUM[2] * SRC - DEN[2] * tmp; \ } 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]; + // TODO: merge both filters in one? FILTER(y, x, ebur128->pre_b, ebur128->pre_a); // apply pre-filter - FILTER(z, y, ebur128->rlb_b, ebur128->rlb_a); // apply RLB-filter - - bin = ebur128->z[ch * 3] * ebur128->z[ch * 3]; + FILTER(z, *y, ebur128->rlb_b, ebur128->rlb_a); // apply RLB-filter /* add the new value, and limit the sum to the cache size (400ms or 3s) * by removing the oldest one */ + double bin = *z * *z; ebur128->i400.sum [ch] = ebur128->i400.sum [ch] + bin - ebur128->i400.cache [ch][bin_id_400]; ebur128->i3000.sum[ch] = ebur128->i3000.sum[ch] + bin - ebur128->i3000.cache[ch][bin_id_3000]; @@ -1073,7 +1067,6 @@ static av_cold void uninit(AVFilterContext *ctx) } av_freep(&ebur128->y_line_ref); - av_freep(&ebur128->x); av_freep(&ebur128->y); av_freep(&ebur128->z); av_freep(&ebur128->ch_weighting); -- 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-13 16:38 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-06-13 16:37 [FFmpeg-devel] [PATCH v2 01/13] avfilter/f_ebur128: use transformed direct form II Niklas Haas 2025-06-13 16:37 ` Niklas Haas [this message] 2025-06-13 16:37 ` [FFmpeg-devel] [PATCH v2 03/13] avfilter/f_ebur128: use structs for biquad weights Niklas Haas 2025-06-13 16:37 ` [FFmpeg-devel] [PATCH v2 04/13] avfilter/f_ebur128: use a single packed array for the integrator cache Niklas Haas 2025-06-13 16:37 ` [FFmpeg-devel] [PATCH v2 05/13] avfilter/f_ebur128: move weights and cache to EBUR128DSPContext Niklas Haas 2025-06-13 16:37 ` [FFmpeg-devel] [PATCH v2 06/13] avfilter/f_ebur128: split off C implementation to separate function Niklas Haas 2025-06-13 16:37 ` [FFmpeg-devel] [PATCH v2 07/13] avfilter/x86/f_ebur128: add x86 AVX implementation Niklas Haas 2025-06-14 1:12 ` Michael Niedermayer 2025-06-16 11:19 ` Niklas Haas 2025-06-14 1:20 ` James Almer 2025-06-16 11:15 ` Niklas Haas 2025-06-13 16:37 ` [FFmpeg-devel] [PATCH v2 08/13] avfilter/f_ebur128: remove pointless macro Niklas Haas 2025-06-13 16:37 ` [FFmpeg-devel] [PATCH v2 09/13] avfilter/f_ebur128: move true peak calculation out of main loop Niklas Haas 2025-06-13 16:37 ` [FFmpeg-devel] [PATCH v2 10/13] avfilter/f_ebur128: lift sample " Niklas Haas 2025-06-13 16:37 ` [FFmpeg-devel] [PATCH v2 11/13] avfilter/f_ebur128: move variable declarations to usage site Niklas Haas 2025-06-13 16:37 ` [FFmpeg-devel] [PATCH v2 12/13] avfilter/f_ebur128: move true peak calculation to DSP function Niklas Haas 2025-06-13 16:37 ` [FFmpeg-devel] [PATCH v2 13/13] avfilter/x86/f_ebur128: implement AVX true peak calculation Niklas Haas 2025-06-16 11:19 [FFmpeg-devel] [PATCH v2 01/13] avfilter/f_ebur128: use transformed direct form II Niklas Haas 2025-06-16 11:19 ` [FFmpeg-devel] [PATCH v2 02/13] avfilter/f_ebur128: simplify sample cache array 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=20250613163801.197737-2-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