Switch at3_standalone to C++ to avoid namespace clashes

This commit is contained in:
Henrik Rydgård 2024-04-11 10:24:14 +02:00
parent 91df8ebfda
commit e10b90b718
27 changed files with 410 additions and 547 deletions

View File

@ -396,9 +396,7 @@
<ClInclude Include="..\ext\at3_standalone\fft.h" />
<ClInclude Include="..\ext\at3_standalone\float_dsp.h" />
<ClInclude Include="..\ext\at3_standalone\get_bits.h" />
<ClInclude Include="..\ext\at3_standalone\intmath.h" />
<ClInclude Include="..\ext\at3_standalone\intreadwrite.h" />
<ClInclude Include="..\ext\at3_standalone\log.h" />
<ClInclude Include="..\ext\at3_standalone\mathematics.h" />
<ClInclude Include="..\ext\at3_standalone\mem.h" />
<ClInclude Include="..\ext\at3_standalone\sinewin.h" />
@ -601,21 +599,20 @@
<ClInclude Include="x64Emitter.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\ext\at3_standalone\atrac.c" />
<ClCompile Include="..\ext\at3_standalone\atrac3.c" />
<ClCompile Include="..\ext\at3_standalone\atrac3plus.c" />
<ClCompile Include="..\ext\at3_standalone\atrac3plusdec.c" />
<ClCompile Include="..\ext\at3_standalone\atrac3plusdsp.c" />
<ClCompile Include="..\ext\at3_standalone\get_bits.c" />
<ClCompile Include="..\ext\at3_standalone\channel_layout.c" />
<ClCompile Include="..\ext\at3_standalone\compat.c" />
<ClCompile Include="..\ext\at3_standalone\fft.c" />
<ClCompile Include="..\ext\at3_standalone\float_dsp.c" />
<ClCompile Include="..\ext\at3_standalone\mathematics.c" />
<ClCompile Include="..\ext\at3_standalone\mdct_template.c" />
<ClCompile Include="..\ext\at3_standalone\mem.c" />
<ClCompile Include="..\ext\at3_standalone\avcodec.c" />
<ClCompile Include="..\ext\at3_standalone\sinewin.c" />
<ClCompile Include="..\ext\at3_standalone\atrac.cpp" />
<ClCompile Include="..\ext\at3_standalone\atrac3.cpp" />
<ClCompile Include="..\ext\at3_standalone\atrac3plus.cpp" />
<ClCompile Include="..\ext\at3_standalone\atrac3plusdec.cpp" />
<ClCompile Include="..\ext\at3_standalone\atrac3plusdsp.cpp" />
<ClCompile Include="..\ext\at3_standalone\get_bits.cpp" />
<ClCompile Include="..\ext\at3_standalone\channel_layout.cpp" />
<ClCompile Include="..\ext\at3_standalone\compat.cpp" />
<ClCompile Include="..\ext\at3_standalone\fft.cpp" />
<ClCompile Include="..\ext\at3_standalone\float_dsp.cpp" />
<ClCompile Include="..\ext\at3_standalone\mathematics.cpp" />
<ClCompile Include="..\ext\at3_standalone\mem.cpp" />
<ClCompile Include="..\ext\at3_standalone\avcodec.cpp" />
<ClCompile Include="..\ext\at3_standalone\sinewin.cpp" />
<ClCompile Include="..\ext\basis_universal\basisu_transcoder.cpp" />
<ClCompile Include="..\ext\libpng17\png.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>

View File

@ -569,12 +569,6 @@
<ClInclude Include="..\ext\at3_standalone\sinewin.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
<ClInclude Include="..\ext\at3_standalone\log.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
<ClInclude Include="..\ext\at3_standalone\intmath.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ABI.cpp" />
@ -1032,49 +1026,46 @@
<ClCompile Include="..\ext\minimp3\minimp3.cpp">
<Filter>ext\minimp3</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\atrac3.c">
<ClCompile Include="..\ext\at3_standalone\atrac3.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\atrac3plus.c">
<ClCompile Include="..\ext\at3_standalone\atrac3plus.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\atrac3plusdec.c">
<ClCompile Include="..\ext\at3_standalone\atrac3plusdec.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\atrac3plusdsp.c">
<ClCompile Include="..\ext\at3_standalone\atrac3plusdsp.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\float_dsp.c">
<ClCompile Include="..\ext\at3_standalone\float_dsp.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\mem.c">
<ClCompile Include="..\ext\at3_standalone\mem.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\sinewin.c">
<ClCompile Include="..\ext\at3_standalone\sinewin.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\avcodec.c">
<ClCompile Include="..\ext\at3_standalone\avcodec.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\channel_layout.c">
<ClCompile Include="..\ext\at3_standalone\channel_layout.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\atrac.c">
<ClCompile Include="..\ext\at3_standalone\atrac.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\mathematics.c">
<ClCompile Include="..\ext\at3_standalone\mathematics.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\mdct_template.c">
<ClCompile Include="..\ext\at3_standalone\fft.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\fft.c">
<ClCompile Include="..\ext\at3_standalone\get_bits.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\get_bits.c">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\compat.c">
<ClCompile Include="..\ext\at3_standalone\compat.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
</ItemGroup>

View File

@ -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)

View File

@ -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;

View File

@ -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,
};

View File

@ -29,7 +29,7 @@
#include <stdlib.h>
//#include "avcodec.h"
#include "intmath.h"
#include "mathematics.h"
#include "get_bits.h"
#include "atrac3plus.h"
#include "atrac3plus_data.h"

View File

@ -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,
};

View File

@ -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;

View File

@ -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;
/**

View File

@ -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)

View File

@ -1,34 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#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
};

View File

@ -0,0 +1,23 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#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;
}

View File

@ -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)

View File

@ -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; i<m/4; i++)
tab[m/2-i] = tab[i];
#endif
@ -134,10 +125,10 @@ int ff_fft_init(FFTContext *s, int nbits, int inverse)
s->nbits = 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 <stdlib.h>
#include <string.h>
#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);
}

View File

@ -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 */

View File

@ -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);
}

View File

@ -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);

View File

@ -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"

View File

@ -1,130 +0,0 @@
/*
* Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
*
* 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 <stdint.h>
#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

View File

@ -27,7 +27,6 @@
#include <limits.h>
#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;
}

View File

@ -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 <stdint.h>
#include <math.h>
@ -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 */

View File

@ -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 <stdlib.h>
#include <string.h>
#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;i<n4;i++) {
alpha = 2 * M_PI * (i + theta) / n;
s->tcos[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;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);
}

View File

@ -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);
}