From e10b90b7187be1636df90c6123646f330677e652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 11 Apr 2024 10:24:14 +0200 Subject: [PATCH] Switch at3_standalone to C++ to avoid namespace clashes --- Common/Common.vcxproj | 31 ++- Common/Common.vcxproj.filters | 37 ++-- Core/HW/Atrac3Standalone.cpp | 2 - ext/at3_standalone/at3_decoders.h | 11 +- ext/at3_standalone/{atrac.c => atrac.cpp} | 0 ext/at3_standalone/{atrac3.c => atrac3.cpp} | 23 +-- .../{atrac3plus.c => atrac3plus.cpp} | 2 +- .../{atrac3plusdec.c => atrac3plusdec.cpp} | 18 +- .../{atrac3plusdsp.c => atrac3plusdsp.cpp} | 0 ext/at3_standalone/{avcodec.c => avcodec.cpp} | 5 +- ext/at3_standalone/avcodec.h | 10 - .../{channel_layout.c => channel_layout.cpp} | 50 ++--- ext/at3_standalone/compat.c | 34 --- ext/at3_standalone/compat.cpp | 23 +++ ext/at3_standalone/compat.h | 9 - ext/at3_standalone/{fft.c => fft.cpp} | 194 ++++++++++++++++-- ext/at3_standalone/fft.h | 20 +- .../{float_dsp.c => float_dsp.cpp} | 0 .../{get_bits.c => get_bits.cpp} | 7 +- ext/at3_standalone/get_bits.h | 6 +- ext/at3_standalone/intmath.c | 19 -- ext/at3_standalone/intmath.h | 130 ------------ .../{mathematics.c => mathematics.cpp} | 56 ++++- ext/at3_standalone/mathematics.h | 76 ++++++- ext/at3_standalone/mdct_template.c | 192 ----------------- ext/at3_standalone/{mem.c => mem.cpp} | 2 +- ext/at3_standalone/{sinewin.c => sinewin.cpp} | 0 27 files changed, 410 insertions(+), 547 deletions(-) rename ext/at3_standalone/{atrac.c => atrac.cpp} (100%) rename ext/at3_standalone/{atrac3.c => atrac3.cpp} (98%) rename ext/at3_standalone/{atrac3plus.c => atrac3plus.cpp} (99%) rename ext/at3_standalone/{atrac3plusdec.c => atrac3plusdec.cpp} (97%) rename ext/at3_standalone/{atrac3plusdsp.c => atrac3plusdsp.cpp} (100%) rename ext/at3_standalone/{avcodec.c => avcodec.cpp} (95%) rename ext/at3_standalone/{channel_layout.c => channel_layout.cpp} (73%) delete mode 100644 ext/at3_standalone/compat.c create mode 100644 ext/at3_standalone/compat.cpp rename ext/at3_standalone/{fft.c => fft.cpp} (66%) rename ext/at3_standalone/{float_dsp.c => float_dsp.cpp} (100%) rename ext/at3_standalone/{get_bits.c => get_bits.cpp} (98%) delete mode 100644 ext/at3_standalone/intmath.c delete mode 100644 ext/at3_standalone/intmath.h rename ext/at3_standalone/{mathematics.c => mathematics.cpp} (81%) delete mode 100644 ext/at3_standalone/mdct_template.c rename ext/at3_standalone/{mem.c => mem.cpp} (98%) rename ext/at3_standalone/{sinewin.c => sinewin.cpp} (100%) diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj index 2b258e8440..3db89e65b3 100644 --- a/Common/Common.vcxproj +++ b/Common/Common.vcxproj @@ -396,9 +396,7 @@ - - @@ -601,21 +599,20 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + NotUsing diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters index d255b9e331..a7857c5ebf 100644 --- a/Common/Common.vcxproj.filters +++ b/Common/Common.vcxproj.filters @@ -569,12 +569,6 @@ ext\at3_standalone - - ext\at3_standalone - - - ext\at3_standalone - @@ -1032,49 +1026,46 @@ ext\minimp3 - + ext\at3_standalone - + ext\at3_standalone - + ext\at3_standalone - + ext\at3_standalone - + ext\at3_standalone - + ext\at3_standalone - + ext\at3_standalone - + ext\at3_standalone - + ext\at3_standalone - + ext\at3_standalone - + ext\at3_standalone - + ext\at3_standalone - + ext\at3_standalone - - ext\at3_standalone - - + ext\at3_standalone diff --git a/Core/HW/Atrac3Standalone.cpp b/Core/HW/Atrac3Standalone.cpp index 11be9105f4..517f56b117 100644 --- a/Core/HW/Atrac3Standalone.cpp +++ b/Core/HW/Atrac3Standalone.cpp @@ -3,9 +3,7 @@ #include "SimpleAudioDec.h" #include "ext/at3_standalone/at3_decoders.h" -extern "C" { #include "ext/at3_standalone/avcodec.h" -} inline int16_t clamp16(float f) { if (f >= 1.0f) diff --git a/ext/at3_standalone/at3_decoders.h b/ext/at3_standalone/at3_decoders.h index 4dc6d98329..a9cb81edb7 100644 --- a/ext/at3_standalone/at3_decoders.h +++ b/ext/at3_standalone/at3_decoders.h @@ -5,12 +5,9 @@ struct AVCodecContext; struct AVFrame; -extern "C" { - #include "avcodec.h" - int atrac3_decode_frame(AVCodecContext *avctx, float *out_data[2], int *nb_samples, int *got_frame_ptr, const uint8_t *buf, int buf_size); - int atrac3p_decode_frame(AVCodecContext *avctx, float *out_data[2], int *nb_samples, int *got_frame_ptr, const uint8_t *buf, int buf_size); - extern AVCodec ff_atrac3p_decoder; - extern AVCodec ff_atrac3_decoder; -} +int atrac3_decode_frame(AVCodecContext *avctx, float *out_data[2], int *nb_samples, int *got_frame_ptr, const uint8_t *buf, int buf_size); +int atrac3p_decode_frame(AVCodecContext *avctx, float *out_data[2], int *nb_samples, int *got_frame_ptr, const uint8_t *buf, int buf_size); +extern AVCodec ff_atrac3p_decoder; +extern AVCodec ff_atrac3_decoder; diff --git a/ext/at3_standalone/atrac.c b/ext/at3_standalone/atrac.cpp similarity index 100% rename from ext/at3_standalone/atrac.c rename to ext/at3_standalone/atrac.cpp diff --git a/ext/at3_standalone/atrac3.c b/ext/at3_standalone/atrac3.cpp similarity index 98% rename from ext/at3_standalone/atrac3.c rename to ext/at3_standalone/atrac3.cpp index f78e1784dd..2227f9c1f4 100644 --- a/ext/at3_standalone/atrac3.c +++ b/ext/at3_standalone/atrac3.cpp @@ -186,7 +186,7 @@ static void init_imdct_window(void) static int atrac3_decode_close(AVCodecContext *avctx) { - ATRAC3Context *q = avctx->priv_data; + ATRAC3Context *q = (ATRAC3Context * )avctx->priv_data; av_freep(&q->units); av_freep(&q->decoded_bytes_buffer); @@ -638,7 +638,7 @@ static int decode_channel_sound_unit(ATRAC3Context *q, GetBitContext *gb, static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, float **out_samples) { - ATRAC3Context *q = avctx->priv_data; + ATRAC3Context *q = (ATRAC3Context *)avctx->priv_data; int ret, i; uint8_t *ptr1; @@ -732,7 +732,7 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, int atrac3_decode_frame(AVCodecContext *avctx, float *out_data[2], int *nb_samples, int *got_frame_ptr, const uint8_t *buf, int buf_size) { - ATRAC3Context *q = avctx->priv_data; + ATRAC3Context *q = (ATRAC3Context *)avctx->priv_data; int ret; const uint8_t *databuf; @@ -789,7 +789,7 @@ static int atrac3_decode_init(AVCodecContext *avctx) int i, ret; int version, delay, samples_per_frame, frame_factor; const uint8_t *edata_ptr = avctx->extradata; - ATRAC3Context *q = avctx->priv_data; + ATRAC3Context *q = (ATRAC3Context * )avctx->priv_data; if (avctx->channels <= 0 || avctx->channels > 2) { av_log(avctx, AV_LOG_ERROR, "Channel configuration error!\n"); @@ -879,8 +879,7 @@ static int atrac3_decode_init(AVCodecContext *avctx) if (avctx->block_align >= UINT_MAX / 2) return AVERROR(EINVAL); - q->decoded_bytes_buffer = av_mallocz(FFALIGN(avctx->block_align, 4) + - AV_INPUT_BUFFER_PADDING_SIZE); + q->decoded_bytes_buffer = (uint8_t *)av_mallocz(FFALIGN(avctx->block_align, 4) + AV_INPUT_BUFFER_PADDING_SIZE); if (!q->decoded_bytes_buffer) return AVERROR(ENOMEM); @@ -907,7 +906,7 @@ static int atrac3_decode_init(AVCodecContext *avctx) ff_atrac_init_gain_compensation(&q->gainc_ctx, 4, 3); - q->units = av_mallocz_array(avctx->channels, sizeof(*q->units)); + q->units = (ChannelUnit *)av_mallocz_array(avctx->channels, sizeof(*q->units)); if (!q->units) { atrac3_decode_close(avctx); return AVERROR(ENOMEM); @@ -917,9 +916,9 @@ static int atrac3_decode_init(AVCodecContext *avctx) } AVCodec ff_atrac3_decoder = { - .name = "atrac3", - .id = AV_CODEC_ID_ATRAC3, - .priv_data_size = sizeof(ATRAC3Context), - .init = atrac3_decode_init, - .close = atrac3_decode_close, + "atrac3", + AV_CODEC_ID_ATRAC3, + sizeof(ATRAC3Context), + &atrac3_decode_init, + &atrac3_decode_close, }; diff --git a/ext/at3_standalone/atrac3plus.c b/ext/at3_standalone/atrac3plus.cpp similarity index 99% rename from ext/at3_standalone/atrac3plus.c rename to ext/at3_standalone/atrac3plus.cpp index 4551517541..053b3404c6 100644 --- a/ext/at3_standalone/atrac3plus.c +++ b/ext/at3_standalone/atrac3plus.cpp @@ -29,7 +29,7 @@ #include //#include "avcodec.h" -#include "intmath.h" +#include "mathematics.h" #include "get_bits.h" #include "atrac3plus.h" #include "atrac3plus_data.h" diff --git a/ext/at3_standalone/atrac3plusdec.c b/ext/at3_standalone/atrac3plusdec.cpp similarity index 97% rename from ext/at3_standalone/atrac3plusdec.c rename to ext/at3_standalone/atrac3plusdec.cpp index 4216cb9f9b..15a35dfc30 100644 --- a/ext/at3_standalone/atrac3plusdec.c +++ b/ext/at3_standalone/atrac3plusdec.cpp @@ -66,7 +66,7 @@ typedef struct ATRAC3PContext { int atrac3p_decode_close(AVCodecContext *avctx) { - ATRAC3PContext *ctx = avctx->priv_data; + ATRAC3PContext *ctx = (ATRAC3PContext *)avctx->priv_data; av_freep(&ctx->ch_units); @@ -144,7 +144,7 @@ static int set_channel_params(ATRAC3PContext *ctx, int atrac3p_decode_init(AVCodecContext *avctx) { - ATRAC3PContext *ctx = avctx->priv_data; + ATRAC3PContext *ctx = (ATRAC3PContext *)avctx->priv_data; int i, ch, ret; if (!avctx->block_align) { @@ -168,7 +168,7 @@ int atrac3p_decode_init(AVCodecContext *avctx) ctx->my_channel_layout = avctx->channel_layout; - ctx->ch_units = av_mallocz_array(ctx->num_channel_blocks, sizeof(*ctx->ch_units)); + ctx->ch_units = (Atrac3pChanUnitCtx *)av_mallocz_array(ctx->num_channel_blocks, sizeof(*ctx->ch_units)); if (!ctx->ch_units) { atrac3p_decode_close(avctx); @@ -324,7 +324,7 @@ static void reconstruct_frame(ATRAC3PContext *ctx, Atrac3pChanUnitCtx *ch_unit, int atrac3p_decode_frame(AVCodecContext *avctx, float *out_data[2], int *nb_samples, int *got_frame_ptr, const uint8_t *avpkt_data, int avpkt_size) { - ATRAC3PContext *ctx = avctx->priv_data; + ATRAC3PContext *ctx = (ATRAC3PContext *)avctx->priv_data; int i, ret, ch_unit_id, ch_block = 0, out_ch_index = 0, channels_to_process; float **samples_p = out_data; @@ -378,9 +378,9 @@ int atrac3p_decode_frame(AVCodecContext *avctx, float *out_data[2], int *nb_samp } AVCodec ff_atrac3p_decoder = { - .name = "atrac3plus", - .id = AV_CODEC_ID_ATRAC3P, - .priv_data_size = sizeof(ATRAC3PContext), - .init = atrac3p_decode_init, - .close = atrac3p_decode_close, + "atrac3plus", + AV_CODEC_ID_ATRAC3P, + sizeof(ATRAC3PContext), + atrac3p_decode_init, + atrac3p_decode_close, }; diff --git a/ext/at3_standalone/atrac3plusdsp.c b/ext/at3_standalone/atrac3plusdsp.cpp similarity index 100% rename from ext/at3_standalone/atrac3plusdsp.c rename to ext/at3_standalone/atrac3plusdsp.cpp diff --git a/ext/at3_standalone/avcodec.c b/ext/at3_standalone/avcodec.cpp similarity index 95% rename from ext/at3_standalone/avcodec.c rename to ext/at3_standalone/avcodec.cpp index 19cf6a2b3f..0ef45272c8 100644 --- a/ext/at3_standalone/avcodec.c +++ b/ext/at3_standalone/avcodec.cpp @@ -39,7 +39,7 @@ AVCodecContext *avcodec_alloc_context3(const AVCodec *codec) { - AVCodecContext *avctx = av_mallocz(sizeof(AVCodecContext)); + AVCodecContext *avctx = (AVCodecContext *)av_mallocz(sizeof(AVCodecContext)); if (!avctx) return NULL; int flags = 0; @@ -73,8 +73,7 @@ void avcodec_free_context(AVCodecContext **pavctx) av_freep(pavctx); } - -int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, void **options) +int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, void *options) { int ret = 0; diff --git a/ext/at3_standalone/avcodec.h b/ext/at3_standalone/avcodec.h index 330e3209b0..1b444e0222 100644 --- a/ext/at3_standalone/avcodec.h +++ b/ext/at3_standalone/avcodec.h @@ -496,11 +496,6 @@ typedef struct AVCodec { */ int priv_data_size; - /** - * Initialize codec static data, called from avcodec_register(). - */ - void (*init_static_data)(struct AVCodec *codec); - int (*init)(AVCodecContext *); /** * Encode data to an AVPacket. @@ -518,11 +513,6 @@ typedef struct AVCodec { * Will be called when seeking */ void (*flush)(AVCodecContext *); - /** - * Internal codec capabilities. - * See FF_CODEC_CAP_* in internal.h - */ - int caps_internal; } AVCodec; /** diff --git a/ext/at3_standalone/channel_layout.c b/ext/at3_standalone/channel_layout.cpp similarity index 73% rename from ext/at3_standalone/channel_layout.c rename to ext/at3_standalone/channel_layout.cpp index f35dbf50f2..f045a381d3 100644 --- a/ext/at3_standalone/channel_layout.c +++ b/ext/at3_standalone/channel_layout.cpp @@ -39,31 +39,31 @@ struct channel_name { }; static const struct channel_name channel_names[] = { - [0] = { "FL", "front left" }, - [1] = { "FR", "front right" }, - [2] = { "FC", "front center" }, - [3] = { "LFE", "low frequency" }, - [4] = { "BL", "back left" }, - [5] = { "BR", "back right" }, - [6] = { "FLC", "front left-of-center" }, - [7] = { "FRC", "front right-of-center" }, - [8] = { "BC", "back center" }, - [9] = { "SL", "side left" }, - [10] = { "SR", "side right" }, - [11] = { "TC", "top center" }, - [12] = { "TFL", "top front left" }, - [13] = { "TFC", "top front center" }, - [14] = { "TFR", "top front right" }, - [15] = { "TBL", "top back left" }, - [16] = { "TBC", "top back center" }, - [17] = { "TBR", "top back right" }, - [29] = { "DL", "downmix left" }, - [30] = { "DR", "downmix right" }, - [31] = { "WL", "wide left" }, - [32] = { "WR", "wide right" }, - [33] = { "SDL", "surround direct left" }, - [34] = { "SDR", "surround direct right" }, - [35] = { "LFE2", "low frequency 2" }, + { "FL", "front left" }, + { "FR", "front right" }, + { "FC", "front center" }, + { "LFE", "low frequency" }, + { "BL", "back left" }, + { "BR", "back right" }, + { "FLC", "front left-of-center" }, + { "FRC", "front right-of-center" }, + { "BC", "back center" }, + { "SL", "side left" }, + { "SR", "side right" }, + { "TC", "top center" }, + { "TFL", "top front left" }, + { "TFC", "top front center" }, + { "TFR", "top front right" }, + { "TBL", "top back left" }, + { "TBC", "top back center" }, + { "TBR", "top back right" }, + { "DL", "downmix left" }, + { "DR", "downmix right" }, + { "WL", "wide left" }, + { "WR", "wide right" }, + { "SDL", "surround direct left" }, + { "SDR", "surround direct right" }, + { "LFE2", "low frequency 2" }, }; static const char *get_channel_name(int channel_id) diff --git a/ext/at3_standalone/compat.c b/ext/at3_standalone/compat.c deleted file mode 100644 index a1b0ba4d2d..0000000000 --- a/ext/at3_standalone/compat.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include - -#include "ext/at3_standalone/compat.h" - -void av_log(void *avcl, int level, const char *fmt, ...) { - -} - -int av_get_cpu_flags(void) { - return 0; -} - -size_t av_strlcpy(char *dst, const char *src, size_t size) -{ - size_t len = 0; - while (++len < size && *src) - *dst++ = *src++; - if (len <= size) - *dst = 0; - return len + strlen(src) - 1; -} - -const uint8_t ff_log2_tab[256] = { - 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, - 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, - 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, - 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 -}; diff --git a/ext/at3_standalone/compat.cpp b/ext/at3_standalone/compat.cpp new file mode 100644 index 0000000000..de17629718 --- /dev/null +++ b/ext/at3_standalone/compat.cpp @@ -0,0 +1,23 @@ +#include +#include +#include + +#include "ext/at3_standalone/compat.h" + +void av_log(void *avcl, int level, const char *fmt, ...) { + +} + +int av_get_cpu_flags(void) { + return 0; +} + +size_t av_strlcpy(char *dst, const char *src, size_t size) +{ + size_t len = 0; + while (++len < size && *src) + *dst++ = *src++; + if (len <= size) + *dst = 0; + return len + strlen(src) - 1; +} diff --git a/ext/at3_standalone/compat.h b/ext/at3_standalone/compat.h index 64217744e3..30bc8578f7 100644 --- a/ext/at3_standalone/compat.h +++ b/ext/at3_standalone/compat.h @@ -33,7 +33,6 @@ #define av_assert1(cond) #define av_assert2(cond) #define attribute_deprecated -#define attribute_align_arg #define av_printf_format(a,b) #define avpriv_report_missing_feature(...) @@ -81,14 +80,6 @@ void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4); #define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) #define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0])) -#ifndef av_log2 -av_const int av_log2(unsigned v); -#endif - -#ifndef av_log2_16bit -av_const int av_log2_16bit(unsigned v); -#endif - #define MKTAG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((unsigned)(d) << 24)) #pragma warning(disable:4305) diff --git a/ext/at3_standalone/fft.c b/ext/at3_standalone/fft.cpp similarity index 66% rename from ext/at3_standalone/fft.c rename to ext/at3_standalone/fft.cpp index 128de80f83..e4c7d67f54 100644 --- a/ext/at3_standalone/fft.c +++ b/ext/at3_standalone/fft.cpp @@ -35,15 +35,6 @@ #define sqrthalf (float)M_SQRT1_2 -#define BF(x, y, a, b) do { \ - x = a - b; \ - y = a + b; \ - } while (0) - -#define ff_imdct_calc_c ff_imdct_calc_c -#define ff_imdct_half_c ff_imdct_half_c -#define ff_mdct_calc_c ff_mdct_calc_c - void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input); void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input); void ff_mdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input); @@ -103,7 +94,7 @@ void ff_init_ff_cos_tabs(int index) double freq = 2*M_PI/m; FFTSample *tab = ff_cos_tabs[index]; for(i=0; i<=m/4; i++) - tab[i] = FIX15(cos(i*freq)); + tab[i] = cos(i*freq); for(i=1; inbits = nbits; n = 1 << nbits; - s->revtab = av_malloc(n * sizeof(uint16_t)); + s->revtab = (uint16_t *)av_malloc(n * sizeof(uint16_t)); if (!s->revtab) goto fail; - s->tmp_buf = av_malloc(n * sizeof(FFTComplex)); + s->tmp_buf = (FFTComplex *)av_malloc(n * sizeof(FFTComplex)); if (!s->tmp_buf) goto fail; s->inverse = inverse; @@ -147,7 +138,6 @@ int ff_fft_init(FFTContext *s, int nbits, int inverse) s->imdct_calc = ff_imdct_calc_c; s->imdct_half = ff_imdct_half_c; s->mdct_calc = ff_mdct_calc_c; - s->mdct_calcw = s->mdct_calc; for(j=4; j<=nbits; j++) { ff_init_ff_cos_tabs(j); } @@ -182,6 +172,11 @@ void ff_fft_end(FFTContext *s) av_freep(&s->tmp_buf); } +#define BF(x, y, a, b) do { \ + x = a - b; \ + y = a + b; \ + } while (0) + #define BUTTERFLIES(a0,a1,a2,a3) {\ BF(t3, t5, t5, t1);\ BF(a2.re, a0.re, a0.re, t5);\ @@ -327,3 +322,176 @@ static void fft_calc_c(FFTContext *s, FFTComplex *z) { fft_dispatch[s->nbits-2](z); } + + +#include +#include + +#include "mathematics.h" +#include "fft.h" +#include "mem.h" + +/** + * init MDCT or IMDCT computation. + */ +int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale) +{ + int n, n4, i; + double alpha, theta; + int tstep; + + memset(s, 0, sizeof(*s)); + n = 1 << nbits; + s->mdct_bits = nbits; + s->mdct_size = n; + n4 = n >> 2; + s->mdct_permutation = FF_MDCT_PERM_NONE; + + if (ff_fft_init(s, s->mdct_bits - 2, inverse) < 0) + goto fail; + + s->tcos = (FFTSample *)av_malloc_array(n / 2, sizeof(FFTSample)); + if (!s->tcos) + goto fail; + + switch (s->mdct_permutation) { + case FF_MDCT_PERM_NONE: + s->tsin = s->tcos + n4; + tstep = 1; + break; + case FF_MDCT_PERM_INTERLEAVE: + s->tsin = s->tcos + 1; + tstep = 2; + break; + default: + goto fail; + } + + theta = 1.0 / 8.0 + (scale < 0 ? n4 : 0); + scale = sqrt(fabs(scale)); + for (i = 0; i < n4; i++) { + alpha = 2 * M_PI * (i + theta) / n; + s->tcos[i * tstep] = -cos(alpha) * scale; + s->tsin[i * tstep] = -sin(alpha) * scale; + } + return 0; +fail: + ff_mdct_end(s); + return -1; +} + +/** + * Compute the middle half of the inverse MDCT of size N = 2^nbits, + * thus excluding the parts that can be derived by symmetry + * @param output N/2 samples + * @param input N/2 samples + */ +void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input) +{ + int k, n8, n4, n2, n, j; + const uint16_t *revtab = s->revtab; + const FFTSample *tcos = s->tcos; + const FFTSample *tsin = s->tsin; + const FFTSample *in1, *in2; + FFTComplex *z = (FFTComplex *)output; + + n = 1 << s->mdct_bits; + n2 = n >> 1; + n4 = n >> 2; + n8 = n >> 3; + + /* pre rotation */ + in1 = input; + in2 = input + n2 - 1; + for (k = 0; k < n4; k++) { + j = revtab[k]; + CMUL(z[j].re, z[j].im, *in2, *in1, tcos[k], tsin[k]); + in1 += 2; + in2 -= 2; + } + s->fft_calc(s, z); + + /* post rotation + reordering */ + for (k = 0; k < n8; k++) { + FFTSample r0, i0, r1, i1; + CMUL(r0, i1, z[n8 - k - 1].im, z[n8 - k - 1].re, tsin[n8 - k - 1], tcos[n8 - k - 1]); + CMUL(r1, i0, z[n8 + k].im, z[n8 + k].re, tsin[n8 + k], tcos[n8 + k]); + z[n8 - k - 1].re = r0; + z[n8 - k - 1].im = i0; + z[n8 + k].re = r1; + z[n8 + k].im = i1; + } +} + +/** + * Compute inverse MDCT of size N = 2^nbits + * @param output N samples + * @param input N/2 samples + */ +void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input) +{ + int k; + int n = 1 << s->mdct_bits; + int n2 = n >> 1; + int n4 = n >> 2; + + ff_imdct_half_c(s, output + n4, input); + + for (k = 0; k < n4; k++) { + output[k] = -output[n2 - k - 1]; + output[n - k - 1] = output[n2 + k]; + } +} + +/** + * Compute MDCT of size N = 2^nbits + * @param input N samples + * @param out N/2 samples + */ +void ff_mdct_calc_c(FFTContext *s, FFTSample *out, const FFTSample *input) +{ + int i, j, n, n8, n4, n2, n3; + FFTDouble re, im; + const uint16_t *revtab = s->revtab; + const FFTSample *tcos = s->tcos; + const FFTSample *tsin = s->tsin; + FFTComplex *x = (FFTComplex *)out; + + n = 1 << s->mdct_bits; + n2 = n >> 1; + n4 = n >> 2; + n8 = n >> 3; + n3 = 3 * n4; + + /* pre rotation */ + for (i = 0; i < n8; i++) { + re = (-input[2 * i + n3] - input[n3 - 1 - 2 * i]); + im = (-input[n4 + 2 * i] + input[n4 - 1 - 2 * i]); + j = revtab[i]; + CMUL(x[j].re, x[j].im, re, im, -tcos[i], tsin[i]); + + re = (input[2 * i] - input[n2 - 1 - 2 * i]); + im = (-input[n2 + 2 * i] - input[n - 1 - 2 * i]); + j = revtab[n8 + i]; + CMUL(x[j].re, x[j].im, re, im, -tcos[n8 + i], tsin[n8 + i]); + } + + s->fft_calc(s, x); + + /* post rotation */ + for (i = 0; i < n8; i++) { + FFTSample r0, i0, r1, i1; + CMUL(i1, r0, x[n8 - i - 1].re, x[n8 - i - 1].im, -tsin[n8 - i - 1], -tcos[n8 - i - 1]); + CMUL(i0, r1, x[n8 + i].re, x[n8 + i].im, -tsin[n8 + i], -tcos[n8 + i]); + x[n8 - i - 1].re = r0; + x[n8 - i - 1].im = i0; + x[n8 + i].re = r1; + x[n8 + i].im = i1; + } +} + +void ff_mdct_end(FFTContext *s) +{ + av_freep(&s->tcos); + ff_fft_end(s); +} diff --git a/ext/at3_standalone/fft.h b/ext/at3_standalone/fft.h index 2bc28275eb..79725efcbf 100644 --- a/ext/at3_standalone/fft.h +++ b/ext/at3_standalone/fft.h @@ -19,18 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVCODEC_FFT_H -#define AVCODEC_FFT_H - -#ifndef FFT_FLOAT -#define FFT_FLOAT 1 -#endif - -#ifndef FFT_FIXED_32 -#define FFT_FIXED_32 0 -#endif - -#define FIX15(v) (v) +#pragma once #define CMUL(dre, dim, are, aim, bre, bim) do { \ (dre) = (are) * (bre) - (aim) * (bim); \ @@ -51,10 +40,6 @@ typedef struct FFTContext FFTContext; typedef float FFTDouble; -typedef struct FFTDComplex { - FFTDouble re, im; -} FFTDComplex; - /* FFT computation */ enum mdct_permutation_type { @@ -84,7 +69,6 @@ struct FFTContext { void (*imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input); void (*imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input); void (*mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input); - void (*mdct_calcw)(struct FFTContext *s, FFTDouble *output, const FFTSample *input); enum mdct_permutation_type mdct_permutation; }; @@ -123,5 +107,3 @@ void ff_fft_end(FFTContext *s); int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale); void ff_mdct_end(FFTContext *s); - -#endif /* AVCODEC_FFT_H */ diff --git a/ext/at3_standalone/float_dsp.c b/ext/at3_standalone/float_dsp.cpp similarity index 100% rename from ext/at3_standalone/float_dsp.c rename to ext/at3_standalone/float_dsp.cpp diff --git a/ext/at3_standalone/get_bits.c b/ext/at3_standalone/get_bits.cpp similarity index 98% rename from ext/at3_standalone/get_bits.c rename to ext/at3_standalone/get_bits.cpp index 34b8a3fd5b..818099d5f8 100644 --- a/ext/at3_standalone/get_bits.c +++ b/ext/at3_standalone/get_bits.cpp @@ -82,7 +82,7 @@ static int alloc_table(VLC *vlc, int size, int use_static) if (use_static) abort(); // cannot do anything, init_vlc() is used with too little memory vlc->table_allocated += (1 << vlc->bits); - vlc->table = av_realloc_f(vlc->table, vlc->table_allocated, sizeof(VLC_TYPE) * 2); + vlc->table = (VLC_TYPE(*)[2])av_realloc_f(vlc->table, vlc->table_allocated, sizeof(VLC_TYPE) * 2); if (!vlc->table) { vlc->table_allocated = 0; vlc->table_size = 0; @@ -111,7 +111,8 @@ typedef struct VLCcode { static int compare_vlcspec(const void *a, const void *b) { - const VLCcode *sa = a, *sb = b; + const VLCcode *sa = (VLCcode *)a; + const VLCcode *sb = (VLCcode *)b; return (sa->code >> 1) - (sb->code >> 1); } /** @@ -258,7 +259,7 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, vlc->table_allocated = 0; vlc->table_size = 0; - buf = av_malloc_array((nb_codes + 1), sizeof(VLCcode)); + buf = (VLCcode *)av_malloc_array((nb_codes + 1), sizeof(VLCcode)); if (!buf) return AVERROR(ENOMEM); } diff --git a/ext/at3_standalone/get_bits.h b/ext/at3_standalone/get_bits.h index 0a4b581785..2b915981ea 100644 --- a/ext/at3_standalone/get_bits.h +++ b/ext/at3_standalone/get_bits.h @@ -207,7 +207,7 @@ static inline int get_bits_count(const GetBitContext *s) static inline int get_sbits(GetBitContext *s, int n) { - register int tmp; + int tmp; OPEN_READER(re, s); av_assert2(n>0 && n<=25); UPDATE_CACHE(re, s); @@ -222,7 +222,7 @@ static inline int get_sbits(GetBitContext *s, int n) */ static inline unsigned int get_bits(GetBitContext *s, int n) { - register int tmp; + int tmp; OPEN_READER(re, s); av_assert2(n>0 && n<=25); UPDATE_CACHE(re, s); @@ -242,7 +242,7 @@ static av_always_inline int get_bitsz(GetBitContext *s, int n) static inline unsigned int get_bits_le(GetBitContext *s, int n) { - register int tmp; + int tmp; OPEN_READER(re, s); av_assert2(n>0 && n<=25); UPDATE_CACHE_LE(re, s); diff --git a/ext/at3_standalone/intmath.c b/ext/at3_standalone/intmath.c deleted file mode 100644 index ca9521f987..0000000000 --- a/ext/at3_standalone/intmath.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "intmath.h" diff --git a/ext/at3_standalone/intmath.h b/ext/at3_standalone/intmath.h deleted file mode 100644 index 41020aaefd..0000000000 --- a/ext/at3_standalone/intmath.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2010 Mans Rullgard - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#pragma once - -#include - -#include "compat.h" - -#if HAVE_FAST_CLZ -#if AV_GCC_VERSION_AT_LEAST(3,4) -#ifndef ff_log2 -# define ff_log2(x) (31 - __builtin_clz((x)|1)) -# ifndef ff_log2_16bit -# define ff_log2_16bit av_log2 -# endif -#endif /* ff_log2 */ -#endif /* AV_GCC_VERSION_AT_LEAST(3,4) */ -#endif - -extern const uint8_t ff_log2_tab[256]; - -#ifndef ff_log2 -#define ff_log2 ff_log2_c -static av_always_inline av_const int ff_log2_c(unsigned int v) -{ - int n = 0; - if (v & 0xffff0000) { - v >>= 16; - n += 16; - } - if (v & 0xff00) { - v >>= 8; - n += 8; - } - n += ff_log2_tab[v]; - - return n; -} -#endif - -#ifndef ff_log2_16bit -#define ff_log2_16bit ff_log2_16bit_c -static av_always_inline av_const int ff_log2_16bit_c(unsigned int v) -{ - int n = 0; - if (v & 0xff00) { - v >>= 8; - n += 8; - } - n += ff_log2_tab[v]; - - return n; -} -#endif - -#define av_log2 ff_log2 -#define av_log2_16bit ff_log2_16bit - -/** - * @addtogroup lavu_math - * @{ - */ - -#if HAVE_FAST_CLZ -#if AV_GCC_VERSION_AT_LEAST(3,4) -#ifndef ff_ctz -#define ff_ctz(v) __builtin_ctz(v) -#endif -#ifndef ff_ctzll -#define ff_ctzll(v) __builtin_ctzll(v) -#endif -#ifndef ff_clz -#define ff_clz(v) __builtin_clz(v) -#endif -#endif -#endif - -#ifndef ff_ctz -#define ff_ctz ff_ctz_c -/** - * Trailing zero bit count. - * - * @param v input value. If v is 0, the result is undefined. - * @return the number of trailing 0-bits - */ -/* We use the De-Bruijn method outlined in: - * http://supertech.csail.mit.edu/papers/debruijn.pdf. */ -static av_always_inline av_const int ff_ctz_c(int v) -{ - static const uint8_t debruijn_ctz32[32] = { - 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, - 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 - }; - return debruijn_ctz32[(uint32_t)((v & -v) * 0x077CB531U) >> 27]; -} -#endif - -#ifndef ff_ctzll -#define ff_ctzll ff_ctzll_c -/* We use the De-Bruijn method outlined in: - * http://supertech.csail.mit.edu/papers/debruijn.pdf. */ -static av_always_inline av_const int ff_ctzll_c(long long v) -{ - static const uint8_t debruijn_ctz64[64] = { - 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, - 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11, - 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, - 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 - }; - return debruijn_ctz64[(uint64_t)((v & -v) * 0x022FDD63CC95386DU) >> 58]; -} -#endif diff --git a/ext/at3_standalone/mathematics.c b/ext/at3_standalone/mathematics.cpp similarity index 81% rename from ext/at3_standalone/mathematics.c rename to ext/at3_standalone/mathematics.cpp index 65d63085c7..f99bf1b0d0 100644 --- a/ext/at3_standalone/mathematics.c +++ b/ext/at3_standalone/mathematics.cpp @@ -27,7 +27,6 @@ #include #include "mathematics.h" -#include "intmath.h" #include "compat.h" /* Stein's binary GCD algorithm: @@ -66,11 +65,11 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd) if (rnd & AV_ROUND_PASS_MINMAX) { if (a == INT64_MIN || a == INT64_MAX) return a; - rnd -= AV_ROUND_PASS_MINMAX; + rnd = (AVRounding)(rnd - AV_ROUND_PASS_MINMAX); } if (a < 0) - return -(uint64_t)av_rescale_rnd(-FFMAX(a, -INT64_MAX), b, c, rnd ^ ((rnd >> 1) & 1)); + return -(uint64_t)av_rescale_rnd(-FFMAX(a, -INT64_MAX), b, c, (AVRounding)((int)rnd ^ (((int)rnd >> 1) & 1))); if (rnd == AV_ROUND_NEAR_INF) r = c / 2; @@ -155,7 +154,7 @@ int av_reduce(int *dst_num, int *dst_den, den = FFABS(den) / gcd; } if (num <= max && den <= max) { - a1 = (AVRational){ num, den }; + a1 = AVRational{ (int)num, (int)den }; den = 0; } @@ -170,12 +169,12 @@ int av_reduce(int *dst_num, int *dst_den, if (a1.den) x = FFMIN(x, (max - a0.den) / a1.den); if (den * (2 * x * a1.den + a0.den) > num * a1.den) - a1 = (AVRational){ x * a1.num + a0.num, x * a1.den + a0.den }; + a1 = AVRational{(int)(x * a1.num + a0.num), (int)(x * a1.den + a0.den) }; break; } a0 = a1; - a1 = (AVRational){ a2n, a2d }; + a1 = AVRational{(int)a2n, (int)a2d }; num = den; den = next_den; } @@ -198,7 +197,7 @@ AVRational av_mul_q(AVRational b, AVRational c) AVRational av_div_q(AVRational b, AVRational c) { - return av_mul_q(b, (AVRational) { c.den, c.num }); + return av_mul_q(b, AVRational { c.den, c.num }); } AVRational av_add_q(AVRational b, AVRational c) { @@ -215,9 +214,9 @@ AVRational av_d2q(double d, int max) int exponent; int64_t den; if (isnan(d)) - return (AVRational) { 0, 0 }; + return AVRational { 0, 0 }; if (fabs(d) > INT_MAX + 3LL) - return (AVRational) { d < 0 ? -1 : 1, 0 }; + return AVRational { d < 0 ? -1 : 1, 0 }; frexp(d, &exponent); exponent = FFMAX(exponent - 1, 0); den = 1LL << (61 - exponent); @@ -228,3 +227,42 @@ AVRational av_d2q(double d, int max) return a; } + +static const uint8_t ff_logg2_tab[256] = { + 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, + 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 +}; + +int av_log2(unsigned int v) +{ + int n = 0; + if (v & 0xffff0000) { + v >>= 16; + n += 16; + } + if (v & 0xff00) { + v >>= 8; + n += 8; + } + n += ff_logg2_tab[v]; + + return n; +} + +int av_log2_16bit(unsigned int v) +{ + int n = 0; + if (v & 0xff00) { + v >>= 8; + n += 8; + } + n += ff_logg2_tab[v]; + + return n; +} diff --git a/ext/at3_standalone/mathematics.h b/ext/at3_standalone/mathematics.h index 5fd4af7a2d..4a026e59cb 100644 --- a/ext/at3_standalone/mathematics.h +++ b/ext/at3_standalone/mathematics.h @@ -18,8 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVUTIL_MATHEMATICS_H -#define AVUTIL_MATHEMATICS_H +#pragma once #include #include @@ -27,8 +26,75 @@ #include "compat.h" -extern const uint32_t ff_inverse[257]; -extern const uint8_t ff_sqrt_tab[256]; + +#if HAVE_FAST_CLZ +#if AV_GCC_VERSION_AT_LEAST(3,4) +#ifndef ff_log2 +# define ff_log2(x) (31 - __builtin_clz((x)|1)) +# ifndef ff_log2_16bit +# define ff_log2_16bit av_log2 +# endif +#endif /* ff_log2 */ +#endif /* AV_GCC_VERSION_AT_LEAST(3,4) */ +#endif + +int av_log2(unsigned int v); +int av_log2_16bit(unsigned int v); + +/** + * @addtogroup lavu_math + * @{ + */ + +#if HAVE_FAST_CLZ +#if AV_GCC_VERSION_AT_LEAST(3,4) +#ifndef ff_ctz +#define ff_ctz(v) __builtin_ctz(v) +#endif +#ifndef ff_ctzll +#define ff_ctzll(v) __builtin_ctzll(v) +#endif +#ifndef ff_clz +#define ff_clz(v) __builtin_clz(v) +#endif +#endif +#endif + +#ifndef ff_ctz +#define ff_ctz ff_ctz_c + /** + * Trailing zero bit count. + * + * @param v input value. If v is 0, the result is undefined. + * @return the number of trailing 0-bits + */ + /* We use the De-Bruijn method outlined in: + * http://supertech.csail.mit.edu/papers/debruijn.pdf. */ +static av_always_inline av_const int ff_ctz_c(int v) +{ + static const uint8_t debruijn_ctz32[32] = { + 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, + 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 + }; + return debruijn_ctz32[(uint32_t)((v & -v) * 0x077CB531U) >> 27]; +} +#endif + +#ifndef ff_ctzll +#define ff_ctzll ff_ctzll_c +/* We use the De-Bruijn method outlined in: + * http://supertech.csail.mit.edu/papers/debruijn.pdf. */ +static av_always_inline av_const int ff_ctzll_c(long long v) +{ + static const uint8_t debruijn_ctz64[64] = { + 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, + 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11, + 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, + 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 + }; + return debruijn_ctz64[(uint64_t)((v & -v) * 0x022FDD63CC95386DU) >> 58]; +} +#endif static inline int sign_extend(int val, unsigned bits) { @@ -258,5 +324,3 @@ static inline int av_popcount64(uint64_t x) { return av_popcount((uint32_t)x) + av_popcount((uint32_t)(x >> 32)); } - -#endif /* AVUTIL_MATHEMATICS_H */ diff --git a/ext/at3_standalone/mdct_template.c b/ext/at3_standalone/mdct_template.c deleted file mode 100644 index f17dd1c118..0000000000 --- a/ext/at3_standalone/mdct_template.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * MDCT/IMDCT transforms - * Copyright (c) 2002 Fabrice Bellard - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include - -#include "mathematics.h" -#include "fft.h" -#include "mem.h" - -/** - * init MDCT or IMDCT computation. - */ -int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale) -{ - int n, n4, i; - double alpha, theta; - int tstep; - - memset(s, 0, sizeof(*s)); - n = 1 << nbits; - s->mdct_bits = nbits; - s->mdct_size = n; - n4 = n >> 2; - s->mdct_permutation = FF_MDCT_PERM_NONE; - - if (ff_fft_init(s, s->mdct_bits - 2, inverse) < 0) - goto fail; - - s->tcos = av_malloc_array(n/2, sizeof(FFTSample)); - if (!s->tcos) - goto fail; - - switch (s->mdct_permutation) { - case FF_MDCT_PERM_NONE: - s->tsin = s->tcos + n4; - tstep = 1; - break; - case FF_MDCT_PERM_INTERLEAVE: - s->tsin = s->tcos + 1; - tstep = 2; - break; - default: - goto fail; - } - - theta = 1.0 / 8.0 + (scale < 0 ? n4 : 0); - scale = sqrt(fabs(scale)); - for(i=0;itcos[i*tstep] = FIX15(-cos(alpha) * scale); - s->tsin[i*tstep] = FIX15(-sin(alpha) * scale); - } - return 0; - fail: - ff_mdct_end(s); - return -1; -} - -/** - * Compute the middle half of the inverse MDCT of size N = 2^nbits, - * thus excluding the parts that can be derived by symmetry - * @param output N/2 samples - * @param input N/2 samples - */ -void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input) -{ - int k, n8, n4, n2, n, j; - const uint16_t *revtab = s->revtab; - const FFTSample *tcos = s->tcos; - const FFTSample *tsin = s->tsin; - const FFTSample *in1, *in2; - FFTComplex *z = (FFTComplex *)output; - - n = 1 << s->mdct_bits; - n2 = n >> 1; - n4 = n >> 2; - n8 = n >> 3; - - /* pre rotation */ - in1 = input; - in2 = input + n2 - 1; - for(k = 0; k < n4; k++) { - j=revtab[k]; - CMUL(z[j].re, z[j].im, *in2, *in1, tcos[k], tsin[k]); - in1 += 2; - in2 -= 2; - } - s->fft_calc(s, z); - - /* post rotation + reordering */ - for(k = 0; k < n8; k++) { - FFTSample r0, i0, r1, i1; - CMUL(r0, i1, z[n8-k-1].im, z[n8-k-1].re, tsin[n8-k-1], tcos[n8-k-1]); - CMUL(r1, i0, z[n8+k ].im, z[n8+k ].re, tsin[n8+k ], tcos[n8+k ]); - z[n8-k-1].re = r0; - z[n8-k-1].im = i0; - z[n8+k ].re = r1; - z[n8+k ].im = i1; - } -} - -/** - * Compute inverse MDCT of size N = 2^nbits - * @param output N samples - * @param input N/2 samples - */ -void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input) -{ - int k; - int n = 1 << s->mdct_bits; - int n2 = n >> 1; - int n4 = n >> 2; - - ff_imdct_half_c(s, output+n4, input); - - for(k = 0; k < n4; k++) { - output[k] = -output[n2-k-1]; - output[n-k-1] = output[n2+k]; - } -} - -/** - * Compute MDCT of size N = 2^nbits - * @param input N samples - * @param out N/2 samples - */ -void ff_mdct_calc_c(FFTContext *s, FFTSample *out, const FFTSample *input) -{ - int i, j, n, n8, n4, n2, n3; - FFTDouble re, im; - const uint16_t *revtab = s->revtab; - const FFTSample *tcos = s->tcos; - const FFTSample *tsin = s->tsin; - FFTComplex *x = (FFTComplex *)out; - - n = 1 << s->mdct_bits; - n2 = n >> 1; - n4 = n >> 2; - n8 = n >> 3; - n3 = 3 * n4; - - /* pre rotation */ - for(i=0;ifft_calc(s, x); - - /* post rotation */ - for(i=0;itcos); - ff_fft_end(s); -} diff --git a/ext/at3_standalone/mem.c b/ext/at3_standalone/mem.cpp similarity index 98% rename from ext/at3_standalone/mem.c rename to ext/at3_standalone/mem.cpp index 0e2314fb3b..d9ade84de3 100644 --- a/ext/at3_standalone/mem.c +++ b/ext/at3_standalone/mem.cpp @@ -104,7 +104,7 @@ void av_freep(void *arg) void *val; memcpy(&val, arg, sizeof(val)); - memcpy(arg, &(void *){ NULL }, sizeof(val)); + memset(arg, 0, sizeof(val)); av_free(val); } diff --git a/ext/at3_standalone/sinewin.c b/ext/at3_standalone/sinewin.cpp similarity index 100% rename from ext/at3_standalone/sinewin.c rename to ext/at3_standalone/sinewin.cpp