1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-15 14:13:16 +02:00

atrac3plus: convert to lavu/tx

This commit is contained in:
Lynne
2022-11-01 09:44:27 +01:00
parent b59e6b5d99
commit 34330adb29
4 changed files with 34 additions and 36 deletions

2
configure vendored
View File

@@ -2792,8 +2792,6 @@ asv1_encoder_select="aandcttables bswapdsp fdctdsp pixblockdsp"
asv2_decoder_select="blockdsp bswapdsp idctdsp" asv2_decoder_select="blockdsp bswapdsp idctdsp"
asv2_encoder_select="aandcttables bswapdsp fdctdsp pixblockdsp" asv2_encoder_select="aandcttables bswapdsp fdctdsp pixblockdsp"
atrac1_decoder_select="sinewin" atrac1_decoder_select="sinewin"
atrac3p_decoder_select="mdct sinewin"
atrac3pal_decoder_select="mdct sinewin"
av1_decoder_select="av1_frame_split_bsf cbs_av1" av1_decoder_select="av1_frame_split_bsf cbs_av1"
bink_decoder_select="blockdsp hpeldsp" bink_decoder_select="blockdsp hpeldsp"
binkaudio_dct_decoder_select="dct wma_freqs" binkaudio_dct_decoder_select="dct wma_freqs"

View File

@@ -32,10 +32,10 @@
#include "libavutil/float_dsp.h" #include "libavutil/float_dsp.h"
#include "libavutil/mem_internal.h" #include "libavutil/mem_internal.h"
#include "libavutil/tx.h"
#include "atrac.h" #include "atrac.h"
#include "avcodec.h" #include "avcodec.h"
#include "fft.h"
#include "get_bits.h" #include "get_bits.h"
/** Global unit sizes */ /** Global unit sizes */
@@ -172,14 +172,6 @@ void ff_atrac3p_init_vlcs(void);
int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
int num_channels, AVCodecContext *avctx); int num_channels, AVCodecContext *avctx);
/**
* Initialize IMDCT transform.
*
* @param[in] avctx ptr to the AVCodecContext
* @param[in] mdct_ctx pointer to MDCT transform context
*/
void ff_atrac3p_init_imdct(AVCodecContext *avctx, FFTContext *mdct_ctx);
/** /**
* Initialize sine waves synthesizer and ff_sine_* tables. * Initialize sine waves synthesizer and ff_sine_* tables.
*/ */
@@ -221,8 +213,9 @@ void ff_atrac3p_power_compensation(Atrac3pChanUnitCtx *ctx, AVFloatDSPContext *f
* @param[in] wind_id which MDCT window to apply * @param[in] wind_id which MDCT window to apply
* @param[in] sb subband number * @param[in] sb subband number
*/ */
void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, FFTContext *mdct_ctx, float *pIn, void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, AVTXContext *mdct_ctx,
float *pOut, int wind_id, int sb); av_tx_fn mdct_fn, float *pIn, float *pOut,
int wind_id, int sb);
/** /**
* Subband synthesis filter based on the polyphase quadrature (pseudo-QMF) * Subband synthesis filter based on the polyphase quadrature (pseudo-QMF)
@@ -233,8 +226,8 @@ void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, FFTContext *mdct_ctx, float *pIn,
* @param[in] in input data to process * @param[in] in input data to process
* @param[out] out receives processed data * @param[out] out receives processed data
*/ */
void ff_atrac3p_ipqf(FFTContext *dct_ctx, Atrac3pIPQFChannelCtx *hist, void ff_atrac3p_ipqf(AVTXContext *dct_ctx, av_tx_fn dct_fn,
const float *in, float *out); Atrac3pIPQFChannelCtx *hist, const float *in, float *out);
extern const uint16_t ff_atrac3p_qu_to_spec_pos[33]; extern const uint16_t ff_atrac3p_qu_to_spec_pos[33];
extern const float ff_atrac3p_sf_tab[64]; extern const float ff_atrac3p_sf_tab[64];

View File

