History

avfilter/af_afir: cache xfade coefficients

Paul B Mahol committed 3 years ago

Commit a0cb2921 parent 0b352e33 files · +40 −4Browse files

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

Unified · Split

3 files
  1. libavfilter/af_afir.c +35 −2
  2. libavfilter/af_afir.h +1 −0
  3. libavfilter/afir_template.c +4 −2
libavfilter/af_afir.c+35−2
@@ -298,8 +298,6 @@ static int convert_coeffs(AVFilterContext *ctx, int selir) · 297 unmodified lines
298298 part_size = 1 << av_log2(s->minp);
299299 max_part_size = 1 << av_log2(s->maxp);
300300
301− s->min_part_size = part_size;
302−
303301 for (int i = 0; left > 0; i++) {
304302 int step = part_size == max_part_size ? INT_MAX : 1 + (i == 0);
305303 int nb_partitions = FFMIN(step, (left + part_size - 1) / part_size);
@@ -592,6 +590,36 @@ FF_ENABLE_DEPRECATION_WARNINGS · 286 unmodified lines
592590 if (!s->loading)
593591 return AVERROR(ENOMEM);
594592
593+ s->xfade[0] = ff_get_audio_buffer(outlink, s->min_part_size);
594+ s->xfade[1] = ff_get_audio_buffer(outlink, s->min_part_size);
595+ if (!s->xfade[0] || !s->xfade[1])
596+ return AVERROR(ENOMEM);
597+
598+ switch (s->format) {
599+ case AV_SAMPLE_FMT_FLTP:
600+ for (int ch = 0; ch < s->nb_channels; ch++) {
601+ float *dst0 = (float *)s->xfade[0]->extended_data[ch];
602+ float *dst1 = (float *)s->xfade[1]->extended_data[ch];
603+
604+ for (int n = 0; n < s->min_part_size; n++) {
605+ dst0[n] = (n + 1.f) / s->min_part_size;
606+ dst1[n] = 1.f - dst0[n];
607+ }
608+ }
609+ break;
610+ case AV_SAMPLE_FMT_DBLP:
611+ for (int ch = 0; ch < s->nb_channels; ch++) {
612+ double *dst0 = (double *)s->xfade[0]->extended_data[ch];
613+ double *dst1 = (double *)s->xfade[1]->extended_data[ch];
614+
615+ for (int n = 0; n < s->min_part_size; n++) {
616+ dst0[n] = (n + 1.0) / s->min_part_size;
617+ dst1[n] = 1.0 - dst0[n];
618+ }
619+ }
620+ break;
621+ }
622+
595623 return 0;
596624 }
597625
@@ -610,6 +638,9 @@ static av_cold void uninit(AVFilterContext *ctx) · 12 unmodified lines
610638 av_frame_free(&s->norm_ir[i]);
611639 }
612640
641+ av_frame_free(&s->xfade[0]);
642+ av_frame_free(&s->xfade[1]);
643+
613644 av_frame_free(&s->video);
614645 }
615646
@@ -691,6 +722,8 @@ static av_cold int init(AVFilterContext *ctx) · 75 unmodified lines
691722
692723 ff_afir_init(&s->afirdsp);
693724
725+ s->min_part_size = 1 << av_log2(s->minp);
726+
694727 return 0;
695728 }
696729
libavfilter/af_afir.h+1−0
@@ -90,6 +90,7 @@ typedef struct AudioFIRContext { · 89 unmodified lines
9090 AudioFIRSegment seg[MAX_IR_STREAMS][1024];
9191
9292 AVFrame *in;
93+ AVFrame *xfade[2];
9394 AVFrame *ir[MAX_IR_STREAMS];
9495 AVFrame *norm_ir[MAX_IR_STREAMS];
9596 AVFrame *video;
libavfilter/afir_template.c+4−2
@@ -292,6 +292,8 @@ static int fn(fir_quantum)(AVFilterContext *ctx, AVFrame *out, int ch, int offse · 291 unmodified lines
292292 ftype *blockout, *ptr = (ftype *)out->extended_data[ch] + offset;
293293 const int min_part_size = s->min_part_size;
294294 const int nb_samples = FFMIN(min_part_size, out->nb_samples - offset);
295+ const ftype *xfade0 = (const ftype *)s->xfade[0]->extended_data[ch];
296+ const ftype *xfade1 = (const ftype *)s->xfade[1]->extended_data[ch];
295297 const int nb_segments = s->nb_segments[selir];
296298 const float dry_gain = s->dry_gain;
297299
@@ -370,7 +372,7 @@ static int fn(fir_quantum)(AVFilterContext *ctx, AVFrame *out, int ch, int offse · 72 unmodified lines
370372 if (selir == s->selir) {
371373 if (s->loading[ch] <= min_part_size) {
372374 for (int n = 0; n < nb_samples; n++)
373− ptr[n] += dst[n] * ((n + 1.f) / nb_samples);
375+ ptr[n] += dst[n] * xfade0[n];
374376 }
375377 } else {
376378 fn(fir_fadd)(s, ptr, dst, nb_samples);
@@ -388,7 +390,7 @@ static int fn(fir_quantum)(AVFilterContext *ctx, AVFrame *out, int ch, int offse · 11 unmodified lines
388390 if (selir != s->selir) {
389391 if (s->loading[ch] <= min_part_size) {
390392 for (int n = 0; n < nb_samples; n++)
391− ptr[n] *= (nb_samples - n * 1.f) / nb_samples;
393+ ptr[n] *= xfade1[n];
392394 }
393395 return 0;
394396 }

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