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
031c1ab2
Commit
031c1ab2
authored
Dec 14, 2018
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanups related to block size.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
b6a3ec39
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
13 deletions
+19
-13
audiowmark.cc
src/audiowmark.cc
+19
-13
No files found.
src/audiowmark.cc
View file @
031c1ab2
...
@@ -26,7 +26,7 @@ namespace Params
...
@@ -26,7 +26,7 @@ namespace Params
static
double
water_delta
=
0.015
;
// strength of the watermark
static
double
water_delta
=
0.015
;
// strength of the watermark
static
double
pre_scale
=
0.95
;
// rescale the signal to avoid clipping after watermark is added
static
double
pre_scale
=
0.95
;
// rescale the signal to avoid clipping after watermark is added
static
bool
mix
=
true
;
static
bool
mix
=
true
;
static
int
block
=
32
;
// block size for mix step (non-linear bit storage)
static
int
block
_size
=
32
;
// block size for mix step (non-linear bit storage)
static
unsigned
int
seed
=
0
;
static
unsigned
int
seed
=
0
;
}
}
...
@@ -204,6 +204,12 @@ frame_count (const WavData& wav_data)
...
@@ -204,6 +204,12 @@ frame_count (const WavData& wav_data)
return
(
wav_data
.
n_values
()
/
wav_data
.
n_channels
()
+
(
Params
::
frame_size
-
1
))
/
Params
::
frame_size
;
return
(
wav_data
.
n_values
()
/
wav_data
.
n_channels
()
+
(
Params
::
frame_size
-
1
))
/
Params
::
frame_size
;
}
}
int
block_count
(
const
WavData
&
wav_data
)
{
return
frame_count
(
wav_data
)
/
(
Params
::
block_size
*
Params
::
frames_per_bit
);
}
/*
/*
* get one audio frame, Params::frame_size samples if available
* get one audio frame, Params::frame_size samples if available
*
*
...
@@ -418,7 +424,7 @@ gen_mix_entries (int block)
...
@@ -418,7 +424,7 @@ gen_mix_entries (int block)
{
{
vector
<
MixEntry
>
mix_entries
;
vector
<
MixEntry
>
mix_entries
;
for
(
int
f
=
0
;
f
<
Params
::
block
*
Params
::
frames_per_bit
;
f
++
)
for
(
int
f
=
0
;
f
<
Params
::
block
_size
*
Params
::
frames_per_bit
;
f
++
)
{
{
vector
<
int
>
up
;
vector
<
int
>
up
;
vector
<
int
>
down
;
vector
<
int
>
down
;
...
@@ -490,7 +496,7 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
...
@@ -490,7 +496,7 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
* to avoid processing a partly filled block
* to avoid processing a partly filled block
*/
*/
vector
<
float
>
in_signal
(
in_wav_data
.
samples
());
vector
<
float
>
in_signal
(
in_wav_data
.
samples
());
while
(
in_signal
.
size
()
%
(
in_wav_data
.
n_channels
()
*
Params
::
frame_size
*
Params
::
block
*
Params
::
frames_per_bit
))
while
(
in_signal
.
size
()
%
(
in_wav_data
.
n_channels
()
*
Params
::
frame_size
*
Params
::
block
_size
*
Params
::
frames_per_bit
))
in_signal
.
push_back
(
0
);
in_signal
.
push_back
(
0
);
WavData
wav_data
(
in_signal
,
in_wav_data
.
n_channels
(),
in_wav_data
.
mix_freq
(),
in_wav_data
.
bit_depth
());
WavData
wav_data
(
in_signal
,
in_wav_data
.
n_channels
(),
in_wav_data
.
mix_freq
(),
in_wav_data
.
bit_depth
());
...
@@ -510,12 +516,12 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
...
@@ -510,12 +516,12 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
fft_delta_spect
.
push_back
(
vector
<
complex
<
float
>>
(
fft_out
.
back
().
size
()));
fft_delta_spect
.
push_back
(
vector
<
complex
<
float
>>
(
fft_out
.
back
().
size
()));
}
}
}
}
for
(
int
block
=
0
;
block
<
frame_count
(
wav_data
)
/
(
Params
::
block
*
Params
::
frames_per_bit
);
block
++
)
for
(
int
block
=
0
;
block
<
block_count
(
wav_data
);
block
++
)
{
{
vector
<
MixEntry
>
mix_entries
=
gen_mix_entries
(
block
);
vector
<
MixEntry
>
mix_entries
=
gen_mix_entries
(
block
);
const
int
block_start
=
block
*
Params
::
block
*
Params
::
frames_per_bit
;
const
int
block_start
=
block
*
Params
::
block
_size
*
Params
::
frames_per_bit
;
for
(
int
f
=
0
;
f
<
Params
::
block
*
Params
::
frames_per_bit
;
f
++
)
for
(
int
f
=
0
;
f
<
Params
::
block
_size
*
Params
::
frames_per_bit
;
f
++
)
{
{
for
(
int
ch
=
0
;
ch
<
wav_data
.
n_channels
();
ch
++
)
for
(
int
ch
=
0
;
ch
<
wav_data
.
n_channels
();
ch
++
)
{
{
...
@@ -608,7 +614,7 @@ void
...
@@ -608,7 +614,7 @@ void
truncate_to_block_size
(
WavData
&
wav_data
)
truncate_to_block_size
(
WavData
&
wav_data
)
{
{
vector
<
float
>
in_signal
(
wav_data
.
samples
());
vector
<
float
>
in_signal
(
wav_data
.
samples
());
while
(
in_signal
.
size
()
%
(
wav_data
.
n_channels
()
*
Params
::
frame_size
*
Params
::
block
*
Params
::
frames_per_bit
))
while
(
in_signal
.
size
()
%
(
wav_data
.
n_channels
()
*
Params
::
frame_size
*
Params
::
block
_size
*
Params
::
frames_per_bit
))
in_signal
.
pop_back
();
in_signal
.
pop_back
();
wav_data
.
set_samples
(
in_signal
);
wav_data
.
set_samples
(
in_signal
);
...
@@ -631,12 +637,12 @@ get_watermark (const string& infile, const string& orig_pattern)
...
@@ -631,12 +637,12 @@ get_watermark (const string& infile, const string& orig_pattern)
vector
<
vector
<
complex
<
float
>>>
fft_out
=
compute_frame_ffts
(
wav_data
);
vector
<
vector
<
complex
<
float
>>>
fft_out
=
compute_frame_ffts
(
wav_data
);
if
(
Params
::
mix
)
if
(
Params
::
mix
)
{
{
for
(
int
block
=
0
;
block
<
frame_count
(
wav_data
)
/
(
Params
::
block
*
Params
::
frames_per_bit
);
block
++
)
for
(
int
block
=
0
;
block
<
block_count
(
wav_data
);
block
++
)
{
{
vector
<
MixEntry
>
mix_entries
=
gen_mix_entries
(
block
);
vector
<
MixEntry
>
mix_entries
=
gen_mix_entries
(
block
);
double
umag
=
0
,
dmag
=
0
;
double
umag
=
0
,
dmag
=
0
;
for
(
int
f
=
0
;
f
<
Params
::
block
*
Params
::
frames_per_bit
;
f
++
)
for
(
int
f
=
0
;
f
<
Params
::
block
_size
*
Params
::
frames_per_bit
;
f
++
)
{
{
for
(
int
ch
=
0
;
ch
<
wav_data
.
n_channels
();
ch
++
)
for
(
int
ch
=
0
;
ch
<
wav_data
.
n_channels
();
ch
++
)
{
{
...
@@ -645,7 +651,7 @@ get_watermark (const string& infile, const string& orig_pattern)
...
@@ -645,7 +651,7 @@ get_watermark (const string& infile, const string& orig_pattern)
int
b
=
f
*
Params
::
bands_per_frame
+
frame_b
;
int
b
=
f
*
Params
::
bands_per_frame
+
frame_b
;
const
double
min_db
=
-
96
;
const
double
min_db
=
-
96
;
const
int
index
=
(
block
*
(
Params
::
block
*
Params
::
frames_per_bit
)
+
mix_entries
[
b
].
frame
)
*
wav_data
.
n_channels
()
+
ch
;
const
int
index
=
(
block
*
(
Params
::
block
_size
*
Params
::
frames_per_bit
)
+
mix_entries
[
b
].
frame
)
*
wav_data
.
n_channels
()
+
ch
;
const
int
u
=
mix_entries
[
b
].
up
;
const
int
u
=
mix_entries
[
b
].
up
;
{
{
umag
+=
db_from_factor
(
abs
(
fft_out
[
index
][
u
]),
min_db
);
umag
+=
db_from_factor
(
abs
(
fft_out
[
index
][
u
]),
min_db
);
...
@@ -739,12 +745,12 @@ get_watermark_delta (const string& origfile, const string& infile, const string&
...
@@ -739,12 +745,12 @@ get_watermark_delta (const string& origfile, const string& infile, const string&
vector
<
vector
<
complex
<
float
>>>
fft_out
=
compute_frame_ffts
(
wav_data
);
vector
<
vector
<
complex
<
float
>>>
fft_out
=
compute_frame_ffts
(
wav_data
);
vector
<
vector
<
complex
<
float
>>>
fft_orig_out
=
compute_frame_ffts
(
orig_wav_data
);
vector
<
vector
<
complex
<
float
>>>
fft_orig_out
=
compute_frame_ffts
(
orig_wav_data
);
for
(
int
block
=
0
;
block
<
frame_count
(
wav_data
)
/
(
Params
::
block
*
Params
::
frames_per_bit
);
block
++
)
for
(
int
block
=
0
;
block
<
block_count
(
wav_data
);
block
++
)
{
{
vector
<
MixEntry
>
mix_entries
=
gen_mix_entries
(
block
);
vector
<
MixEntry
>
mix_entries
=
gen_mix_entries
(
block
);
double
umag
=
0
,
dmag
=
0
;
double
umag
=
0
,
dmag
=
0
;
for
(
int
f
=
0
;
f
<
Params
::
block
*
Params
::
frames_per_bit
;
f
++
)
for
(
int
f
=
0
;
f
<
Params
::
block
_size
*
Params
::
frames_per_bit
;
f
++
)
{
{
for
(
int
ch
=
0
;
ch
<
wav_data
.
n_channels
();
ch
++
)
for
(
int
ch
=
0
;
ch
<
wav_data
.
n_channels
();
ch
++
)
{
{
...
@@ -753,7 +759,7 @@ get_watermark_delta (const string& origfile, const string& infile, const string&
...
@@ -753,7 +759,7 @@ get_watermark_delta (const string& origfile, const string& infile, const string&
int
b
=
f
*
Params
::
bands_per_frame
+
frame_b
;
int
b
=
f
*
Params
::
bands_per_frame
+
frame_b
;
const
double
min_db
=
-
96
;
const
double
min_db
=
-
96
;
const
int
index
=
(
block
*
(
Params
::
block
*
Params
::
frames_per_bit
)
+
mix_entries
[
b
].
frame
)
*
wav_data
.
n_channels
()
+
ch
;
const
int
index
=
(
block
*
(
Params
::
block
_size
*
Params
::
frames_per_bit
)
+
mix_entries
[
b
].
frame
)
*
wav_data
.
n_channels
()
+
ch
;
const
int
u
=
mix_entries
[
b
].
up
;
const
int
u
=
mix_entries
[
b
].
up
;
{
{
umag
+=
db_from_factor
(
abs
(
fft_out
[
index
][
u
]),
min_db
);
umag
+=
db_from_factor
(
abs
(
fft_out
[
index
][
u
]),
min_db
);
...
...
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