[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
|
// Could also span more for even better measurements, with larger
|
||||||
// computation cost and latency
|
// computation cost and latency
|
||||||
float f = frequencies[idx];
|
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);
|
* sampling_rate);
|
||||||
vector<float> window(window_size);
|
vector<float> window(window_size);
|
||||||
vector<float> window_deriv(window_size);
|
vector<float> window_deriv(window_size);
|
||||||
|
@ -89,9 +89,9 @@ void Analyser::analyzer_setup(float max_buffer_duration)
|
||||||
i += 4;
|
i += 4;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
float t = (float)(i-window_size-1) / sampling_rate;
|
float t = (float)(i - window_size - 1) / sampling_rate;
|
||||||
float re = cosf(-two_pi*t*f);
|
float re = cosf(-two_pi * t * f);
|
||||||
float im = sinf(-two_pi*t*f);
|
float im = sinf(-two_pi * t * f);
|
||||||
v4sf ws = {
|
v4sf ws = {
|
||||||
re * window[i],
|
re * window[i],
|
||||||
im * window[i],
|
im * window[i],
|
||||||
|
@ -102,7 +102,7 @@ void Analyser::analyzer_setup(float max_buffer_duration)
|
||||||
wsum += window[i];
|
wsum += window[i];
|
||||||
++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);
|
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)
|
for (int i{0}; i < size; ++i)
|
||||||
{
|
{
|
||||||
float p = i * two_over_N - 1.;
|
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
|
// Derivative of the Kaiser window with a parameter of alpha=3 that nullifies the window on edges
|
||||||
int size = window.size();
|
int size = window.size();
|
||||||
|
@ -137,8 +137,8 @@ void Analyser::initialize_window_deriv(std::vector<float> &window)
|
||||||
for (int i{1}; i < size; ++i)
|
for (int i{1}; i < size; ++i)
|
||||||
{
|
{
|
||||||
float p = i * two_over_N - 1.;
|
float p = i * two_over_N - 1.;
|
||||||
window[i] = boost::math::cyl_bessel_i(1., alpha_pi * sqrt(1. - p*p)) *
|
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;
|
inv_denom * alpha_pi / sqrt(1. - p * p) * (-p) * two_over_N;
|
||||||
}
|
}
|
||||||
// lim I1(x)/x as x->0 = 1/2
|
// lim I1(x)/x as x->0 = 1/2
|
||||||
window[0] = 0.5 * inv_denom * alpha_pi * alpha_pi * two_over_N;
|
window[0] = 0.5 * inv_denom * alpha_pi * alpha_pi * two_over_N;
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
int max;
|
int max;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::function<void(const processor_to_ui&)> send_message;
|
std::function<void(processor_to_ui&&)> send_message;
|
||||||
|
|
||||||
// Define inputs and outputs ports.
|
// Define inputs and outputs ports.
|
||||||
// See the docs at https://github.com/celtera/avendish
|
// 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});
|
self.send_message({.min = self.inputs.min.value, .max = this->value});
|
||||||
}
|
}
|
||||||
} max;
|
} max;
|
||||||
halp::spinbox_i32<"Analyze num. periods",
|
halp::spinbox_i32<"Periods",
|
||||||
halp::range{.min = 0, .max = 99, .init = 30}> periods_nb;
|
halp::range{.min = 0, .max = 99, .init = 30}> periods;
|
||||||
} inputs;
|
} inputs;
|
||||||
|
|
||||||
void process_message(const std::vector<float>& frequencies)
|
void process_message(const std::vector<float>& frequencies)
|
||||||
|
|
|
@ -20,7 +20,7 @@ struct Analyser::ui
|
||||||
halp_meta(layout, vbox)
|
halp_meta(layout, vbox)
|
||||||
halp::item<&ins::min> min;
|
halp::item<&ins::min> min;
|
||||||
halp::item<&ins::max> max;
|
halp::item<&ins::max> max;
|
||||||
halp::item<&ins::periods_nb> periods;
|
halp::item<&ins::periods> periods;
|
||||||
} controls;
|
} controls;
|
||||||
|
|
||||||
halp::custom_actions_item<SpiralDisplay> spiral{.x = 0, .y = 0};
|
halp::custom_actions_item<SpiralDisplay> spiral{.x = 0, .y = 0};
|
||||||
|
@ -29,16 +29,16 @@ struct Analyser::ui
|
||||||
// Define the communication between UI and processor.
|
// Define the communication between UI and processor.
|
||||||
struct bus
|
struct bus
|
||||||
{
|
{
|
||||||
// std::function<void(const std::vector<float>&)> send_message;
|
std::function<void(const std::vector<float>&)> send_message;
|
||||||
|
|
||||||
// // Set up connections
|
// Set up connections
|
||||||
// void init(ui& self)
|
void init(ui& self)
|
||||||
// {
|
{
|
||||||
// self.spiral.on_new_frequencies = [&]
|
self.spiral.on_new_frequencies = [&]
|
||||||
// {
|
{
|
||||||
// send_message(self.spiral.get_frequencies());
|
send_message(self.spiral.get_frequencies());
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Receive a message on the UI thread from the processing thread
|
// Receive a message on the UI thread from the processing thread
|
||||||
static void process_message(ui& self, const processor_to_ui& msg)
|
static void process_message(ui& self, const processor_to_ui& msg)
|
||||||
|
|
|
@ -4,6 +4,7 @@ Amuencha::SpiralDisplay::SpiralDisplay()
|
||||||
: min_midi_note{24}
|
: min_midi_note{24}
|
||||||
, max_midi_note{72}
|
, max_midi_note{72}
|
||||||
, gain{1.f}
|
, 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);
|
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.);
|
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)
|
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