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
d38bea12
Commit
d38bea12
authored
Jan 15, 2024
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor speed detection API to use a key list instead of a single key.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
938befd7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
31 deletions
+59
-31
wmget.cc
src/wmget.cc
+34
-30
wmspeed.cc
src/wmspeed.cc
+18
-0
wmspeed.hh
src/wmspeed.hh
+7
-1
No files found.
src/wmget.cc
View file @
d38bea12
...
@@ -634,41 +634,45 @@ static int
...
@@ -634,41 +634,45 @@ static int
decode_and_report
(
const
vector
<
Key
>&
key_list
,
const
WavData
&
wav_data
,
const
vector
<
int
>&
orig_bits
)
decode_and_report
(
const
vector
<
Key
>&
key_list
,
const
WavData
&
wav_data
,
const
vector
<
int
>&
orig_bits
)
{
{
ResultSet
result_set
;
ResultSet
result_set
;
double
speed
=
1.0
;
for
(
auto
key
:
key_list
)
/*
* The strategy for integrating speed detection into decoding is this:
* - we always (unconditionally) try to decode the watermark on the original wav data
* - if detected speed is somewhat different than 1.0, we also try to decode stretched data
* - we report all normal and speed results we get
*
* The reason to do it this way is that the detected speed may be wrong (on short clips)
* and we don't want to loose a successful clip decoder match in this case.
*/
if
(
Params
::
detect_speed
||
Params
::
detect_speed_patient
||
Params
::
try_speed
>
0
)
{
{
/*
vector
<
DetectSpeedResult
>
speed_results
;
* The strategy for integrating speed detection into decoding is this:
if
(
Params
::
detect_speed
||
Params
::
detect_speed_patient
)
* - we always (unconditionally) try to decode the watermark on the original wav data
speed_results
=
detect_speed
(
key_list
,
wav_data
,
!
orig_bits
.
empty
());
* - if detected speed is somewhat different than 1.0, we also try to decode stretched data
else
* - we report all normal and speed results we get
*
* The reason to do it this way is that the detected speed may be wrong (on short clips)
* and we don't want to loose a successful clip decoder match in this case.
*/
if
(
Params
::
detect_speed
||
Params
::
detect_speed_patient
||
Params
::
try_speed
>
0
)
{
{
if
(
Params
::
detect_speed
||
Params
::
detect_speed_patient
)
for
(
const
auto
&
key
:
key_list
)
speed
=
detect_speed
(
key
,
wav_data
,
!
orig_bits
.
empty
());
else
speed
=
Params
::
try_speed
;
// speeds closer to 1.0 than this usually work without stretching before decode
if
(
speed
<
0.9999
||
speed
>
1.0001
)
{
{
if
(
Params
::
json_output
!=
"-"
)
DetectSpeedResult
speed_result
;
printf
(
"speed %.6f
\n
"
,
speed
);
speed_result
.
key
=
key
;
WavData
wav_data_speed
=
resample
(
wav_data
,
Params
::
mark_sample_rate
*
speed
);
speed_result
.
speed
=
Params
::
try_speed
;
speed_results
.
push_back
(
speed_result
);
}
}
result_set
.
set_speed_pattern
(
true
);
for
(
const
auto
&
speed_result
:
speed_results
)
BlockDecoder
block_decoder
;
{
block_decoder
.
run
({
key
},
wav_data_speed
,
result_set
);
if
(
Params
::
json_output
!=
"-"
)
printf
(
"speed %.6f
\n
"
,
speed_result
.
speed
);
WavData
wav_data_speed
=
resample
(
wav_data
,
Params
::
mark_sample_rate
*
speed_result
.
speed
);
ClipDecoder
clip_decoder
;
result_set
.
set_speed_pattern
(
true
);
clip_decoder
.
run
({
key
},
wav_data_speed
,
result_set
);
BlockDecoder
block_decoder
;
result_set
.
set_speed_pattern
(
false
);
block_decoder
.
run
({
speed_result
.
key
},
wav_data_speed
,
result_set
);
}
ClipDecoder
clip_decoder
;
clip_decoder
.
run
({
speed_result
.
key
},
wav_data_speed
,
result_set
);
result_set
.
set_speed_pattern
(
false
);
}
}
}
}
...
@@ -681,7 +685,7 @@ decode_and_report (const vector<Key>& key_list, const WavData& wav_data, const v
...
@@ -681,7 +685,7 @@ decode_and_report (const vector<Key>& key_list, const WavData& wav_data, const v
result_set
.
sort_by_time
();
result_set
.
sort_by_time
();
if
(
!
Params
::
json_output
.
empty
())
if
(
!
Params
::
json_output
.
empty
())
result_set
.
print_json
(
wav_data
,
Params
::
json_output
,
speed
);
result_set
.
print_json
(
wav_data
,
Params
::
json_output
,
42
/*FIXME */
);
if
(
Params
::
json_output
!=
"-"
)
if
(
Params
::
json_output
!=
"-"
)
result_set
.
print
();
result_set
.
print
();
...
...
src/wmspeed.cc
View file @
d38bea12
...
@@ -730,3 +730,21 @@ detect_speed (const Key& key, const WavData& in_data, bool print_results)
...
@@ -730,3 +730,21 @@ detect_speed (const Key& key, const WavData& in_data, bool print_results)
else
else
return
1
;
return
1
;
}
}
vector
<
DetectSpeedResult
>
detect_speed
(
const
vector
<
Key
>&
key_list
,
const
WavData
&
in_data
,
bool
print_results
)
{
vector
<
DetectSpeedResult
>
results
;
for
(
const
auto
&
key
:
key_list
)
{
DetectSpeedResult
speed_result
;
speed_result
.
key
=
key
;
speed_result
.
speed
=
detect_speed
(
key
,
in_data
,
print_results
);
// speeds closer to 1.0 than this usually work without stretching before decode
if
(
speed_result
.
speed
<
0.9999
||
speed_result
.
speed
>
1.0001
)
results
.
push_back
(
speed_result
);
}
return
results
;
}
src/wmspeed.hh
View file @
d38bea12
...
@@ -21,6 +21,12 @@
...
@@ -21,6 +21,12 @@
#include "wavdata.hh"
#include "wavdata.hh"
#include "random.hh"
#include "random.hh"
double
detect_speed
(
const
Key
&
key
,
const
WavData
&
in_data
,
bool
print_results
);
struct
DetectSpeedResult
{
Key
key
;
double
speed
=
0
;
};
std
::
vector
<
DetectSpeedResult
>
detect_speed
(
const
std
::
vector
<
Key
>&
key_list
,
const
WavData
&
in_data
,
bool
print_results
);
#endif
/* AUDIOWMARK_WM_SPEED_HH */
#endif
/* AUDIOWMARK_WM_SPEED_HH */
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