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
86822cfc
Commit
86822cfc
authored
May 20, 2020
by
Paul B Mahol
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avfilter/af_aiir: fix phase and group delay calculation
Properly unwrap phase.
parent
74dfc88b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
16 deletions
+44
-16
af_aiir.c
libavfilter/af_aiir.c
+44
-16
No files found.
libavfilter/af_aiir.c
View file @
86822cfc
...
...
@@ -819,11 +819,11 @@ static void get_response(int channel, int format, double w,
*
i
=
imag
;
}
static
void
draw_response
(
AVFilterContext
*
ctx
,
AVFrame
*
out
)
static
void
draw_response
(
AVFilterContext
*
ctx
,
AVFrame
*
out
,
int
sample_rate
)
{
AudioIIRContext
*
s
=
ctx
->
priv
;
float
*
mag
,
*
phase
,
*
delay
,
min
=
FLT_MAX
,
max
=
FLT_MIN
;
float
min_delay
=
FLT_MAX
,
max_delay
=
FLT_MIN
;
double
*
mag
,
*
phase
,
*
temp
,
*
delay
,
min
=
DBL_MAX
,
max
=
-
DBL_MAX
;
double
min_delay
,
max_delay
,
min_phase
,
max_phase
;
int
prev_ymag
=
-
1
,
prev_yphase
=
-
1
,
prev_ydelay
=
-
1
;
char
text
[
32
];
int
ch
,
i
;
...
...
@@ -831,9 +831,10 @@ static void draw_response(AVFilterContext *ctx, AVFrame *out)
memset
(
out
->
data
[
0
],
0
,
s
->
h
*
out
->
linesize
[
0
]);
phase
=
av_malloc_array
(
s
->
w
,
sizeof
(
*
phase
));
temp
=
av_malloc_array
(
s
->
w
,
sizeof
(
*
temp
));
mag
=
av_malloc_array
(
s
->
w
,
sizeof
(
*
mag
));
delay
=
av_malloc_array
(
s
->
w
,
sizeof
(
*
delay
));
if
(
!
mag
||
!
phase
||
!
delay
)
if
(
!
mag
||
!
phase
||
!
delay
||
!
temp
)
goto
end
;
ch
=
av_clip
(
s
->
ir_channel
,
0
,
s
->
channels
-
1
);
...
...
@@ -849,16 +850,34 @@ static void draw_response(AVFilterContext *ctx, AVFrame *out)
mag
[
i
]
=
s
->
iir
[
ch
].
g
*
hypot
(
real
,
imag
);
phase
[
i
]
=
atan2
(
imag
,
real
);
min
=
fmin
f
(
min
,
mag
[
i
]);
max
=
fmax
f
(
max
,
mag
[
i
]);
min
=
fmin
(
min
,
mag
[
i
]);
max
=
fmax
(
max
,
mag
[
i
]);
}
temp
[
0
]
=
0
.;
for
(
i
=
0
;
i
<
s
->
w
-
1
;
i
++
)
{
float
dw
=
M_PI
/
(
s
->
w
-
1
);
double
d
=
phase
[
i
]
-
phase
[
i
+
1
];
temp
[
i
+
1
]
=
ceil
(
fabs
(
d
)
/
(
2
.
*
M_PI
))
*
2
.
*
M_PI
*
((
d
>
M_PI
)
-
(
d
<
-
M_PI
));
}
delay
[
i
]
=
-
(
phase
[
i
+
1
]
-
phase
[
i
])
/
dw
;
min_delay
=
fminf
(
min_delay
,
delay
[
i
]);
max_delay
=
fmaxf
(
max_delay
,
delay
[
i
]);
min_phase
=
phase
[
0
];
max_phase
=
phase
[
0
];
for
(
i
=
1
;
i
<
s
->
w
;
i
++
)
{
temp
[
i
]
+=
temp
[
i
-
1
];
phase
[
i
]
+=
temp
[
i
];
min_phase
=
fmin
(
min_phase
,
phase
[
i
]);
max_phase
=
fmax
(
max_phase
,
phase
[
i
]);
}
delay
[
0
]
=
0
.;
min_delay
=
0
.;
max_delay
=
0
.;
for
(
i
=
0
;
i
<
s
->
w
-
1
;
i
++
)
{
double
div
=
s
->
w
/
(
double
)
sample_rate
;
delay
[
i
+
1
]
=
-
(
phase
[
i
]
-
phase
[
i
+
1
])
/
div
;
min_delay
=
fmin
(
min_delay
,
delay
[
i
+
1
]);
max_delay
=
fmax
(
max_delay
,
delay
[
i
+
1
]);
}
delay
[
i
]
=
delay
[
i
-
1
];
...
...
@@ -866,7 +885,7 @@ static void draw_response(AVFilterContext *ctx, AVFrame *out)
for
(
i
=
0
;
i
<
s
->
w
;
i
++
)
{
int
ymag
=
mag
[
i
]
/
max
*
(
s
->
h
-
1
);
int
ydelay
=
(
delay
[
i
]
-
min_delay
)
/
(
max_delay
-
min_delay
)
*
(
s
->
h
-
1
);
int
yphase
=
(
0
.
5
*
(
1
.
+
phase
[
i
]
/
M_PI
)
)
*
(
s
->
h
-
1
);
int
yphase
=
(
phase
[
i
]
-
min_phase
)
/
(
max_phase
-
min_phase
)
*
(
s
->
h
-
1
);
ymag
=
s
->
h
-
1
-
av_clip
(
ymag
,
0
,
s
->
h
-
1
);
yphase
=
s
->
h
-
1
-
av_clip
(
yphase
,
0
,
s
->
h
-
1
);
...
...
@@ -897,17 +916,26 @@ static void draw_response(AVFilterContext *ctx, AVFrame *out)
snprintf
(
text
,
sizeof
(
text
),
"%.2f"
,
min
);
drawtext
(
out
,
15
*
8
+
2
,
12
,
text
,
0xDDDDDDDD
);
drawtext
(
out
,
2
,
22
,
"Max Delay:"
,
0xDDDDDDDD
);
drawtext
(
out
,
2
,
22
,
"Max Phase:"
,
0xDDDDDDDD
);
snprintf
(
text
,
sizeof
(
text
),
"%.2f"
,
max_phase
);
drawtext
(
out
,
15
*
8
+
2
,
22
,
text
,
0xDDDDDDDD
);
drawtext
(
out
,
2
,
32
,
"Min Phase:"
,
0xDDDDDDDD
);
snprintf
(
text
,
sizeof
(
text
),
"%.2f"
,
min_phase
);
drawtext
(
out
,
15
*
8
+
2
,
32
,
text
,
0xDDDDDDDD
);
drawtext
(
out
,
2
,
42
,
"Max Delay:"
,
0xDDDDDDDD
);
snprintf
(
text
,
sizeof
(
text
),
"%.2f"
,
max_delay
);
drawtext
(
out
,
11
*
8
+
2
,
2
2
,
text
,
0xDDDDDDDD
);
drawtext
(
out
,
11
*
8
+
2
,
4
2
,
text
,
0xDDDDDDDD
);
drawtext
(
out
,
2
,
3
2
,
"Min Delay:"
,
0xDDDDDDDD
);
drawtext
(
out
,
2
,
5
2
,
"Min Delay:"
,
0xDDDDDDDD
);
snprintf
(
text
,
sizeof
(
text
),
"%.2f"
,
min_delay
);
drawtext
(
out
,
11
*
8
+
2
,
3
2
,
text
,
0xDDDDDDDD
);
drawtext
(
out
,
11
*
8
+
2
,
5
2
,
text
,
0xDDDDDDDD
);
}
end:
av_free
(
delay
);
av_free
(
temp
);
av_free
(
phase
);
av_free
(
mag
);
}
...
...
@@ -951,7 +979,7 @@ static int config_output(AVFilterLink *outlink)
if
(
!
s
->
video
)
return
AVERROR
(
ENOMEM
);
draw_response
(
ctx
,
s
->
video
);
draw_response
(
ctx
,
s
->
video
,
inlink
->
sample_rate
);
}
if
(
s
->
format
==
0
)
...
...
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