From b428003c1cc9da561073dff90b0d0fa4688cf64d Mon Sep 17 00:00:00 2001 From: Lynne Date: Sun, 30 Oct 2022 12:13:42 +0100 Subject: [PATCH] dcaenc: convert to lavu/tx The encoder is fixed point, and uses an MDCT only for analysis. Due to the slightly different rounding, the encoder makes a different decision, so the tests have to be adjusted as well. --- configure | 1 - libavcodec/dcaenc.c | 14 +++++++------- tests/fate/acodec.mak | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/configure b/configure index 53779e96e7..44889f7617 100755 --- a/configure +++ b/configure @@ -2807,7 +2807,6 @@ comfortnoise_encoder_select="lpc" cook_decoder_select="audiodsp sinewin" cri_decoder_select="mjpeg_decoder" cscd_decoder_suggest="zlib" -dca_encoder_select="mdct" dds_decoder_select="texturedsp" dirac_decoder_select="dirac_parse dwt golomb videodsp mpegvideoenc" dnxhd_decoder_select="blockdsp idctdsp" diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c index eec6965b5f..4cab54ef1b 100644 --- a/libavcodec/dcaenc.c +++ b/libavcodec/dcaenc.c @@ -21,8 +21,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#define FFT_FLOAT 0 - #include "libavutil/avassert.h" #include "libavutil/channel_layout.h" #include "libavutil/common.h" @@ -30,6 +28,7 @@ #include "libavutil/mem_internal.h" #include "libavutil/opt.h" #include "libavutil/thread.h" +#include "libavutil/tx.h" #include "avcodec.h" #include "codec_internal.h" #include "dca.h" @@ -39,7 +38,6 @@ #include "dcadata.h" #include "dcaenc.h" #include "encode.h" -#include "fft.h" #include "put_bits.h" #define MAX_CHANNELS 6 @@ -63,7 +61,8 @@ typedef struct DCAEncContext { AVClass *class; PutBitContext pb; DCAADPCMEncContext adpcm_ctx; - FFTContext mdct; + AVTXContext *mdct; + av_tx_fn mdct_fn; CompressionOptions options; int frame_size; int frame_bits; @@ -206,6 +205,7 @@ static int encode_init(AVCodecContext *avctx) DCAEncContext *c = avctx->priv_data; AVChannelLayout layout = avctx->ch_layout; int i, j, k, min_frame_bits; + float scale = 1.0f; int ret; if ((ret = subband_bufer_alloc(c)) < 0) @@ -287,7 +287,7 @@ static int encode_init(AVCodecContext *avctx) avctx->frame_size = 32 * SUBBAND_SAMPLES; - if ((ret = ff_mdct_init(&c->mdct, 9, 0, 1.0)) < 0) + if ((ret = av_tx_init(&c->mdct, &c->mdct_fn, AV_TX_INT32_MDCT, 0, 256, &scale, 0)) < 0) return ret; /* Init all tables */ @@ -354,7 +354,7 @@ static int encode_init(AVCodecContext *avctx) static av_cold int encode_close(AVCodecContext *avctx) { DCAEncContext *c = avctx->priv_data; - ff_mdct_end(&c->mdct); + av_tx_uninit(&c->mdct); subband_bufer_free(c); ff_dcaadpcm_free(&c->adpcm_ctx); @@ -506,7 +506,7 @@ static void calc_power(DCAEncContext *c, for (i = 0; i < 512; i++) data[i] = norm__(mul32(in[i], 0x3fffffff - (COS_T(4 * i + 2) >> 1)), 4); - c->mdct.mdct_calc(&c->mdct, coeff, data); + c->mdct_fn(c->mdct, coeff, data, sizeof(int32_t)); for (i = 0; i < 256; i++) { const int32_t cb = get_cb(c, coeff[i]); power[i] = add_cb(c, cb, cb); diff --git a/tests/fate/acodec.mak b/tests/fate/acodec.mak index 27b69ad9fc..b15b1dcc20 100644 --- a/tests/fate/acodec.mak +++ b/tests/fate/acodec.mak @@ -126,7 +126,7 @@ fate-acodec-dca2: CMD = enc_dec_pcm dts wav s16le $(SRC) -c:a dca -strict -2 -fl fate-acodec-dca2: REF = $(SRC) fate-acodec-dca2: CMP = stddev fate-acodec-dca2: CMP_SHIFT = -2048 -fate-acodec-dca2: CMP_TARGET = 535 +fate-acodec-dca2: CMP_TARGET = 534 fate-acodec-dca2: SIZE_TOLERANCE = 1632 FATE_ACODEC-$(call ENCDEC, FLAC, FLAC) += fate-acodec-flac fate-acodec-flac-exact-rice