diff options
author | Paul B Mahol <onemda@gmail.com> | 2023-11-19 23:45:19 +0100 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2023-11-19 23:47:52 +0100 |
commit | 6579d95df3d16e73735e0bf6cc5b02aaef0fb38f (patch) | |
tree | 7f3620150c269c303644c360a3066bab7be3c957 /libavfilter/afir_template.c | |
parent | bbdd604b9ed9566ea996514d2068c3f89c81efb6 (diff) | |
download | ffmpeg-6579d95df3d16e73735e0bf6cc5b02aaef0fb38f.tar.gz |
avfilter/af_afir: refactor crossfade code
Diffstat (limited to 'libavfilter/afir_template.c')
-rw-r--r-- | libavfilter/afir_template.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/libavfilter/afir_template.c b/libavfilter/afir_template.c index fb7bfca168..08e1ca4692 100644 --- a/libavfilter/afir_template.c +++ b/libavfilter/afir_template.c @@ -242,3 +242,53 @@ static int fn(fir_quantum)(AVFilterContext *ctx, AVFrame *out, int ch, int ioffs return 0; } + +static void fn(fir_quantums)(AVFilterContext *ctx, AudioFIRContext *s, AVFrame *out, + int min_part_size, int ch, int offset, + int prev_selir, int selir) +{ + if (ctx->is_disabled || s->prev_is_disabled) { + const ftype *in = (const ftype *)s->in->extended_data[ch] + offset; + const ftype *xfade0 = (const ftype *)s->xfade[0]->extended_data[ch]; + const ftype *xfade1 = (const ftype *)s->xfade[1]->extended_data[ch]; + ftype *src0 = (ftype *)s->fadein[0]->extended_data[ch]; + ftype *src1 = (ftype *)s->fadein[1]->extended_data[ch]; + ftype *dst = ((ftype *)out->extended_data[ch]) + offset; + + if (ctx->is_disabled && !s->prev_is_disabled) { + memset(src0, 0, min_part_size * sizeof(ftype)); + fn(fir_quantum)(ctx, s->fadein[0], ch, offset, 0, selir); + for (int n = 0; n < min_part_size; n++) + dst[n] = xfade1[n] * src0[n] + xfade0[n] * in[n]; + } else if (!ctx->is_disabled && s->prev_is_disabled) { + memset(src1, 0, min_part_size * sizeof(ftype)); + fn(fir_quantum)(ctx, s->fadein[1], ch, offset, 0, selir); + for (int n = 0; n < min_part_size; n++) + dst[n] = xfade1[n] * in[n] + xfade0[n] * src1[n]; + } else { + memcpy(dst, in, sizeof(ftype) * min_part_size); + } + } else if (prev_selir != selir && s->loading[ch] != 0) { + const ftype *xfade0 = (const ftype *)s->xfade[0]->extended_data[ch]; + const ftype *xfade1 = (const ftype *)s->xfade[1]->extended_data[ch]; + ftype *src0 = (ftype *)s->fadein[0]->extended_data[ch]; + ftype *src1 = (ftype *)s->fadein[1]->extended_data[ch]; + ftype *dst = ((ftype *)out->extended_data[ch]) + offset; + + memset(src0, 0, min_part_size * sizeof(ftype)); + memset(src1, 0, min_part_size * sizeof(ftype)); + + fn(fir_quantum)(ctx, s->fadein[0], ch, offset, 0, prev_selir); + fn(fir_quantum)(ctx, s->fadein[1], ch, offset, 0, selir); + + if (s->loading[ch] > s->max_offset[selir]) { + for (int n = 0; n < min_part_size; n++) + dst[n] = xfade1[n] * src0[n] + xfade0[n] * src1[n]; + s->loading[ch] = 0; + } else { + memcpy(dst, src0, min_part_size * sizeof(ftype)); + } + } else { + fn(fir_quantum)(ctx, out, ch, offset, offset, selir); + } +} |