summaryrefslogtreecommitdiff
path: root/libavcodec/fft-test.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-07-24 01:22:31 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-07-24 01:22:31 +0200
commit02ea384abd8ef53a1e4654ab0c9e72e08141d751 (patch)
tree27dd65c965e6f3f7132f8f7da7a8b76fac0c470a /libavcodec/fft-test.c
parent629e5e28f70a3511d7267f328773b191c5f086ac (diff)
parent6133d65861f265d429ade53e910fe877c95a1615 (diff)
downloadffmpeg-02ea384abd8ef53a1e4654ab0c9e72e08141d751.tar.gz
Merge commit '6133d65861f265d429ade53e910fe877c95a1615'
* commit '6133d65861f265d429ade53e910fe877c95a1615': fft-test: K&R formatting cosmetics Conflicts: libavcodec/fft-test.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/fft-test.c')
-rw-r--r--libavcodec/fft-test.c165
1 files changed, 85 insertions, 80 deletions
diff --git a/libavcodec/fft-test.c b/libavcodec/fft-test.c
index 755c85d2d8..6b745cb21c 100644
--- a/libavcodec/fft-test.c
+++ b/libavcodec/fft-test.c
@@ -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,28 +33,38 @@
#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))
+#define MUL16(a, b) ((a) * (b))
-#define CMAC(pre, pim, are, aim, bre, bim) \
-{\
- pre += (MUL16(are, bre) - MUL16(aim, bim));\
- pim += (MUL16(are, bim) + MUL16(bre, aim));\
-}
+#define CMAC(pre, pim, are, aim, bre, bim) \
+ { \
+ pre += (MUL16(are, bre) - MUL16(aim, bim)); \
+ pim += (MUL16(are, bim) + MUL16(bre, aim)); \
+ }
#if FFT_FLOAT
-# define RANGE 1.0
-# define REF_SCALE(x, bits) (x)
-# define FMT "%10.6f"
+#define RANGE 1.0
+#define REF_SCALE(x, bits) (x)
+#define FMT "%10.6f"
#elif FFT_FIXED_32
-# define RANGE 8388608
-# define REF_SCALE(x, bits) (x)
-# define FMT "%6d"
+#define RANGE 8388608
+#define REF_SCALE(x, bits) (x)
+#define FMT "%6d"
#else
-# define RANGE 16384
-# define REF_SCALE(x, bits) ((x) / (1<<(bits)))
-# define FMT "%6d"
+#define RANGE 16384
+#define REF_SCALE(x, bits) ((x) / (1 << (bits)))
+#define FMT "%6d"
#endif
static struct {
@@ -75,8 +79,8 @@ static int fft_ref_init(int nbits, int inverse)
if (!exptab)
return AVERROR(ENOMEM);
- for (i = 0; i < (n/2); i++) {
- double alpha = 2 * M_PI * (float)i / (float)n;
+ for (i = 0; i < (n / 2); i++) {
+ double alpha = 2 * M_PI * (float) i / (float) n;
double c1 = cos(alpha), s1 = sin(alpha);
if (!inverse)
s1 = -s1;
@@ -120,9 +124,9 @@ static void imdct_ref(FFTSample *out, FFTSample *in, int nbits)
for (i = 0; i < n; i++) {
double sum = 0;
- for (k = 0; k < n/2; k++) {
+ for (k = 0; k < n / 2; k++) {
int a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
- double f = cos(M_PI * a / (double)(2 * n));
+ double f = cos(M_PI * a / (double) (2 * n));
sum += f * in[k];
}
out[i] = REF_SCALE(-sum, nbits - 2);
@@ -135,7 +139,7 @@ static void mdct_ref(FFTSample *output, FFTSample *input, int nbits)
int i, k, n = 1 << nbits;
/* do it by hand */
- for (k = 0; k < n/2; k++) {
+ for (k = 0; k < n / 2; k++) {
double s = 0;
for (i = 0; i < n; i++) {
double a = (2 * M_PI * (2 * i + 1 + n / 2) * (2 * k + 1) / (4 * n));
@@ -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,10 +184,9 @@ 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;
+ return (int16_t) av_lfg_get(prng) / 32768.0 * RANGE;
}
static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale)
@@ -197,17 +201,18 @@ static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale)
i, tab1[i], tab2[i]);
err = 1;
}
- error+= e*e;
- if(e>max) max= e;
+ error += e * e;
+ if (e > max)
+ max = e;
}
- av_log(NULL, AV_LOG_INFO, "max:%f e:%g\n", max, sqrt(error/n));
+ 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 {
@@ -248,11 +252,11 @@ int main(int argc, char **argv)
av_lfg_init(&prng, 1);
- for(;;) {
+ for (;;) {
int c = getopt(argc, argv, "hsimrdn:f:c:");
if (c == -1)
break;
- switch(c) {
+ switch (c) {
case 'h':
help();
return 1;
@@ -291,10 +295,10 @@ int main(int argc, char **argv)
}
fft_size = 1 << fft_nbits;
- tab = av_malloc_array(fft_size, sizeof(FFTComplex));
- tab1 = av_malloc_array(fft_size, sizeof(FFTComplex));
- tab_ref = av_malloc_array(fft_size, sizeof(FFTComplex));
- tab2 = av_malloc_array(fft_size, sizeof(FFTSample));
+ tab = av_malloc_array(fft_size, sizeof(FFTComplex));
+ tab1 = av_malloc_array(fft_size, sizeof(FFTComplex));
+ tab_ref = av_malloc_array(fft_size, sizeof(FFTComplex));
+ tab2 = av_malloc_array(fft_size, sizeof(FFTSample));
if (!(tab && tab1 && tab_ref && tab2))
goto cleanup;
@@ -302,19 +306,19 @@ int main(int argc, char **argv)
switch (transform) {
#if CONFIG_MDCT
case TRANSFORM_MDCT:
- av_log(NULL, AV_LOG_INFO,"Scale factor is set to %f\n", scale);
+ av_log(NULL, AV_LOG_INFO, "Scale factor is set to %f\n", scale);
if (do_inverse)
- av_log(NULL, AV_LOG_INFO,"IMDCT");
+ av_log(NULL, AV_LOG_INFO, "IMDCT");
else
- av_log(NULL, AV_LOG_INFO,"MDCT");
+ av_log(NULL, AV_LOG_INFO, "MDCT");
ff_mdct_init(&m, fft_nbits, do_inverse, scale);
break;
#endif /* CONFIG_MDCT */
case TRANSFORM_FFT:
if (do_inverse)
- av_log(NULL, AV_LOG_INFO,"IFFT");
+ av_log(NULL, AV_LOG_INFO, "IFFT");
else
- av_log(NULL, AV_LOG_INFO,"FFT");
+ av_log(NULL, AV_LOG_INFO, "FFT");
ff_fft_init(&s, fft_nbits, do_inverse);
if ((err = fft_ref_init(fft_nbits, do_inverse)) < 0)
goto cleanup;
@@ -323,9 +327,9 @@ int main(int argc, char **argv)
# if CONFIG_RDFT
case TRANSFORM_RDFT:
if (do_inverse)
- av_log(NULL, AV_LOG_INFO,"IDFT_C2R");
+ av_log(NULL, AV_LOG_INFO, "IDFT_C2R");
else
- av_log(NULL, AV_LOG_INFO,"DFT_R2C");
+ av_log(NULL, AV_LOG_INFO, "DFT_R2C");
ff_rdft_init(&r, fft_nbits, do_inverse ? IDFT_C2R : DFT_R2C);
if ((err = fft_ref_init(fft_nbits, do_inverse)) < 0)
goto cleanup;
@@ -334,9 +338,9 @@ int main(int argc, char **argv)
# if CONFIG_DCT
case TRANSFORM_DCT:
if (do_inverse)
- av_log(NULL, AV_LOG_INFO,"DCT_III");
+ av_log(NULL, AV_LOG_INFO, "DCT_III");
else
- av_log(NULL, AV_LOG_INFO,"DCT_II");
+ av_log(NULL, AV_LOG_INFO, "DCT_II");
ff_dct_init(&d, fft_nbits, do_inverse ? DCT_III : DCT_II);
break;
# endif /* CONFIG_DCT */
@@ -345,7 +349,7 @@ int main(int argc, char **argv)
av_log(NULL, AV_LOG_ERROR, "Requested transform not supported\n");
goto cleanup;
}
- av_log(NULL, AV_LOG_INFO," %d test\n", fft_size);
+ av_log(NULL, AV_LOG_INFO, " %d test\n", fft_size);
/* generate random data */
@@ -355,21 +359,21 @@ int main(int argc, char **argv)
}
/* checking result */
- av_log(NULL, AV_LOG_INFO,"Checking...\n");
+ av_log(NULL, AV_LOG_INFO, "Checking...\n");
switch (transform) {
#if CONFIG_MDCT
case TRANSFORM_MDCT:
if (do_inverse) {
- imdct_ref((FFTSample *)tab_ref, (FFTSample *)tab1, fft_nbits);
- m.imdct_calc(&m, tab2, (FFTSample *)tab1);
- err = check_diff((FFTSample *)tab_ref, tab2, fft_size, scale);
+ imdct_ref((FFTSample *) tab_ref, (FFTSample *) tab1, fft_nbits);
+ m.imdct_calc(&m, tab2, (FFTSample *) tab1);
+ err = check_diff((FFTSample *) tab_ref, tab2, fft_size, scale);
} else {
- mdct_ref((FFTSample *)tab_ref, (FFTSample *)tab1, fft_nbits);
+ mdct_ref((FFTSample *) tab_ref, (FFTSample *) tab1, fft_nbits);
- m.mdct_calc(&m, tab2, (FFTSample *)tab1);
+ m.mdct_calc(&m, tab2, (FFTSample *) tab1);
- err = check_diff((FFTSample *)tab_ref, tab2, fft_size / 2, scale);
+ err = check_diff((FFTSample *) tab_ref, tab2, fft_size / 2, scale);
}
break;
#endif /* CONFIG_MDCT */
@@ -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
@@ -387,11 +392,11 @@ int main(int argc, char **argv)
{
int fft_size_2 = fft_size >> 1;
if (do_inverse) {
- tab1[ 0].im = 0;
+ tab1[0].im = 0;
tab1[fft_size_2].im = 0;
for (i = 1; i < fft_size_2; i++) {
- tab1[fft_size_2+i].re = tab1[fft_size_2-i].re;
- tab1[fft_size_2+i].im = -tab1[fft_size_2-i].im;
+ tab1[fft_size_2 + i].re = tab1[fft_size_2 - i].re;
+ tab1[fft_size_2 + i].im = -tab1[fft_size_2 - i].im;
}
memcpy(tab2, tab1, fft_size * sizeof(FFTSample));
@@ -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;
@@ -412,7 +418,7 @@ int main(int argc, char **argv)
r.rdft_calc(&r, tab2);
fft_ref(tab_ref, tab1, fft_nbits);
tab_ref[0].im = tab_ref[fft_size_2].re;
- err = check_diff((float *)tab_ref, (float *)tab2, fft_size, 1.0);
+ err = check_diff((float *) tab_ref, (float *) tab2, fft_size, 1.0);
}
break;
}
@@ -421,12 +427,11 @@ 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);
+ err = check_diff((float *) tab_ref, (float *) tab, fft_size, 1.0);
break;
#endif /* CONFIG_DCT */
#endif /* FFT_FLOAT */
@@ -438,19 +443,18 @@ int main(int argc, char **argv)
int64_t time_start, duration;
int nb_its;
- av_log(NULL, AV_LOG_INFO,"Speed test...\n");
+ av_log(NULL, AV_LOG_INFO, "Speed test...\n");
/* we measure during about 1 seconds */
nb_its = 1;
- for(;;) {
+ for (;;) {
time_start = av_gettime_relative();
for (it = 0; it < nb_its; it++) {
switch (transform) {
case TRANSFORM_MDCT:
- if (do_inverse) {
- m.imdct_calc(&m, (FFTSample *)tab, (FFTSample *)tab1);
- } else {
- m.mdct_calc(&m, (FFTSample *)tab, (FFTSample *)tab1);
- }
+ if (do_inverse)
+ m.imdct_calc(&m, (FFTSample *) tab, (FFTSample *) tab1);
+ else
+ m.mdct_calc(&m, (FFTSample *) tab, (FFTSample *) tab1);
break;
case TRANSFORM_FFT:
memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
@@ -473,9 +477,10 @@ 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",
- (double)duration / nb_its,
- (double)duration / 1000000.0,
+ 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);
}