From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 3ED7F4EE8D for ; Fri, 13 Jun 2025 16:38:57 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 7402068C98C; Fri, 13 Jun 2025 19:38:15 +0300 (EEST) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id BA18A68C8BA for ; Fri, 13 Jun 2025 19:38:07 +0300 (EEST) Received: from haasn.dev (unknown [10.30.1.1]) by haasn.dev (Postfix) with UTF8SMTP id 209A3434B3; Fri, 13 Jun 2025 18:38:03 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 13 Jun 2025 18:37:53 +0200 Message-ID: <20250613163801.197737-10-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613163801.197737-1-ffmpeg@haasn.xyz> References: <20250613163801.197737-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 10/13] avfilter/f_ebur128: lift sample peak calculation out of main loop X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Niklas Haas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Niklas Haas 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".