Commit c0073aa6 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Implement alternative exponent for changing bands with pow().

However, testing shows that this version is not as good as the original
version.
Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 33e58a76
......@@ -331,34 +331,39 @@ compute_frame_ffts (const WavData& wav_data, size_t start_index, size_t frame_co
return fft_out;
}
complex<float>
mark_delta (complex<float> spect_value, double exponent)
{
const float mag_factor = pow (abs (spect_value), exponent) / abs (spect_value);
return spect_value * (mag_factor - 1);
}
void
mark_bit_linear (int f, const vector<complex<float>>& fft_out, vector<complex<float>>& fft_delta_spect, int data_bit, Random::Stream random_stream)
{
vector<int> up;
vector<int> down;
get_up_down (f, up, down, random_stream);
const double data_bit_sign = data_bit > 0 ? 1 : -1;
const double exponent = data_bit ? 1 / (1 + Params::water_delta) : (1 + Params::water_delta);
for (auto u : up)
{
/*
* for up bands, we want do use [for a 1 bit] (pow (mag, 1 - water_delta))
* for up bands, we want do use [for a 1 bit] (pow (mag, ...)))
*
* this actually increases the amount of energy because mag is less than 1.0
*/
const float mag_factor = pow (abs (fft_out[u]), -Params::water_delta * data_bit_sign);
fft_delta_spect[u] = fft_out[u] * (mag_factor - 1);
fft_delta_spect[u] = mark_delta (fft_out[u], exponent);
}
for (auto d : down)
{
/*
* for down bands, we want do use [for a 1 bit] (pow (mag, 1 + water_delta))
* for down bands, we want do use [for a 1 bit] (pow (mag, ...))
*
* this actually decreases the amount of energy because mag is less than 1.0
*/
const float mag_factor = pow (abs (fft_out[d]), Params::water_delta * data_bit_sign);
fft_delta_spect[d] = fft_out[d] * (mag_factor - 1);
fft_delta_spect[d] = mark_delta (fft_out[d], 1 / exponent);
}
}
......@@ -418,21 +423,14 @@ mark_data (const WavData& wav_data, int start_frame, const vector<vector<complex
int b = f * Params::bands_per_frame + frame_b;
const int data_bit = bitvec[f / Params::frames_per_bit];
const double data_bit_sign = data_bit > 0 ? 1 : -1;
const double exponent = data_bit ? 1 / (1 + Params::water_delta) : (1 + Params::water_delta);
const int u = mix_entries[b].up;
const int index = (start_frame + mix_entries[b].frame) * wav_data.n_channels() + ch;
{
const float mag_factor = pow (abs (fft_out[index][u]), -Params::water_delta * data_bit_sign);
fft_delta_spect[index][u] = mark_delta (fft_out[index][u], exponent);
fft_delta_spect[index][u] = fft_out[index][u] * (mag_factor - 1);
}
const int d = mix_entries[b].down;
{
const float mag_factor = pow (abs (fft_out[index][d]), Params::water_delta * data_bit_sign);
fft_delta_spect[index][d] = fft_out[index][d] * (mag_factor - 1);
}
fft_delta_spect[index][d] = mark_delta (fft_out[index][d], 1 / exponent);
}
}
}
......@@ -457,6 +455,16 @@ mark_sync_frame_count()
return Params::sync_bits * Params::sync_frames_per_bit;
}
double
mags_to_raw_bit (double umag, double dmag)
{
/* convert umag and dmag to soft bit, avoiding bias in either direction */
if (umag > dmag)
return 1 - umag / dmag;
else
return dmag / umag - 1;
}
void
mark_sync (const WavData& wav_data, int start_frame, const vector<vector<complex<float>>>& fft_out, vector<vector<complex<float>>>& fft_delta_spect)
{
......@@ -705,7 +713,7 @@ mix_decode (vector<vector<complex<float>>>& fft_out, vector<vector<complex<float
}
if ((f % Params::frames_per_bit) == (Params::frames_per_bit - 1))
{
raw_bit_vec.push_back (umag - dmag);
raw_bit_vec.push_back (mags_to_raw_bit (umag, dmag));
umag = 0;
dmag = 0;
}
......@@ -747,7 +755,7 @@ linear_decode (vector<vector<complex<float>>>& fft_out, vector<vector<complex<fl
}
if ((f % Params::frames_per_bit) == (Params::frames_per_bit - 1))
{
raw_bit_vec.push_back (umag - dmag);
raw_bit_vec.push_back (mags_to_raw_bit (umag, dmag));
umag = 0;
dmag = 0;
}
......@@ -820,9 +828,9 @@ class SyncFinder
dmag += fft_out_db[index + down[bit][i]];
}
}
const int expect_data_bit = bit & 1; /* expect 010101 */
const int sign = (bit & 1) ? 1 : -1; /* expect 010101 */
const double q = expect_data_bit ? (1 - umag / dmag) : (umag / dmag - 1);
const double q = mags_to_raw_bit (umag, dmag) * sign;
sync_quality += q;
}
sync_quality /= Params::sync_bits;
......
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