]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blobdiff - libavcodec/fft-test.c
frsh: Export information about the last RTP contract and VRES
[frescor/ffmpeg.git] / libavcodec / fft-test.c
index f0529c1b2369d84ae9d724f5fa3ec5807a1f2980..1cefa3202f22167f951f9ac2e4ac155420d730f6 100644 (file)
  */
 
 /**
- * @file fft-test.c
+ * @file libavcodec/fft-test.c
  * FFT and MDCT tests.
  */
 
+#include "libavutil/lfg.h"
 #include "dsputil.h"
 #include <math.h>
 #include <unistd.h>
@@ -31,9 +32,6 @@
 #include <string.h>
 
 #undef exit
-#undef random
-
-int mm_flags;
 
 /* reference fft */
 
@@ -47,7 +45,7 @@ int mm_flags;
 
 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;
@@ -66,7 +64,7 @@ void fft_ref_init(int nbits, int inverse)
     }
 }
 
-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;
@@ -95,8 +93,9 @@ void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
     }
 }
 
-void imdct_ref(float *out, float *in, int n)
+static void imdct_ref(float *out, float *in, int nbits)
 {
+    int n = 1<<nbits;
     int k, i, a;
     double sum, f;
 
@@ -112,8 +111,9 @@ void imdct_ref(float *out, float *in, int n)
 }
 
 /* NOTE: no normalisation by 1 / N is done */
-void mdct_ref(float *output, float *input, int n)
+static void mdct_ref(float *output, float *input, int nbits)
 {
+    int n = 1<<nbits;
     int k, i;
     double a, s;
 
@@ -129,19 +129,21 @@ void mdct_ref(float *output, float *input, int n)
 }
 
 
-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)
 {
     int i;
     double max= 0;
@@ -160,7 +162,7 @@ void check_diff(float *tab1, float *tab2, int n)
 }
 
 
-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"
@@ -177,7 +179,7 @@ void help(void)
 int main(int argc, char **argv)
 {
     FFTComplex *tab, *tab1, *tab_ref;
-    FFTSample *tabtmp, *tab2;
+    FFTSample *tab2;
     int it, i, c;
     int do_speed = 0;
     int do_mdct = 0;
@@ -186,7 +188,6 @@ int main(int argc, char **argv)
     MDCTContext m1, *m = &m1;
     int fft_nbits, fft_size;
 
-    mm_flags = 0;
     fft_nbits = 9;
     for(;;) {
         c = getopt(argc, argv, "hsimn:");
@@ -215,7 +216,6 @@ int main(int argc, char **argv)
     tab = av_malloc(fft_size * sizeof(FFTComplex));
     tab1 = av_malloc(fft_size * sizeof(FFTComplex));
     tab_ref = av_malloc(fft_size * sizeof(FFTComplex));
-    tabtmp = av_malloc(fft_size / 2 * sizeof(FFTSample));
     tab2 = av_malloc(fft_size * sizeof(FFTSample));
 
     if (do_mdct) {
@@ -246,13 +246,13 @@ int main(int argc, char **argv)
 
     if (do_mdct) {
         if (do_inverse) {
-            imdct_ref((float *)tab_ref, (float *)tab1, fft_size);
-            ff_imdct_calc(m, tab2, (float *)tab1, tabtmp);
+            imdct_ref((float *)tab_ref, (float *)tab1, fft_nbits);
+            ff_imdct_calc(m, tab2, (float *)tab1);
             check_diff((float *)tab_ref, tab2, fft_size);
         } else {
-            mdct_ref((float *)tab_ref, (float *)tab1, fft_size);
+            mdct_ref((float *)tab_ref, (float *)tab1, fft_nbits);
 
-            ff_mdct_calc(m, tab2, (float *)tab1, tabtmp);
+            ff_mdct_calc(m, tab2, (float *)tab1);
 
             check_diff((float *)tab_ref, tab2, fft_size / 2);
         }
@@ -279,9 +279,9 @@ int main(int argc, char **argv)
             for(it=0;it<nb_its;it++) {
                 if (do_mdct) {
                     if (do_inverse) {
-                        ff_imdct_calc(m, (float *)tab, (float *)tab1, tabtmp);
+                        ff_imdct_calc(m, (float *)tab, (float *)tab1);
                     } else {
-                        ff_mdct_calc(m, (float *)tab, (float *)tab1, tabtmp);
+                        ff_mdct_calc(m, (float *)tab, (float *)tab1);
                     }
                 } else {
                     memcpy(tab, tab1, fft_size * sizeof(FFTComplex));