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
2df880aa
Commit
2df880aa
authored
Dec 14, 2018
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify linear watermark generation.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
356b2c06
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
67 deletions
+34
-67
audiowmark.cc
src/audiowmark.cc
+34
-67
No files found.
src/audiowmark.cc
View file @
2df880aa
...
@@ -353,63 +353,6 @@ watermark_mix2frame (vector<float>& frame, vector<complex<float>>& fft_delta_spe
...
@@ -353,63 +353,6 @@ watermark_mix2frame (vector<float>& frame, vector<complex<float>>& fft_delta_spe
frame
[
i
]
+=
fft_delta_out
[
i
]
*
synth_window
[
i
];
frame
[
i
]
+=
fft_delta_out
[
i
]
*
synth_window
[
i
];
}
}
vector
<
complex
<
float
>>
watermark_frame
(
const
vector
<
float
>&
input_frame
,
int
f
,
int
data_bit
)
{
vector
<
float
>
frame
=
input_frame
;
/* windowing */
double
window_weight
=
0
;
for
(
size_t
i
=
0
;
i
<
frame
.
size
();
i
++
)
{
const
double
fsize_2
=
frame
.
size
()
/
2.0
;
// const double win = window_cos ((i - fsize_2) / fsize_2);
const
double
win
=
window_hamming
((
i
-
fsize_2
)
/
fsize_2
);
//const double win = 1;
frame
[
i
]
*=
win
;
window_weight
+=
win
;
}
/* to get normalized fft output corrected by window weight */
for
(
size_t
i
=
0
;
i
<
frame
.
size
();
i
++
)
frame
[
i
]
*=
2.0
/
window_weight
;
/* FFT transform */
vector
<
complex
<
float
>>
fft_out
=
fft
(
frame
);
vector
<
complex
<
float
>>
fft_delta_spect
(
fft_out
.
size
());
vector
<
int
>
up
;
vector
<
int
>
down
;
get_up_down
(
f
,
up
,
down
);
const
double
data_bit_sign
=
data_bit
>
0
?
1
:
-
1
;
for
(
auto
u
:
up
)
{
/*
* for up bands, we want do use [for a 1 bit] (pow (mag, 1 - water_delta))
*
* this actually increases the amount of energy because mag is less than 1.0
*/
const
float
mag_factor
=
pow
(
abs
(
fft_out
[
u
]),
-
Params
::
water_delta
*
data_bit_sign
);
fft_delta_spect
[
u
]
=
fft_out
[
u
]
*
(
mag_factor
-
1
);
}
for
(
auto
d
:
down
)
{
/*
* for down bands, we want do use [for a 1 bit] (pow (mag, 1 + water_delta))
*
* this actually decreases the amount of energy because mag is less than 1.0
*/
const
float
mag_factor
=
pow
(
abs
(
fft_out
[
d
]),
Params
::
water_delta
*
data_bit_sign
);
fft_delta_spect
[
d
]
=
fft_out
[
d
]
*
(
mag_factor
-
1
);
}
return
fft_delta_spect
;
}
struct
MixEntry
struct
MixEntry
{
{
int
frame
;
int
frame
;
...
@@ -505,9 +448,6 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
...
@@ -505,9 +448,6 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
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_delta_spect
;
vector
<
vector
<
complex
<
float
>>>
fft_delta_spect
;
if
(
Params
::
mix
)
{
for
(
int
f
=
0
;
f
<
frame_count
(
wav_data
);
f
++
)
for
(
int
f
=
0
;
f
<
frame_count
(
wav_data
);
f
++
)
{
{
for
(
int
ch
=
0
;
ch
<
wav_data
.
n_channels
();
ch
++
)
for
(
int
ch
=
0
;
ch
<
wav_data
.
n_channels
();
ch
++
)
...
@@ -515,6 +455,8 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
...
@@ -515,6 +455,8 @@ 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
()));
}
}
}
}
if
(
Params
::
mix
)
{
for
(
int
block
=
0
;
block
<
block_count
(
wav_data
);
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
);
...
@@ -556,11 +498,36 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
...
@@ -556,11 +498,36 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
{
{
for
(
int
ch
=
0
;
ch
<
wav_data
.
n_channels
();
ch
++
)
for
(
int
ch
=
0
;
ch
<
wav_data
.
n_channels
();
ch
++
)
{
{
vector
<
float
>
frame
=
get_frame
(
wav_data
,
f
,
ch
);
size_t
index
=
f
*
wav_data
.
n_channels
()
+
ch
;
vector
<
int
>
up
;
vector
<
int
>
down
;
get_up_down
(
f
,
up
,
down
);
const
int
data_bit
=
bitvec
[(
f
/
Params
::
frames_per_bit
)
%
bitvec
.
size
()];
const
int
data_bit
=
bitvec
[(
f
/
Params
::
frames_per_bit
)
%
bitvec
.
size
()];
const
double
data_bit_sign
=
data_bit
>
0
?
1
:
-
1
;
for
(
auto
u
:
up
)
{
/*
* for up bands, we want do use [for a 1 bit] (pow (mag, 1 - water_delta))
*
* this actually increases the amount of energy because mag is less than 1.0
*/
const
float
mag_factor
=
pow
(
abs
(
fft_out
[
index
][
u
]),
-
Params
::
water_delta
*
data_bit_sign
);
fft_delta_spect
.
push_back
(
watermark_frame
(
frame
,
f
,
data_bit
));
fft_delta_spect
[
index
][
u
]
=
fft_out
[
index
][
u
]
*
(
mag_factor
-
1
);
}
for
(
auto
d
:
down
)
{
/*
* for down bands, we want do use [for a 1 bit] (pow (mag, 1 + water_delta))
*
* this actually decreases the amount of energy because mag is less than 1.0
*/
const
float
mag_factor
=
pow
(
abs
(
fft_out
[
index
][
d
]),
Params
::
water_delta
*
data_bit_sign
);
fft_delta_spect
[
index
][
d
]
=
fft_out
[
index
][
d
]
*
(
mag_factor
-
1
);
}
}
}
}
}
}
}
...
...
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