|
|
|
@ -23,14 +23,8 @@ |
|
|
|
|
* FFT and MDCT tests. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include "libavutil/cpu.h" |
|
|
|
|
#include "libavutil/mathematics.h" |
|
|
|
|
#include "libavutil/lfg.h" |
|
|
|
|
#include "libavutil/log.h" |
|
|
|
|
#include "libavutil/time.h" |
|
|
|
|
#include "fft.h" |
|
|
|
|
#include "dct.h" |
|
|
|
|
#include "rdft.h" |
|
|
|
|
#include "config.h" |
|
|
|
|
|
|
|
|
|
#include <math.h> |
|
|
|
|
#if HAVE_UNISTD_H |
|
|
|
|
#include <unistd.h> |
|
|
|
@ -39,6 +33,16 @@ |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
|
#include "libavutil/cpu.h" |
|
|
|
|
#include "libavutil/lfg.h" |
|
|
|
|
#include "libavutil/log.h" |
|
|
|
|
#include "libavutil/mathematics.h" |
|
|
|
|
#include "libavutil/time.h" |
|
|
|
|
|
|
|
|
|
#include "dct.h" |
|
|
|
|
#include "fft.h" |
|
|
|
|
#include "rdft.h" |
|
|
|
|
|
|
|
|
|
/* reference fft */ |
|
|
|
|
|
|
|
|
|
#define MUL16(a, b) ((a) * (b)) |
|
|
|
@ -162,6 +166,7 @@ static void idct_ref(FFTSample *output, FFTSample *input, int nbits) |
|
|
|
|
output[i] = 2 * s / n; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void dct_ref(FFTSample *output, FFTSample *input, int nbits) |
|
|
|
|
{ |
|
|
|
|
int i, k, n = 1 << nbits; |
|
|
|
@ -179,7 +184,6 @@ static void dct_ref(FFTSample *output, FFTSample *input, int nbits) |
|
|
|
|
#endif /* CONFIG_DCT */ |
|
|
|
|
#endif /* FFT_FLOAT */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static FFTSample frandom(AVLFG *prng) |
|
|
|
|
{ |
|
|
|
|
return (int16_t) av_lfg_get(prng) / 32768.0 * RANGE; |
|
|
|
@ -198,16 +202,17 @@ static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale) |
|
|
|
|
err = 1; |
|
|
|
|
} |
|
|
|
|
error += e * e; |
|
|
|
|
if(e>max) max= e; |
|
|
|
|
if (e > max) |
|
|
|
|
max = e; |
|
|
|
|
} |
|
|
|
|
av_log(NULL, AV_LOG_INFO, "max:%f e:%g\n", max, sqrt(error / n)); |
|
|
|
|
return err; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void help(void) |
|
|
|
|
{ |
|
|
|
|
av_log(NULL, AV_LOG_INFO,"usage: fft-test [-h] [-s] [-i] [-n b]\n" |
|
|
|
|
av_log(NULL, AV_LOG_INFO, |
|
|
|
|
"usage: fft-test [-h] [-s] [-i] [-n b]\n" |
|
|
|
|
"-h print this help\n" |
|
|
|
|
"-s speed test\n" |
|
|
|
|
"-m (I)MDCT test\n" |
|
|
|
@ -215,8 +220,7 @@ static void help(void) |
|
|
|
|
"-r (I)RDFT test\n" |
|
|
|
|
"-i inverse transform test\n" |
|
|
|
|
"-n b set the transform size to 2^b\n" |
|
|
|
|
"-f x set scale factor for output data of (I)MDCT to x\n" |
|
|
|
|
); |
|
|
|
|
"-f x set scale factor for output data of (I)MDCT to x\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
enum tf_transform { |
|
|
|
@ -379,7 +383,8 @@ int main(int argc, char **argv) |
|
|
|
|
s.fft_calc(&s, tab); |
|
|
|
|
|
|
|
|
|
fft_ref(tab_ref, tab1, fft_nbits); |
|
|
|
|
err = check_diff((FFTSample *)tab_ref, (FFTSample *)tab, fft_size * 2, 1.0); |
|
|
|
|
err = check_diff((FFTSample *) tab_ref, (FFTSample *) tab, |
|
|
|
|
fft_size * 2, 1.0); |
|
|
|
|
break; |
|
|
|
|
#if FFT_FLOAT |
|
|
|
|
#if CONFIG_RDFT |
|
|
|
@ -403,7 +408,8 @@ int main(int argc, char **argv) |
|
|
|
|
tab[i].re = tab2[i]; |
|
|
|
|
tab[i].im = 0; |
|
|
|
|
} |
|
|
|
|
err = check_diff((float *)tab_ref, (float *)tab, fft_size * 2, 0.5); |
|
|
|
|
err = check_diff((float *) tab_ref, (float *) tab, |
|
|
|
|
fft_size * 2, 0.5); |
|
|
|
|
} else { |
|
|
|
|
for (i = 0; i < fft_size; i++) { |
|
|
|
|
tab2[i] = tab1[i].re; |
|
|
|
@ -421,11 +427,10 @@ int main(int argc, char **argv) |
|
|
|
|
case TRANSFORM_DCT: |
|
|
|
|
memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); |
|
|
|
|
d.dct_calc(&d, (FFTSample *)tab); |
|
|
|
|
if (do_inverse) { |
|
|
|
|
if (do_inverse) |
|
|
|
|
idct_ref((FFTSample*)tab_ref, (FFTSample *)tab1, fft_nbits); |
|
|
|
|
} else { |
|
|
|
|
else |
|
|
|
|
dct_ref((FFTSample*)tab_ref, (FFTSample *)tab1, fft_nbits); |
|
|
|
|
} |
|
|
|
|
err = check_diff((float *) tab_ref, (float *) tab, fft_size, 1.0); |
|
|
|
|
break; |
|
|
|
|
#endif /* CONFIG_DCT */ |
|
|
|
@ -446,11 +451,10 @@ int main(int argc, char **argv) |
|
|
|
|
for (it = 0; it < nb_its; it++) { |
|
|
|
|
switch (transform) { |
|
|
|
|
case TRANSFORM_MDCT: |
|
|
|
|
if (do_inverse) { |
|
|
|
|
if (do_inverse) |
|
|
|
|
m.imdct_calc(&m, (FFTSample *) tab, (FFTSample *) tab1); |
|
|
|
|
} else { |
|
|
|
|
else |
|
|
|
|
m.mdct_calc(&m, (FFTSample *) tab, (FFTSample *) tab1); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case TRANSFORM_FFT: |
|
|
|
|
memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); |
|
|
|
@ -473,7 +477,8 @@ int main(int argc, char **argv) |
|
|
|
|
break; |
|
|
|
|
nb_its *= 2; |
|
|
|
|
} |
|
|
|
|
av_log(NULL, AV_LOG_INFO,"time: %0.1f us/transform [total time=%0.2f s its=%d]\n", |
|
|
|
|
av_log(NULL, AV_LOG_INFO, |
|
|
|
|
"time: %0.1f us/transform [total time=%0.2f s its=%d]\n", |
|
|
|
|
(double) duration / nb_its, |
|
|
|
|
(double) duration / 1000000.0, |
|
|
|
|
nb_its); |
|
|
|
|