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
89da8e5b
Commit
89da8e5b
authored
Feb 04, 2020
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add basic limiter prototype.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
4a2f0b2d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
1 deletion
+96
-1
Makefile.am
src/Makefile.am
+4
-1
testlimiter.cc
src/testlimiter.cc
+92
-0
No files found.
src/Makefile.am
View file @
89da8e5b
...
...
@@ -9,7 +9,7 @@ COMMON_LIBS = $(SNDFILE_LIBS) $(FFTW_LIBS) $(LIBGCRYPT_LIBS) $(LIBMPG123_LIBS)
audiowmark_SOURCES
=
audiowmark.cc wmget.cc wmadd.cc
$(COMMON_SRC)
audiowmark_LDFLAGS
=
$(COMMON_LIBS)
noinst_PROGRAMS
=
testconvcode testrandom testmp3 teststream
noinst_PROGRAMS
=
testconvcode testrandom testmp3 teststream
testlimiter
testconvcode_SOURCES
=
testconvcode.cc
$(COMMON_SRC)
testconvcode_LDFLAGS
=
$(COMMON_LIBS)
...
...
@@ -22,3 +22,6 @@ testmp3_LDFLAGS = $(COMMON_LIBS)
teststream_SOURCES
=
teststream.cc
$(COMMON_SRC)
teststream_LDFLAGS
=
$(COMMON_LIBS)
testlimiter_SOURCES
=
testlimiter.cc
$(COMMON_SRC)
testlimiter_LDFLAGS
=
$(COMMON_LIBS)
src/testlimiter.cc
0 → 100644
View file @
89da8e5b
#include <string>
#include <vector>
#include <sndfile.h>
#include <assert.h>
#include <math.h>
#include "sfinputstream.hh"
#include "stdoutwavoutputstream.hh"
#include "utils.hh"
using
std
::
string
;
using
std
::
vector
;
using
std
::
max
;
using
std
::
min
;
class
Limiter
{
float
mx
=
1
;
uint
look_ahead
=
0
;
vector
<
float
>
buffer
;
public
:
Limiter
(
int
sample_rate
)
{
look_ahead
=
sample_rate
*
0.005
;
assert
(
look_ahead
>=
1
);
}
vector
<
float
>
process
(
const
vector
<
float
>&
samples
)
{
for
(
size_t
i
=
0
;
i
<
samples
.
size
();
i
++
)
buffer
.
push_back
(
samples
[
i
]);
vector
<
float
>
out
;
if
(
buffer
.
size
()
>
look_ahead
)
{
size_t
todo
=
buffer
.
size
()
-
look_ahead
;
for
(
size_t
i
=
0
;
i
<
todo
;
i
++
)
{
float
xmx
=
1
;
for
(
uint
j
=
0
;
j
<
look_ahead
;
j
++
)
xmx
=
max
(
fabs
(
buffer
[
i
+
j
]),
xmx
);
mx
=
mx
*
0.99
+
xmx
*
0.01
;
out
.
push_back
(
buffer
[
i
]
/
mx
);
printf
(
"%f %f
\n
"
,
buffer
[
i
],
out
.
back
());
}
#if 0
for (size_t i = 0; i < samples.size(); i++)
{
if (fabs (samples[i]) > mx)
mx = fabs (samples[i]);
out.push_back (samples[i] / mx);
if (mx > 1)
mx = max (mx - 0.01f, 1.f);
}
#endif
buffer
.
erase
(
buffer
.
begin
(),
buffer
.
begin
()
+
todo
);
}
return
out
;
}
};
int
main
(
int
argc
,
char
**
argv
)
{
SFInputStream
in
;
StdoutWavOutputStream
out
;
std
::
string
filename
=
(
argc
>=
2
)
?
argv
[
1
]
:
"-"
;
Error
err
=
in
.
open
(
filename
.
c_str
());
if
(
err
)
{
fprintf
(
stderr
,
"teststream: open input failed: %s
\n
"
,
err
.
message
());
return
1
;
}
err
=
out
.
open
(
in
.
n_channels
(),
in
.
sample_rate
(),
16
,
in
.
n_frames
());
if
(
err
)
{
fprintf
(
stderr
,
"teststream: open output failed: %s
\n
"
,
err
.
message
());
return
1
;
}
Limiter
limiter
(
in
.
sample_rate
());
vector
<
float
>
samples
;
do
{
in
.
read_frames
(
samples
,
1024
);
for
(
auto
&
s
:
samples
)
s
*=
1.1
;
samples
=
limiter
.
process
(
samples
);
//out.write_frames (samples);
}
while
(
samples
.
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