Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
audiowmark
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
audiowmark
Commits
f0dc1fb8
Commit
f0dc1fb8
authored
Feb 17, 2020
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize limiter: re-use block maximum.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
b974b26d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
15 deletions
+30
-15
limiter.cc
src/limiter.cc
+22
-10
limiter.hh
src/limiter.hh
+8
-5
No files found.
src/limiter.cc
View file @
f0dc1fb8
...
...
@@ -51,18 +51,27 @@ Limiter::process (const vector<float>& samples)
return
out
;
}
float
Limiter
::
block_max
(
const
float
*
in
)
{
float
maximum
=
ceiling
;
for
(
uint
x
=
0
;
x
<
block_size
*
n_channels
;
x
++
)
maximum
=
max
(
maximum
,
fabs
(
in
[
x
]));
return
maximum
;
}
void
Limiter
::
process_block
(
const
float
*
in
,
float
*
out
)
{
float
block_max
=
ceiling
;
float
block_max2
=
ceiling
;
for
(
size_t
x
=
0
;
x
<
block_size
*
n_channels
;
x
++
)
{
block_max
=
max
(
block_max
,
fabs
(
in
[
x
]));
block_max2
=
max
(
block_max2
,
fabs
(
in
[
x
+
block_size
*
n_channels
])
);
}
const
float
scale_start
=
ceiling
/
max
(
last_block_max
,
block_max
);
const
float
scale_end
=
ceiling
/
max
(
block_max
,
block_max2
);
if
(
block_max_last
<
ceiling
)
block_max_last
=
ceiling
;
if
(
block_max_current
<
ceiling
)
block_max_current
=
block_max
(
in
);
if
(
block_max_next
<
ceiling
)
block_max_next
=
block_max
(
in
+
block_size
*
n_channels
);
const
float
scale_start
=
ceiling
/
max
(
block_max_last
,
block_max_current
);
const
float
scale_end
=
ceiling
/
max
(
block_max
_current
,
block_max_next
);
const
float
scale_step
=
(
scale_end
-
scale_start
)
/
block_size
;
for
(
size_t
i
=
0
;
i
<
block_size
;
i
++
)
{
...
...
@@ -72,7 +81,10 @@ Limiter::process_block (const float *in, float *out)
for
(
uint
c
=
0
;
c
<
n_channels
;
c
++
)
out
[
i
*
n_channels
+
c
]
=
in
[
i
*
n_channels
+
c
]
*
scale
;
}
last_block_max
=
block_max
;
block_max_last
=
block_max_current
;
block_max_current
=
block_max_next
;
block_max_next
=
0
;
}
void
...
...
src/limiter.hh
View file @
f0dc1fb8
...
...
@@ -6,14 +6,17 @@
class
Limiter
{
float
ceiling
=
1
;
float
last_block_max
=
0
;
uint
block_size
=
0
;
uint
n_channels
=
0
;
uint
sample_rate
=
0
;
float
ceiling
=
1
;
float
block_max_last
=
0
;
float
block_max_current
=
0
;
float
block_max_next
=
0
;
uint
block_size
=
0
;
uint
n_channels
=
0
;
uint
sample_rate
=
0
;
std
::
vector
<
float
>
buffer
;
void
process_block
(
const
float
*
in
,
float
*
out
);
float
block_max
(
const
float
*
in
);
void
debug_scale
(
float
scale
);
public
:
Limiter
(
int
n_channels
,
int
sample_rate
);
...
...
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