From 978963a77b27d52000f83c647ef46b6d0c390326 Mon Sep 17 00:00:00 2001 From: Lynne Date: Tue, 1 Nov 2022 08:45:27 +0100 Subject: [PATCH] wma: convert to lavu/tx Converts both the decoder and encoders. --- configure | 8 ++++---- libavcodec/wma.c | 2 +- libavcodec/wma.h | 7 ++++--- libavcodec/wmadec.c | 13 ++++++++----- libavcodec/wmaenc.c | 9 ++++++--- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/configure b/configure index d49638b381..820f88d2c9 100755 --- a/configure +++ b/configure @@ -2992,10 +2992,10 @@ wcmv_decoder_select="inflate_wrapper" webp_decoder_select="vp8_decoder exif" wmalossless_decoder_select="llauddsp" wmapro_decoder_select="sinewin wma_freqs" -wmav1_decoder_select="mdct sinewin wma_freqs" -wmav1_encoder_select="mdct sinewin wma_freqs" -wmav2_decoder_select="mdct sinewin wma_freqs" -wmav2_encoder_select="mdct sinewin wma_freqs" +wmav1_decoder_select="sinewin wma_freqs" +wmav1_encoder_select="sinewin wma_freqs" +wmav2_decoder_select="sinewin wma_freqs" +wmav2_encoder_select="sinewin wma_freqs" wmavoice_decoder_select="lsp rdft dct sinewin" wmv1_decoder_select="msmpeg4dec" wmv1_encoder_select="msmpeg4enc" diff --git a/libavcodec/wma.c b/libavcodec/wma.c index ddf50d087c..41d16e52f8 100644 --- a/libavcodec/wma.c +++ b/libavcodec/wma.c @@ -369,7 +369,7 @@ int ff_wma_end(AVCodecContext *avctx) int i; for (i = 0; i < s->nb_block_sizes; i++) - ff_mdct_end(&s->mdct_ctx[i]); + av_tx_uninit(&s->mdct_ctx[i]); if (s->use_exp_vlc) ff_free_vlc(&s->exp_vlc); diff --git a/libavcodec/wma.h b/libavcodec/wma.h index 80e52687fd..5dc604154d 100644 --- a/libavcodec/wma.h +++ b/libavcodec/wma.h @@ -24,9 +24,9 @@ #include "libavutil/float_dsp.h" #include "libavutil/mem_internal.h" +#include "libavutil/tx.h" #include "avcodec.h" -#include "fft.h" #include "get_bits.h" #include "put_bits.h" @@ -115,8 +115,9 @@ typedef struct WMACodecContext { float max_exponent[MAX_CHANNELS]; WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE]; DECLARE_ALIGNED(32, float, coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE]; - DECLARE_ALIGNED(32, FFTSample, output)[BLOCK_MAX_SIZE * 2]; - FFTContext mdct_ctx[BLOCK_NB_SIZES]; + DECLARE_ALIGNED(32, float, output)[BLOCK_MAX_SIZE * 2]; + AVTXContext *mdct_ctx[BLOCK_NB_SIZES]; + av_tx_fn mdct_fn[BLOCK_NB_SIZES]; const float *windows[BLOCK_NB_SIZES]; /* output buffer for one frame and the last for IMDCT windowing */ DECLARE_ALIGNED(32, float, frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE * 2]; diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c index 4bc6a28daf..15d6fb42b2 100644 --- a/libavcodec/wmadec.c +++ b/libavcodec/wmadec.c @@ -111,8 +111,9 @@ static av_cold int wma_decode_init(AVCodecContext *avctx) /* init MDCT */ for (i = 0; i < s->nb_block_sizes; i++) { - ret = ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, - 1, 1.0 / 32768.0); + float scale = 1.0 / 32768.0; + ret = av_tx_init(&s->mdct_ctx[i], &s->mdct_fn[i], AV_TX_FLOAT_MDCT, + 1, 1 << (s->frame_len_bits - i), &scale, AV_TX_FULL_IMDCT); if (ret < 0) return ret; } @@ -448,7 +449,8 @@ static int wma_decode_block(WMACodecContext *s) int coef_nb_bits, total_gain; int nb_coefs[MAX_CHANNELS]; float mdct_norm; - FFTContext *mdct; + AVTXContext *mdct; + av_tx_fn mdct_fn; #ifdef TRACE ff_tlog(s->avctx, "***decode_block: %d:%d\n", @@ -757,14 +759,15 @@ static int wma_decode_block(WMACodecContext *s) } next: - mdct = &s->mdct_ctx[bsize]; + mdct = s->mdct_ctx[bsize]; + mdct_fn = s->mdct_fn[bsize]; for (ch = 0; ch < channels; ch++) { int n4, index; n4 = s->block_len / 2; if (s->channel_coded[ch]) - mdct->imdct_calc(mdct, s->output, s->coefs[ch]); + mdct_fn(mdct, s->output, s->coefs[ch], sizeof(float)); else if (!(s->ms_stereo && ch == 1)) memset(s->output, 0, sizeof(s->output)); diff --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c index 90bb6949cb..2c647af13b 100644 --- a/libavcodec/wmaenc.c +++ b/libavcodec/wmaenc.c @@ -92,7 +92,9 @@ static av_cold int encode_init(AVCodecContext *avctx) /* init MDCT */ for (i = 0; i < s->nb_block_sizes; i++) { - ret = ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 0, 1.0); + float scale = 1.0f; + ret = av_tx_init(&s->mdct_ctx[i], &s->mdct_fn[i], AV_TX_FLOAT_MDCT, + 0, 1 << (s->frame_len_bits - i), &scale, 0); if (ret < 0) return ret; } @@ -112,7 +114,8 @@ static int apply_window_and_mdct(AVCodecContext *avctx, const AVFrame *frame) const float *const *audio = (const float *const *) frame->extended_data; int len = frame->nb_samples; int window_index = s->frame_len_bits - s->block_len_bits; - FFTContext *mdct = &s->mdct_ctx[window_index]; + AVTXContext *mdct = s->mdct_ctx[window_index]; + av_tx_fn mdct_fn = s->mdct_fn[window_index]; int ch; const float *win = s->windows[window_index]; int window_len = 1 << s->block_len_bits; @@ -124,7 +127,7 @@ static int apply_window_and_mdct(AVCodecContext *avctx, const AVFrame *frame) s->fdsp->vector_fmul_reverse(&s->output[window_len], s->frame_out[ch], win, len); s->fdsp->vector_fmul(s->frame_out[ch], s->frame_out[ch], win, len); - mdct->mdct_calc(mdct, s->coefs[ch], s->output); + mdct_fn(mdct, s->coefs[ch], s->output, sizeof(float)); if (!isfinite(s->coefs[ch][0])) { av_log(avctx, AV_LOG_ERROR, "Input contains NaN/+-Inf\n"); return AVERROR(EINVAL);