]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/fft-test.c
mpegaudiodec: fix short_start calculation
[ffmpeg] / libavcodec / fft-test.c
index 0112c6fcbb2abd2be26b09d2a6380e6c22702e44..1e4675019ca5c3785a03cb3d50197f2d4e371adb 100644 (file)
  * 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"
 #if CONFIG_FFT_FLOAT
 #include "dct.h"
 #include "rdft.h"
 #endif
 #include <math.h>
+#if HAVE_UNISTD_H
 #include <unistd.h>
-#include <sys/time.h>
+#endif
 #include <stdlib.h>
 #include <string.h>
 
-#undef exit
-
 /* reference fft */
 
 #define MUL16(a,b) ((a) * (b))
@@ -187,13 +188,6 @@ static FFTSample frandom(AVLFG *prng)
     return (int16_t)av_lfg_get(prng) / 32768.0 * RANGE;
 }
 
-static int64_t gettime(void)
-{
-    struct timeval tv;
-    gettimeofday(&tv,NULL);
-    return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
-}
-
 static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale)
 {
     int i;
@@ -228,7 +222,6 @@ static void help(void)
            "-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);
 }
 
 enum tf_transform {
@@ -238,11 +231,16 @@ enum tf_transform {
     TRANSFORM_DCT,
 };
 
+#if !HAVE_GETOPT
+#include "compat/getopt.c"
+#endif
+
 int main(int argc, char **argv)
 {
     FFTComplex *tab, *tab1, *tab_ref;
     FFTSample *tab2;
     int it, i, c;
+    int cpuflags;
     int do_speed = 0;
     int err = 1;
     enum tf_transform transform = TRANSFORM_FFT;
@@ -252,21 +250,22 @@ int main(int argc, char **argv)
 #if CONFIG_FFT_FLOAT
     RDFTContext r1, *r = &r1;
     DCTContext d1, *d = &d1;
+    int fft_size_2;
 #endif
-    int fft_nbits, fft_size, fft_size_2;
+    int fft_nbits, fft_size;
     double scale = 1.0;
     AVLFG prng;
     av_lfg_init(&prng, 1);
 
     fft_nbits = 9;
     for(;;) {
-        c = getopt(argc, argv, "hsimrdn:f:");
+        c = getopt(argc, argv, "hsimrdn:f:c:");
         if (c == -1)
             break;
         switch(c) {
         case 'h':
             help();
-            break;
+            return 1;
         case 's':
             do_speed = 1;
             break;
@@ -288,11 +287,16 @@ int main(int argc, char **argv)
         case 'f':
             scale = atof(optarg);
             break;
+        case 'c':
+            cpuflags = av_parse_cpu_flags(optarg);
+            if (cpuflags < 0)
+                return 1;
+            av_set_cpu_flags_mask(cpuflags);
+            break;
         }
     }
 
     fft_size = 1 << fft_nbits;
-    fft_size_2 = fft_size >> 1;
     tab = av_malloc(fft_size * sizeof(FFTComplex));
     tab1 = av_malloc(fft_size * sizeof(FFTComplex));
     tab_ref = av_malloc(fft_size * sizeof(FFTComplex));
@@ -372,6 +376,7 @@ int main(int argc, char **argv)
         break;
 #if CONFIG_FFT_FLOAT
     case TRANSFORM_RDFT:
+        fft_size_2 = fft_size >> 1;
         if (do_inverse) {
             tab1[         0].im = 0;
             tab1[fft_size_2].im = 0;
@@ -424,7 +429,7 @@ int main(int argc, char **argv)
         /* we measure during about 1 seconds */
         nb_its = 1;
         for(;;) {
-            time_start = gettime();
+            time_start = av_gettime();
             for (it = 0; it < nb_its; it++) {
                 switch (transform) {
                 case TRANSFORM_MDCT:
@@ -450,7 +455,7 @@ int main(int argc, char **argv)
 #endif
                 }
             }
-            duration = gettime() - time_start;
+            duration = av_gettime() - time_start;
             if (duration >= 1000000)
                 break;
             nb_its *= 2;