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
5312268b
Commit
5312268b
authored
Sep 28, 2012
by
Justin Ruggles
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eval: treat dB as decibels instead of decibytes
parent
ac7eb4cb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
3 deletions
+30
-3
eval.c
libavutil/eval.c
+24
-3
eval
tests/ref/fate/eval
+6
-0
No files found.
libavutil/eval.c
View file @
5312268b
...
...
@@ -81,7 +81,11 @@ double av_strtod(const char *numstr, char **tail)
d
=
strtod
(
numstr
,
&
next
);
/* if parsing succeeded, check for and interpret postfixes */
if
(
next
!=
numstr
)
{
if
(
*
next
>=
'E'
&&
*
next
<=
'z'
)
{
if
(
next
[
0
]
==
'd'
&&
next
[
1
]
==
'B'
)
{
/* treat dB as decibels instead of decibytes */
d
=
pow
(
10
,
d
/
20
);
next
+=
2
;
}
else
if
(
*
next
>=
'E'
&&
*
next
<=
'z'
)
{
int
e
=
si_prefixes
[
*
next
-
'E'
];
if
(
e
)
{
if
(
next
[
1
]
==
'i'
)
{
...
...
@@ -339,16 +343,31 @@ static int parse_pow(AVExpr **e, Parser *p, int *sign)
return
parse_primary
(
e
,
p
);
}
static
int
parse_dB
(
AVExpr
**
e
,
Parser
*
p
,
int
*
sign
)
{
/* do not filter out the negative sign when parsing a dB value.
for example, -3dB is not the same as -(3dB) */
if
(
*
p
->
s
==
'-'
)
{
char
*
next
;
strtod
(
p
->
s
,
&
next
);
if
(
next
!=
p
->
s
&&
next
[
0
]
==
'd'
&&
next
[
1
]
==
'B'
)
{
*
sign
=
0
;
return
parse_primary
(
e
,
p
);
}
}
return
parse_pow
(
e
,
p
,
sign
);
}
static
int
parse_factor
(
AVExpr
**
e
,
Parser
*
p
)
{
int
sign
,
sign2
,
ret
;
AVExpr
*
e0
,
*
e1
,
*
e2
;
if
((
ret
=
parse_
pow
(
&
e0
,
p
,
&
sign
))
<
0
)
if
((
ret
=
parse_
dB
(
&
e0
,
p
,
&
sign
))
<
0
)
return
ret
;
while
(
p
->
s
[
0
]
==
'^'
){
e1
=
e0
;
p
->
s
++
;
if
((
ret
=
parse_
pow
(
&
e2
,
p
,
&
sign2
))
<
0
)
{
if
((
ret
=
parse_
dB
(
&
e2
,
p
,
&
sign2
))
<
0
)
{
av_expr_free
(
e1
);
return
ret
;
}
...
...
@@ -629,6 +648,8 @@ int main(int argc, char **argv)
"not(1)"
,
"not(NAN)"
,
"not(0)"
,
"6.0206dB"
,
"-3.0103dB"
,
NULL
};
...
...
tests/ref/fate/eval
View file @
5312268b
...
...
@@ -184,5 +184,11 @@ Evaluating 'not(NAN)'
Evaluating 'not(0)'
'not(0)' -> 1.000000
Evaluating '6.0206dB'
'6.0206dB' -> 2.000000
Evaluating '-3.0103dB'
'-3.0103dB' -> 0.707107
12.700000 == 12.7
0.931323 == 0.931322575
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