Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Releases
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
ffmpeg
Commits
45fa85a7
Commit
45fa85a7
authored
May 29, 2023
by
Paul B Mahol
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avfilter/silenceremove_template: refactor detectors using common peaks code
parent
f02964ae
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
145 deletions
+72
-145
silenceremove_template.c
libavfilter/silenceremove_template.c
+72
-145
No files found.
libavfilter/silenceremove_template.c
View file @
45fa85a7
...
@@ -105,73 +105,76 @@ static void fn(queue_sample)(AVFilterContext *ctx,
...
@@ -105,73 +105,76 @@ static void fn(queue_sample)(AVFilterContext *ctx,
*
window_pos
=
0
;
*
window_pos
=
0
;
}
}
static
ftype
fn
(
compute_avg
)(
ftype
*
cache
,
ftype
sample
,
ftype
wsample
,
static
ftype
fn
(
compute_avg
)(
ftype
*
cache
,
ftype
x
,
ftype
px
,
int
window_size
,
int
*
unused
,
int
*
unused2
)
int
window_size
,
int
*
unused
,
int
*
unused2
)
{
{
ftype
r
;
ftype
r
;
cache
[
0
]
+=
FABS
(
sample
);
cache
[
0
]
+=
FABS
(
x
);
cache
[
0
]
-=
FABS
(
wsample
);
cache
[
0
]
-=
FABS
(
px
);
cache
[
0
]
=
r
=
FMAX
(
cache
[
0
],
ZERO
);
cache
[
0
]
=
r
=
FMAX
(
cache
[
0
],
ZERO
);
return
r
/
window_size
;
return
r
/
window_size
;
}
}
static
ftype
fn
(
compute_median
)(
ftype
*
peak
,
ftype
sample
,
ftype
wsample
,
#define PEAKS(empty_value,op,sample, psample)\
int
size
,
int
*
ffront
,
int
*
bback
)
if (!empty && psample == ss[front]) { \
ss[front] = empty_value; \
if (back != front) { \
front--; \
if (front < 0) \
front = n - 1; \
} \
empty = front == back; \
} \
\
if (!empty && sample op ss[front]) { \
while (1) { \
ss[front] = empty_value; \
if (back == front) { \
empty = 1; \
break; \
} \
front--; \
if (front < 0) \
front = n - 1; \
} \
} \
\
while (!empty && sample op ss[back]) { \
ss[back] = empty_value; \
if (back == front) { \
empty = 1; \
break; \
} \
back++; \
if (back >= n) \
back = 0; \
} \
\
if (!empty) { \
back--; \
if (back < 0) \
back = n - 1; \
}
static
ftype
fn
(
compute_median
)(
ftype
*
ss
,
ftype
x
,
ftype
px
,
int
n
,
int
*
ffront
,
int
*
bback
)
{
{
ftype
r
,
a
bs_sample
=
FABS
(
sample
);
ftype
r
,
a
x
=
FABS
(
x
);
int
front
=
*
ffront
;
int
front
=
*
ffront
;
int
back
=
*
bback
;
int
back
=
*
bback
;
int
empty
=
front
==
back
&&
peak
[
front
]
==
-
ONE
;
int
empty
=
front
==
back
&&
ss
[
front
]
==
-
ONE
;
int
idx
;
int
idx
;
if
(
!
empty
&&
FABS
(
wsample
)
==
peak
[
front
])
{
PEAKS
(
-
ONE
,
>
,
ax
,
FABS
(
px
))
peak
[
front
]
=
-
ONE
;
if
(
back
!=
front
)
{
front
--
;
if
(
front
<
0
)
front
=
size
-
1
;
}
empty
=
front
==
back
;
}
if
(
!
empty
&&
abs_sample
>
peak
[
front
])
{
while
(
1
)
{
peak
[
front
]
=
-
ONE
;
if
(
back
==
front
)
{
empty
=
1
;
break
;
}
front
--
;
if
(
front
<
0
)
front
=
size
-
1
;
}
}
while
(
!
empty
&&
abs_sample
>
peak
[
back
])
{
peak
[
back
]
=
-
ONE
;
if
(
back
==
front
)
{
empty
=
1
;
break
;
}
back
++
;
if
(
back
>=
size
)
back
=
0
;
}
if
(
!
empty
)
{
back
--
;
if
(
back
<
0
)
back
=
size
-
1
;
}
peak
[
back
]
=
abs_sample
;
ss
[
back
]
=
ax
;
idx
=
(
back
<=
front
)
?
back
+
(
front
-
back
+
1
)
/
2
:
back
+
(
size
+
front
-
back
+
1
)
/
2
;
idx
=
(
back
<=
front
)
?
back
+
(
front
-
back
+
1
)
/
2
:
back
+
(
n
+
front
-
back
+
1
)
/
2
;
if
(
idx
>=
size
)
if
(
idx
>=
n
)
idx
-=
size
;
idx
-=
n
;
av_assert2
(
idx
>=
0
&&
idx
<
size
);
av_assert2
(
idx
>=
0
&&
idx
<
n
);
r
=
peak
[
idx
];
r
=
ss
[
idx
];
*
ffront
=
front
;
*
ffront
=
front
;
*
bback
=
back
;
*
bback
=
back
;
...
@@ -179,56 +182,18 @@ static ftype fn(compute_median)(ftype *peak, ftype sample, ftype wsample,
...
@@ -179,56 +182,18 @@ static ftype fn(compute_median)(ftype *peak, ftype sample, ftype wsample,
return
r
;
return
r
;
}
}
static
ftype
fn
(
compute_peak
)(
ftype
*
peak
,
ftype
sample
,
ftype
wsample
,
static
ftype
fn
(
compute_peak
)(
ftype
*
ss
,
ftype
x
,
ftype
px
,
int
size
,
int
*
ffront
,
int
*
bback
)
int
n
,
int
*
ffront
,
int
*
bback
)
{
{
ftype
r
,
a
bs_sample
=
FABS
(
sample
);
ftype
r
,
a
x
=
FABS
(
x
);
int
front
=
*
ffront
;
int
front
=
*
ffront
;
int
back
=
*
bback
;
int
back
=
*
bback
;
int
empty
=
front
==
back
&&
peak
[
front
]
==
ZERO
;
int
empty
=
front
==
back
&&
ss
[
front
]
==
ZERO
;
if
(
!
empty
&&
FABS
(
wsample
)
==
peak
[
front
])
{
peak
[
front
]
=
ZERO
;
if
(
back
!=
front
)
{
front
--
;
if
(
front
<
0
)
front
=
size
-
1
;
}
empty
=
front
==
back
;
}
if
(
!
empty
&&
abs_sample
>=
peak
[
front
])
{
while
(
1
)
{
peak
[
front
]
=
ZERO
;
if
(
back
==
front
)
{
empty
=
1
;
break
;
}
front
--
;
if
(
front
<
0
)
front
=
size
-
1
;
}
}
while
(
!
empty
&&
abs_sample
>=
peak
[
back
])
{
peak
[
back
]
=
ZERO
;
if
(
back
==
front
)
{
empty
=
1
;
break
;
}
back
++
;
if
(
back
>=
size
)
back
=
0
;
}
if
(
!
empty
)
{
PEAKS
(
ZERO
,
>=
,
ax
,
FABS
(
px
))
back
--
;
if
(
back
<
0
)
back
=
size
-
1
;
}
peak
[
back
]
=
abs_sample
;
ss
[
back
]
=
ax
;
r
=
peak
[
front
];
r
=
ss
[
front
];
*
ffront
=
front
;
*
ffront
=
front
;
*
bback
=
back
;
*
bback
=
back
;
...
@@ -236,57 +201,19 @@ static ftype fn(compute_peak)(ftype *peak, ftype sample, ftype wsample,
...
@@ -236,57 +201,19 @@ static ftype fn(compute_peak)(ftype *peak, ftype sample, ftype wsample,
return
r
;
return
r
;
}
}
static
ftype
fn
(
compute_ptp
)(
ftype
*
peak
,
ftype
sample
,
ftype
wsample
,
static
ftype
fn
(
compute_ptp
)(
ftype
*
ss
,
ftype
x
,
ftype
px
,
int
size
,
int
*
ffront
,
int
*
bback
)
int
n
,
int
*
ffront
,
int
*
bback
)
{
{
int
front
=
*
ffront
;
int
front
=
*
ffront
;
int
back
=
*
bback
;
int
back
=
*
bback
;
int
empty
=
front
==
back
&&
peak
[
front
]
==
TMIN
;
int
empty
=
front
==
back
&&
ss
[
front
]
==
TMIN
;
ftype
r
,
max
,
min
;
ftype
r
,
max
,
min
;
if
(
!
empty
&&
wsample
==
peak
[
front
])
{
PEAKS
(
TMIN
,
>=
,
x
,
px
)
peak
[
front
]
=
TMIN
;
if
(
back
!=
front
)
{
front
--
;
if
(
front
<
0
)
front
=
size
-
1
;
}
empty
=
front
==
back
;
}
if
(
!
empty
&&
sample
>=
peak
[
front
])
{
while
(
1
)
{
peak
[
front
]
=
TMIN
;
if
(
back
==
front
)
{
empty
=
1
;
break
;
}
front
--
;
if
(
front
<
0
)
front
=
size
-
1
;
}
}
while
(
!
empty
&&
sample
>=
peak
[
back
])
{
peak
[
back
]
=
TMIN
;
if
(
back
==
front
)
{
empty
=
1
;
break
;
}
back
++
;
if
(
back
>=
size
)
back
=
0
;
}
if
(
!
empty
)
{
back
--
;
if
(
back
<
0
)
back
=
size
-
1
;
}
peak
[
back
]
=
sample
;
ss
[
back
]
=
x
;
max
=
peak
[
front
];
max
=
ss
[
front
];
min
=
sample
;
min
=
x
;
r
=
FABS
(
min
)
+
FABS
(
max
-
min
);
r
=
FABS
(
min
)
+
FABS
(
max
-
min
);
*
ffront
=
front
;
*
ffront
=
front
;
...
@@ -295,13 +222,13 @@ static ftype fn(compute_ptp)(ftype *peak, ftype sample, ftype wsample,
...
@@ -295,13 +222,13 @@ static ftype fn(compute_ptp)(ftype *peak, ftype sample, ftype wsample,
return
r
;
return
r
;
}
}
static
ftype
fn
(
compute_rms
)(
ftype
*
cache
,
ftype
sample
,
ftype
wsample
,
static
ftype
fn
(
compute_rms
)(
ftype
*
cache
,
ftype
x
,
ftype
px
,
int
window_size
,
int
*
unused
,
int
*
unused2
)
int
window_size
,
int
*
unused
,
int
*
unused2
)
{
{
ftype
r
;
ftype
r
;
cache
[
0
]
+=
sample
*
sample
;
cache
[
0
]
+=
x
*
x
;
cache
[
0
]
-=
wsample
*
wsample
;
cache
[
0
]
-=
px
*
px
;
cache
[
0
]
=
r
=
FMAX
(
cache
[
0
],
ZERO
);
cache
[
0
]
=
r
=
FMAX
(
cache
[
0
],
ZERO
);
return
SQRT
(
r
/
window_size
);
return
SQRT
(
r
/
window_size
);
...
...
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