@@ -69,8 +69,10 @@ typedef struct ATRAC3PContext {
DECLARE_ALIGNED(32, float, outp_buf)[2][ATRAC3P_FRAME_SAMPLES]; DECLARE_ALIGNED(32, float, outp_buf)[2][ATRAC3P_FRAME_SAMPLES];
AtracGCContext gainc_ctx; ///< gain compensation context AtracGCContext gainc_ctx; ///< gain compensation context
FFTContext mdct_ctx; AVTXContext *mdct_ctx;
FFTContext ipqf_dct_ctx; ///< IDCT context used by IPQF av_tx_fn mdct_fn;
AVTXContext *ipqf_dct_ctx; ///< IDCT context used by IPQF
av_tx_fn ipqf_dct_fn;
Atrac3pChanUnitCtx *ch_units; ///< global channel units Atrac3pChanUnitCtx *ch_units; ///< global channel units
@@ -86,8 +88,8 @@ static av_cold int atrac3p_decode_close(AVCodecContext *avctx)
av_freep(&ctx->ch_units); av_freep(&ctx->ch_units);
av_freep(&ctx->fdsp); av_freep(&ctx->fdsp);
ff_mdct_end(&ctx->mdct_ctx); av_tx_uninit(&ctx->mdct_ctx);
ff_mdct_end(&ctx->ipqf_dct_ctx); av_tx_uninit(&ctx->ipqf_dct_ctx);
return 0; return 0;
} }
@@ -170,6 +172,7 @@ static av_cold int atrac3p_decode_init(AVCodecContext *avctx)
{ {
static AVOnce init_static_once = AV_ONCE_INIT; static AVOnce init_static_once = AV_ONCE_INIT;
ATRAC3PContext *ctx = avctx->priv_data; ATRAC3PContext *ctx = avctx->priv_data;
float scale;
int i, ch, ret; int i, ch, ret;
if (!avctx->block_align) { if (!avctx->block_align) {
@@ -178,9 +181,17 @@ static av_cold int atrac3p_decode_init(AVCodecContext *avctx)
} }
/* initialize IPQF */ /* initialize IPQF */
ff_mdct_init(&ctx->ipqf_dct_ctx, 5, 1, 32.0 / 32768.0); scale = 32.0 / 32768.0;
ret = av_tx_init(&ctx->ipqf_dct_ctx, &ctx->ipqf_dct_fn, AV_TX_FLOAT_MDCT,
1, 16, &scale, 0);
if (ret < 0)
return ret;
ff_atrac3p_init_imdct(avctx, &ctx->mdct_ctx); scale = -1.0f;
ret = av_tx_init(&ctx->mdct_ctx, &ctx->mdct_fn, AV_TX_FLOAT_MDCT,
1, 128, &scale, AV_TX_FULL_IMDCT);
if (ret < 0)
return ret;
ff_atrac_init_gain_compensation(&ctx->gainc_ctx, 6, 2); ff_atrac_init_gain_compensation(&ctx->gainc_ctx, 6, 2);
@@ -288,7 +299,7 @@ static void reconstruct_frame(ATRAC3PContext *ctx, Atrac3pChanUnitCtx *ch_unit,
for (ch = 0; ch < num_channels; ch++) { for (ch = 0; ch < num_channels; ch++) {
for (sb = 0; sb < ch_unit->num_subbands; sb++) { for (sb = 0; sb < ch_unit->num_subbands; sb++) {
/* inverse transform and windowing */ /* inverse transform and windowing */
ff_atrac3p_imdct(ctx->fdsp, &ctx->mdct_ctx, ff_atrac3p_imdct(ctx->fdsp, ctx->mdct_ctx, ctx->mdct_fn,
&ctx->samples[ch][sb * ATRAC3P_SUBBAND_SAMPLES], &ctx->samples[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
&ctx->mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES], &ctx->mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
(ch_unit->channels[ch].wnd_shape_prev[sb] << 1) + (ch_unit->channels[ch].wnd_shape_prev[sb] << 1) +
@@ -328,8 +339,9 @@ static void reconstruct_frame(ATRAC3PContext *ctx, Atrac3pChanUnitCtx *ch_unit,
} }
/* subband synthesis and acoustic signal output */ /* subband synthesis and acoustic signal output */
ff_atrac3p_ipqf(&ctx->ipqf_dct_ctx, &ch_unit->ipqf_ctx[ch], ff_atrac3p_ipqf(ctx->ipqf_dct_ctx, ctx->ipqf_dct_fn,
&ctx->time_buf[ch][0], &ctx->outp_buf[ch][0]); &ch_unit->ipqf_ctx[ch], &ctx->time_buf[ch][0],
&ctx->outp_buf[ch][0]);
} }
/* swap window shape and gain control buffers. */ /* swap window shape and gain control buffers. */

View File

@@ -79,12 +79,6 @@ const float ff_atrac3p_mant_tab[8] = {
#define ATRAC3P_MDCT_SIZE (ATRAC3P_SUBBAND_SAMPLES * 2) #define ATRAC3P_MDCT_SIZE (ATRAC3P_SUBBAND_SAMPLES * 2)
av_cold void ff_atrac3p_init_imdct(AVCodecContext *avctx, FFTContext *mdct_ctx)
{
/* Initialize the MDCT transform. */
ff_mdct_init(mdct_ctx, 8, 1, -1.0);
}
#define TWOPI (2 * M_PI) #define TWOPI (2 * M_PI)
#define DEQUANT_PHASE(ph) (((ph) & 0x1F) << 6) #define DEQUANT_PHASE(ph) (((ph) & 0x1F) << 6)
@@ -463,8 +457,9 @@ void ff_atrac3p_power_compensation(Atrac3pChanUnitCtx *ctx, AVFloatDSPContext *f
} }
} }
void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, FFTContext *mdct_ctx, float *pIn, void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, AVTXContext *mdct_ctx,
float *pOut, int wind_id, int sb) av_tx_fn mdct_fn, float *pIn, float *pOut,
int wind_id, int sb)
{ {
int i; int i;
@@ -472,7 +467,7 @@ void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, FFTContext *mdct_ctx, float *pIn,
for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES / 2; i++) for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES / 2; i++)
FFSWAP(float, pIn[i], pIn[ATRAC3P_SUBBAND_SAMPLES - 1 - i]); FFSWAP(float, pIn[i], pIn[ATRAC3P_SUBBAND_SAMPLES - 1 - i]);
mdct_ctx->imdct_calc(mdct_ctx, pOut, pIn); mdct_fn(mdct_ctx, pOut, pIn, sizeof(float));
/* Perform windowing on the output. /* Perform windowing on the output.
* ATRAC3+ uses two different MDCT windows: * ATRAC3+ uses two different MDCT windows:
@@ -604,8 +599,8 @@ static const float ipqf_coeffs2[ATRAC3P_PQF_FIR_LEN][16] = {
-4.4400572e-8, -4.2005411e-7, -8.0604229e-7, -5.8336207e-7 } -4.4400572e-8, -4.2005411e-7, -8.0604229e-7, -5.8336207e-7 }
}; };
void ff_atrac3p_ipqf(FFTContext *dct_ctx, Atrac3pIPQFChannelCtx *hist, void ff_atrac3p_ipqf(AVTXContext *dct_ctx, av_tx_fn dct_fn,
const float *in, float *out) Atrac3pIPQFChannelCtx *hist, const float *in, float *out)
{ {
int i, s, sb, t, pos_now, pos_next; int i, s, sb, t, pos_now, pos_next;
LOCAL_ALIGNED(32, float, idct_in, [ATRAC3P_SUBBANDS]); LOCAL_ALIGNED(32, float, idct_in, [ATRAC3P_SUBBANDS]);
@@ -619,7 +614,7 @@ void ff_atrac3p_ipqf(FFTContext *dct_ctx, Atrac3pIPQFChannelCtx *hist,
idct_in[sb] = in[sb * ATRAC3P_SUBBAND_SAMPLES + s]; idct_in[sb] = in[sb * ATRAC3P_SUBBAND_SAMPLES + s];
/* Calculate the sine and cosine part of the PQF using IDCT-IV */ /* Calculate the sine and cosine part of the PQF using IDCT-IV */
dct_ctx->imdct_half(dct_ctx, idct_out, idct_in); dct_fn(dct_ctx, idct_out, idct_in, sizeof(float));
/* append the result to the history */ /* append the result to the history */
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {