[model] cleanup iterate over output channels instead

This commit is contained in:
thibaud keller 2024-10-30 20:59:17 +00:00
parent 0bcd3b7822
commit ec4285ce8f
3 changed files with 27 additions and 29 deletions

View file

@ -6,6 +6,9 @@
namespace Ottobit namespace Ottobit
{ {
#define BITS 16
#define RATE 64
void Senior::prepare(setup info) void Senior::prepare(setup info)
{ {
// Initialization, this method will be called with buffer size, etc. // 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.set_sample_rate(info.rate);
lfo.freq(5); lfo.freq(5);
skipped_frames.resize(info.input_channels); skipped_frames.resize(info.output_channels);
fms.resize(info.input_channels); fms.resize(info.output_channels);
lpfs.resize(info.input_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.set_sample_rate(info.rate);
fm.maxDelay(0.1); fm.maxDelay(0.1);
lpf.set_sample_rate(info.rate); lpf.set_sample_rate(info.rate);
lpf.type(gam::LOW_PASS); lpf.type(gam::LOW_PASS);
}
phases.resize(info.output_channels); ph = init_phase;
init_phase += phase_frac;
float phase_frac{1.f / info.output_channels};
for (int i{0}; i < info.output_channels; i++)
{
phases[i] = i * phase_frac;
} }
} }
@ -67,11 +68,11 @@ void Senior::operator()(tick t)
previous_am_fm = inputs.am_fm; previous_am_fm = inputs.am_fm;
} }
// Process the input buffer // Process the input buffer for each ouput channels
for(int i{0}; i < inputs.audio.channels; i++) for(int i{0}; i < outputs.audio.channels; i++)
{ {
auto* in = inputs.audio[i]; auto* out{outputs.audio[i]};
auto* out = outputs.audio[i % outputs.audio.channels]; auto* in{inputs.audio[i % inputs.audio.channels]};
// Init current_frame and out_frame for each channel // Init current_frame and out_frame for each channel
double current_frame{crush(in[0])}; double current_frame{crush(in[0])};
@ -109,7 +110,7 @@ void Senior::operator()(tick t)
if (inputs.filter < 1.f) if (inputs.filter < 1.f)
{ {
lpfs[i].freq(inputs.filter * 2920. + 80.); lpfs[i].freq(inputs.filter * 3000.);
out[j] = lpfs[i](out_frame); out[j] = lpfs[i](out_frame);
} }
else else
@ -120,18 +121,18 @@ void Senior::operator()(tick t)
void Senior::set_bit_factor() 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) double Senior::crush(const double& f)
{ {
if (inputs.bits == BITS) if (inputs.bits < 1.f)
return f;
else
// Rounding using static_cast // Rounding using static_cast
// return static_cast<double>(static_cast<int>(f * bit_factor)) / bit_factor; // return static_cast<double>(static_cast<int>(f * bit_factor)) / bit_factor;
// Close, but prefer the use of roundMagic from Lance Putnam's Gama // Close, but prefer the use of roundMagic from Lance Putnam's Gama
return gam::scl::round<double>(f * bit_factor) / bit_factor; return gam::scl::round<double>(f * bit_factor) / bit_factor;
else
return f;
} }
} // namespace Ottobit } // namespace Ottobit

View file

@ -17,9 +17,6 @@ namespace Ottobit
{ {
class Senior class Senior
{ {
#define BITS 16
#define RATE 64
public: public:
halp_meta(name, "Senior") halp_meta(name, "Senior")
halp_meta(category, "Audio") halp_meta(category, "Audio")
@ -32,10 +29,10 @@ public:
{ {
halp::dynamic_audio_bus<"Input", double> audio; 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<"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<std::ratio<95, 100>>; using log_map = halp::log_mapper<std::ratio<95, 100>>;
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; using mapper = log_map;
} bits; } bits;
@ -69,8 +66,8 @@ private:
int bit_factor, step_size{0}; int bit_factor, step_size{0};
double double
previous_bits{BITS},
previous_rate{1}, previous_rate{1},
previous_bits{1},
previous_depth{0}, previous_depth{0},
previous_am_fm{0}, previous_am_fm{0},
am_amp{0}, am_amp{0},

View file

@ -16,9 +16,9 @@ struct Senior::ui
struct struct
{ {
halp_meta(layout, hbox) halp_meta(layout, hbox)
halp::item<&ins::bits> bits;
halp::item<&ins::filter> filter;
halp::item<&ins::s_rate> s_rate; halp::item<&ins::s_rate> s_rate;
halp::item<&ins::filter> filter;
halp::item<&ins::bits> bits;
} res; } res;
struct struct