[messages] working messages between ui and processor thread
This commit is contained in:
parent
50233de626
commit
8565037ac2
4 changed files with 24 additions and 23 deletions
|
@ -47,7 +47,7 @@ void Analyser::analyzer_setup(float max_buffer_duration)
|
|||
// Could also span more for even better measurements, with larger
|
||||
// computation cost and latency
|
||||
float f = frequencies[idx];
|
||||
int window_size = (int)(min(inputs.periods_nb.value / f, max_buffer_duration * 0.001f)
|
||||
int window_size = (int)(min(inputs.periods.value / f, max_buffer_duration * 0.001f)
|
||||
* sampling_rate);
|
||||
vector<float> window(window_size);
|
||||
vector<float> window_deriv(window_size);
|
||||
|
@ -89,9 +89,9 @@ void Analyser::analyzer_setup(float max_buffer_duration)
|
|||
i += 4;
|
||||
continue;
|
||||
}
|
||||
float t = (float)(i-window_size-1) / sampling_rate;
|
||||
float re = cosf(-two_pi*t*f);
|
||||
float im = sinf(-two_pi*t*f);
|
||||
float t = (float)(i - window_size - 1) / sampling_rate;
|
||||
float re = cosf(-two_pi * t * f);
|
||||
float im = sinf(-two_pi * t * f);
|
||||
v4sf ws = {
|
||||
re * window[i],
|
||||
im * window[i],
|
||||
|
@ -102,7 +102,7 @@ void Analyser::analyzer_setup(float max_buffer_duration)
|
|||
wsum += window[i];
|
||||
++i;
|
||||
}
|
||||
power_normalization_factors[idx] = 1. / (wsum*wsum);
|
||||
power_normalization_factors[idx] = 1. / (wsum * wsum);
|
||||
big_buffer_size = max(big_buffer_size, window_size);
|
||||
}
|
||||
|
||||
|
@ -122,11 +122,11 @@ void Analyser::initialize_window(std::vector<float>& window)
|
|||
for (int i{0}; i < size; ++i)
|
||||
{
|
||||
float p = i * two_over_N - 1.;
|
||||
window[i] = boost::math::cyl_bessel_i(0., alpha_pi * sqrt(1. - p*p)) * inv_denom;
|
||||
window[i] = boost::math::cyl_bessel_i(0., alpha_pi * sqrt(1. - p * p)) * inv_denom;
|
||||
}
|
||||
}
|
||||
|
||||
void Analyser::initialize_window_deriv(std::vector<float> &window)
|
||||
void Analyser::initialize_window_deriv(std::vector<float>& window)
|
||||
{
|
||||
// Derivative of the Kaiser window with a parameter of alpha=3 that nullifies the window on edges
|
||||
int size = window.size();
|
||||
|
@ -137,8 +137,8 @@ void Analyser::initialize_window_deriv(std::vector<float> &window)
|
|||
for (int i{1}; i < size; ++i)
|
||||
{
|
||||
float p = i * two_over_N - 1.;
|
||||
window[i] = boost::math::cyl_bessel_i(1., alpha_pi * sqrt(1. - p*p)) *
|
||||
inv_denom * alpha_pi / sqrt(1. - p*p) * (-p)*two_over_N;
|
||||
window[i] = boost::math::cyl_bessel_i(1., alpha_pi * sqrt(1. - p * p)) *
|
||||
inv_denom * alpha_pi / sqrt(1. - p * p) * (-p) * two_over_N;
|
||||
}
|
||||
// lim I1(x)/x as x->0 = 1/2
|
||||
window[0] = 0.5 * inv_denom * alpha_pi * alpha_pi * two_over_N;
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
int max;
|
||||
};
|
||||
|
||||
std::function<void(const processor_to_ui&)> send_message;
|
||||
std::function<void(processor_to_ui&&)> send_message;
|
||||
|
||||
// Define inputs and outputs ports.
|
||||
// See the docs at https://github.com/celtera/avendish
|
||||
|
@ -43,8 +43,8 @@ public:
|
|||
self.send_message({.min = self.inputs.min.value, .max = this->value});
|
||||
}
|
||||
} max;
|
||||
halp::spinbox_i32<"Analyze num. periods",
|
||||
halp::range{.min = 0, .max = 99, .init = 30}> periods_nb;
|
||||
halp::spinbox_i32<"Periods",
|
||||
halp::range{.min = 0, .max = 99, .init = 30}> periods;
|
||||
} inputs;
|
||||
|
||||
void process_message(const std::vector<float>& frequencies)
|
||||
|
|
|
@ -20,7 +20,7 @@ struct Analyser::ui
|
|||
halp_meta(layout, vbox)
|
||||
halp::item<&ins::min> min;
|
||||
halp::item<&ins::max> max;
|
||||
halp::item<&ins::periods_nb> periods;
|
||||
halp::item<&ins::periods> periods;
|
||||
} controls;
|
||||
|
||||
halp::custom_actions_item<SpiralDisplay> spiral{.x = 0, .y = 0};
|
||||
|
@ -29,16 +29,16 @@ struct Analyser::ui
|
|||
// Define the communication between UI and processor.
|
||||
struct bus
|
||||
{
|
||||
// std::function<void(const std::vector<float>&)> send_message;
|
||||
std::function<void(const std::vector<float>&)> send_message;
|
||||
|
||||
// // Set up connections
|
||||
// void init(ui& self)
|
||||
// {
|
||||
// self.spiral.on_new_frequencies = [&]
|
||||
// {
|
||||
// send_message(self.spiral.get_frequencies());
|
||||
// };
|
||||
// }
|
||||
// Set up connections
|
||||
void init(ui& self)
|
||||
{
|
||||
self.spiral.on_new_frequencies = [&]
|
||||
{
|
||||
send_message(self.spiral.get_frequencies());
|
||||
};
|
||||
}
|
||||
|
||||
// Receive a message on the UI thread from the processing thread
|
||||
static void process_message(ui& self, const processor_to_ui& msg)
|
||||
|
|
|
@ -4,6 +4,7 @@ Amuencha::SpiralDisplay::SpiralDisplay()
|
|||
: min_midi_note{24}
|
||||
, max_midi_note{72}
|
||||
, gain{1.f}
|
||||
, on_new_frequencies{[]{}}
|
||||
{
|
||||
for (int i{0}; i < 12; i++) note_positions[i] = std::polar(.9f, half_pi - i * two_pi / 12);
|
||||
|
||||
|
@ -90,7 +91,7 @@ void Amuencha::SpiralDisplay::compute_frequencies()
|
|||
fill(display_spectrum[id].begin(), display_spectrum[id].end(), 0.);
|
||||
}
|
||||
|
||||
// on_new_frequencies();
|
||||
on_new_frequencies();
|
||||
}
|
||||
|
||||
void Amuencha::SpiralDisplay::power_handler(int ID, const std::vector<float> &reassigned_frequencies, const std::vector<float> &power_spectrum)
|
||||
|
|
Loading…
Add table
Reference in a new issue