Commit d5936d8b authored by Stefan Westerfeld's avatar Stefan Westerfeld

Add --detect-speed-slow option for cpu intensive but more reliable search.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent b117b808
...@@ -592,6 +592,10 @@ parse_get_options (ArgParser& ap) ...@@ -592,6 +592,10 @@ parse_get_options (ArgParser& ap)
{ {
Params::detect_speed = true; Params::detect_speed = true;
} }
if (ap.parse_opt ("--detect-speed-slow"))
{
Params::detect_speed_slow = true;
}
if (ap.parse_opt ("--detect-speed-hint", f)) if (ap.parse_opt ("--detect-speed-hint", f))
{ {
Params::detect_speed_hint = f; Params::detect_speed_hint = f;
......
...@@ -26,6 +26,7 @@ bool Params::mix = true; ...@@ -26,6 +26,7 @@ bool Params::mix = true;
bool Params::hard = false; // hard decode bits? (soft decoding is better) bool Params::hard = false; // hard decode bits? (soft decoding is better)
bool Params::snr = false; // compute/show snr while adding watermark bool Params::snr = false; // compute/show snr while adding watermark
bool Params::detect_speed = false; bool Params::detect_speed = false;
bool Params::detect_speed_slow = false;
double Params::detect_speed_hint = -1; double Params::detect_speed_hint = -1;
int Params::have_key = 0; int Params::have_key = 0;
size_t Params::payload_size = 128; size_t Params::payload_size = 128;
......
...@@ -44,6 +44,7 @@ public: ...@@ -44,6 +44,7 @@ public:
static int have_key; static int have_key;
static bool detect_speed; static bool detect_speed;
static bool detect_speed_slow;
static double detect_speed_hint; // for debugging --detect-speed static double detect_speed_hint; // for debugging --detect-speed
static size_t payload_size; // number of payload bits for the watermark static size_t payload_size; // number of payload bits for the watermark
......
...@@ -1201,26 +1201,31 @@ decode_and_report (const WavData& in_data, const string& orig_pattern) ...@@ -1201,26 +1201,31 @@ decode_and_report (const WavData& in_data, const string& orig_pattern)
{ {
WavData wav_data; WavData wav_data;
if (Params::detect_speed) if (Params::detect_speed || Params::detect_speed_slow)
{ {
double speed; double speed;
/* first pass: find approximation for speed */ if (Params::detect_speed_slow) /* SLOW */
speed = speed_scan (in_data); {
/* first pass: find approximation for speed */
/* SLOW */ speed = detect_speed (in_data, 1.0, 1.001, /* steps */ 200, /* seconds */ 15, nullptr);
// speed = detect_speed (in_data, 1.0, 1.001, /* steps */ 200, /* seconds */ 15);
/* second pass: fast refine (not always perfect) */ /* second pass: refine speed */
SpeedSync speed_sync; speed = detect_speed (in_data, speed, 1.00005, /* steps */ 20, /* seconds */ 50, nullptr);
auto scores = speed_sync.search (in_data, speed, 1.00005, 20, /* seconds */ 50); }
sort (scores.begin(), scores.end(), [] (SpeedSync::Score s_a, SpeedSync::Score s_b) { return s_a.quality > s_b.quality; }); else /* better performance, less accurate */
if (!scores.empty()) {
speed = scores[0].speed; /* first pass: find approximation for speed */
printf ("## speed refined %f\n", speed); speed = speed_scan (in_data);
/* second pass: fast refine (not always perfect) */
SpeedSync speed_sync;
auto scores = speed_sync.search (in_data, speed, 1.00005, 20, /* seconds */ 50);
sort (scores.begin(), scores.end(), [] (SpeedSync::Score s_a, SpeedSync::Score s_b) { return s_a.quality > s_b.quality; });
if (!scores.empty())
speed = scores[0].speed;
}
printf ("## delta %.5f %%\n", 100 * fabs (speed - Params::detect_speed_hint) / Params::detect_speed_hint); printf ("## delta %.5f %%\n", 100 * fabs (speed - Params::detect_speed_hint) / Params::detect_speed_hint);
printf ("## speed refined %f\n", speed);
/* SLOW */
// speed = detect_speed (in_data, speed, 1.00005, /* steps */ 20, /* seconds */ 50);
int r = Params::mark_sample_rate * speed; int r = Params::mark_sample_rate * speed;
if (r != Params::mark_sample_rate) if (r != Params::mark_sample_rate)
......
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