lavu/tx: generalize MDCTs

The same code can perform any-length MDCTs with minimal changes.
This commit is contained in:
Lynne 2022-09-10 02:28:10 +02:00
parent 645a1f4422
commit 51172223fd
No known key found for this signature in database
GPG Key ID: A2FEA5F03F034464

View File

@ -940,12 +940,12 @@ static const FFTXCodelet TX_NAME(ff_tx_mdct_naive_inv_def) = {
.prio = FF_TX_PRIO_MIN, .prio = FF_TX_PRIO_MIN,
}; };
static av_cold int TX_NAME(ff_tx_mdct_sr_init)(AVTXContext *s, static av_cold int TX_NAME(ff_tx_mdct_init)(AVTXContext *s,
const FFTXCodelet *cd, const FFTXCodelet *cd,
uint64_t flags, uint64_t flags,
FFTXCodeletOptions *opts, FFTXCodeletOptions *opts,
int len, int inv, int len, int inv,
const void *scale) const void *scale)
{ {
int ret; int ret;
FFTXCodeletOptions sub_opts = { .invert_lookup = inv }; FFTXCodeletOptions sub_opts = { .invert_lookup = inv };
@ -955,32 +955,49 @@ static av_cold int TX_NAME(ff_tx_mdct_sr_init)(AVTXContext *s,
flags &= ~FF_TX_OUT_OF_PLACE; /* We want the subtransform to be */ flags &= ~FF_TX_OUT_OF_PLACE; /* We want the subtransform to be */
flags |= AV_TX_INPLACE; /* in-place */ flags |= AV_TX_INPLACE; /* in-place */
flags |= FF_TX_PRESHUFFLE; /* This function handles the permute step */ flags |= FF_TX_PRESHUFFLE; /* First try with an in-place transform */
if ((ret = ff_tx_init_subtx(s, TX_TYPE(FFT), flags, &sub_opts, len >> 1, if ((ret = ff_tx_init_subtx(s, TX_TYPE(FFT), flags, &sub_opts, len >> 1,
inv, scale))) inv, scale))) {
return ret; flags &= ~FF_TX_PRESHUFFLE; /* Now try with a generic FFT */
if ((ret = ff_tx_init_subtx(s, TX_TYPE(FFT), flags, &sub_opts, len >> 1,
inv, scale)))
return ret;
}
if ((ret = TX_TAB(ff_tx_mdct_gen_exp)(s, inv ? s->sub->map : NULL))) /* If we need to preshuffle just steal the map from the subcontext */
if (s->sub[0].flags & FF_TX_PRESHUFFLE) {
s->map = s->sub[0].map;
s->sub[0].map = NULL;
} else {
s->map = av_malloc((len >> 1)*sizeof(*s->map));
if (!s->map)
return AVERROR(ENOMEM);
for (int i = 0; i < len >> 1; i++)
s->map[i] = i;
}
if ((ret = TX_TAB(ff_tx_mdct_gen_exp)(s, inv ? s->map : NULL)))
return ret; return ret;
/* Saves a multiply in a hot path. */ /* Saves a multiply in a hot path. */
if (inv) if (inv)
for (int i = 0; i < (s->len >> 1); i++) for (int i = 0; i < (s->len >> 1); i++)
s->sub->map[i] <<= 1; s->map[i] <<= 1;
return 0; return 0;
} }
static void TX_NAME(ff_tx_mdct_sr_fwd)(AVTXContext *s, void *_dst, void *_src, static void TX_NAME(ff_tx_mdct_fwd)(AVTXContext *s, void *_dst, void *_src,
ptrdiff_t stride) ptrdiff_t stride)
{ {
TXSample *src = _src, *dst = _dst; TXSample *src = _src, *dst = _dst;
TXComplex *exp = s->exp, tmp, *z = _dst; TXComplex *exp = s->exp, tmp, *z = _dst;
const int len2 = s->len >> 1; const int len2 = s->len >> 1;
const int len4 = s->len >> 2; const int len4 = s->len >> 2;
const int len3 = len2 * 3; const int len3 = len2 * 3;
const int *sub_map = s->sub->map; const int *sub_map = s->map;
stride /= sizeof(*dst); stride /= sizeof(*dst);
@ -1011,14 +1028,14 @@ static void TX_NAME(ff_tx_mdct_sr_fwd)(AVTXContext *s, void *_dst, void *_src,
} }
} }
static void TX_NAME(ff_tx_mdct_sr_inv)(AVTXContext *s, void *_dst, void *_src, static void TX_NAME(ff_tx_mdct_inv)(AVTXContext *s, void *_dst, void *_src,
ptrdiff_t stride) ptrdiff_t stride)
{ {
TXComplex *z = _dst, *exp = s->exp; TXComplex *z = _dst, *exp = s->exp;
const TXSample *src = _src, *in1, *in2; const TXSample *src = _src, *in1, *in2;
const int len2 = s->len >> 1; const int len2 = s->len >> 1;
const int len4 = s->len >> 2; const int len4 = s->len >> 2;
const int *sub_map = s->sub->map; const int *sub_map = s->map;
stride /= sizeof(*src); stride /= sizeof(*src);
in1 = src; in1 = src;
@ -1043,28 +1060,28 @@ static void TX_NAME(ff_tx_mdct_sr_inv)(AVTXContext *s, void *_dst, void *_src,
} }
} }
static const FFTXCodelet TX_NAME(ff_tx_mdct_sr_fwd_def) = { static const FFTXCodelet TX_NAME(ff_tx_mdct_fwd_def) = {
.name = TX_NAME_STR("mdct_sr_fwd"), .name = TX_NAME_STR("mdct_fwd"),
.function = TX_NAME(ff_tx_mdct_sr_fwd), .function = TX_NAME(ff_tx_mdct_fwd),
.type = TX_TYPE(MDCT), .type = TX_TYPE(MDCT),
.flags = AV_TX_UNALIGNED | FF_TX_OUT_OF_PLACE | FF_TX_FORWARD_ONLY, .flags = AV_TX_UNALIGNED | FF_TX_OUT_OF_PLACE | FF_TX_FORWARD_ONLY,
.factors[0] = 2, .factors = { 2, TX_FACTOR_ANY },
.min_len = 2, .min_len = 2,
.max_len = TX_LEN_UNLIMITED, .max_len = TX_LEN_UNLIMITED,
.init = TX_NAME(ff_tx_mdct_sr_init), .init = TX_NAME(ff_tx_mdct_init),
.cpu_flags = FF_TX_CPU_FLAGS_ALL, .cpu_flags = FF_TX_CPU_FLAGS_ALL,
.prio = FF_TX_PRIO_BASE, .prio = FF_TX_PRIO_BASE,
}; };
static const FFTXCodelet TX_NAME(ff_tx_mdct_sr_inv_def) = { static const FFTXCodelet TX_NAME(ff_tx_mdct_inv_def) = {
.name = TX_NAME_STR("mdct_sr_inv"), .name = TX_NAME_STR("mdct_inv"),
.function = TX_NAME(ff_tx_mdct_sr_inv), .function = TX_NAME(ff_tx_mdct_inv),
.type = TX_TYPE(MDCT), .type = TX_TYPE(MDCT),
.flags = AV_TX_UNALIGNED | FF_TX_OUT_OF_PLACE | FF_TX_INVERSE_ONLY, .flags = AV_TX_UNALIGNED | FF_TX_OUT_OF_PLACE | FF_TX_INVERSE_ONLY,
.factors[0] = 2, .factors = { 2, TX_FACTOR_ANY },
.min_len = 2, .min_len = 2,
.max_len = TX_LEN_UNLIMITED, .max_len = TX_LEN_UNLIMITED,
.init = TX_NAME(ff_tx_mdct_sr_init), .init = TX_NAME(ff_tx_mdct_init),
.cpu_flags = FF_TX_CPU_FLAGS_ALL, .cpu_flags = FF_TX_CPU_FLAGS_ALL,
.prio = FF_TX_PRIO_BASE, .prio = FF_TX_PRIO_BASE,
}; };
@ -1477,8 +1494,8 @@ const FFTXCodelet * const TX_NAME(ff_tx_codelet_list)[] = {
&TX_NAME(ff_tx_fft_pfa_9xM_def), &TX_NAME(ff_tx_fft_pfa_9xM_def),
&TX_NAME(ff_tx_fft_pfa_15xM_def), &TX_NAME(ff_tx_fft_pfa_15xM_def),
&TX_NAME(ff_tx_fft_naive_def), &TX_NAME(ff_tx_fft_naive_def),
&TX_NAME(ff_tx_mdct_sr_fwd_def), &TX_NAME(ff_tx_mdct_fwd_def),
&TX_NAME(ff_tx_mdct_sr_inv_def), &TX_NAME(ff_tx_mdct_inv_def),
&TX_NAME(ff_tx_mdct_pfa_3xM_fwd_def), &TX_NAME(ff_tx_mdct_pfa_3xM_fwd_def),
&TX_NAME(ff_tx_mdct_pfa_5xM_fwd_def), &TX_NAME(ff_tx_mdct_pfa_5xM_fwd_def),
&TX_NAME(ff_tx_mdct_pfa_7xM_fwd_def), &TX_NAME(ff_tx_mdct_pfa_7xM_fwd_def),