Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
d445c865
Commit
d445c865
authored
Jun 26, 2014
by
Diego Biurrun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fft-test: Reduce variable scope where sensibly possible
Also merge variable declaration and initialization.
parent
eac77fcd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
51 deletions
+36
-51
fft-test.c
libavcodec/fft-test.c
+36
-51
No files found.
libavcodec/fft-test.c
View file @
d445c865
...
...
@@ -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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment