avfilter/silenceremove_template: fix peak detector

The implementation was not working correctly.
pull/389/head
Paul B Mahol 2 years ago
parent 29710dd7f2
commit 68d0b881de
  1. 36
      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]) {
back++;
if (back >= size)
back = 0;
if (!empty && abs_sample >= peak[front]) {
while (1) {
peak[front] = ZERO;
if (back == front) {
empty = 1;
break;
}
if (front != back && FABS(wsample) == peak[front]) {
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 (!empty) {
back--;
if (back < 0)
back = size - 1;
av_assert2(back != front);
peak[back] = abs_sample;
}
peak[back] = abs_sample;
r = peak[front];
*ffront = front;

Loading…
Cancel
Save