History

imc: convert to lavu/tx, remove NIH iMDCT and replace with a standard one

Lynne committed 4 years ago

Commit e6afa611 parent b85e1063 files · +25 −80Browse files

Unified · Split

3 files
  1. configure +1 −1
  2. libavcodec/imc.c +23 −79
  3. tests/fate/audio.mak +1 −0
configure+1−1
@@ -2850,7 +2850,7 @@ huffyuv_decoder_select="bswapdsp huffyuvdsp llviddsp" · 2849 unmodified lines
28502850 huffyuv_encoder_select="bswapdsp huffman huffyuvencdsp llvidencdsp"
28512851 hymt_decoder_select="huffyuv_decoder"
28522852 iac_decoder_select="imc_decoder"
2853−imc_decoder_select="bswapdsp fft mdct sinewin"
2853+imc_decoder_select="bswapdsp sinewin"
28542854 imm4_decoder_select="bswapdsp idctdsp"
28552855 imm5_decoder_select="h264_decoder hevc_decoder"
28562856 indeo3_decoder_select="hpeldsp"
libavcodec/imc.c+23−79
@@ -40,13 +40,13 @@ · 39 unmodified lines
4040 #include "libavutil/internal.h"
4141 #include "libavutil/mem_internal.h"
4242 #include "libavutil/thread.h"
43+#include "libavutil/tx.h"
4344
4445 #include "avcodec.h"
4546 #include "bswapdsp.h"
4647 #include "codec_internal.h"
4748 #include "decode.h"
4849 #include "get_bits.h"
49−#include "fft.h"
5050 #include "sinewin.h"
5151
5252 #include "imcdata.h"
@@ -64,7 +64,7 @@ typedef struct IMCChannel { · 11 unmodified lines
6464 float flcoeffs4[BANDS];
6565 float flcoeffs5[BANDS];
6666 float flcoeffs6[BANDS];
67− float CWdecoded[COEFFS];
67+ DECLARE_ALIGNED(32, float, CWdecoded)[COEFFS];
6868
6969 int bandWidthT[BANDS]; ///< codewords per band
7070 int bitsBandT[BANDS]; ///< how many bits per codeword in band
@@ -78,31 +78,25 @@ typedef struct IMCChannel { · 7 unmodified lines
7878 int skipFlags[COEFFS]; ///< skip coefficient decoding or not
7979 int codewords[COEFFS]; ///< raw codewords read from bitstream
8080
81− float last_fft_im[COEFFS];
82−
8381 int decoder_reset;
82+ DECLARE_ALIGNED(32, float, prev_win)[128];
8483 } IMCChannel;
8584
8685 typedef struct IMCContext {
8786 IMCChannel chctx[2];
8887
8988 /** MDCT tables */
90− //@{
91− float mdct_sine_window[COEFFS];
92− float post_cos[COEFFS];
93− float post_sin[COEFFS];
94− float pre_coef1[COEFFS];
95− float pre_coef2[COEFFS];
96− //@}
89+ DECLARE_ALIGNED(32, float, mdct_sine_window)[COEFFS];
9790
9891 float sqrt_tab[30];
9992 GetBitContext gb;
10093
94+ AVFloatDSPContext *fdsp;
10195 BswapDSPContext bdsp;
102− void (*butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len);
103− FFTContext fft;
104− DECLARE_ALIGNED(32, FFTComplex, samples)[COEFFS / 2];
96+ AVTXContext *mdct;
97+ av_tx_fn mdct_fn;
10598 float *out_samples;
99+ DECLARE_ALIGNED(32, float, temp)[256];
106100
107101 int coef0_pos;
108102
@@ -196,8 +190,7 @@ static av_cold int imc_decode_init(AVCodecContext *avctx) · 87 unmodified lines
196190 int i, j, ret;
197191 IMCContext *q = avctx->priv_data;
198192 static AVOnce init_static_once = AV_ONCE_INIT;
199− AVFloatDSPContext *fdsp;
200− double r1, r2;
193+ float scale = 1.0f / (16384);
201194
202195 if (avctx->codec_id == AV_CODEC_ID_IAC && avctx->sample_rate > 96000) {
203196 av_log(avctx, AV_LOG_ERROR,
@@ -222,33 +215,14 @@ static av_cold int imc_decode_init(AVCodecContext *avctx) · 18 unmodified lines
222215
223216 for (i = 0; i < BANDS; i++)
224217 q->chctx[j].old_floor[i] = 1.0;
225−
226− for (i = 0; i < COEFFS / 2; i++)
227− q->chctx[j].last_fft_im[i] = 0;
228218 }
229219
230220 /* Build mdct window, a simple sine window normalized with sqrt(2) */
231221 ff_sine_window_init(q->mdct_sine_window, COEFFS);
232222 for (i = 0; i < COEFFS; i++)
233223 q->mdct_sine_window[i] *= sqrt(2.0);
234− for (i = 0; i < COEFFS / 2; i++) {
235− q->post_cos[i] = (1.0f / 32768) * cos(i / 256.0 * M_PI);
236− q->post_sin[i] = (1.0f / 32768) * sin(i / 256.0 * M_PI);
237−
238− r1 = sin((i * 4.0 + 1.0) / 1024.0 * M_PI);
239− r2 = cos((i * 4.0 + 1.0) / 1024.0 * M_PI);
240−
241− if (i & 0x1) {
242− q->pre_coef1[i] = (r1 + r2) * sqrt(2.0);
243− q->pre_coef2[i] = -(r1 - r2) * sqrt(2.0);
244− } else {
245− q->pre_coef1[i] = -(r1 + r2) * sqrt(2.0);
246− q->pre_coef2[i] = (r1 - r2) * sqrt(2.0);
247− }
248− }
249224
250225 /* Generate a square root table */
251−
252226 for (i = 0; i < 30; i++)
253227 q->sqrt_tab[i] = sqrt(i);
254228
@@ -261,15 +235,14 @@ static av_cold int imc_decode_init(AVCodecContext *avctx) · 6 unmodified lines
261235 memcpy(q->weights2, imc_weights2, sizeof(imc_weights2));
262236 }
263237
264− fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
265− if (!fdsp)
238+ q->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
239+ if (!q->fdsp)
266240 return AVERROR(ENOMEM);
267− q->butterflies_float = fdsp->butterflies_float;
268− av_free(fdsp);
269− if ((ret = ff_fft_init(&q->fft, 7, 1))) {
270− av_log(avctx, AV_LOG_INFO, "FFT init failed\n");
241+
242+ ret = av_tx_init(&q->mdct, &q->mdct_fn, AV_TX_FLOAT_MDCT, 1, COEFFS, &scale, 0);
243+ if (ret < 0)
271244 return ret;
272− }
245+
273246 ff_bswapdsp_init(&q->bdsp);
274247
275248 avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
@@ -726,39 +699,6 @@ static void imc_adjust_bit_allocation(IMCContext *q, IMCChannel *chctx, · 450 unmodified lines
726699 }
727700 }
728701
729−static void imc_imdct256(IMCContext *q, IMCChannel *chctx, int channels)
730−{
731− int i;
732− float re, im;
733− float *dst1 = q->out_samples;
734− float *dst2 = q->out_samples + (COEFFS - 1);
735−
736− /* prerotation */
737− for (i = 0; i < COEFFS / 2; i++) {
738− q->samples[i].re = -(q->pre_coef1[i] * chctx->CWdecoded[COEFFS - 1 - i * 2]) -
739− (q->pre_coef2[i] * chctx->CWdecoded[i * 2]);
740− q->samples[i].im = (q->pre_coef2[i] * chctx->CWdecoded[COEFFS - 1 - i * 2]) -
741− (q->pre_coef1[i] * chctx->CWdecoded[i * 2]);
742− }
743−
744− /* FFT */
745− q->fft.fft_permute(&q->fft, q->samples);
746− q->fft.fft_calc(&q->fft, q->samples);
747−
748− /* postrotation, window and reorder */
749− for (i = 0; i < COEFFS / 2; i++) {
750− re = ( q->samples[i].re * q->post_cos[i]) + (-q->samples[i].im * q->post_sin[i]);
751− im = (-q->samples[i].im * q->post_cos[i]) - ( q->samples[i].re * q->post_sin[i]);
752− *dst1 = (q->mdct_sine_window[COEFFS - 1 - i * 2] * chctx->last_fft_im[i])
753− + (q->mdct_sine_window[i * 2] * re);
754− *dst2 = (q->mdct_sine_window[i * 2] * chctx->last_fft_im[i])
755− - (q->mdct_sine_window[COEFFS - 1 - i * 2] * re);
756− dst1 += 2;
757− dst2 -= 2;
758− chctx->last_fft_im[i] = im;
759− }
760−}
761−
762702 static int inverse_quant_coeff(IMCContext *q, IMCChannel *chctx,
763703 int stream_format_code)
764704 {
@@ -1012,7 +952,10 @@ static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch) · 247 unmodified lines
1012952
1013953 memset(chctx->skipFlags, 0, sizeof(chctx->skipFlags));
1014954
1015− imc_imdct256(q, chctx, avctx->ch_layout.nb_channels);
955+ q->mdct_fn(q->mdct, q->temp, chctx->CWdecoded, sizeof(float));
956+ q->fdsp->vector_fmul_window(q->out_samples, chctx->prev_win, q->temp,
957+ q->mdct_sine_window, 128);
958+ memcpy(chctx->prev_win, q->temp + 128, sizeof(float)*128);
1016959
1017960 return 0;
1018961 }
@@ -1054,8 +997,8 @@ static int imc_decode_frame(AVCodecContext *avctx, AVFrame *frame, · 35 unmodified lines
1054997 }
1055998
1056999 if (avctx->ch_layout.nb_channels == 2) {
1057− q->butterflies_float((float *)frame->extended_data[0],
1058− (float *)frame->extended_data[1], COEFFS);
1000+ q->fdsp->butterflies_float((float *)frame->extended_data[0],
1001+ (float *)frame->extended_data[1], COEFFS);
10591002 }
10601003
10611004 *got_frame_ptr = 1;
@@ -1067,7 +1010,8 @@ static av_cold int imc_decode_close(AVCodecContext * avctx) · 5 unmodified lines
10671010 {
10681011 IMCContext *q = avctx->priv_data;
10691012
1070− ff_fft_end(&q->fft);
1013+ av_free(q->fdsp);
1014+ av_tx_uninit(&q->mdct);
10711015
10721016 return 0;
10731017 }
tests/fate/audio.mak+1−0
@@ -43,6 +43,7 @@ fate-dsf-dst: REF = $(SAMPLES)/dst/dst-64fs44-2ch.pcm · 42 unmodified lines
4343 FATE_SAMPLES_AUDIO-$(call DEMDEC, AVI, IMC) += fate-imc
4444 fate-imc: CMD = pcm -i $(TARGET_SAMPLES)/imc/imc.avi
4545 fate-imc: CMP = oneoff
46+fate-imc: CMP_TARGET = 59416
4647 fate-imc: REF = $(SAMPLES)/imc/imc-201706.pcm
4748
4849 FATE_SAMPLES_AUDIO-$(call DEMDEC, FLV, NELLYMOSER) += fate-nellymoser

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t