50 #define MUL16(a, b) ((a) * (b))
52 #define CMAC(pre, pim, are, aim, bre, bim) \
54 pre += (MUL16(are, bre) - MUL16(aim, bim)); \
55 pim += (MUL16(are, bim) + MUL16(bre, aim)); \
60 #define REF_SCALE(x, bits) (x)
64 #define REF_SCALE(x, bits) (x)
68 #define REF_SCALE(x, bits) ((x) / (1 << (bits)))
78 int i,
n = 1 << nbits;
84 for (i = 0; i < (n / 2); i++) {
85 double alpha = 2 *
M_PI * (float) i / (
float)
n;
86 double c1 = cos(alpha),
s1 = sin(alpha);
101 for (i = 0; i <
n; i++) {
102 double tmp_re = 0, tmp_im = 0;
104 for (j = 0; j <
n; j++) {
106 int k = (i * j) & (n - 1);
114 CMAC(tmp_re, tmp_im, c, s, q->
re, q->
im);
125 int i, k,
n = 1 << nbits;
127 for (i = 0; i <
n; i++) {
129 for (k = 0; k < n / 2; k++) {
130 int a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
131 double f = cos(
M_PI * a / (
double) (2 * n));
141 int i, k, n = 1 << nbits;
144 for (k = 0; k < n / 2; k++) {
146 for (i = 0; i <
n; i++) {
147 double a = (2 *
M_PI * (2 * i + 1 + n / 2) * (2 * k + 1) / (4 *
n));
148 s += input[i] * cos(a);
159 int i, k, n = 1 << nbits;
162 for (i = 0; i <
n; i++) {
163 double s = 0.5 * input[0];
164 for (k = 1; k <
n; k++) {
165 double a =
M_PI * k * (i + 0.5) /
n;
166 s += input[k] * cos(
a);
168 output[i] = 2 * s /
n;
174 int i, k, n = 1 << nbits;
177 for (k = 0; k <
n; k++) {
179 for (i = 0; i <
n; i++) {
180 double a =
M_PI * k * (i + 0.5) /
n;
181 s += input[i] * cos(
a);
197 double error = 0, max = 0;
199 for (i = 0; i <
n; i++) {
200 double e = fabs(tab1[i] - (tab2[i] / scale)) /
RANGE;
203 i, tab1[i], tab2[i]);
217 "usage: fft-test [-h] [-s] [-i] [-n b]\n"
218 "-h print this help\n"
223 "-i inverse transform test\n"
224 "-n b set the transform size to 2^b\n"
225 "-f x set scale factor for output data of (I)MDCT to x\n");
239 int main(
int argc,
char **argv)
250 int do_speed = 0, do_inverse = 0;
251 int fft_nbits = 9, fft_size;
258 int c =
getopt(argc, argv,
"hsimrdn:f:c:");
299 fft_size = 1 << fft_nbits;
305 if (!(tab && tab1 && tab_ref && tab2))
358 for (i = 0; i < fft_size; i++) {
370 imdct_ref(&tab_ref->
re, &tab1->
re, fft_nbits);
374 mdct_ref(&tab_ref->
re, &tab1->
re, fft_nbits);
376 err =
check_diff(&tab_ref->
re, tab2, fft_size / 2, scale);
381 memcpy(tab, tab1, fft_size *
sizeof(
FFTComplex));
385 fft_ref(tab_ref, tab1, fft_nbits);
392 int fft_size_2 = fft_size >> 1;
395 tab1[fft_size_2].
im = 0;
396 for (i = 1; i < fft_size_2; i++) {
397 tab1[fft_size_2 + i].
re = tab1[fft_size_2 - i].
re;
398 tab1[fft_size_2 + i].
im = -tab1[fft_size_2 - i].
im;
401 memcpy(tab2, tab1, fft_size *
sizeof(
FFTSample));
402 tab2[1] = tab1[fft_size_2].
re;
405 fft_ref(tab_ref, tab1, fft_nbits);
406 for (i = 0; i < fft_size; i++) {
412 for (i = 0; i < fft_size; i++) {
413 tab2[i] = tab1[i].
re;
417 fft_ref(tab_ref, tab1, fft_nbits);
418 tab_ref[0].
im = tab_ref[fft_size_2].
re;
426 memcpy(tab, tab1, fft_size *
sizeof(
FFTComplex));
429 idct_ref(&tab_ref->
re, &tab1->
re, fft_nbits);
431 dct_ref(&tab_ref->
re, &tab1->
re, fft_nbits);
449 for (it = 0; it < nb_its; it++) {
458 memcpy(tab, tab1, fft_size *
sizeof(
FFTComplex));
463 memcpy(tab2, tab1, fft_size *
sizeof(
FFTSample));
467 memcpy(tab2, tab1, fft_size *
sizeof(
FFTSample));
474 if (duration >= 1000000)
479 "time: %0.1f us/transform [total time=%0.2f s its=%d]\n",
480 (
double) duration / nb_its,
481 (
double) duration / 1000000.0,
516 printf(
"Error: %d.\n", err);
av_cold void ff_rdft_end(RDFTContext *s)
void(* dct_calc)(struct DCTContext *s, FFTSample *data)
void(* mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
void(* fft_permute)(struct FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling fft_calc().
static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
static double alpha(void *priv, double x, double y)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static FFTSample frandom(AVLFG *prng)
int av_parse_cpu_caps(unsigned *flags, const char *s)
Parse CPU caps from a string and update the given AV_CPU_* flags based on that.
void(* rdft_calc)(struct RDFTContext *s, FFTSample *z)
void(* imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
#define CMAC(pre, pim, are, aim, bre, bim)
#define REF_SCALE(x, bits)
static const int8_t transform[32][32]
#define AV_LOG_INFO
Standard information.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static int getopt(int argc, char *argv[], char *opts)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse)
Set up DCT.
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
int main(int argc, char **argv)
void(* fft_calc)(struct FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in ff_fft_init().
static struct @45 * exptab
static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale)
av_cold void ff_dct_end(DCTContext *s)
static const struct twinvq_data tab
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
static int fft_ref_init(int nbits, int inverse)
static uint32_t inverse(uint32_t v)
find multiplicative inverse modulo 2 ^ 32
#define av_malloc_array(a, b)
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans)
Set up a real FFT.
static av_cold void cleanup(FlashSV2Context *s)