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 @@ ...@@ -23,6 +23,7 @@
using std::complex; using std::complex;
using std::vector; using std::vector;
using std::string;
using std::min; using std::min;
void void
...@@ -274,7 +275,7 @@ SyncFinder::search_refine (const WavData& wav_data, Mode mode, vector<Score>& sy ...@@ -274,7 +275,7 @@ SyncFinder::search_refine (const WavData& wav_data, Mode mode, vector<Score>& sy
for (const auto& score : sync_scores) 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 // refine match
double best_quality = score.quality; double best_quality = score.quality;
...@@ -298,7 +299,7 @@ SyncFinder::search_refine (const WavData& wav_data, Mode mode, vector<Score>& sy ...@@ -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) if (best_quality > Params::sync_threshold2)
result_scores.push_back (Score { best_index, best_quality, best_block_type }); 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, ...@@ -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) SyncFinder::find_closest_sync (size_t index)
{ {
int wm_length = (mark_data_frame_count() + mark_sync_frame_count()) * Params::frame_size; 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) ...@@ -423,7 +424,5 @@ SyncFinder::find_closest_sync (size_t index)
best_error = error; best_error = error;
} }
} }
static char buffer[1024]; // this code is for debugging only, so this should be ok return string_printf ("n:%d offset:%d", best, int (index) - (wm_offset + best * wm_length));
sprintf (buffer, "n:%d offset:%d", best, int (index) - (wm_offset + best * wm_length));
return buffer;
} }
...@@ -108,7 +108,7 @@ private: ...@@ -108,7 +108,7 @@ private:
std::vector<float>& fft_out_db, std::vector<float>& fft_out_db,
std::vector<char>& have_frames, std::vector<char>& have_frames,
const std::vector<char>& want_frames); const std::vector<char>& want_frames);
const char *find_closest_sync (size_t index); std::string find_closest_sync (size_t index);
}; };
#endif #endif
...@@ -111,12 +111,8 @@ vec_to_hex_str (const vector<unsigned char>& vec) ...@@ -111,12 +111,8 @@ vec_to_hex_str (const vector<unsigned char>& vec)
{ {
string s; string s;
for (auto byte : vec) for (auto byte : vec)
{ s += string_printf ("%02x", byte);
char buffer[256];
sprintf (buffer, "%02x", byte);
s += buffer;
}
return s; 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