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
3b86c8af
Commit
3b86c8af
authored
Dec 13, 2018
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Share synth window code between linear/mix watermark generation.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
40019adf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
49 deletions
+39
-49
audiowmark.cc
src/audiowmark.cc
+39
-49
No files found.
src/audiowmark.cc
View file @
3b86c8af
...
...
@@ -18,16 +18,16 @@ using std::min;
namespace
Params
{
static
size_t
frame_size
=
1024
;
static
int
frames_per_bit
=
4
;
static
in
t
bands_per_frame
=
30
;
static
int
max_band
=
100
;
static
int
min_band
=
20
;
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
bool
mix
=
true
;
static
int
block
=
32
;
// block size for mix step (non-linear bit storage)
static
unsigned
int
seed
=
0
;
static
size_t
frame_size
=
1024
;
static
int
frames_per_bit
=
4
;
static
size_
t
bands_per_frame
=
30
;
static
int
max_band
=
100
;
static
int
min_band
=
20
;
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
bool
mix
=
true
;
static
int
block
=
32
;
// block size for mix step (non-linear bit storage)
static
unsigned
int
seed
=
0
;
}
void
...
...
@@ -325,6 +325,28 @@ bit_vec_to_str (const vector<int>& bit_vec)
return
bit_str
;
}
void
watermark_mix2frame
(
vector
<
float
>&
frame
,
vector
<
complex
<
float
>>&
fft_delta_spect
)
{
/* mix watermark signal to output frame */
vector
<
float
>
fft_delta_out
=
ifft
(
fft_delta_spect
);
vector
<
float
>
synth_window
(
Params
::
frame_size
);
for
(
size_t
i
=
0
;
i
<
Params
::
frame_size
;
i
++
)
{
const
double
threshold
=
0.2
;
// triangular basic window
const
double
tri
=
min
(
1.0
-
fabs
(
double
(
2
*
i
)
/
Params
::
frame_size
-
1.0
),
threshold
)
/
threshold
;
// cosine
synth_window
[
i
]
=
(
cos
(
tri
*
M_PI
+
M_PI
)
+
1
)
*
0.5
;
}
for
(
size_t
i
=
0
;
i
<
frame
.
size
();
i
++
)
frame
[
i
]
+=
fft_delta_out
[
i
]
*
synth_window
[
i
];
}
vector
<
float
>
watermark_frame
(
const
vector
<
float
>&
input_frame
,
int
f
,
int
data_bit
)
{
...
...
@@ -379,24 +401,8 @@ watermark_frame (const vector<float>& input_frame, int f, int data_bit)
fft_delta_spect
[
d
]
=
fft_out
[
d
]
*
(
mag_factor
-
1
);
}
/* add watermark to output frame */
vector
<
float
>
fft_delta_out
=
ifft
(
fft_delta_spect
);
vector
<
float
>
synth_window
(
Params
::
frame_size
);
for
(
size_t
i
=
0
;
i
<
Params
::
frame_size
;
i
++
)
{
const
double
threshold
=
0.2
;
// triangular basic window
const
double
tri
=
min
(
1.0
-
fabs
(
double
(
2
*
i
)
/
Params
::
frame_size
-
1.0
),
threshold
)
/
threshold
;
// cosine
synth_window
[
i
]
=
(
cos
(
tri
*
M_PI
+
M_PI
)
+
1
)
*
0.5
;
}
vector
<
float
>
new_frame
=
input_frame
;
for
(
size_t
i
=
0
;
i
<
frame
.
size
();
i
++
)
new_frame
[
i
]
+=
fft_delta_out
[
i
]
*
synth_window
[
i
];
watermark_mix2frame
(
new_frame
,
fft_delta_spect
);
return
new_frame
;
}
...
...
@@ -499,7 +505,7 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
{
for
(
int
ch
=
0
;
ch
<
wav_data
.
n_channels
();
ch
++
)
{
for
(
in
t
frame_b
=
0
;
frame_b
<
Params
::
bands_per_frame
;
frame_b
++
)
for
(
size_
t
frame_b
=
0
;
frame_b
<
Params
::
bands_per_frame
;
frame_b
++
)
{
int
b
=
f
*
Params
::
bands_per_frame
+
frame_b
;
...
...
@@ -529,28 +535,12 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
for
(
int
ch
=
0
;
ch
<
wav_data
.
n_channels
();
ch
++
)
{
/* add watermark to output frame */
vector
<
float
>
fft_delta_out
=
ifft
(
fft_delta_spect
[
f
*
wav_data
.
n_channels
()
+
ch
]);
vector
<
float
>
input_frame
=
get_frame
(
wav_data
,
f
,
ch
);
vector
<
float
>
synth_window
(
Params
::
frame_size
);
for
(
size_t
i
=
0
;
i
<
Params
::
frame_size
;
i
++
)
{
const
double
threshold
=
0.2
;
// triangular basic window
const
double
tri
=
min
(
1.0
-
fabs
(
double
(
2
*
i
)
/
Params
::
frame_size
-
1.0
),
threshold
)
/
threshold
;
// cosine
synth_window
[
i
]
=
(
cos
(
tri
*
M_PI
+
M_PI
)
+
1
)
*
0.5
;
}
vector
<
float
>
new_frame
=
input_frame
;
for
(
size_t
i
=
0
;
i
<
new_frame
.
size
();
i
++
)
new_frame
[
i
]
+=
fft_delta_out
[
i
]
*
synth_window
[
i
];
vector
<
float
>
frame
=
get_frame
(
wav_data
,
f
,
ch
);
watermark_mix2frame
(
frame
,
fft_delta_spect
[
f
*
wav_data
.
n_channels
()
+
ch
]);
/* modify out signal */
for
(
size_t
i
=
0
;
i
<
new_
frame
.
size
();
i
++
)
out_signal
[(
f
*
Params
::
frame_size
+
i
)
*
wav_data
.
n_channels
()
+
ch
]
=
new_
frame
[
i
]
*
Params
::
pre_scale
;
for
(
size_t
i
=
0
;
i
<
frame
.
size
();
i
++
)
out_signal
[(
f
*
Params
::
frame_size
+
i
)
*
wav_data
.
n_channels
()
+
ch
]
=
frame
[
i
]
*
Params
::
pre_scale
;
}
}
}
...
...
@@ -656,7 +646,7 @@ get_watermark (const string& infile, const string& orig_pattern)
{
for
(
int
ch
=
0
;
ch
<
wav_data
.
n_channels
();
ch
++
)
{
for
(
in
t
frame_b
=
0
;
frame_b
<
Params
::
bands_per_frame
;
frame_b
++
)
for
(
size_
t
frame_b
=
0
;
frame_b
<
Params
::
bands_per_frame
;
frame_b
++
)
{
int
b
=
f
*
Params
::
bands_per_frame
+
frame_b
;
const
double
min_db
=
-
96
;
...
...
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