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 B8E4F4F392 for ; Mon, 16 Jun 2025 13:06:17 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id CC5EC68DB6A; Mon, 16 Jun 2025 16:06:13 +0300 (EEST) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 099F268D867 for ; Mon, 16 Jun 2025 16:06:07 +0300 (EEST) Received: from haasn.dev (unknown [10.30.1.1]) by haasn.dev (Postfix) with UTF8SMTP id D0F2F402F2; Mon, 16 Jun 2025 15:06:06 +0200 (CEST) Date: Mon, 16 Jun 2025 15:06:06 +0200 Message-ID: <20250616150606.GB72482@haasn.xyz> From: Niklas Haas To: ffmpeg-devel@ffmpeg.org In-Reply-To: <20250616112003.10665-9-ffmpeg@haasn.xyz> References: <20250616112003.10665-1-ffmpeg@haasn.xyz> <20250616112003.10665-9-ffmpeg@haasn.xyz> MIME-Version: 1.0 Content-Disposition: inline Subject: Re: [FFmpeg-devel] [PATCH v2 09/13] avfilter/f_ebur128: move true 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: On Mon, 16 Jun 2025 13:19:57 +0200 Niklas Haas wrote: > From: Niklas Haas > > Easier to read, less convoluted, and ~30% faster. Most importantly, this > avoids repeating the redundant recalculation of the true peak on every single > sample, by moving the FIND_PEAK() loop out of the main loop. (Note that > FIND_PEAK() does not depend on the current sample index at all, so there is no > reason for it to ever be recomputed here) Fixed the commit message formatting locally. > --- > libavfilter/f_ebur128.c | 23 ++++++++++++++--------- > 1 file changed, 14 insertions(+), 9 deletions(-) > > diff --git a/libavfilter/f_ebur128.c b/libavfilter/f_ebur128.c > index 2e1eedd855..23092b597f 100644 > --- a/libavfilter/f_ebur128.c > +++ b/libavfilter/f_ebur128.c > @@ -668,16 +668,22 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) > (const uint8_t **)insamples->data, nb_samples); > if (ret < 0) > return ret; > - for (ch = 0; ch < nb_channels; ch++) > - ebur128->true_peaks_per_frame[ch] = 0.0; > - for (idx_insample = 0; idx_insample < ret; idx_insample++) { > - for (ch = 0; ch < nb_channels; ch++) { > - ebur128->true_peaks[ch] = FFMAX(ebur128->true_peaks[ch], fabs(*swr_samples)); > - ebur128->true_peaks_per_frame[ch] = FFMAX(ebur128->true_peaks_per_frame[ch], > - fabs(*swr_samples)); > - swr_samples++; > + > + double maxpeak = 0.0; > + for (int ch = 0; ch < nb_channels; ch++) { > + double tp = ebur128->true_peaks[ch]; > + double tppf = 0.0; > + for (int i = 0; i < ret; i++) { > + const double sample = fabs(swr_samples[i * nb_channels]); > + tp = FFMAX(tp, sample); > + tppf = FFMAX(tppf, sample); > } > + maxpeak = FFMAX(maxpeak, tp); > + ebur128->true_peaks[ch] = tp; > + ebur128->true_peaks_per_frame[ch] = tppf; > } > + > + ebur128->true_peak = DBFS(maxpeak); > } > #endif > > @@ -720,7 +726,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) > } > > FIND_PEAK(ebur128->sample_peak, ebur128->sample_peaks, SAMPLES); > - FIND_PEAK(ebur128->true_peak, ebur128->true_peaks, TRUE); > > /* For integrated loudness, gating blocks are 400ms long with 75% > * overlap (see BS.1770-2 p5), so a re-computation is needed each 100ms > -- > 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".