Commit 1fd49b31 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Replace sprintf with string_printf.

Fixes #33.
Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 9f94e591
......@@ -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", score.index, find_closest_sync (score.index), score.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,7 +407,7 @@ 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 wm_length = (mark_data_frame_count() + mark_sync_frame_count()) * Params::frame_size;
......@@ -423,7 +424,5 @@ SyncFinder::find_closest_sync (size_t index)
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) - (wm_offset + best * wm_length));
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