59 #define MUL16(a, b) ((a) * (b))
61 #define CMAC(pre, pim, are, aim, bre, bim) \
63 pre += (MUL16(are, bre) - MUL16(aim, bim)); \
64 pim += (MUL16(are, bim) + MUL16(bre, aim)); \
67 #if FFT_FLOAT || AVFFT
69 #define REF_SCALE(x, bits) (x)
73 #define REF_SCALE(x, bits) (x)
77 #define REF_SCALE(x, bits) ((x) / (1 << (bits)))
87 int i, n = 1 << nbits;
93 for (
i = 0;
i < (n / 2);
i++) {
94 double alpha = 2 *
M_PI * (float)
i / (
float) n;
110 for (
i = 0;
i < n;
i++) {
111 double tmp_re = 0, tmp_im = 0;
113 for (j = 0; j < n; j++) {
115 int k = (
i * j) & (n - 1);
134 int i, k, n = 1 << nbits;
136 for (
i = 0;
i < n;
i++) {
138 for (k = 0; k < n / 2; k++) {
139 int a = (2 *
i + 1 + (n / 2)) * (2 * k + 1);
140 double f = cos(
M_PI *
a / (
double) (2 * n));
150 int i, k, n = 1 << nbits;
153 for (k = 0; k < n / 2; k++) {
155 for (
i = 0;
i < n;
i++) {
156 double a = (2 *
M_PI * (2 *
i + 1 + n / 2) * (2 * k + 1) / (4 * n));
157 s += input[
i] * cos(
a);
168 int i, k, n = 1 << nbits;
171 for (
i = 0;
i < n;
i++) {
172 double s = 0.5 * input[0];
173 for (k = 1; k < n; k++) {
174 double a =
M_PI * k * (
i + 0.5) / n;
175 s += input[k] * cos(
a);
177 output[
i] = 2 *
s / n;
183 int i, k, n = 1 << nbits;
186 for (k = 0; k < n; k++) {
188 for (
i = 0;
i < n;
i++) {
189 double a =
M_PI * k * (
i + 0.5) / n;
190 s += input[
i] * cos(
a);
208 for (
i = 0;
i < n;
i++) {
246 s->mdct_calc(
s, output, input);
255 s->imdct_calc(
s, output, input);
264 s->fft_permute(
s, z);
319 r->rdft_calc(
r,
tab);
354 "usage: fft-test [-h] [-s] [-i] [-n b]\n"
355 "-h print this help\n"
360 "-i inverse transform test\n"
361 "-n b set the transform size to 2^b\n"
362 "-f x set scale factor for output data of (I)MDCT to x\n");
376 int main(
int argc,
char **argv)
387 int do_speed = 0, do_inverse = 0;
388 int fft_nbits = 9, fft_size;
397 #if !AVFFT && FFT_FLOAT
405 int c =
getopt(argc, argv,
"hsimrdn:f:c:");
446 fft_size = 1 << fft_nbits;
463 mdct_init(&m, fft_nbits, do_inverse, scale);
505 for (
i = 0;
i < fft_size;
i++) {
517 imdct_ref(&tab_ref->
re, &
tab1->re, fft_nbits);
521 mdct_ref(&tab_ref->
re, &
tab1->re, fft_nbits);
539 int fft_size_2 = fft_size >> 1;
542 tab1[fft_size_2].im = 0;
543 for (
i = 1;
i < fft_size_2;
i++) {
544 tab1[fft_size_2 +
i].re =
tab1[fft_size_2 -
i].re;
545 tab1[fft_size_2 +
i].im = -
tab1[fft_size_2 -
i].im;
553 for (
i = 0;
i < fft_size;
i++) {
559 for (
i = 0;
i < fft_size;
i++) {
565 tab_ref[0].
im = tab_ref[fft_size_2].
re;
574 dct_calc(d, &
tab->re);
576 idct_ref(&tab_ref->
re, &
tab1->re, fft_nbits);
578 dct_ref(&tab_ref->
re, &
tab1->re, fft_nbits);
596 for (it = 0; it < nb_its; it++) {
626 "time: %0.1f us/transform [total time=%0.2f s its=%d]\n",
667 #if !AVFFT && FFT_FLOAT
673 printf(
"Error: %d.\n", err);
static uint32_t inverse(uint32_t v)
find multiplicative inverse modulo 2 ^ 32
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} 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;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
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.
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
static __device__ float fabs(float a)
av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse)
Set up DCT.
av_cold void ff_dct_end(DCTContext *s)
static void mdct_end(FFTContext *s)
static FFTSample frandom(AVLFG *prng)
int main(int argc, char **argv)
static int fft_ref_init(int nbits, int inverse)
static void fft_end(FFTContext *s)
static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale)
static void fft_calc(FFTContext *s, FFTComplex *z)
static void mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
static void fft_init(FFTContext **s, int nbits, int inverse)
static void fft_permute(FFTContext *s, FFTComplex *z)
#define CMAC(pre, pim, are, aim, bre, bim)
static struct @135 * exptab
#define REF_SCALE(x, bits)
static void mdct_init(FFTContext **s, int nbits, int inverse, double scale)
static void imdct_calc(struct FFTContext *s, FFTSample *output, const FFTSample *input)
static av_cold void cleanup(FlashSV2Context *s)
static int getopt(int argc, char *argv[], char *opts)
void av_dct_calc(DCTContext *s, FFTSample *data)
void av_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
DCTContext * av_dct_init(int nbits, enum DCTTransformType type)
Set up DCT.
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
void av_rdft_calc(RDFTContext *s, FFTSample *data)
FFTContext * av_mdct_init(int nbits, int inverse, double scale)
void av_rdft_end(RDFTContext *s)
av_cold void av_fft_end(FFTContext *s)
void av_mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
void av_mdct_end(FFTContext *s)
void av_dct_end(DCTContext *s)
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static const int8_t transform[32][32]
static const int16_t alpha[]
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
static av_cold int dct_init(MpegEncContext *s)
av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans)
Set up a real FFT.
av_cold void ff_rdft_end(RDFTContext *s)
Context structure for the Lagged Fibonacci PRNG.
void(* dct_calc)(struct DCTContext *s, FFTSample *data)
#define av_malloc_array(a, b)
static void error(const char *err)
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
static const struct twinvq_data tab