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
fcdf0a43
Commit
fcdf0a43
authored
Jan 20, 2011
by
Justin Ruggles
Committed by
Mans Rullgard
Jan 20, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add biquad high-pass and low-pass IIR filters.
Signed-off-by:
Mans Rullgard
<
mans@mansr.com
>
parent
66c6b5e2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
iirfilter.c
libavcodec/iirfilter.c
+50
-0
iirfilter.h
libavcodec/iirfilter.h
+1
-0
No files found.
libavcodec/iirfilter.c
View file @
fcdf0a43
...
...
@@ -112,6 +112,51 @@ static int butterworth_init_coeffs(void *avc, struct FFIIRFilterCoeffs *c,
return
0
;
}
static
int
biquad_init_coeffs
(
void
*
avc
,
struct
FFIIRFilterCoeffs
*
c
,
enum
IIRFilterMode
filt_mode
,
int
order
,
float
cutoff_ratio
,
float
stopband
)
{
double
cos_w0
,
sin_w0
;
double
a0
,
x0
,
x1
;
if
(
filt_mode
!=
FF_FILTER_MODE_HIGHPASS
&&
filt_mode
!=
FF_FILTER_MODE_LOWPASS
)
{
av_log
(
avc
,
AV_LOG_ERROR
,
"Biquad filter currently only supports "
"high-pass and low-pass filter modes
\n
"
);
return
-
1
;
}
if
(
order
!=
2
)
{
av_log
(
avc
,
AV_LOG_ERROR
,
"Biquad filter must have order of 2
\n
"
);
return
-
1
;
}
cos_w0
=
cos
(
M_PI
*
cutoff_ratio
);
sin_w0
=
sin
(
M_PI
*
cutoff_ratio
);
a0
=
1
.
0
+
(
sin_w0
/
2
.
0
);
if
(
filt_mode
==
FF_FILTER_MODE_HIGHPASS
)
{
c
->
gain
=
((
1
.
0
+
cos_w0
)
/
2
.
0
)
/
a0
;
x0
=
(
-
(
1
.
0
+
cos_w0
))
/
a0
;
x1
=
((
1
.
0
+
cos_w0
)
/
2
.
0
)
/
a0
;
}
else
{
// FF_FILTER_MODE_LOWPASS
c
->
gain
=
((
1
.
0
-
cos_w0
)
/
2
.
0
)
/
a0
;
x0
=
(
1
.
0
-
cos_w0
)
/
a0
;
x1
=
((
1
.
0
-
cos_w0
)
/
2
.
0
)
/
a0
;
}
c
->
cy
[
0
]
=
(
2
.
0
*
cos_w0
)
/
a0
;
c
->
cy
[
1
]
=
(
-
1
.
0
+
(
sin_w0
/
2
.
0
))
/
a0
;
// divide by gain to make the x coeffs integers.
// during filtering, the delay state will include the gain multiplication
c
->
cx
[
0
]
=
lrintf
(
x0
/
c
->
gain
);
c
->
cx
[
1
]
=
lrintf
(
x1
/
c
->
gain
);
c
->
cy
[
0
]
/=
c
->
gain
;
c
->
cy
[
1
]
/=
c
->
gain
;
return
0
;
}
av_cold
struct
FFIIRFilterCoeffs
*
ff_iir_filter_init_coeffs
(
void
*
avc
,
enum
IIRFilterType
filt_type
,
enum
IIRFilterMode
filt_mode
,
...
...
@@ -136,6 +181,11 @@ av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc,
stopband
))
{
goto
init_fail
;
}
}
else
if
(
filt_type
==
FF_FILTER_TYPE_BIQUAD
)
{
if
(
biquad_init_coeffs
(
avc
,
c
,
filt_mode
,
order
,
cutoff_ratio
,
stopband
))
{
goto
init_fail
;
}
}
else
{
av_log
(
avc
,
AV_LOG_ERROR
,
"filter type is not currently implemented
\n
"
);
goto
init_fail
;
...
...
libavcodec/iirfilter.h
View file @
fcdf0a43
...
...
@@ -34,6 +34,7 @@ struct FFIIRFilterState;
enum
IIRFilterType
{
FF_FILTER_TYPE_BESSEL
,
FF_FILTER_TYPE_BIQUAD
,
FF_FILTER_TYPE_BUTTERWORTH
,
FF_FILTER_TYPE_CHEBYSHEV
,
FF_FILTER_TYPE_ELLIPTIC
,
...
...
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