From: Niklas Haas <ffmpeg@haasn.xyz> To: ffmpeg-devel@ffmpeg.org Cc: Niklas Haas <git@haasn.dev> Subject: [FFmpeg-devel] [PATCH v2 10/13] avfilter/f_ebur128: lift sample peak calculation out of main loop Date: Mon, 16 Jun 2025 13:19:58 +0200 Message-ID: <20250616112003.10665-10-ffmpeg@haasn.xyz> (raw) In-Reply-To: <20250616112003.10665-1-ffmpeg@haasn.xyz> From: Niklas Haas <git@haasn.dev> This is substantially faster (~55%) than the transposed loop, and also avoids an unnecessary macro. --- libavfilter/f_ebur128.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/libavfilter/f_ebur128.c b/libavfilter/f_ebur128.c index 23092b597f..4051b1ea95 100644 --- a/libavfilter/f_ebur128.c +++ b/libavfilter/f_ebur128.c @@ -687,6 +687,24 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) } #endif + if (ebur128->peak_mode & PEAK_MODE_SAMPLES_PEAKS) { + double maxpeak = 0.0; + for (int ch = 0; ch < nb_channels; ch++) { + const double *restrict samples_ch = &samples[ch]; + double sp = ebur128->sample_peaks[ch]; + + for (int i = ebur128->idx_insample; i < nb_samples; i++) { + const double sample = fabs(samples_ch[nb_channels * i]); + sp = FFMAX(sp, sample); + } + maxpeak = FFMAX(maxpeak, sp); + ebur128->sample_peaks[ch] = sp; + } + + ebur128->sample_peak = DBFS(maxpeak); + } + + for (idx_insample = ebur128->idx_insample; idx_insample < nb_samples; idx_insample++) { const int bin_id_400 = ebur128->i400.cache_pos++; const int bin_id_3000 = ebur128->i3000.cache_pos++; @@ -707,26 +725,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) ebur128->i400.sum, ebur128->i3000.sum, nb_channels); -#define FIND_PEAK(global, sp, ptype) do { \ - int ch; \ - double maxpeak; \ - maxpeak = 0.0; \ - if (ebur128->peak_mode & PEAK_MODE_ ## ptype ## _PEAKS) { \ - for (ch = 0; ch < ebur128->nb_channels; ch++) \ - maxpeak = FFMAX(maxpeak, sp[ch]); \ - global = DBFS(maxpeak); \ - } \ -} while (0) - - if (ebur128->peak_mode & PEAK_MODE_SAMPLES_PEAKS) { - for (ch = 0; ch < nb_channels; ch++) { - const double sample = samples[idx_insample * nb_channels + ch]; - ebur128->sample_peaks[ch] = FFMAX(ebur128->sample_peaks[ch], fabs(sample)); - } - } - - FIND_PEAK(ebur128->sample_peak, ebur128->sample_peaks, SAMPLES); - /* For integrated loudness, gating blocks are 400ms long with 75% * overlap (see BS.1770-2 p5), so a re-computation is needed each 100ms * (4800 samples at 48kHz). */ -- 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-16 11:21 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 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 2025-06-16 11:19 ` [FFmpeg-devel] [PATCH v2 03/13] avfilter/f_ebur128: use structs for biquad weights Niklas Haas 2025-06-16 11:19 ` [FFmpeg-devel] [PATCH v2 04/13] avfilter/f_ebur128: use a single packed array for the integrator cache Niklas Haas 2025-06-16 11:19 ` [FFmpeg-devel] [PATCH v2 05/13] avfilter/f_ebur128: move weights and cache to EBUR128DSPContext Niklas Haas 2025-06-16 14:40 ` Michael Niedermayer 2025-06-16 11:19 ` [FFmpeg-devel] [PATCH v2 06/13] avfilter/f_ebur128: split off C implementation to separate function Niklas Haas 2025-06-16 11:19 ` [FFmpeg-devel] [PATCH v2 07/13] avfilter/x86/f_ebur128: add x86 AVX implementation Niklas Haas 2025-06-16 14:18 ` Michael Niedermayer 2025-06-16 11:19 ` [FFmpeg-devel] [PATCH v2 08/13] avfilter/f_ebur128: remove pointless macro Niklas Haas 2025-06-16 11:19 ` [FFmpeg-devel] [PATCH v2 09/13] avfilter/f_ebur128: move true peak calculation out of main loop Niklas Haas 2025-06-16 13:06 ` Niklas Haas 2025-06-16 11:19 ` Niklas Haas [this message] 2025-06-16 11:19 ` [FFmpeg-devel] [PATCH v2 11/13] avfilter/f_ebur128: move variable declarations to usage site Niklas Haas 2025-06-16 11:20 ` [FFmpeg-devel] [PATCH v2 12/13] avfilter/f_ebur128: move true peak calculation to DSP function Niklas Haas 2025-06-16 11:20 ` [FFmpeg-devel] [PATCH v2 13/13] avfilter/x86/f_ebur128: implement AVX true peak calculation Niklas Haas -- strict thread matches above, loose matches on Subject: below -- 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 ` [FFmpeg-devel] [PATCH v2 10/13] avfilter/f_ebur128: lift sample peak calculation out of main loop 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=20250616112003.10665-10-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