changeset 9674:dac20d8df581 libavcodec

Support for testing (i)MDCT output scale factor in fft-test tool.
author serge
date Wed, 20 May 2009 07:23:09 +0000
parents 3e1a08ba8481
children 2e84b386a8b6
files fft-test.c
diffstat 1 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/fft-test.c	Tue May 19 22:58:09 2009 +0000
+++ b/fft-test.c	Wed May 20 07:23:09 2009 +0000
@@ -143,14 +143,14 @@
     return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
 }
 
-static 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]);
@@ -170,6 +170,7 @@
            "-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);
 }
@@ -187,10 +188,11 @@
     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) {
@@ -209,6 +211,9 @@
         case 'n':
             fft_nbits = atoi(optarg);
             break;
+        case 'f':
+            scale = atof(optarg);
+            break;
         }
     }
 
@@ -219,11 +224,12 @@
     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, 1.0);
+        ff_mdct_init(m, fft_nbits, do_inverse, scale);
     } else {
         if (do_inverse)
             av_log(NULL, AV_LOG_INFO,"IFFT");
@@ -248,13 +254,13 @@
         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));
@@ -262,7 +268,7 @@
         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 */