Commit d38bea12 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Refactor speed detection API to use a key list instead of a single key.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 938befd7
......@@ -634,41 +634,45 @@ static int
decode_and_report (const vector<Key>& key_list, const WavData& wav_data, const vector<int>& orig_bits)
{
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)
{
/*
* 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;
if (Params::detect_speed || Params::detect_speed_patient)
speed_results = detect_speed (key_list, wav_data, !orig_bits.empty());
else
{
if (Params::detect_speed || Params::detect_speed_patient)
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)
for (const auto& key : key_list)
{
if (Params::json_output != "-")
printf ("speed %.6f\n", speed);
WavData wav_data_speed = resample (wav_data, Params::mark_sample_rate * speed);
DetectSpeedResult speed_result;
speed_result.key = key;
speed_result.speed = Params::try_speed;
speed_results.push_back (speed_result);
}
}
result_set.set_speed_pattern (true);
BlockDecoder block_decoder;
block_decoder.run ({ key }, wav_data_speed, result_set);
for (const auto& speed_result : speed_results)
{
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;
clip_decoder.run ({ key }, wav_data_speed, result_set);
result_set.set_speed_pattern (false);
}
result_set.set_speed_pattern (true);
BlockDecoder block_decoder;
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
result_set.sort_by_time();
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 != "-")
result_set.print();
......
......@@ -730,3 +730,21 @@ detect_speed (const Key& key, const WavData& in_data, bool print_results)
else
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;
}
......@@ -21,6 +21,12 @@
#include "wavdata.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 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment