| @@ -37,6 +37,7 @@ · 36 unmodified lines |
| 37 | #include "libavutil/channel_layout.h" | 37 | #include "libavutil/channel_layout.h" |
| 38 | #include "libavutil/mem_internal.h" | 38 | #include "libavutil/mem_internal.h" |
| 39 | #include "libavutil/thread.h" | 39 | #include "libavutil/thread.h" |
| | 40 | #include "libavutil/tx.h" |
| 40 | | 41 | |
| 41 | #define BITSTREAM_READER_LE | 42 | #define BITSTREAM_READER_LE |
| 42 | #include "avcodec.h" | 43 | #include "avcodec.h" |
| @@ -46,7 +47,6 @@ · 3 unmodified lines |
| 46 | #include "decode.h" | 47 | #include "decode.h" |
| 47 | #include "mpegaudio.h" | 48 | #include "mpegaudio.h" |
| 48 | #include "mpegaudiodsp.h" | 49 | #include "mpegaudiodsp.h" |
| 49 | #include "rdft.h" | | |
| 50 | | 50 | |
| 51 | #include "qdm2_tablegen.h" | 51 | #include "qdm2_tablegen.h" |
| 52 | | 52 | |
| @@ -96,14 +96,9 @@ typedef struct QDM2SubPNode { · 43 unmodified lines |
| 96 | struct QDM2SubPNode *next; ///< pointer to next packet in the list, NULL if leaf node | 96 | struct QDM2SubPNode *next; ///< pointer to next packet in the list, NULL if leaf node |
| 97 | } QDM2SubPNode; | 97 | } QDM2SubPNode; |
| 98 | | 98 | |
| 99 | typedef struct QDM2Complex { | | |
| 100 | float re; | | |
| 101 | float im; | | |
| 102 | } QDM2Complex; | | |
| 103 | | | |
| 104 | typedef struct FFTTone { | 99 | typedef struct FFTTone { |
| 105 | float level; | 100 | float level; |
| 106 | QDM2Complex *complex; | 101 | AVComplexFloat *complex; |
| 107 | const float *table; | 102 | const float *table; |
| 108 | int phase; | 103 | int phase; |
| 109 | int phase_shift; | 104 | int phase_shift; |
| @@ -121,7 +116,8 @@ typedef struct FFTCoefficient { · 11 unmodified lines |
| 121 | } FFTCoefficient; | 116 | } FFTCoefficient; |
| 122 | | 117 | |
| 123 | typedef struct QDM2FFT { | 118 | typedef struct QDM2FFT { |
| 124 | DECLARE_ALIGNED(32, QDM2Complex, complex)[MPA_MAX_CHANNELS][256]; | 119 | DECLARE_ALIGNED(32, AVComplexFloat, complex)[MPA_MAX_CHANNELS][256 + 1]; |
| | 120 | DECLARE_ALIGNED(32, AVComplexFloat, temp)[MPA_MAX_CHANNELS][256]; |
| 125 | } QDM2FFT; | 121 | } QDM2FFT; |
| 126 | | 122 | |
| 127 | /** | 123 | /** |
| @@ -161,7 +157,8 @@ typedef struct QDM2Context { · 33 unmodified lines |
| 161 | int fft_coefs_min_index[5]; | 157 | int fft_coefs_min_index[5]; |
| 162 | int fft_coefs_max_index[5]; | 158 | int fft_coefs_max_index[5]; |
| 163 | int fft_level_exp[6]; | 159 | int fft_level_exp[6]; |
| 164 | RDFTContext rdft_ctx; | 160 | AVTXContext *rdft_ctx; |
| | 161 | av_tx_fn rdft_fn; |
| 165 | QDM2FFT fft; | 162 | QDM2FFT fft; |
| 166 | | 163 | |
| 167 | /// I/O data | 164 | /// I/O data |
| @@ -1428,7 +1425,7 @@ static void qdm2_fft_generate_tone(QDM2Context *q, FFTTone *tone) · 1260 unmodified lines |
| 1428 | { | 1425 | { |
| 1429 | float level, f[6]; | 1426 | float level, f[6]; |
| 1430 | int i; | 1427 | int i; |
| 1431 | QDM2Complex c; | 1428 | AVComplexFloat c; |
| 1432 | const double iscale = 2.0 * M_PI / 512.0; | 1429 | const double iscale = 2.0 * M_PI / 512.0; |
| 1433 | | 1430 | |
| 1434 | tone->phase += tone->phase_shift; | 1431 | tone->phase += tone->phase_shift; |
| @@ -1476,7 +1473,7 @@ static void qdm2_fft_tone_synthesizer(QDM2Context *q, int sub_packet) · 41 unmodified lines |
| 1476 | const double iscale = 0.25 * M_PI; | 1473 | const double iscale = 0.25 * M_PI; |
| 1477 | | 1474 | |
| 1478 | for (ch = 0; ch < q->channels; ch++) { | 1475 | for (ch = 0; ch < q->channels; ch++) { |
| 1479 | memset(q->fft.complex[ch], 0, q->fft_size * sizeof(QDM2Complex)); | 1476 | memset(q->fft.complex[ch], 0, q->fft_size * sizeof(AVComplexFloat)); |
| 1480 | } | 1477 | } |
| 1481 | | 1478 | |
| 1482 | | 1479 | |
| @@ -1484,7 +1481,7 @@ static void qdm2_fft_tone_synthesizer(QDM2Context *q, int sub_packet) · 1 unmodified line |
| 1484 | if (q->fft_coefs_min_index[4] >= 0) | 1481 | if (q->fft_coefs_min_index[4] >= 0) |
| 1485 | for (i = q->fft_coefs_min_index[4]; i < q->fft_coefs_max_index[4]; i++) { | 1482 | for (i = q->fft_coefs_min_index[4]; i < q->fft_coefs_max_index[4]; i++) { |
| 1486 | float level; | 1483 | float level; |
| 1487 | QDM2Complex c; | 1484 | AVComplexFloat c; |
| 1488 | | 1485 | |
| 1489 | if (q->fft_coefs[i].sub_packet != sub_packet) | 1486 | if (q->fft_coefs[i].sub_packet != sub_packet) |
| 1490 | break; | 1487 | break; |
| @@ -1545,14 +1542,19 @@ static void qdm2_calculate_fft(QDM2Context *q, int channel, int sub_packet) · 54 unmodified lines |
| 1545 | { | 1542 | { |
| 1546 | const float gain = (q->channels == 1 && q->nb_channels == 2) ? 0.5f : 1.0f; | 1543 | const float gain = (q->channels == 1 && q->nb_channels == 2) ? 0.5f : 1.0f; |
| 1547 | float *out = q->output_buffer + channel; | 1544 | float *out = q->output_buffer + channel; |
| 1548 | int i; | 1545 | |
| 1549 | q->fft.complex[channel][0].re *= 2.0f; | 1546 | q->fft.complex[channel][0].re *= 2.0f; |
| 1550 | q->fft.complex[channel][0].im = 0.0f; | 1547 | q->fft.complex[channel][0].im = 0.0f; |
| 1551 | q->rdft_ctx.rdft_calc(&q->rdft_ctx, (FFTSample *)q->fft.complex[channel]); | 1548 | q->fft.complex[channel][q->fft_size].re = 0.0f; |
| | 1549 | q->fft.complex[channel][q->fft_size].im = 0.0f; |
| | 1550 | |
| | 1551 | q->rdft_fn(q->rdft_ctx, q->fft.temp[channel], q->fft.complex[channel], |
| | 1552 | sizeof(AVComplexFloat)); |
| | 1553 | |
| 1552 | /* add samples to output buffer */ | 1554 | /* add samples to output buffer */ |
| 1553 | for (i = 0; i < FFALIGN(q->fft_size, 8); i++) { | 1555 | for (int i = 0; i < FFALIGN(q->fft_size, 8); i++) { |
| 1554 | out[0] += q->fft.complex[channel][i].re * gain; | 1556 | out[0] += q->fft.temp[channel][i].re * gain; |
| 1555 | out[q->channels] += q->fft.complex[channel][i].im * gain; | 1557 | out[q->channels] += q->fft.temp[channel][i].im * gain; |
| 1556 | out += 2 * q->channels; | 1558 | out += 2 * q->channels; |
| 1557 | } | 1559 | } |
| 1558 | } | 1560 | } |
| @@ -1613,7 +1615,8 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx) · 54 unmodified lines |
| 1613 | { | 1615 | { |
| 1614 | static AVOnce init_static_once = AV_ONCE_INIT; | 1616 | static AVOnce init_static_once = AV_ONCE_INIT; |
| 1615 | QDM2Context *s = avctx->priv_data; | 1617 | QDM2Context *s = avctx->priv_data; |
| 1616 | int tmp_val, tmp, size; | 1618 | int ret, tmp_val, tmp, size; |
| | 1619 | float scale = 1.0f / 2.0f; |
| 1617 | GetByteContext gb; | 1620 | GetByteContext gb; |
| 1618 | | 1621 | |
| 1619 | /* extradata parsing | 1622 | /* extradata parsing |
| @@ -1756,7 +1759,10 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx) · 136 unmodified lines |
| 1756 | return AVERROR_INVALIDDATA; | 1759 | return AVERROR_INVALIDDATA; |
| 1757 | } | 1760 | } |
| 1758 | | 1761 | |
| 1759 | ff_rdft_init(&s->rdft_ctx, s->fft_order, IDFT_C2R); | 1762 | ret = av_tx_init(&s->rdft_ctx, &s->rdft_fn, AV_TX_FLOAT_RDFT, 1, 2*s->fft_size, &scale, 0); |
| | 1763 | if (ret < 0) |
| | 1764 | return ret; |
| | 1765 | |
| 1760 | ff_mpadsp_init(&s->mpadsp); | 1766 | ff_mpadsp_init(&s->mpadsp); |
| 1761 | | 1767 | |
| 1762 | avctx->sample_fmt = AV_SAMPLE_FMT_S16; | 1768 | avctx->sample_fmt = AV_SAMPLE_FMT_S16; |
| @@ -1770,7 +1776,7 @@ static av_cold int qdm2_decode_close(AVCodecContext *avctx) · 7 unmodified lines |
| 1770 | { | 1776 | { |
| 1771 | QDM2Context *s = avctx->priv_data; | 1777 | QDM2Context *s = avctx->priv_data; |
| 1772 | | 1778 | |
| 1773 | ff_rdft_end(&s->rdft_ctx); | 1779 | av_tx_uninit(&s->rdft_ctx); |
| 1774 | | 1780 | |
| 1775 | return 0; | 1781 | return 0; |
| 1776 | } | 1782 | } |