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,10 +634,7 @@ 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
......@@ -649,28 +646,35 @@ decode_and_report (const vector<Key>& key_list, const WavData& wav_data, const v
*/
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 = detect_speed (key, wav_data, !orig_bits.empty());
speed_results = detect_speed (key_list, wav_data, !orig_bits.empty());
else
speed = Params::try_speed;
{
for (const auto& key : key_list)
{
DetectSpeedResult speed_result;
speed_result.key = key;
speed_result.speed = Params::try_speed;
speed_results.push_back (speed_result);
}
}
// speeds closer to 1.0 than this usually work without stretching before decode
if (speed < 0.9999 || speed > 1.0001)
for (const auto& speed_result : speed_results)
{
if (Params::json_output != "-")
printf ("speed %.6f\n", speed);
WavData wav_data_speed = resample (wav_data, Params::mark_sample_rate * speed);
printf ("speed %.6f\n", speed_result.speed);
WavData wav_data_speed = resample (wav_data, Params::mark_sample_rate * speed_result.speed);
result_set.set_speed_pattern (true);
BlockDecoder block_decoder;
block_decoder.run ({ key }, wav_data_speed, result_set);
block_decoder.run ({ speed_result.key }, wav_data_speed, result_set);
ClipDecoder clip_decoder;
clip_decoder.run ({ key }, wav_data_speed, result_set);
clip_decoder.run ({ speed_result.key }, wav_data_speed, result_set);
result_set.set_speed_pattern (false);
}
}
}
BlockDecoder block_decoder;
block_decoder.run (key_list, wav_data, result_set);
......@@ -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