Commit 71786892 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Merge branch 'avoid-sprintf'

* avoid-sprintf:
  Replace sprintf with string_printf.
	Fixes #33.
  SyncFinder: update debug code to current watermark length / offset
Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parents a633a7c1 1fd49b31
......@@ -23,6 +23,7 @@
using std::complex;
using std::vector;
using std::string;
using std::min;
void
......@@ -274,7 +275,7 @@ SyncFinder::search_refine (const WavData& wav_data, Mode mode, vector<Score>& sy
for (const auto& score : sync_scores)
{
//printf ("%zd %s %f", sync_scores[i].index, find_closest_sync (sync_scores[i].index), sync_scores[i].quality);
//printf ("%zd %s %f", score.index, find_closest_sync (score.index).c_str(), score.quality);
// refine match
double best_quality = score.quality;
......@@ -298,7 +299,7 @@ SyncFinder::search_refine (const WavData& wav_data, Mode mode, vector<Score>& sy
}
}
}
//printf (" => refined: %zd %s %f\n", best_index, find_closest_sync (best_index), best_quality);
//printf (" => refined: %zd %s %f\n", best_index, find_closest_sync (best_index).c_str(), best_quality);
if (best_quality > Params::sync_threshold2)
result_scores.push_back (Score { best_index, best_quality, best_block_type });
}
......@@ -406,22 +407,22 @@ SyncFinder::sync_fft (const WavData& wav_data, size_t index, size_t frame_count,
}
}
const char*
string
SyncFinder::find_closest_sync (size_t index)
{
int best_error = 0xffff;
int wm_length = (mark_data_frame_count() + mark_sync_frame_count()) * Params::frame_size;
int wm_offset = Params::frames_pad_start * Params::frame_size;
int best_error = wm_length * 2;
int best = 0;
for (int i = 0; i < 100; i++)
{
int error = abs (int (index) - int (i * Params::sync_bits * Params::sync_frames_per_bit * Params::frame_size));
int error = abs (int (index) - (wm_offset + i * wm_length));
if (error < best_error)
{
best = i;
best_error = error;
}
}
static char buffer[1024]; // this code is for debugging only, so this should be ok
sprintf (buffer, "n:%d offset:%d", best, int (index) - int (best * Params::sync_bits * Params::sync_frames_per_bit * Params::frame_size));
return buffer;
return string_printf ("n:%d offset:%d", best, int (index) - (wm_offset + best * wm_length));
}
......@@ -108,7 +108,7 @@ private:
std::vector<float>& fft_out_db,
std::vector<char>& have_frames,
const std::vector<char>& want_frames);
const char *find_closest_sync (size_t index);
std::string find_closest_sync (size_t index);
};
#endif
......@@ -111,12 +111,8 @@ vec_to_hex_str (const vector<unsigned char>& vec)
{
string s;
for (auto byte : vec)
{
char buffer[256];
s += string_printf ("%02x", byte);
sprintf (buffer, "%02x", byte);
s += buffer;
}
return s;
}
......
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