mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-28 18:32:22 +00:00
avfilter/af_silenceremove: add ptp detector
This commit is contained in:
parent
163e3a299e
commit
e53260c1f4
@ -6472,6 +6472,8 @@ Root squared mean of absolute values of samples in moving window.
|
||||
Maximum of absolute values of samples in moving window.
|
||||
@item median
|
||||
Median of absolute values of samples in moving window.
|
||||
@item ptp
|
||||
Absolute of max peak to min peak difference of samples in moving window.
|
||||
@end table
|
||||
Default value is @code{rms}.
|
||||
|
||||
|
@ -37,6 +37,7 @@ enum SilenceDetect {
|
||||
D_RMS,
|
||||
D_PEAK,
|
||||
D_MEDIAN,
|
||||
D_PTP,
|
||||
D_NB
|
||||
};
|
||||
|
||||
@ -135,6 +136,7 @@ static const AVOption silenceremove_options[] = {
|
||||
{ "rms", "use root mean squared values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_RMS}, 0, 0, AF, "detection" },
|
||||
{ "peak", "use max absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_PEAK},0, 0, AF, "detection" },
|
||||
{ "median", "use median of absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_MEDIAN},0, 0, AF, "detection" },
|
||||
{ "ptp", "use absolute of max peak to min peak difference", 0, AV_OPT_TYPE_CONST, {.i64=D_PTP}, 0, 0, AF, "detection" },
|
||||
{ "window", "set duration of window for silence detection", OFFSET(window_duration_opt), AV_OPT_TYPE_DURATION, {.i64=20000}, 0, 100000000, AF },
|
||||
{ NULL }
|
||||
};
|
||||
@ -237,6 +239,10 @@ static int config_output(AVFilterLink *outlink)
|
||||
s->compute_flt = compute_avg_flt;
|
||||
s->compute_dbl = compute_avg_dbl;
|
||||
break;
|
||||
case D_PTP:
|
||||
s->compute_flt = compute_ptp_flt;
|
||||
s->compute_dbl = compute_ptp_dbl;
|
||||
break;
|
||||
case D_MEDIAN:
|
||||
s->compute_flt = compute_median_flt;
|
||||
s->compute_dbl = compute_median_dbl;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#undef SQRT
|
||||
#undef ZERO
|
||||
#undef ONE
|
||||
#undef TMIN
|
||||
#if DEPTH == 32
|
||||
#define SAMPLE_FORMAT flt
|
||||
#define SQRT sqrtf
|
||||
@ -31,6 +32,7 @@
|
||||
#define ftype float
|
||||
#define ZERO 0.f
|
||||
#define ONE 1.f
|
||||
#define TMIN -FLT_MAX
|
||||
#else
|
||||
#define SAMPLE_FORMAT dbl
|
||||
#define SQRT sqrt
|
||||
@ -39,6 +41,7 @@
|
||||
#define ftype double
|
||||
#define ZERO 0.0
|
||||
#define ONE 1.0
|
||||
#define TMIN -DBL_MAX
|
||||
#endif
|
||||
|
||||
#define fn3(a,b) a##_##b
|
||||
@ -233,6 +236,65 @@ static ftype fn(compute_peak)(ftype *peak, ftype sample, ftype wsample,
|
||||
return r;
|
||||
}
|
||||
|
||||
static ftype fn(compute_ptp)(ftype *peak, ftype sample, ftype wsample,
|
||||
int size, int *ffront, int *bback)
|
||||
{
|
||||
int front = *ffront;
|
||||
int back = *bback;
|
||||
int empty = front == back && peak[front] == TMIN;
|
||||
ftype r, max, min;
|
||||
|
||||
if (!empty && wsample == peak[front]) {
|
||||
peak[front] = TMIN;
|
||||
if (back != front) {
|
||||
front--;
|
||||
if (front < 0)
|
||||
front = size - 1;
|
||||
}
|
||||
empty = front == back;
|
||||
}
|
||||
|
||||
if (!empty && sample >= peak[front]) {
|
||||
while (1) {
|
||||
peak[front] = TMIN;
|
||||
if (back == front) {
|
||||
empty = 1;
|
||||
break;
|
||||
}
|
||||
front--;
|
||||
if (front < 0)
|
||||
front = size - 1;
|
||||
}
|
||||
}
|
||||
|
||||
while (!empty && sample >= peak[back]) {
|
||||
peak[back] = TMIN;
|
||||
if (back == front) {
|
||||
empty = 1;
|
||||
break;
|
||||
}
|
||||
back++;
|
||||
if (back >= size)
|
||||
back = 0;
|
||||
}
|
||||
|
||||
if (!empty) {
|
||||
back--;
|
||||
if (back < 0)
|
||||
back = size - 1;
|
||||
}
|
||||
|
||||
peak[back] = sample;
|
||||
max = peak[front];
|
||||
min = (back == front) ? -sample : sample;
|
||||
r = FABS(max - min);
|
||||
|
||||
*ffront = front;
|
||||
*bback = back;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static ftype fn(compute_rms)(ftype *cache, ftype sample, ftype wsample,
|
||||
int window_size, int *unused, int *unused2)
|
||||
{
|
||||
@ -281,7 +343,8 @@ static void fn(filter_start)(AVFilterContext *ctx,
|
||||
if (s->start_found_periods < 0)
|
||||
goto skip;
|
||||
|
||||
if (s->detection != D_PEAK && s->detection != D_MEDIAN)
|
||||
if (s->detection != D_PEAK && s->detection != D_MEDIAN &&
|
||||
s->detection != D_PTP)
|
||||
window_size = s->start_window_size;
|
||||
|
||||
for (int ch = 0; ch < nb_channels; ch++) {
|
||||
@ -374,7 +437,8 @@ static void fn(filter_stop)(AVFilterContext *ctx,
|
||||
stop_nb_samples,
|
||||
stop_window_nb_samples);
|
||||
|
||||
if (s->detection != D_PEAK && s->detection != D_MEDIAN)
|
||||
if (s->detection != D_PEAK && s->detection != D_MEDIAN &&
|
||||
s->detection != D_PTP)
|
||||
window_size = s->stop_window_size;
|
||||
|
||||
for (int ch = 0; ch < nb_channels; ch++) {
|
||||
|
Loading…
Reference in New Issue
Block a user