[FFmpeg-cvslog] avfilter/silenceremove_template: fix peak detector
Paul B Mahol
git at videolan.org
Sat May 27 01:35:37 EEST 2023
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Fri May 26 22:29:31 2023 +0200| [68d0b881dea35960275fb168030ae1f19dcf1a0f] | committer: Paul B Mahol
avfilter/silenceremove_template: fix peak detector
The implementation was not working correctly.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=68d0b881dea35960275fb168030ae1f19dcf1a0f
---
libavfilter/silenceremove_template.c | 40 +++++++++++++++++++++++++-----------
1 file changed, 28 insertions(+), 12 deletions(-)
diff --git a/libavfilter/silenceremove_template.c b/libavfilter/silenceremove_template.c
index f5f0957240..be51beb300 100644
--- a/libavfilter/silenceremove_template.c
+++ b/libavfilter/silenceremove_template.c
@@ -117,33 +117,49 @@ static ftype fn(compute_peak)(ftype *peak, ftype sample, ftype wsample,
ftype r, abs_sample = FABS(sample);
int front = *ffront;
int back = *bback;
+ int empty = front == back && peak[front] == ZERO;
- if (front != back && abs_sample > peak[front]) {
- while (front != back) {
+ if (!empty && FABS(wsample) == peak[front]) {
+ peak[front] = ZERO;
+ if (back != front) {
front--;
if (front < 0)
front = size - 1;
}
+ empty = front == back;
}
- while (front != back && abs_sample > peak[back]) {
+ if (!empty && abs_sample >= peak[front]) {
+ while (1) {
+ peak[front] = ZERO;
+ if (back == front) {
+ empty = 1;
+ break;
+ }
+ front--;
+ if (front < 0)
+ front = size - 1;
+ }
+ }
+
+ while (!empty && abs_sample >= peak[back]) {
+ peak[back] = ZERO;
+ if (back == front) {
+ empty = 1;
+ break;
+ }
back++;
if (back >= size)
back = 0;
}
- if (front != back && FABS(wsample) == peak[front]) {
- front--;
- if (front < 0)
- front = size - 1;
+ if (!empty) {
+ back--;
+ if (back < 0)
+ back = size - 1;
}
- back--;
- if (back < 0)
- back = size - 1;
- av_assert2(back != front);
peak[back] = abs_sample;
-
r = peak[front];
*ffront = front;
More information about the ffmpeg-cvslog
mailing list