avfilter/af_afir: refactor crossfade code
This commit is contained in:
parent
bbdd604b9e
commit
6579d95df3
@ -63,96 +63,10 @@ static int fir_channel(AVFilterContext *ctx, AVFrame *out, int ch)
|
|||||||
for (int offset = 0; offset < out->nb_samples; offset += min_part_size) {
|
for (int offset = 0; offset < out->nb_samples; offset += min_part_size) {
|
||||||
switch (s->format) {
|
switch (s->format) {
|
||||||
case AV_SAMPLE_FMT_FLTP:
|
case AV_SAMPLE_FMT_FLTP:
|
||||||
if (ctx->is_disabled || s->prev_is_disabled) {
|
fir_quantums_float(ctx, s, out, min_part_size, ch, offset, prev_selir, selir);
|
||||||
const float *in = (const float *)s->in->extended_data[ch] + offset;
|
|
||||||
const float *xfade0 = (const float *)s->xfade[0]->extended_data[ch];
|
|
||||||
const float *xfade1 = (const float *)s->xfade[1]->extended_data[ch];
|
|
||||||
float *src0 = (float *)s->fadein[0]->extended_data[ch];
|
|
||||||
float *src1 = (float *)s->fadein[1]->extended_data[ch];
|
|
||||||
float *dst = ((float *)out->extended_data[ch]) + offset;
|
|
||||||
|
|
||||||
if (ctx->is_disabled && !s->prev_is_disabled) {
|
|
||||||
memset(src0, 0, min_part_size * sizeof(float));
|
|
||||||
fir_quantum_float(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(float));
|
|
||||||
fir_quantum_float(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(float) * min_part_size);
|
|
||||||
}
|
|
||||||
} else if (prev_selir != selir && s->loading[ch] != 0) {
|
|
||||||
const float *xfade0 = (const float *)s->xfade[0]->extended_data[ch];
|
|
||||||
const float *xfade1 = (const float *)s->xfade[1]->extended_data[ch];
|
|
||||||
float *src0 = (float *)s->fadein[0]->extended_data[ch];
|
|
||||||
float *src1 = (float *)s->fadein[1]->extended_data[ch];
|
|
||||||
float *dst = ((float *)out->extended_data[ch]) + offset;
|
|
||||||
|
|
||||||
memset(src0, 0, min_part_size * sizeof(float));
|
|
||||||
memset(src1, 0, min_part_size * sizeof(float));
|
|
||||||
|
|
||||||
fir_quantum_float(ctx, s->fadein[0], ch, offset, 0, prev_selir);
|
|
||||||
fir_quantum_float(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(float));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fir_quantum_float(ctx, out, ch, offset, offset, selir);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case AV_SAMPLE_FMT_DBLP:
|
case AV_SAMPLE_FMT_DBLP:
|
||||||
if (ctx->is_disabled || s->prev_is_disabled) {
|
fir_quantums_double(ctx, s, out, min_part_size, ch, offset, prev_selir, selir);
|
||||||
const double *in = (const double *)s->in->extended_data[ch] + offset;
|
|
||||||
const double *xfade0 = (const double *)s->xfade[0]->extended_data[ch];
|
|
||||||
const double *xfade1 = (const double *)s->xfade[1]->extended_data[ch];
|
|
||||||
double *src0 = (double *)s->fadein[0]->extended_data[ch];
|
|
||||||
double *src1 = (double *)s->fadein[1]->extended_data[ch];
|
|
||||||
double *dst = ((double *)out->extended_data[ch]) + offset;
|
|
||||||
|
|
||||||
if (ctx->is_disabled && !s->prev_is_disabled) {
|
|
||||||
memset(src0, 0, min_part_size * sizeof(double));
|
|
||||||
fir_quantum_double(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(double));
|
|
||||||
fir_quantum_double(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(double) * min_part_size);
|
|
||||||
}
|
|
||||||
} else if (prev_selir != selir && s->loading[ch] != 0) {
|
|
||||||
const double *xfade0 = (const double *)s->xfade[0]->extended_data[ch];
|
|
||||||
const double *xfade1 = (const double *)s->xfade[1]->extended_data[ch];
|
|
||||||
double *src0 = (double *)s->fadein[0]->extended_data[ch];
|
|
||||||
double *src1 = (double *)s->fadein[1]->extended_data[ch];
|
|
||||||
double *dst = ((double *)out->extended_data[ch]) + offset;
|
|
||||||
|
|
||||||
memset(src0, 0, min_part_size * sizeof(double));
|
|
||||||
memset(src1, 0, min_part_size * sizeof(double));
|
|
||||||
|
|
||||||
fir_quantum_double(ctx, s->fadein[0], ch, offset, 0, prev_selir);
|
|
||||||
fir_quantum_double(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(double));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fir_quantum_double(ctx, out, ch, offset, offset, selir);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,3 +242,53 @@ static int fn(fir_quantum)(AVFilterContext *ctx, AVFrame *out, int ch, int ioffs
|
|||||||
|
|
||||||
return 0;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user