History

avfilter/af_silenceremove: use separate variable for size of cache

Paul B Mahol committed 3 years ago

Commit aa4acc11 parent 364c03d2 files · +20 −5Browse files

Showing the changes to libavfilter (2 of 2 files). Show all

Unified · Split

2 files
  1. libavfilter/af_silenceremove.c +15 −2
  2. libavfilter/silenceremove_template.c +5 −3
libavfilter/af_silenceremove.c+15−2
@@ -94,6 +94,7 @@ typedef struct SilenceRemoveContext { · 93 unmodified lines
9494 int *stop_back;
9595
9696 int64_t window_duration;
97+ int cache_size;
9798
9899 int start_window_pos;
99100 int start_window_size;
@@ -224,10 +225,22 @@ static int config_output(AVFilterLink *outlink) · 124 unmodified lines
224225 AVFilterContext *ctx = outlink->src;
225226 SilenceRemoveContext *s = ctx->priv;
226227
228+ switch (s->detection) {
229+ case D_AVG:
230+ case D_RMS:
231+ s->cache_size = 1;
232+ break;
233+ case D_MEDIAN:
234+ case D_PEAK:
235+ case D_PTP:
236+ s->cache_size = s->window_duration;
237+ break;
238+ }
239+
227240 s->start_window = ff_get_audio_buffer(outlink, s->window_duration);
228241 s->stop_window = ff_get_audio_buffer(outlink, s->window_duration);
229− s->start_cache = av_calloc(outlink->ch_layout.nb_channels, s->window_duration * sizeof(*s->start_cache));
230− s->stop_cache = av_calloc(outlink->ch_layout.nb_channels, s->window_duration * sizeof(*s->stop_cache));
242+ s->start_cache = av_calloc(outlink->ch_layout.nb_channels, s->cache_size * sizeof(*s->start_cache));
243+ s->stop_cache = av_calloc(outlink->ch_layout.nb_channels, s->cache_size * sizeof(*s->stop_cache));
231244 if (!s->start_window || !s->stop_window || !s->start_cache || !s->stop_cache)
232245 return AVERROR(ENOMEM);
233246
libavfilter/silenceremove_template.c+5−3
@@ -328,6 +328,7 @@ static void fn(filter_start)(AVFilterContext *ctx, · 327 unmodified lines
328328 ftype *start_cache = (ftype *)s->start_cache;
329329 const int start_silence = s->start_silence;
330330 int window_size = start_window_nb_samples;
331+ const int cache_size = s->cache_size;
331332 int *front = s->start_front;
332333 int *back = s->start_back;
333334
@@ -352,7 +353,7 @@ static void fn(filter_start)(AVFilterContext *ctx, · 18 unmodified lines
352353 ftype start_ow = startw[start_wpos + ch];
353354 ftype tstart;
354355
355− tstart = fn(s->compute)(start_cache + ch * start_window_nb_samples,
356+ tstart = fn(s->compute)(start_cache + ch * cache_size,
356357 start_sample,
357358 start_ow,
358359 window_size,
@@ -423,8 +424,9 @@ static void fn(filter_stop)(AVFilterContext *ctx, · 64 unmodified lines
423424 const int stop_duration = s->stop_duration;
424425 ftype *stop_cache = (ftype *)s->stop_cache;
425426 const int stop_silence = s->stop_silence;
426− const int restart = s->restart;
427427 int window_size = stop_window_nb_samples;
428+ const int cache_size = s->cache_size;
429+ const int restart = s->restart;
428430 int *front = s->stop_front;
429431 int *back = s->stop_back;
430432
@@ -446,7 +448,7 @@ static void fn(filter_stop)(AVFilterContext *ctx, · 15 unmodified lines
446448 ftype stop_ow = stopw[stop_wpos + ch];
447449 ftype tstop;
448450
449− tstop = fn(s->compute)(stop_cache + ch * stop_window_nb_samples,
451+ tstop = fn(s->compute)(stop_cache + ch * cache_size,
450452 stop_sample,
451453 stop_ow,
452454 window_size,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t