| @@ -40,13 +40,13 @@ · 39 unmodified lines |
| 40 | #include "libavutil/internal.h" | 40 | #include "libavutil/internal.h" |
| 41 | #include "libavutil/mem_internal.h" | 41 | #include "libavutil/mem_internal.h" |
| 42 | #include "libavutil/thread.h" | 42 | #include "libavutil/thread.h" |
| | 43 | #include "libavutil/tx.h" |
| 43 | | 44 | |
| 44 | #include "avcodec.h" | 45 | #include "avcodec.h" |
| 45 | #include "bswapdsp.h" | 46 | #include "bswapdsp.h" |
| 46 | #include "codec_internal.h" | 47 | #include "codec_internal.h" |
| 47 | #include "decode.h" | 48 | #include "decode.h" |
| 48 | #include "get_bits.h" | 49 | #include "get_bits.h" |
| 49 | #include "fft.h" | | |
| 50 | #include "sinewin.h" | 50 | #include "sinewin.h" |
| 51 | | 51 | |
| 52 | #include "imcdata.h" | 52 | #include "imcdata.h" |
| @@ -64,7 +64,7 @@ typedef struct IMCChannel { · 11 unmodified lines |
| 64 | float flcoeffs4[BANDS]; | 64 | float flcoeffs4[BANDS]; |
| 65 | float flcoeffs5[BANDS]; | 65 | float flcoeffs5[BANDS]; |
| 66 | float flcoeffs6[BANDS]; | 66 | float flcoeffs6[BANDS]; |
| 67 | float CWdecoded[COEFFS]; | 67 | DECLARE_ALIGNED(32, float, CWdecoded)[COEFFS]; |
| 68 | | 68 | |
| 69 | int bandWidthT[BANDS]; ///< codewords per band | 69 | int bandWidthT[BANDS]; ///< codewords per band |
| 70 | int bitsBandT[BANDS]; ///< how many bits per codeword in band | 70 | int bitsBandT[BANDS]; ///< how many bits per codeword in band |
| @@ -78,31 +78,25 @@ typedef struct IMCChannel { · 7 unmodified lines |
| 78 | int skipFlags[COEFFS]; ///< skip coefficient decoding or not | 78 | int skipFlags[COEFFS]; ///< skip coefficient decoding or not |
| 79 | int codewords[COEFFS]; ///< raw codewords read from bitstream | 79 | int codewords[COEFFS]; ///< raw codewords read from bitstream |
| 80 | | 80 | |
| 81 | float last_fft_im[COEFFS]; | | |
| 82 | | | |
| 83 | int decoder_reset; | 81 | int decoder_reset; |
| | 82 | DECLARE_ALIGNED(32, float, prev_win)[128]; |
| 84 | } IMCChannel; | 83 | } IMCChannel; |
| 85 | | 84 | |
| 86 | typedef struct IMCContext { | 85 | typedef struct IMCContext { |
| 87 | IMCChannel chctx[2]; | 86 | IMCChannel chctx[2]; |
| 88 | | 87 | |
| 89 | /** MDCT tables */ | 88 | /** MDCT tables */ |
| 90 | //@{ | 89 | DECLARE_ALIGNED(32, float, mdct_sine_window)[COEFFS]; |
| 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 | //@} | | |
| 97 | | 90 | |
| 98 | float sqrt_tab[30]; | 91 | float sqrt_tab[30]; |
| 99 | GetBitContext gb; | 92 | GetBitContext gb; |
| 100 | | 93 | |
| | 94 | AVFloatDSPContext *fdsp; |
| 101 | BswapDSPContext bdsp; | 95 | BswapDSPContext bdsp; |
| 102 | void (*butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len); | 96 | AVTXContext *mdct; |
| 103 | FFTContext fft; | 97 | av_tx_fn mdct_fn; |
| 104 | DECLARE_ALIGNED(32, FFTComplex, samples)[COEFFS / 2]; | | |
| 105 | float *out_samples; | 98 | float *out_samples; |
| | 99 | DECLARE_ALIGNED(32, float, temp)[256]; |
| 106 | | 100 | |
| 107 | int coef0_pos; | 101 | int coef0_pos; |
| 108 | | 102 | |
| @@ -196,8 +190,7 @@ static av_cold int imc_decode_init(AVCodecContext *avctx) · 87 unmodified lines |
| 196 | int i, j, ret; | 190 | int i, j, ret; |
| 197 | IMCContext *q = avctx->priv_data; | 191 | IMCContext *q = avctx->priv_data; |
| 198 | static AVOnce init_static_once = AV_ONCE_INIT; | 192 | static AVOnce init_static_once = AV_ONCE_INIT; |
| 199 | AVFloatDSPContext *fdsp; | 193 | float scale = 1.0f / (16384); |
| 200 | double r1, r2; | | |
| 201 | | 194 | |
| 202 | if (avctx->codec_id == AV_CODEC_ID_IAC && avctx->sample_rate > 96000) { | 195 | if (avctx->codec_id == AV_CODEC_ID_IAC && avctx->sample_rate > 96000) { |
| 203 | av_log(avctx, AV_LOG_ERROR, | 196 | av_log(avctx, AV_LOG_ERROR, |
| @@ -222,33 +215,14 @@ static av_cold int imc_decode_init(AVCodecContext *avctx) · 18 unmodified lines |
| 222 | | 215 | |
| 223 | for (i = 0; i < BANDS; i++) | 216 | for (i = 0; i < BANDS; i++) |
| 224 | q->chctx[j].old_floor[i] = 1.0; | 217 | 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; | | |
| 228 | } | 218 | } |
| 229 | | 219 | |
| 230 | /* Build mdct window, a simple sine window normalized with sqrt(2) */ | 220 | /* Build mdct window, a simple sine window normalized with sqrt(2) */ |
| 231 | ff_sine_window_init(q->mdct_sine_window, COEFFS); | 221 | ff_sine_window_init(q->mdct_sine_window, COEFFS); |
| 232 | for (i = 0; i < COEFFS; i++) | 222 | for (i = 0; i < COEFFS; i++) |
| 233 | q->mdct_sine_window[i] *= sqrt(2.0); | 223 | 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 | } | | |
| 249 | | 224 | |
| 250 | /* Generate a square root table */ | 225 | /* Generate a square root table */ |
| 251 | | | |
| 252 | for (i = 0; i < 30; i++) | 226 | for (i = 0; i < 30; i++) |
| 253 | q->sqrt_tab[i] = sqrt(i); | 227 | q->sqrt_tab[i] = sqrt(i); |
| 254 | | 228 | |
| @@ -261,15 +235,14 @@ static av_cold int imc_decode_init(AVCodecContext *avctx) · 6 unmodified lines |
| 261 | memcpy(q->weights2, imc_weights2, sizeof(imc_weights2)); | 235 | memcpy(q->weights2, imc_weights2, sizeof(imc_weights2)); |
| 262 | } | 236 | } |
| 263 | | 237 | |
| 264 | fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT); | 238 | q->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT); |
| 265 | if (!fdsp) | 239 | if (!q->fdsp) |
| 266 | return AVERROR(ENOMEM); | 240 | return AVERROR(ENOMEM); |
| 267 | q->butterflies_float = fdsp->butterflies_float; | 241 | |
| 268 | av_free(fdsp); | 242 | ret = av_tx_init(&q->mdct, &q->mdct_fn, AV_TX_FLOAT_MDCT, 1, COEFFS, &scale, 0); |
| 269 | if ((ret = ff_fft_init(&q->fft, 7, 1))) { | 243 | if (ret < 0) |
| 270 | av_log(avctx, AV_LOG_INFO, "FFT init failed\n"); | | |
| 271 | return ret; | 244 | return ret; |
| 272 | } | 245 | |
| 273 | ff_bswapdsp_init(&q->bdsp); | 246 | ff_bswapdsp_init(&q->bdsp); |
| 274 | | 247 | |
| 275 | avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; | 248 | avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; |
| @@ -726,39 +699,6 @@ static void imc_adjust_bit_allocation(IMCContext *q, IMCChannel *chctx, · 450 unmodified lines |
| 726 | } | 699 | } |
| 727 | } | 700 | } |
| 728 | | 701 | |
| 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 | | | |
| 762 | static int inverse_quant_coeff(IMCContext *q, IMCChannel *chctx, | 702 | static int inverse_quant_coeff(IMCContext *q, IMCChannel *chctx, |
| 763 | int stream_format_code) | 703 | int stream_format_code) |
| 764 | { | 704 | { |
| @@ -1012,7 +952,10 @@ static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch) · 247 unmodified lines |
| 1012 | | 952 | |
| 1013 | memset(chctx->skipFlags, 0, sizeof(chctx->skipFlags)); | 953 | memset(chctx->skipFlags, 0, sizeof(chctx->skipFlags)); |
| 1014 | | 954 | |
| 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); |
| 1016 | | 959 | |
| 1017 | return 0; | 960 | return 0; |
| 1018 | } | 961 | } |
| @@ -1054,8 +997,8 @@ static int imc_decode_frame(AVCodecContext *avctx, AVFrame *frame, · 35 unmodified lines |
| 1054 | } | 997 | } |
| 1055 | | 998 | |
| 1056 | if (avctx->ch_layout.nb_channels == 2) { | 999 | if (avctx->ch_layout.nb_channels == 2) { |
| 1057 | q->butterflies_float((float *)frame->extended_data[0], | 1000 | q->fdsp->butterflies_float((float *)frame->extended_data[0], |
| 1058 | (float *)frame->extended_data[1], COEFFS); | 1001 | (float *)frame->extended_data[1], COEFFS); |
| 1059 | } | 1002 | } |
| 1060 | | 1003 | |
| 1061 | *got_frame_ptr = 1; | 1004 | *got_frame_ptr = 1; |
| @@ -1067,7 +1010,8 @@ static av_cold int imc_decode_close(AVCodecContext * avctx) · 5 unmodified lines |
| 1067 | { | 1010 | { |
| 1068 | IMCContext *q = avctx->priv_data; | 1011 | IMCContext *q = avctx->priv_data; |
| 1069 | | 1012 | |
| 1070 | ff_fft_end(&q->fft); | 1013 | av_free(q->fdsp); |
| | 1014 | av_tx_uninit(&q->mdct); |
| 1071 | | 1015 | |
| 1072 | return 0; | 1016 | return 0; |
| 1073 | } | 1017 | } |