diff options
author | Diego Biurrun <diego@biurrun.de> | 2014-06-25 17:35:03 -0700 |
---|---|---|
committer | Diego Biurrun <diego@biurrun.de> | 2014-07-23 06:05:02 -0700 |
commit | d445c865f87e7f13230e4dac3f77f5af21da95cb (patch) | |
tree | 1ce1b07e6aaedc80214fccc7025b0276edc4ab2e /libavcodec | |
parent | eac77fcd56fc2a3391f0d86faf54302afb368ff7 (diff) | |
download | ffmpeg-streaming-d445c865f87e7f13230e4dac3f77f5af21da95cb.zip ffmpeg-streaming-d445c865f87e7f13230e4dac3f77f5af21da95cb.tar.gz |
fft-test: Reduce variable scope where sensibly possible
Also merge variable declaration and initialization.
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/fft-test.c | 87 |
1 files changed, 36 insertions, 51 deletions
diff --git a/libavcodec/fft-test.c b/libavcodec/fft-test.c index dbe624d..02096a4 100644 --- a/libavcodec/fft-test.c +++ b/libavcodec/fft-test.c @@ -65,16 +65,13 @@ static struct { static void fft_ref_init(int nbits, int inverse) { - int n, i; - double c1, s1, alpha; + int i, n = 1 << nbits; - n = 1 << nbits; exptab = av_malloc((n / 2) * sizeof(*exptab)); for (i = 0; i < (n/2); i++) { - alpha = 2 * M_PI * (float)i / (float)n; - c1 = cos(alpha); - s1 = sin(alpha); + double alpha = 2 * M_PI * (float)i / (float)n; + double c1 = cos(alpha), s1 = sin(alpha); if (!inverse) s1 = -s1; exptab[i].re = c1; @@ -84,18 +81,16 @@ static void fft_ref_init(int nbits, int inverse) static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits) { - int n, i, j, k, n2; - double tmp_re, tmp_im, s, c; - FFTComplex *q; + int i, j; + int n = 1 << nbits; + int n2 = n >> 1; - n = 1 << nbits; - n2 = n >> 1; for (i = 0; i < n; i++) { - tmp_re = 0; - tmp_im = 0; - q = tab; + double tmp_re = 0, tmp_im = 0; + FFTComplex *q = tab; for (j = 0; j < n; j++) { - k = (i * j) & (n - 1); + double s, c; + int k = (i * j) & (n - 1); if (k >= n2) { c = -exptab[k - n2].re; s = -exptab[k - n2].im; @@ -114,15 +109,13 @@ static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits) #if CONFIG_MDCT static void imdct_ref(FFTSample *out, FFTSample *in, int nbits) { - int n = 1<<nbits; - int k, i, a; - double sum, f; + int i, k, n = 1 << nbits; for (i = 0; i < n; i++) { - sum = 0; + double sum = 0; for (k = 0; k < n/2; k++) { - a = (2 * i + 1 + (n / 2)) * (2 * k + 1); - f = cos(M_PI * a / (double)(2 * n)); + int a = (2 * i + 1 + (n / 2)) * (2 * k + 1); + double f = cos(M_PI * a / (double)(2 * n)); sum += f * in[k]; } out[i] = REF_SCALE(-sum, nbits - 2); @@ -132,15 +125,13 @@ static void imdct_ref(FFTSample *out, FFTSample *in, int nbits) /* NOTE: no normalisation by 1 / N is done */ static void mdct_ref(FFTSample *output, FFTSample *input, int nbits) { - int n = 1<<nbits; - int k, i; - double a, s; + int i, k, n = 1 << nbits; /* do it by hand */ for (k = 0; k < n/2; k++) { - s = 0; + double s = 0; for (i = 0; i < n; i++) { - a = (2*M_PI*(2*i+1+n/2)*(2*k+1) / (4 * n)); + double a = (2 * M_PI * (2 * i + 1 + n / 2) * (2 * k + 1) / (4 * n)); s += input[i] * cos(a); } output[k] = REF_SCALE(s, nbits - 1); @@ -152,15 +143,13 @@ static void mdct_ref(FFTSample *output, FFTSample *input, int nbits) #if CONFIG_DCT static void idct_ref(float *output, float *input, int nbits) { - int n = 1<<nbits; - int k, i; - double a, s; + int i, k, n = 1 << nbits; /* do it by hand */ for (i = 0; i < n; i++) { - s = 0.5 * input[0]; + double s = 0.5 * input[0]; for (k = 1; k < n; k++) { - a = M_PI*k*(i+0.5) / n; + double a = M_PI * k * (i + 0.5) / n; s += input[k] * cos(a); } output[i] = 2 * s / n; @@ -168,15 +157,13 @@ static void idct_ref(float *output, float *input, int nbits) } static void dct_ref(float *output, float *input, int nbits) { - int n = 1<<nbits; - int k, i; - double a, s; + int i, k, n = 1 << nbits; /* do it by hand */ for (k = 0; k < n; k++) { - s = 0; + double s = 0; for (i = 0; i < n; i++) { - a = M_PI*k*(i+0.5) / n; + double a = M_PI * k * (i + 0.5) / n; s += input[i] * cos(a); } output[k] = s; @@ -193,10 +180,8 @@ static FFTSample frandom(AVLFG *prng) static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale) { - int i; - double max= 0; - double error= 0; - int err = 0; + int i, err = 0; + double error = 0, max = 0; for (i = 0; i < n; i++) { double e = fabsf(tab1[i] - (tab2[i] / scale)) / RANGE; @@ -242,27 +227,23 @@ 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; - int do_inverse = 0; FFTContext s1, *s = &s1; FFTContext m1, *m = &m1; #if FFT_FLOAT RDFTContext r1, *r = &r1; DCTContext d1, *d = &d1; - int fft_size_2; #endif /* FFT_FLOAT */ - int fft_nbits, fft_size; + int it, i, err = 1; + int do_speed = 0, do_inverse = 0; + int fft_nbits = 9, fft_size; double scale = 1.0; AVLFG prng; + av_lfg_init(&prng, 1); - fft_nbits = 9; for(;;) { - c = getopt(argc, argv, "hsimrdn:f:c:"); + int c = getopt(argc, argv, "hsimrdn:f:c:"); if (c == -1) break; switch(c) { @@ -291,12 +272,14 @@ int main(int argc, char **argv) scale = atof(optarg); break; case 'c': - cpuflags = av_parse_cpu_flags(optarg); + { + int cpuflags = av_parse_cpu_flags(optarg); if (cpuflags < 0) return 1; av_set_cpu_flags_mask(cpuflags); break; } + } } fft_size = 1 << fft_nbits; @@ -388,7 +371,8 @@ int main(int argc, char **argv) #if FFT_FLOAT #if CONFIG_RDFT case TRANSFORM_RDFT: - fft_size_2 = fft_size >> 1; + { + int fft_size_2 = fft_size >> 1; if (do_inverse) { tab1[ 0].im = 0; tab1[fft_size_2].im = 0; @@ -418,6 +402,7 @@ int main(int argc, char **argv) err = check_diff((float *)tab_ref, (float *)tab2, fft_size, 1.0); } break; + } #endif /* CONFIG_RDFT */ #if CONFIG_DCT case TRANSFORM_DCT: |