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. 40
      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); ftype r, abs_sample = FABS(sample);
int front = *ffront; int front = *ffront;
int back = *bback; int back = *bback;
int empty = front == back && peak[front] == ZERO;
if (front != back && abs_sample > peak[front]) { if (!empty && FABS(wsample) == peak[front]) {
while (front != back) { peak[front] = ZERO;
if (back != front) {
front--; front--;
if (front < 0) if (front < 0)
front = size - 1; 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++; back++;
if (back >= size) if (back >= size)
back = 0; back = 0;
} }
if (front != back && FABS(wsample) == peak[front]) { if (!empty) {
front--; back--;
if (front < 0) if (back < 0)
front = size - 1; back = size - 1;
} }
back--;
if (back < 0)
back = size - 1;
av_assert2(back != front);
peak[back] = abs_sample; peak[back] = abs_sample;
r = peak[front]; r = peak[front];
*ffront = front; *ffront = front;

Loading…
Cancel
Save