History

avfilter/af_acrossover: reduce memory usage

Split biquad coefficients from biquad state.

Paul B Mahol committed 5 years ago

Commit c5cdec91 parent 7eb9cf51 file · +42 −33Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/af_acrossover.c+42−33
@@ -39,9 +39,12 @@ · 38 unmodified lines
3939 #define MAX_SPLITS 16
4040 #define MAX_BANDS MAX_SPLITS + 1
4141
42−typedef struct BiquadContext {
42+typedef struct BiquadCoeffs {
4343 double b0, b1, b2;
4444 double a1, a2;
45+} BiquadCoeffs;
46+
47+typedef struct BiquadContext {
4548 double z1, z2;
4649 } BiquadContext;
4750
@@ -65,6 +68,10 @@ typedef struct AudioCrossoverContext { · 17 unmodified lines
6568 int nb_splits;
6669 float *splits;
6770
71+ BiquadCoeffs lp[MAX_BANDS][20];
72+ BiquadCoeffs hp[MAX_BANDS][20];
73+ BiquadCoeffs ap[MAX_BANDS][20];
74+
6875 CrossoverChannel *xover;
6976
7077 AVFrame *input_frame;
@@ -158,7 +165,7 @@ static av_cold int init(AVFilterContext *ctx) · 87 unmodified lines
158165 return ret;
159166 }
160167
161−static void set_lp(BiquadContext *b, double fc, double q, double sr)
168+static void set_lp(BiquadCoeffs *b, double fc, double q, double sr)
162169 {
163170 double omega = M_PI * fc / sr;
164171 double cosine = cos(omega);
@@ -178,7 +185,7 @@ static void set_lp(BiquadContext *b, double fc, double q, double sr) · 13 unmodified lines
178185 b->a2 = -a2 / a0;
179186 }
180187
181−static void set_hp(BiquadContext *b, double fc, double q, double sr)
188+static void set_hp(BiquadCoeffs *b, double fc, double q, double sr)
182189 {
183190 double omega = M_PI * fc / sr;
184191 double cosine = cos(omega);
@@ -198,7 +205,7 @@ static void set_hp(BiquadContext *b, double fc, double q, double sr) · 13 unmodified lines
198205 b->a2 = -a2 / a0;
199206 }
200207
201−static void set_ap(BiquadContext *b, double fc, double q, double sr)
208+static void set_ap(BiquadCoeffs *b, double fc, double q, double sr)
202209 {
203210 double omega = M_PI * fc / sr;
204211 double cosine = cos(omega);
@@ -218,7 +225,7 @@ static void set_ap(BiquadContext *b, double fc, double q, double sr) · 13 unmodified lines
218225 b->a2 = -a2 / a0;
219226 }
220227
221−static void set_ap1(BiquadContext *b, double fc, double sr)
228+static void set_ap1(BiquadCoeffs *b, double fc, double sr)
222229 {
223230 double omega = M_PI * fc / sr;
224231
@@ -268,15 +275,16 @@ static int query_formats(AVFilterContext *ctx) · 43 unmodified lines
268275 }
269276
270277 #define BIQUAD_PROCESS(name, type) \
271−static void biquad_process_## name(BiquadContext *b, \
278+static void biquad_process_## name(const BiquadCoeffs *const c,\
279+ BiquadContext *b, \
272280 type *dst, const type *src, \
273281 int nb_samples) \
274282 { \
275− const type b0 = b->b0; \
276− const type b1 = b->b1; \
277− const type b2 = b->b2; \
278− const type a1 = b->a1; \
279− const type a2 = b->a2; \
283+ const type b0 = c->b0; \
284+ const type b1 = c->b1; \
285+ const type b2 = c->b2; \
286+ const type a1 = c->a1; \
287+ const type a2 = c->a2; \
280288 type z1 = b->z1; \
281289 type z2 = b->z2; \
282290 \
@@ -321,16 +329,18 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, i · 38 unmodified lines
321329 type *dst = (type *)frames[band + 1]->extended_data[ch]; \
322330 const type *hsrc = f == 0 ? prv : dst; \
323331 BiquadContext *hp = &xover->hp[band][f]; \
332+ BiquadCoeffs *hpc = &s->hp[band][f]; \
324333 \
325− biquad_process_## name(hp, dst, hsrc, nb_samples); \
334+ biquad_process_## name(hpc, hp, dst, hsrc, nb_samples); \
326335 } \
327336 \
328337 for (int f = 0; band + 1 < ctx->nb_outputs && f < s->filter_count; f++) { \
329338 type *dst = (type *)frames[band]->extended_data[ch]; \
330339 const type *lsrc = dst; \
331340 BiquadContext *lp = &xover->lp[band][f]; \
341+ BiquadCoeffs *lpc = &s->lp[band][f]; \
332342 \
333− biquad_process_## name(lp, dst, lsrc, nb_samples); \
343+ biquad_process_## name(lpc, lp, dst, lsrc, nb_samples); \
334344 } \
335345 \
336346 for (int aband = band + 1; aband + 1 < ctx->nb_outputs; aband++) { \
@@ -338,16 +348,18 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, i · 1 unmodified line
338348 const type *asrc = (const type *)frames[band]->extended_data[ch]; \
339349 type *dst = (type *)frames[band]->extended_data[ch]; \
340350 BiquadContext *ap = &xover->ap[band][aband][0]; \
351+ BiquadCoeffs *apc = &s->ap[aband][0]; \
341352 \
342− biquad_process_## name(ap, dst, asrc, nb_samples); \
353+ biquad_process_## name(apc, ap, dst, asrc, nb_samples); \
343354 } \
344355 \
345356 for (int f = s->first_order; f < s->ap_filter_count; f++) { \
346357 const type *asrc = (const type *)frames[band]->extended_data[ch]; \
347358 type *dst = (type *)frames[band]->extended_data[ch]; \
348359 BiquadContext *ap = &xover->ap[band][aband][f]; \
360+ BiquadCoeffs *apc = &s->ap[aband][f]; \
349361 \
350− biquad_process_## name(ap, dst, asrc, nb_samples); \
362+ biquad_process_## name(apc, ap, dst, asrc, nb_samples); \
351363 } \
352364 } \
353365 } \
@@ -385,29 +397,26 @@ static int config_input(AVFilterLink *inlink) · 31 unmodified lines
385397 s->ap_filter_count = s->filter_count / 2 + s->first_order;
386398 calc_q_factors(s->order, q);
387399
388− for (int ch = 0; ch < inlink->channels; ch++) {
389− for (int band = 0; band <= s->nb_splits; band++) {
390− if (s->first_order) {
391− set_lp(&s->xover[ch].lp[band][0], s->splits[band], 0.5, sample_rate);
392− set_hp(&s->xover[ch].hp[band][0], s->splits[band], 0.5, sample_rate);
393− }
400+ for (int band = 0; band <= s->nb_splits; band++) {
401+ if (s->first_order) {
402+ set_lp(&s->lp[band][0], s->splits[band], 0.5, sample_rate);
403+ set_hp(&s->hp[band][0], s->splits[band], 0.5, sample_rate);
404+ }
394405
395− for (int n = s->first_order; n < s->filter_count; n++) {
396− const int idx = s->filter_count / 2 - ((n + s->first_order) / 2 - s->first_order) - 1;
406+ for (int n = s->first_order; n < s->filter_count; n++) {
407+ const int idx = s->filter_count / 2 - ((n + s->first_order) / 2 - s->first_order) - 1;
397408
398− set_lp(&s->xover[ch].lp[band][n], s->splits[band], q[idx], sample_rate);
399− set_hp(&s->xover[ch].hp[band][n], s->splits[band], q[idx], sample_rate);
400− }
409+ set_lp(&s->lp[band][n], s->splits[band], q[idx], sample_rate);
410+ set_hp(&s->hp[band][n], s->splits[band], q[idx], sample_rate);
411+ }
401412
402− for (int x = 0; x <= s->nb_splits && s->first_order; x++)
403− set_ap1(&s->xover[ch].ap[x][band][0], s->splits[band], sample_rate);
413+ if (s->first_order)
414+ set_ap1(&s->ap[band][0], s->splits[band], sample_rate);
404415
405− for (int n = s->first_order; n < s->ap_filter_count; n++) {
406− const int idx = (s->filter_count / 2 - ((n * 2 + s->first_order) / 2 - s->first_order) - 1);
416+ for (int n = s->first_order; n < s->ap_filter_count; n++) {
417+ const int idx = (s->filter_count / 2 - ((n * 2 + s->first_order) / 2 - s->first_order) - 1);
407418
408− for (int x = 0; x <= s->nb_splits; x++)
409− set_ap(&s->xover[ch].ap[x][band][n], s->splits[band], q[idx], sample_rate);
410− }
419+ set_ap(&s->ap[band][n], s->splits[band], q[idx], sample_rate);
411420 }
412421 }
413422

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