From ec4285ce8ffbc43f5d7db65ef692ceb0c0ad4cbd Mon Sep 17 00:00:00 2001 From: thibaudk Date: Wed, 30 Oct 2024 20:59:17 +0000 Subject: [PATCH] [model] cleanup iterate over output channels instead --- Senior/SeniorModel.cpp | 43 +++++++++++++++++++++--------------------- Senior/SeniorModel.hpp | 9 +++------ Senior/SeniorUi.hpp | 4 ++-- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/Senior/SeniorModel.cpp b/Senior/SeniorModel.cpp index fff0fa3..256f3dc 100644 --- a/Senior/SeniorModel.cpp +++ b/Senior/SeniorModel.cpp @@ -6,6 +6,9 @@ namespace Ottobit { +#define BITS 16 +#define RATE 64 + void Senior::prepare(setup info) { // Initialization, this method will be called with buffer size, etc. @@ -13,26 +16,24 @@ void Senior::prepare(setup info) lfo.set_sample_rate(info.rate); lfo.freq(5); - skipped_frames.resize(info.input_channels); - fms.resize(info.input_channels); - lpfs.resize(info.input_channels); + skipped_frames.resize(info.output_channels); + fms.resize(info.output_channels); + lpfs.resize(info.output_channels); + phases.resize(info.output_channels); - for (auto [fm, lpf] : std::views::zip(fms, lpfs)) + float init_phase{0}; + const float phase_frac{1.f / info.output_channels}; + + for (auto [fm, lpf, ph] : std::views::zip(fms, lpfs, phases)) { fm.set_sample_rate(info.rate); fm.maxDelay(0.1); lpf.set_sample_rate(info.rate); lpf.type(gam::LOW_PASS); - } - phases.resize(info.output_channels); - - float phase_frac{1.f / info.output_channels}; - - for (int i{0}; i < info.output_channels; i++) - { - phases[i] = i * phase_frac; + ph = init_phase; + init_phase += phase_frac; } } @@ -67,11 +68,11 @@ void Senior::operator()(tick t) previous_am_fm = inputs.am_fm; } - // Process the input buffer - for(int i{0}; i < inputs.audio.channels; i++) + // Process the input buffer for each ouput channels + for(int i{0}; i < outputs.audio.channels; i++) { - auto* in = inputs.audio[i]; - auto* out = outputs.audio[i % outputs.audio.channels]; + auto* out{outputs.audio[i]}; + auto* in{inputs.audio[i % inputs.audio.channels]}; // Init current_frame and out_frame for each channel double current_frame{crush(in[0])}; @@ -109,7 +110,7 @@ void Senior::operator()(tick t) if (inputs.filter < 1.f) { - lpfs[i].freq(inputs.filter * 2920. + 80.); + lpfs[i].freq(inputs.filter * 3000.); out[j] = lpfs[i](out_frame); } else @@ -120,18 +121,18 @@ void Senior::operator()(tick t) void Senior::set_bit_factor() { - bit_factor = pow(2, inputs.bits) - 1; + bit_factor = pow(2, inputs.bits * BITS) - 1; } double Senior::crush(const double& f) { - if (inputs.bits == BITS) - return f; - else + if (inputs.bits < 1.f) // Rounding using static_cast // return static_cast(static_cast(f * bit_factor)) / bit_factor; // Close, but prefer the use of roundMagic from Lance Putnam's Gama return gam::scl::round(f * bit_factor) / bit_factor; + else + return f; } } // namespace Ottobit diff --git a/Senior/SeniorModel.hpp b/Senior/SeniorModel.hpp index db267d1..dbd4895 100644 --- a/Senior/SeniorModel.hpp +++ b/Senior/SeniorModel.hpp @@ -17,9 +17,6 @@ namespace Ottobit { class Senior { -#define BITS 16 -#define RATE 64 - public: halp_meta(name, "Senior") halp_meta(category, "Audio") @@ -32,10 +29,10 @@ public: { halp::dynamic_audio_bus<"Input", double> audio; halp::knob_f32<"SAMPLE RATE", halp::range{.min = .1, .max = 1., .init = 1.}> s_rate; - halp::knob_f32<"FILTER", halp::range{.min = 0., .max = 1., .init = 1.}> filter; + halp::knob_f32<"FILTER", halp::range{.min = .001, .max = 1., .init = 1.}> filter; using log_map = halp::log_mapper>; - struct : halp::knob_f32<"BITS", halp::range{.min = 3, .max = BITS, .init = BITS}> + struct : halp::knob_f32<"BITS", halp::range{.min = .1, .max = 1., .init = 1.}> { using mapper = log_map; } bits; @@ -69,8 +66,8 @@ private: int bit_factor, step_size{0}; double - previous_bits{BITS}, previous_rate{1}, + previous_bits{1}, previous_depth{0}, previous_am_fm{0}, am_amp{0}, diff --git a/Senior/SeniorUi.hpp b/Senior/SeniorUi.hpp index fe0c7ce..d9324d6 100644 --- a/Senior/SeniorUi.hpp +++ b/Senior/SeniorUi.hpp @@ -16,9 +16,9 @@ struct Senior::ui struct { halp_meta(layout, hbox) - halp::item<&ins::bits> bits; - halp::item<&ins::filter> filter; halp::item<&ins::s_rate> s_rate; + halp::item<&ins::filter> filter; + halp::item<&ins::bits> bits; } res; struct