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
a018405e
Commit
a018405e
authored
Jan 12, 2019
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add error handling if compute_frame_ffts runs out of space.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
8e0cec5b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
36 deletions
+32
-36
audiowmark.cc
src/audiowmark.cc
+32
-36
No files found.
src/audiowmark.cc
View file @
a018405e
...
@@ -307,10 +307,12 @@ gen_mix_entries (int block)
...
@@ -307,10 +307,12 @@ gen_mix_entries (int block)
vector
<
vector
<
complex
<
float
>>>
vector
<
vector
<
complex
<
float
>>>
compute_frame_ffts
(
const
WavData
&
wav_data
,
size_t
start_index
,
size_t
frame_count
)
compute_frame_ffts
(
const
WavData
&
wav_data
,
size_t
start_index
,
size_t
frame_count
)
{
{
assert
(
wav_data
.
n_values
()
>=
(
start_index
+
frame_count
*
Params
::
frame_size
)
*
wav_data
.
n_channels
());
vector
<
vector
<
complex
<
float
>>>
fft_out
;
vector
<
vector
<
complex
<
float
>>>
fft_out
;
/* if there is not enough space for frame_count values, return an error (empty vector) */
if
(
wav_data
.
n_values
()
<
(
start_index
+
frame_count
*
Params
::
frame_size
)
*
wav_data
.
n_channels
())
return
fft_out
;
/* generate analysis window */
/* generate analysis window */
vector
<
float
>
window
(
Params
::
frame_size
);
vector
<
float
>
window
(
Params
::
frame_size
);
...
@@ -939,9 +941,6 @@ public:
...
@@ -939,9 +941,6 @@ public:
vector
<
vector
<
float
>>
vector
<
vector
<
float
>>
sync_fft
(
const
WavData
&
wav_data
,
size_t
index
,
size_t
count
)
sync_fft
(
const
WavData
&
wav_data
,
size_t
index
,
size_t
count
)
{
{
if
(
wav_data
.
n_values
()
<
(
index
+
count
*
Params
::
frame_size
)
*
wav_data
.
n_channels
())
return
{};
/* computing db-magnitude is expensive, so we better do it here */
/* computing db-magnitude is expensive, so we better do it here */
vector
<
vector
<
float
>>
fft_out_db
;
vector
<
vector
<
float
>>
fft_out_db
;
for
(
const
vector
<
complex
<
float
>>&
spect
:
compute_frame_ffts
(
wav_data
,
index
,
count
))
for
(
const
vector
<
complex
<
float
>>&
spect
:
compute_frame_ffts
(
wav_data
,
index
,
count
))
...
@@ -991,45 +990,42 @@ decode_and_report (const WavData& wav_data, const string& orig_pattern)
...
@@ -991,45 +990,42 @@ decode_and_report (const WavData& wav_data, const string& orig_pattern)
const
size_t
index
=
pos
+
(
mark_sync_frame_count
()
*
Params
::
frame_size
);
const
size_t
index
=
pos
+
(
mark_sync_frame_count
()
*
Params
::
frame_size
);
auto
fft_range_out
=
compute_frame_ffts
(
wav_data
,
index
,
count
);
auto
fft_range_out
=
compute_frame_ffts
(
wav_data
,
index
,
count
);
if
(
fft_range_out
.
size
())
{
vector
<
vector
<
complex
<
float
>>>
junk
;
vector
<
vector
<
complex
<
float
>>>
junk
;
vector
<
float
>
soft_bit_vec
;
if
(
Params
::
mix
)
{
soft_bit_vec
=
mix_decode
(
fft_range_out
,
junk
,
wav_data
.
n_channels
());
}
else
{
soft_bit_vec
=
linear_decode
(
fft_range_out
,
junk
,
wav_data
.
n_channels
());
}
vector
<
float
>
soft_bit_vec
;
/* truncate to the required length */
if
(
Params
::
mix
)
assert
(
soft_bit_vec
.
size
()
>=
conv_code_size
(
Params
::
payload_size
));
{
soft_bit_vec
.
resize
(
conv_code_size
(
Params
::
payload_size
));
soft_bit_vec
=
mix_decode
(
fft_range_out
,
junk
,
wav_data
.
n_channels
());
}
else
{
soft_bit_vec
=
linear_decode
(
fft_range_out
,
junk
,
wav_data
.
n_channels
());
}
if
(
soft_bit_vec
.
size
()
<
conv_code_size
(
Params
::
payload_size
))
{
fprintf
(
stderr
,
"audiowmark: input file too short to retrieve watermark
\n
"
);
fprintf
(
stderr
,
" - number of recovered raw bits %zd
\n
"
,
soft_bit_vec
.
size
());
fprintf
(
stderr
,
" - need at least %zd raw bits to get watermark
\n
"
,
conv_code_size
(
Params
::
payload_size
));
return
1
;
}
/* truncate to the required length */
soft_bit_vec
.
resize
(
conv_code_size
(
Params
::
payload_size
));
vector
<
int
>
bit_vec
=
conv_decode_soft
(
randomize_bit_order
(
soft_bit_vec
,
/* encode */
false
));
vector
<
int
>
bit_vec
=
conv_decode_soft
(
randomize_bit_order
(
soft_bit_vec
,
/* encode */
false
));
const
int
seconds
=
lrint
(
pos
/
wav_data
.
mix_freq
());
const
int
seconds
=
lrint
(
pos
/
wav_data
.
mix_freq
());
printf
(
"pattern %2d:%02d %s
\n
"
,
seconds
/
60
,
seconds
%
60
,
bit_vec_to_str
(
bit_vec
).
c_str
());
printf
(
"pattern %2d:%02d %s
\n
"
,
seconds
/
60
,
seconds
%
60
,
bit_vec_to_str
(
bit_vec
).
c_str
());
if
(
!
orig_pattern
.
empty
())
if
(
!
orig_pattern
.
empty
())
{
{
bool
match
=
true
;
bool
match
=
true
;
vector
<
int
>
orig_vec
=
bit_str_to_vec
(
orig_pattern
);
vector
<
int
>
orig_vec
=
bit_str_to_vec
(
orig_pattern
);
for
(
size_t
i
=
0
;
i
<
bit_vec
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
bit_vec
.
size
();
i
++
)
match
=
match
&&
(
bit_vec
[
i
]
==
orig_vec
[
i
%
orig_vec
.
size
()]);
match
=
match
&&
(
bit_vec
[
i
]
==
orig_vec
[
i
%
orig_vec
.
size
()]);
if
(
match
)
if
(
match
)
match_count
++
;
match_count
++
;
}
total_count
++
;
}
}
total_count
++
;
}
}
if
(
!
orig_pattern
.
empty
())
if
(
!
orig_pattern
.
empty
())
...
...
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