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
88dca80d
Commit
88dca80d
authored
Feb 10, 2019
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support computing signal-to-noise ratio during audiowmark add.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
67cc39a3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
audiowmark.cc
src/audiowmark.cc
+23
-0
No files found.
src/audiowmark.cc
View file @
88dca80d
...
...
@@ -35,6 +35,7 @@ namespace Params
static
double
pre_scale
=
0.95
;
// rescale the signal to avoid clipping after watermark is added
static
bool
mix
=
true
;
static
bool
hard
=
false
;
// hard decode bits? (soft decoding is better)
static
bool
snr
=
false
;
// compute/show snr while adding watermark
static
int
have_key
=
0
;
static
size_t
payload_size
=
128
;
// number of payload bits for the watermark
...
...
@@ -173,6 +174,10 @@ parse_options (int *argc_p,
{
Params
::
hard
=
true
;
}
else
if
(
check_arg
(
argc
,
argv
,
&
i
,
"--snr"
))
{
Params
::
snr
=
true
;
}
else
if
(
check_arg
(
argc
,
argv
,
&
i
,
"--test-key"
,
&
opt_arg
))
{
Params
::
have_key
++
;
...
...
@@ -746,6 +751,24 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
vector
<
float
>
samples
=
orig_wav_data
.
samples
();
out_signal
.
resize
(
samples
.
size
());
if
(
Params
::
snr
)
{
/* compute/show signal to noise ratio */
double
delta_power
=
0
;
double
signal_power
=
0
;
for
(
size_t
i
=
0
;
i
<
samples
.
size
();
i
++
)
{
const
double
orig_scaled
=
samples
[
i
];
// original sample
const
double
delta
=
out_signal
[
i
];
// watermark
delta_power
+=
delta
*
delta
;
signal_power
+=
orig_scaled
*
orig_scaled
;
}
delta_power
/=
samples
.
size
();
signal_power
/=
samples
.
size
();
printf
(
"SNR: %f dB
\n
"
,
10
*
log10
(
signal_power
/
delta_power
));
}
float
max_value
=
1e-6
;
for
(
size_t
i
=
0
;
i
<
samples
.
size
();
i
++
)
{
...
...
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