Commit 665e5bbf authored by Stefan Westerfeld's avatar Stefan Westerfeld

Change strategy for decoding after speed detection (can decode twice now).

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent db4a1307
speed detection: speed detection:
- double decode
- maybe truncate cleanup - maybe truncate cleanup
- remove pad start scaling - remove pad start scaling
- test code - test code
......
...@@ -141,11 +141,18 @@ public: ...@@ -141,11 +141,18 @@ public:
float decode_error = 0; float decode_error = 0;
SyncFinder::Score sync_score; SyncFinder::Score sync_score;
Type type; Type type;
bool speed_pattern;
}; };
private: private:
vector<Pattern> patterns; vector<Pattern> patterns;
bool speed_pattern = false;
public: public:
void
set_speed_pattern (bool sp)
{
speed_pattern = sp;
}
void void
add_pattern (SyncFinder::Score sync_score, const vector<int>& bit_vec, float decode_error, Type pattern_type) add_pattern (SyncFinder::Score sync_score, const vector<int>& bit_vec, float decode_error, Type pattern_type)
{ {
...@@ -154,6 +161,7 @@ public: ...@@ -154,6 +161,7 @@ public:
p.bit_vec = bit_vec; p.bit_vec = bit_vec;
p.decode_error = decode_error; p.decode_error = decode_error;
p.type = pattern_type; p.type = pattern_type;
p.speed_pattern = speed_pattern;
patterns.push_back (p); patterns.push_back (p);
} }
...@@ -172,8 +180,13 @@ public: ...@@ -172,8 +180,13 @@ public:
{ {
if (pattern.type == Type::ALL) /* this is the combined pattern "all" */ if (pattern.type == Type::ALL) /* this is the combined pattern "all" */
{ {
printf ("pattern all %s %.3f %.3f\n", bit_vec_to_str (pattern.bit_vec).c_str(), const char *extra = "";
pattern.sync_score.quality, pattern.decode_error); if (pattern.speed_pattern)
extra = " SPEED";
printf ("pattern all %s %.3f %.3f%s\n", bit_vec_to_str (pattern.bit_vec).c_str(),
pattern.sync_score.quality, pattern.decode_error,
extra);
} }
else else
{ {
...@@ -190,6 +203,8 @@ public: ...@@ -190,6 +203,8 @@ public:
} }
if (pattern.type == Type::CLIP) if (pattern.type == Type::CLIP)
block_str = "CLIP-" + block_str; block_str = "CLIP-" + block_str;
if (pattern.speed_pattern)
block_str += "-SPEED";
const int seconds = pattern.sync_score.index / Params::mark_sample_rate; const int seconds = pattern.sync_score.index / Params::mark_sample_rate;
printf ("pattern %2d:%02d %s %.3f %.3f %s\n", seconds / 60, seconds % 60, bit_vec_to_str (pattern.bit_vec).c_str(), printf ("pattern %2d:%02d %s %.3f %.3f %s\n", seconds / 60, seconds % 60, bit_vec_to_str (pattern.bit_vec).c_str(),
...@@ -520,25 +535,37 @@ public: ...@@ -520,25 +535,37 @@ public:
}; };
static int static int
decode_and_report (const WavData& in_data, const string& orig_pattern) decode_and_report (const WavData& wav_data, const string& orig_pattern)
{ {
ResultSet result_set;
WavData wav_data; /*
* 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) if (Params::detect_speed)
{ {
double speed = detect_speed (in_data, !orig_pattern.empty()); double speed = detect_speed (wav_data, !orig_pattern.empty());
int r = Params::mark_sample_rate * speed; // speeds closer to 1.0 than this usually work without stretching before decode
if (r != Params::mark_sample_rate) if (speed < 0.9999 || speed > 1.0001)
wav_data = resample (in_data, Params::mark_sample_rate * speed); {
else WavData wav_data_speed = resample (wav_data, Params::mark_sample_rate * speed);
wav_data = in_data;
} result_set.set_speed_pattern (true);
else BlockDecoder block_decoder;
{ block_decoder.run (wav_data_speed, result_set);
wav_data = in_data;
ClipDecoder clip_decoder;
clip_decoder.run (wav_data_speed, result_set);
result_set.set_speed_pattern (false);
}
} }
ResultSet result_set;
BlockDecoder block_decoder; BlockDecoder block_decoder;
block_decoder.run (wav_data, result_set); block_decoder.run (wav_data, result_set);
......
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