Commit 077e1019 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Performance optimization: use db_from_complex everywhere.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent dd9497f7
......@@ -391,7 +391,7 @@ SyncFinder::sync_fft (const WavData& wav_data, size_t index, size_t frame_count,
/* computing db-magnitude is expensive, so we better do it here */
for (int ch = 0; ch < wav_data.n_channels(); ch++)
for (int i = Params::min_band; i <= Params::max_band; i++)
fft_out_db[out_pos++] = db_from_factor (abs (frame_result[ch][i]), min_db);
fft_out_db[out_pos++] = db_from_complex (frame_result[ch][i], min_db);
have_frames[f] = 1;
}
......
......@@ -49,30 +49,6 @@ std::string Params::output_label;
using std::vector;
using std::complex;
/*
* glibc log2f is a lot faster than glibc log10
*/
inline double
fast_log10 (double l)
{
constexpr double log2_log10_factor = 0.3010299956639811952; // 1 / log2 (10)
return log2f (l) * log2_log10_factor;
}
double
db_from_factor (double factor, double min_dB)
{
if (factor > 0)
{
double dB = fast_log10 (factor); /* Bell */
dB *= 20;
return dB;
}
else
return min_dB;
}
FFTAnalyzer::FFTAnalyzer (int n_channels) :
m_n_channels (n_channels),
m_fft_processor (Params::frame_size)
......
......@@ -136,8 +136,6 @@ struct MixEntry
std::vector<MixEntry> gen_mix_entries();
double db_from_factor (double factor, double min_dB);
size_t mark_data_frame_count();
size_t mark_sync_frame_count();
......@@ -185,6 +183,28 @@ window_hamming (double x) /* sharp (rectangle) cutoffs at boundaries */
return 0.54 + 0.46 * cos (M_PI * x);
}
static inline float
db_from_complex (float re, float im, float min_dB)
{
float abs2 = re * re + im * im;
if (abs2 > 0)
{
constexpr float log2_log10_factor = 3.01029995663981; // 10 / log2 (10)
// glibc log2f is a lot faster than glibc log10
return log2f (abs2) * log2_log10_factor;
}
else
return min_dB;
}
static inline float
db_from_complex (std::complex<float> f, float min_dB)
{
return db_from_complex (f.real(), f.imag(), min_dB);
}
int add_stream_watermark (AudioInputStream *in_stream, AudioOutputStream *out_stream, const std::string& bits, size_t zero_frames);
int add_watermark (const std::string& infile, const std::string& outfile, const std::string& bits);
int get_watermark (const std::string& infile, const std::string& orig_pattern);
......
......@@ -83,8 +83,8 @@ mix_decode (vector<vector<complex<float>>>& fft_out, int n_channels)
const int u = mix_entries[b].up;
const int d = mix_entries[b].down;
umag += db_from_factor (abs (fft_out[index][u]), min_db);
dmag += db_from_factor (abs (fft_out[index][d]), min_db);
umag += db_from_complex (fft_out[index][u], min_db);
dmag += db_from_complex (fft_out[index][d], min_db);
}
}
if ((f % Params::frames_per_bit) == (Params::frames_per_bit - 1))
......@@ -116,10 +116,11 @@ linear_decode (vector<vector<complex<float>>>& fft_out, int n_channels)
const double min_db = -96;
for (auto u : up)
umag += db_from_factor (abs (fft_out[index][u]), min_db);
umag += db_from_complex (fft_out[index][u], min_db);
for (auto d : down)
dmag += db_from_factor (abs (fft_out[index][d]), min_db);
dmag += db_from_complex (fft_out[index][d], min_db);
}
if ((f % Params::frames_per_bit) == (Params::frames_per_bit - 1))
{
......
......@@ -166,22 +166,6 @@ public:
}
};
static inline float
db_from_complex (float re, float im, float min_dB)
{
float abs2 = re * re + im * im;
if (abs2 > 0)
{
constexpr float log2_log10_factor = 3.01029995663981; // 10 / log2 (10)
// glibc log2f is a lot faster than glibc log10
return log2f (abs2) * log2_log10_factor;
}
else
return min_dB;
}
void
SpeedSync::prepare_mags()
{
......
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