mirror of
https://github.com/librempeg/librempeg
synced 2024-11-22 18:49:58 +00:00
avfilter/af_acentercut: refactor code
Remove duplicated TX transform contexts.
This commit is contained in:
parent
3ce296c93c
commit
e9afaf62ef
@ -69,19 +69,11 @@ static int fn(cc_tx_init)(AVFilterContext *ctx)
|
||||
for (int n = 0; n < s->fft_size; n++)
|
||||
fn(s->window)[n] = SIN(M_PI*n/(s->fft_size-1));
|
||||
|
||||
ret = av_tx_init(&s->tx_ctx[0], &s->tx_fn, TX_TYPE, 0, s->fft_size * 2, &scale, 0);
|
||||
ret = av_tx_init(&s->tx_ctx, &s->tx_fn, TX_TYPE, 0, s->fft_size * 2, &scale, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = av_tx_init(&s->tx_ctx[1], &s->tx_fn, TX_TYPE, 0, s->fft_size * 2, &scale, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = av_tx_init(&s->itx_ctx[0], &s->itx_fn, TX_TYPE, 1, s->fft_size * 2, &iscale, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = av_tx_init(&s->itx_ctx[1], &s->itx_fn, TX_TYPE, 1, s->fft_size * 2, &iscale, 0);
|
||||
ret = av_tx_init(&s->itx_ctx, &s->itx_fn, TX_TYPE, 1, s->fft_size * 2, &iscale, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@ -144,8 +136,8 @@ static int fn(cc_stereo)(AVFilterContext *ctx, AVFrame *out)
|
||||
ftype *right_samples = (ftype *)s->in->extended_data[1];
|
||||
ftype *windowed_left = (ftype *)s->windowed_frame->extended_data[0];
|
||||
ftype *windowed_right = (ftype *)s->windowed_frame->extended_data[1];
|
||||
ftype *windowed_oleft = (ftype *)s->windowed_out->extended_data[0];
|
||||
ftype *windowed_oright = (ftype *)s->windowed_out->extended_data[1];
|
||||
ctype *windowed_oleft = (ctype *)s->windowed_out->extended_data[0];
|
||||
ctype *windowed_oright = (ctype *)s->windowed_out->extended_data[1];
|
||||
ftype *left_osamples = (ftype *)out->extended_data[0];
|
||||
ftype *right_osamples = (ftype *)out->extended_data[1];
|
||||
const int overlap = s->overlap;
|
||||
@ -154,37 +146,37 @@ static int fn(cc_stereo)(AVFilterContext *ctx, AVFrame *out)
|
||||
const ftype factor = s->factor;
|
||||
|
||||
// shift in/out buffers
|
||||
memmove(left_in, &left_in[overlap], offset * sizeof(ftype));
|
||||
memmove(right_in, &right_in[overlap], offset * sizeof(ftype));
|
||||
memmove(left_out, &left_out[overlap], offset * sizeof(ftype));
|
||||
memmove(right_out, &right_out[overlap], offset * sizeof(ftype));
|
||||
memmove(left_in, &left_in[overlap], offset * sizeof(*left_in));
|
||||
memmove(right_in, &right_in[overlap], offset * sizeof(*right_in));
|
||||
memmove(left_out, &left_out[overlap], offset * sizeof(*left_out));
|
||||
memmove(right_out, &right_out[overlap], offset * sizeof(*right_out));
|
||||
|
||||
memcpy(&left_in[offset], left_samples, nb_samples * sizeof(ftype));
|
||||
memcpy(&right_in[offset], right_samples, nb_samples * sizeof(ftype));
|
||||
memset(&left_out[offset], 0, overlap * sizeof(ftype));
|
||||
memset(&right_out[offset], 0, overlap * sizeof(ftype));
|
||||
memcpy(&left_in[offset], left_samples, nb_samples * sizeof(*left_in));
|
||||
memcpy(&right_in[offset], right_samples, nb_samples * sizeof(*right_in));
|
||||
memset(&left_out[offset], 0, overlap * sizeof(*left_out));
|
||||
memset(&right_out[offset], 0, overlap * sizeof(*right_out));
|
||||
|
||||
fn(apply_window)(s, left_in, windowed_left, 0);
|
||||
fn(apply_window)(s, right_in, windowed_right, 0);
|
||||
|
||||
s->tx_fn(s->tx_ctx[0], windowed_oleft, windowed_left, sizeof(ftype));
|
||||
s->tx_fn(s->tx_ctx[1], windowed_oright, windowed_right, sizeof(ftype));
|
||||
s->tx_fn(s->tx_ctx, windowed_oleft, windowed_left, sizeof(ftype));
|
||||
s->tx_fn(s->tx_ctx, windowed_oright, windowed_right, sizeof(ftype));
|
||||
|
||||
fn(center_cut)((ctype *)windowed_oleft, (ctype *)windowed_oright,
|
||||
fn(center_cut)(windowed_oleft, windowed_oright,
|
||||
s->fft_size + 1, factor);
|
||||
|
||||
s->itx_fn(s->itx_ctx[0], windowed_left, windowed_oleft, sizeof(ctype));
|
||||
s->itx_fn(s->itx_ctx[1], windowed_right, windowed_oright, sizeof(ctype));
|
||||
s->itx_fn(s->itx_ctx, windowed_left, windowed_oleft, sizeof(ctype));
|
||||
s->itx_fn(s->itx_ctx, windowed_right, windowed_oright, sizeof(ctype));
|
||||
|
||||
fn(apply_window)(s, windowed_left, left_out, 1);
|
||||
fn(apply_window)(s, windowed_right, right_out, 1);
|
||||
|
||||
if (ctx->is_disabled) {
|
||||
memcpy(left_osamples, left_in, overlap * sizeof(ftype));
|
||||
memcpy(right_osamples, right_in, overlap * sizeof(ftype));
|
||||
memcpy(left_osamples, left_in, overlap * sizeof(*left_osamples));
|
||||
memcpy(right_osamples, right_in, overlap * sizeof(*right_osamples));
|
||||
} else {
|
||||
memcpy(left_osamples, left_out, overlap * sizeof(ftype));
|
||||
memcpy(right_osamples, right_out, overlap * sizeof(ftype));
|
||||
memcpy(left_osamples, left_out, overlap * sizeof(*left_osamples));
|
||||
memcpy(right_osamples, right_out, overlap * sizeof(*right_osamples));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -49,7 +49,7 @@ typedef struct AudioCenterCutContext {
|
||||
|
||||
int (*cc_stereo)(AVFilterContext *ctx, AVFrame *out);
|
||||
|
||||
AVTXContext *tx_ctx[2], *itx_ctx[2];
|
||||
AVTXContext *tx_ctx, *itx_ctx;
|
||||
av_tx_fn tx_fn, itx_fn;
|
||||
} AudioCenterCutContext;
|
||||
|
||||
@ -185,10 +185,8 @@ static av_cold void uninit(AVFilterContext *ctx)
|
||||
av_frame_free(&s->windowed_frame);
|
||||
av_frame_free(&s->windowed_out);
|
||||
|
||||
av_tx_uninit(&s->tx_ctx[0]);
|
||||
av_tx_uninit(&s->tx_ctx[1]);
|
||||
av_tx_uninit(&s->itx_ctx[0]);
|
||||
av_tx_uninit(&s->itx_ctx[1]);
|
||||
av_tx_uninit(&s->tx_ctx);
|
||||
av_tx_uninit(&s->itx_ctx);
|
||||
}
|
||||
|
||||
static const AVFilterPad inputs[] = {
|
||||
|
Loading…
Reference in New Issue
Block a user