Commit 6b2b2fd1 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Performance: avoid std::vector overhead in up/down band generation.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 05613217
...@@ -243,6 +243,7 @@ frame_count (const WavData& wav_data) ...@@ -243,6 +243,7 @@ frame_count (const WavData& wav_data)
return wav_data.n_values() / wav_data.n_channels() / Params::frame_size; return wav_data.n_values() / wav_data.n_channels() / Params::frame_size;
} }
typedef std::array<int, 30> UpDownArray;
class UpDownGen class UpDownGen
{ {
Random::Stream random_stream; Random::Stream random_stream;
...@@ -255,9 +256,11 @@ public: ...@@ -255,9 +256,11 @@ public:
random (0, random_stream), random (0, random_stream),
bands_reorder (Params::max_band - Params::min_band + 1) bands_reorder (Params::max_band - Params::min_band + 1)
{ {
UpDownArray x;
assert (x.size() == Params::bands_per_frame);
} }
void void
get (int f, vector<int>& up, vector<int>& down) get (int f, UpDownArray& up, UpDownArray& down)
{ {
for (size_t i = 0; i < bands_reorder.size(); i++) for (size_t i = 0; i < bands_reorder.size(); i++)
bands_reorder[i] = Params::min_band + i; bands_reorder[i] = Params::min_band + i;
...@@ -268,8 +271,8 @@ public: ...@@ -268,8 +271,8 @@ public:
assert (2 * Params::bands_per_frame < bands_reorder.size()); assert (2 * Params::bands_per_frame < bands_reorder.size());
for (size_t i = 0; i < Params::bands_per_frame; i++) for (size_t i = 0; i < Params::bands_per_frame; i++)
{ {
up.push_back (bands_reorder[i]); up[i] = bands_reorder[i];
down.push_back (bands_reorder[Params::bands_per_frame + i]); down[i] = bands_reorder[Params::bands_per_frame + i];
} }
} }
}; };
...@@ -430,8 +433,7 @@ gen_mix_entries() ...@@ -430,8 +433,7 @@ gen_mix_entries()
UpDownGen up_down_gen (Random::Stream::data_up_down); UpDownGen up_down_gen (Random::Stream::data_up_down);
for (int f = 0; f < int (mark_data_frame_count()); f++) for (int f = 0; f < int (mark_data_frame_count()); f++)
{ {
vector<int> up; UpDownArray up, down;
vector<int> down;
up_down_gen.get (f, up, down); up_down_gen.get (f, up, down);
assert (up.size() == down.size()); assert (up.size() == down.size());
...@@ -453,8 +455,7 @@ enum class FrameDelta : uint8_t { ...@@ -453,8 +455,7 @@ enum class FrameDelta : uint8_t {
void void
prepare_frame_delta (UpDownGen& up_down_gen, int f, vector<FrameDelta>& frame_delta, int data_bit) prepare_frame_delta (UpDownGen& up_down_gen, int f, vector<FrameDelta>& frame_delta, int data_bit)
{ {
vector<int> up; UpDownArray up, down;
vector<int> down;
up_down_gen.get (f, up, down); up_down_gen.get (f, up, down);
for (auto u : up) for (auto u : up)
frame_delta[u] = data_bit ? FrameDelta::UP : FrameDelta::DOWN; frame_delta[u] = data_bit ? FrameDelta::UP : FrameDelta::DOWN;
...@@ -1041,8 +1042,7 @@ linear_decode (vector<vector<complex<float>>>& fft_out, int n_channels) ...@@ -1041,8 +1042,7 @@ linear_decode (vector<vector<complex<float>>>& fft_out, int n_channels)
for (int ch = 0; ch < n_channels; ch++) for (int ch = 0; ch < n_channels; ch++)
{ {
const size_t index = data_frame_pos (f) * n_channels + ch; const size_t index = data_frame_pos (f) * n_channels + ch;
vector<int> up; UpDownArray up, down;
vector<int> down;
up_down_gen.get (f, up, down); up_down_gen.get (f, up, down);
const double min_db = -96; const double min_db = -96;
...@@ -1095,7 +1095,7 @@ class SyncFinder ...@@ -1095,7 +1095,7 @@ class SyncFinder
{ {
for (int f = 0; f < Params::sync_frames_per_bit; f++) for (int f = 0; f < Params::sync_frames_per_bit; f++)
{ {
vector<int> frame_up, frame_down; UpDownArray frame_up, frame_down;
up_down_gen.get (f + bit * Params::sync_frames_per_bit, frame_up, frame_down); up_down_gen.get (f + bit * Params::sync_frames_per_bit, frame_up, frame_down);
for (auto u : frame_up) for (auto u : frame_up)
......
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