mirror of https://git.ffmpeg.org/ffmpeg.git
Merge commit 'd445c865f87e7f13230e4dac3f77f5af21da95cb'
* commit 'd445c865f87e7f13230e4dac3f77f5af21da95cb': fft-test: Reduce variable scope where sensibly possible Conflicts: libavcodec/fft-test.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
commit
09f5b3750f
|
@ -69,16 +69,13 @@ static struct {
|
||||||
|
|
||||||
static void fft_ref_init(int nbits, int inverse)
|
static void fft_ref_init(int nbits, int inverse)
|
||||||
{
|
{
|
||||||
int n, i;
|
int i, n = 1 << nbits;
|
||||||
double c1, s1, alpha;
|
|
||||||
|
|
||||||
n = 1 << nbits;
|
|
||||||
exptab = av_malloc_array((n / 2), sizeof(*exptab));
|
exptab = av_malloc_array((n / 2), sizeof(*exptab));
|
||||||
|
|
||||||
for (i = 0; i < (n/2); i++) {
|
for (i = 0; i < (n/2); i++) {
|
||||||
alpha = 2 * M_PI * (float)i / (float)n;
|
double alpha = 2 * M_PI * (float)i / (float)n;
|
||||||
c1 = cos(alpha);
|
double c1 = cos(alpha), s1 = sin(alpha);
|
||||||
s1 = sin(alpha);
|
|
||||||
if (!inverse)
|
if (!inverse)
|
||||||
s1 = -s1;
|
s1 = -s1;
|
||||||
exptab[i].re = c1;
|
exptab[i].re = c1;
|
||||||
|
@ -88,18 +85,16 @@ static void fft_ref_init(int nbits, int inverse)
|
||||||
|
|
||||||
static 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;
|
int i, j;
|
||||||
double tmp_re, tmp_im, s, c;
|
int n = 1 << nbits;
|
||||||
FFTComplex *q;
|
int n2 = n >> 1;
|
||||||
|
|
||||||
n = 1 << nbits;
|
|
||||||
n2 = n >> 1;
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
tmp_re = 0;
|
double tmp_re = 0, tmp_im = 0;
|
||||||
tmp_im = 0;
|
FFTComplex *q = tab;
|
||||||
q = tab;
|
|
||||||
for (j = 0; j < n; j++) {
|
for (j = 0; j < n; j++) {
|
||||||
k = (i * j) & (n - 1);
|
double s, c;
|
||||||
|
int k = (i * j) & (n - 1);
|
||||||
if (k >= n2) {
|
if (k >= n2) {
|
||||||
c = -exptab[k - n2].re;
|
c = -exptab[k - n2].re;
|
||||||
s = -exptab[k - n2].im;
|
s = -exptab[k - n2].im;
|
||||||
|
@ -118,15 +113,13 @@ static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
|
||||||
#if CONFIG_MDCT
|
#if CONFIG_MDCT
|
||||||
static void imdct_ref(FFTSample *out, FFTSample *in, int nbits)
|
static void imdct_ref(FFTSample *out, FFTSample *in, int nbits)
|
||||||
{
|
{
|
||||||
int n = 1<<nbits;
|
int i, k, n = 1 << nbits;
|
||||||
int k, i, a;
|
|
||||||
double sum, f;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
sum = 0;
|
double sum = 0;
|
||||||
for (k = 0; k < n/2; k++) {
|
for (k = 0; k < n/2; k++) {
|
||||||
a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
|
int a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
|
||||||
f = cos(M_PI * a / (double)(2 * n));
|
double f = cos(M_PI * a / (double)(2 * n));
|
||||||
sum += f * in[k];
|
sum += f * in[k];
|
||||||
}
|
}
|
||||||
out[i] = REF_SCALE(-sum, nbits - 2);
|
out[i] = REF_SCALE(-sum, nbits - 2);
|
||||||
|
@ -136,15 +129,13 @@ static void imdct_ref(FFTSample *out, FFTSample *in, int nbits)
|
||||||
/* NOTE: no normalisation by 1 / N is done */
|
/* NOTE: no normalisation by 1 / N is done */
|
||||||
static void mdct_ref(FFTSample *output, FFTSample *input, int nbits)
|
static void mdct_ref(FFTSample *output, FFTSample *input, int nbits)
|
||||||
{
|
{
|
||||||
int n = 1<<nbits;
|
int i, k, n = 1 << nbits;
|
||||||
int k, i;
|
|
||||||
double a, s;
|
|
||||||
|
|
||||||
/* do it by hand */
|
/* do it by hand */
|
||||||
for (k = 0; k < n/2; k++) {
|
for (k = 0; k < n/2; k++) {
|
||||||
s = 0;
|
double s = 0;
|
||||||
for (i = 0; i < n; i++) {
|
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);
|
s += input[i] * cos(a);
|
||||||
}
|
}
|
||||||
output[k] = REF_SCALE(s, nbits - 1);
|
output[k] = REF_SCALE(s, nbits - 1);
|
||||||
|
@ -156,15 +147,13 @@ static void mdct_ref(FFTSample *output, FFTSample *input, int nbits)
|
||||||
#if CONFIG_DCT
|
#if CONFIG_DCT
|
||||||
static void idct_ref(FFTSample *output, FFTSample *input, int nbits)
|
static void idct_ref(FFTSample *output, FFTSample *input, int nbits)
|
||||||
{
|
{
|
||||||
int n = 1<<nbits;
|
int i, k, n = 1 << nbits;
|
||||||
int k, i;
|
|
||||||
double a, s;
|
|
||||||
|
|
||||||
/* do it by hand */
|
/* do it by hand */
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
s = 0.5 * input[0];
|
double s = 0.5 * input[0];
|
||||||
for (k = 1; k < n; k++) {
|
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);
|
s += input[k] * cos(a);
|
||||||
}
|
}
|
||||||
output[i] = 2 * s / n;
|
output[i] = 2 * s / n;
|
||||||
|
@ -172,15 +161,13 @@ static void idct_ref(FFTSample *output, FFTSample *input, int nbits)
|
||||||
}
|
}
|
||||||
static void dct_ref(FFTSample *output, FFTSample *input, int nbits)
|
static void dct_ref(FFTSample *output, FFTSample *input, int nbits)
|
||||||
{
|
{
|
||||||
int n = 1<<nbits;
|
int i, k, n = 1 << nbits;
|
||||||
int k, i;
|
|
||||||
double a, s;
|
|
||||||
|
|
||||||
/* do it by hand */
|
/* do it by hand */
|
||||||
for (k = 0; k < n; k++) {
|
for (k = 0; k < n; k++) {
|
||||||
s = 0;
|
double s = 0;
|
||||||
for (i = 0; i < n; i++) {
|
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);
|
s += input[i] * cos(a);
|
||||||
}
|
}
|
||||||
output[k] = s;
|
output[k] = s;
|
||||||
|
@ -197,10 +184,8 @@ static FFTSample frandom(AVLFG *prng)
|
||||||
|
|
||||||
static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale)
|
static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale)
|
||||||
{
|
{
|
||||||
int i;
|
int i, err = 0;
|
||||||
double max= 0;
|
double error = 0, max = 0;
|
||||||
double error= 0;
|
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
double e = fabsf(tab1[i] - (tab2[i] / scale)) / RANGE;
|
double e = fabsf(tab1[i] - (tab2[i] / scale)) / RANGE;
|
||||||
|
@ -246,27 +231,23 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
FFTComplex *tab, *tab1, *tab_ref;
|
FFTComplex *tab, *tab1, *tab_ref;
|
||||||
FFTSample *tab2;
|
FFTSample *tab2;
|
||||||
int it, i, c;
|
|
||||||
int cpuflags;
|
|
||||||
int do_speed = 0;
|
|
||||||
int err = 1;
|
|
||||||
enum tf_transform transform = TRANSFORM_FFT;
|
enum tf_transform transform = TRANSFORM_FFT;
|
||||||
int do_inverse = 0;
|
|
||||||
FFTContext s1, *s = &s1;
|
FFTContext s1, *s = &s1;
|
||||||
FFTContext m1, *m = &m1;
|
FFTContext m1, *m = &m1;
|
||||||
#if FFT_FLOAT
|
#if FFT_FLOAT
|
||||||
RDFTContext r1, *r = &r1;
|
RDFTContext r1, *r = &r1;
|
||||||
DCTContext d1, *d = &d1;
|
DCTContext d1, *d = &d1;
|
||||||
int fft_size_2;
|
|
||||||
#endif /* FFT_FLOAT */
|
#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;
|
double scale = 1.0;
|
||||||
AVLFG prng;
|
AVLFG prng;
|
||||||
|
|
||||||
av_lfg_init(&prng, 1);
|
av_lfg_init(&prng, 1);
|
||||||
|
|
||||||
fft_nbits = 9;
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
c = getopt(argc, argv, "hsimrdn:f:c:");
|
int c = getopt(argc, argv, "hsimrdn:f:c:");
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
switch(c) {
|
switch(c) {
|
||||||
|
@ -295,7 +276,8 @@ int main(int argc, char **argv)
|
||||||
scale = atof(optarg);
|
scale = atof(optarg);
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
cpuflags = av_get_cpu_flags();
|
{
|
||||||
|
int cpuflags = av_get_cpu_flags();
|
||||||
|
|
||||||
if (av_parse_cpu_caps(&cpuflags, optarg) < 0)
|
if (av_parse_cpu_caps(&cpuflags, optarg) < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -303,6 +285,7 @@ int main(int argc, char **argv)
|
||||||
av_force_cpu_flags(cpuflags);
|
av_force_cpu_flags(cpuflags);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fft_size = 1 << fft_nbits;
|
fft_size = 1 << fft_nbits;
|
||||||
|
@ -394,7 +377,8 @@ int main(int argc, char **argv)
|
||||||
#if FFT_FLOAT
|
#if FFT_FLOAT
|
||||||
#if CONFIG_RDFT
|
#if CONFIG_RDFT
|
||||||
case TRANSFORM_RDFT:
|
case TRANSFORM_RDFT:
|
||||||
fft_size_2 = fft_size >> 1;
|
{
|
||||||
|
int fft_size_2 = fft_size >> 1;
|
||||||
if (do_inverse) {
|
if (do_inverse) {
|
||||||
tab1[ 0].im = 0;
|
tab1[ 0].im = 0;
|
||||||
tab1[fft_size_2].im = 0;
|
tab1[fft_size_2].im = 0;
|
||||||
|
@ -424,6 +408,7 @@ int main(int argc, char **argv)
|
||||||
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;
|
break;
|
||||||
|
}
|
||||||
#endif /* CONFIG_RDFT */
|
#endif /* CONFIG_RDFT */
|
||||||
#if CONFIG_DCT
|
#if CONFIG_DCT
|
||||||
case TRANSFORM_DCT:
|
case TRANSFORM_DCT:
|
||||||
|
|
Loading…
Reference in New Issue