score-avnd-senior/Senior/SeniorModel.hpp

89 lines
2 KiB
C++

#pragma once
#include <cmath>
#include <ranges>
#include <Gamma/Oscillator.h>
#include <Gamma/Delay.h>
#include <halp/compat/gamma.hpp>
#include <halp/audio.hpp>
#include <halp/controls.hpp>
#include <halp/mappers.hpp>
#include <halp/meta.hpp>
namespace Ottobit
{
class Senior
{
#define BITS 16
#define RATE 64
public:
halp_meta(name, "Senior")
halp_meta(category, "Audio")
halp_meta(c_name, "senior")
halp_meta(uuid, "fe8425d7-64d3-4b8b-a652-1d80026edc8b")
// Define inputs and outputs ports.
// See the docs at https://github.com/celtera/avendish
struct ins
{
halp::dynamic_audio_bus<"Input", double> audio;
struct : halp::knob_f32<"Bits", halp::range{.min = 3, .max = BITS, .init = BITS}>
{
using mapper = halp::log_mapper<std::ratio<95, 100>>;
} bits;
halp::knob_f32<"Rate", halp::range{.min = .1, .max = 1., .init = 1.}> rate;
} inputs;
struct
{
halp::dynamic_audio_bus<"Output", double> audio;
} outputs;
using setup = halp::setup;
void prepare(setup info)
{
// Initialization, this method will be called with buffer size, etc.
set_bit_factor();
skipped_frames.resize(info.input_channels);
lfos.resize(info.input_channels);
fms.resize(info.input_channels);
for (auto [lfo, fm] : std::views::zip(lfos, fms))
{
lfo.set_sample_rate(info.rate);
lfo.set(5, 0, 0);
fm.set_sample_rate(info.rate);
fm.maxDelay(0.1);
}
}
// Do our processing for N samples
using tick = halp::tick;
// Defined in the .cpp
void operator()(tick t);
// UI is defined in another file to keep things clear.
struct ui;
private:
int bit_factor, step_size{0};
std::vector<int> skipped_frames;
double previous_bits{BITS}, previous_rate{1};
std::vector<gam::LFO<gam::phsInc::Loop,
halp::compat::gamma_domain>> lfos;
std::vector<gam::Delay<double,
gam::ipl::Linear,
halp::compat::gamma_domain>> fms;
void set_bit_factor();
double crush_frame(const double& f);
};
}