* FFT and MDCT tests.
*/
+#include "libavutil/lfg.h"
#include "dsputil.h"
#include <math.h>
#include <unistd.h>
#include <string.h>
#undef exit
-#undef random
/* reference fft */
FFTComplex *exptab;
-void fft_ref_init(int nbits, int inverse)
+static void fft_ref_init(int nbits, int inverse)
{
int n, i;
double c1, s1, alpha;
}
}
-void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
+static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
{
int n, i, j, k, n2;
double tmp_re, tmp_im, s, c;
}
}
-void imdct_ref(float *out, float *in, int nbits)
+static void imdct_ref(float *out, float *in, int nbits)
{
int n = 1<<nbits;
int k, i, a;
}
/* NOTE: no normalisation by 1 / N is done */
-void mdct_ref(float *output, float *input, int nbits)
+static void mdct_ref(float *output, float *input, int nbits)
{
int n = 1<<nbits;
int k, i;
}
-float frandom(void)
+static float frandom(void)
{
- return (float)((random() & 0xffff) - 32768) / 32768.0;
+ AVLFG prng;
+ av_lfg_init(&prng, 1);
+ return (float)((av_lfg_get(&prng) & 0xffff) - 32768) / 32768.0;
}
-int64_t gettime(void)
+static int64_t gettime(void)
{
struct timeval tv;
gettimeofday(&tv,NULL);
return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
}
-void check_diff(float *tab1, float *tab2, int n)
+static void check_diff(float *tab1, float *tab2, int n, double scale)
{
int i;
double max= 0;
double error= 0;
for(i=0;i<n;i++) {
- double e= fabsf(tab1[i] - tab2[i]);
+ double e= fabsf(tab1[i] - (tab2[i] / scale));
if (e >= 1e-3) {
av_log(NULL, AV_LOG_ERROR, "ERROR %d: %f %f\n",
i, tab1[i], tab2[i]);
}
-void help(void)
+static void help(void)
{
av_log(NULL, AV_LOG_INFO,"usage: fft-test [-h] [-s] [-i] [-n b]\n"
"-h print this help\n"
"-m (I)MDCT 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"
);
exit(1);
}
FFTContext s1, *s = &s1;
MDCTContext m1, *m = &m1;
int fft_nbits, fft_size;
+ double scale = 1.0;
fft_nbits = 9;
for(;;) {
- c = getopt(argc, argv, "hsimn:");
+ c = getopt(argc, argv, "hsimn:f:");
if (c == -1)
break;
switch(c) {
case 'n':
fft_nbits = atoi(optarg);
break;
+ case 'f':
+ scale = atof(optarg);
+ break;
}
}
tab2 = av_malloc(fft_size * sizeof(FFTSample));
if (do_mdct) {
+ av_log(NULL, AV_LOG_INFO,"Scale factor is set to %f\n", scale);
if (do_inverse)
av_log(NULL, AV_LOG_INFO,"IMDCT");
else
av_log(NULL, AV_LOG_INFO,"MDCT");
- ff_mdct_init(m, fft_nbits, do_inverse);
+ ff_mdct_init(m, fft_nbits, do_inverse, scale);
} else {
if (do_inverse)
av_log(NULL, AV_LOG_INFO,"IFFT");
if (do_inverse) {
imdct_ref((float *)tab_ref, (float *)tab1, fft_nbits);
ff_imdct_calc(m, tab2, (float *)tab1);
- check_diff((float *)tab_ref, tab2, fft_size);
+ check_diff((float *)tab_ref, tab2, fft_size, scale);
} else {
mdct_ref((float *)tab_ref, (float *)tab1, fft_nbits);
ff_mdct_calc(m, tab2, (float *)tab1);
- check_diff((float *)tab_ref, tab2, fft_size / 2);
+ check_diff((float *)tab_ref, tab2, fft_size / 2, scale);
}
} else {
memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
ff_fft_calc(s, tab);
fft_ref(tab_ref, tab1, fft_nbits);
- check_diff((float *)tab_ref, (float *)tab, fft_size * 2);
+ check_diff((float *)tab_ref, (float *)tab, fft_size * 2, 1.0);
}
/* do a speed test */