aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/eval.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-12-06 14:33:38 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-12-06 14:33:38 +0100
commit15784c2bab56508565771cd04b5dda64d6717953 (patch)
treea0eade0816e7ea46a08a4cf7ffd2b25e6666c59b /libavutil/eval.c
parent32aedebdc59d5b34ab7a9137855dcc602267e00f (diff)
parent9d5c62ba5b586c80af508b5914934b1c439f6652 (diff)
downloadffmpeg-15784c2bab56508565771cd04b5dda64d6717953.tar.gz
Merge commit '9d5c62ba5b586c80af508b5914934b1c439f6652'
* commit '9d5c62ba5b586c80af508b5914934b1c439f6652': lavu/opt: do not filter out the initial sign character except for flags eval: treat dB as decibels instead of decibytes float_dsp: add vector_dmul_scalar() to multiply a vector of doubles Conflicts: libavutil/eval.c tests/ref/fate/eval Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/eval.c')
-rw-r--r--libavutil/eval.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/libavutil/eval.c b/libavutil/eval.c
index 4a27742729..b41c95c838 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -94,7 +94,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') {
@@ -448,16 +452,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;
}
@@ -744,6 +763,8 @@ int main(int argc, char **argv)
"not(1)",
"not(NAN)",
"not(0)",
+ "6.0206dB",
+ "-3.0103dB",
"pow(0,1.23)",
"pow(PI,1.23)",
"PI^1.23",