score-avnd-senior/Senior/SeniorModel.hpp

93 lines
2.3 KiB
C++

#pragma once
#include <cmath>
#include <ranges>
#include <Gamma/Oscillator.h>
#include <Gamma/Delay.h>
#include <Gamma/Filter.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
{
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;
halp::knob_f32<"SAMPLE RATE", halp::range{.min = .1, .max = 1., .init = 1.}> s_rate;
halp::knob_f32<"FILTER", halp::range{.min = .001, .max = 1., .init = 1.}> filter;
using log_map = halp::log_mapper<std::ratio<95, 100>>;
struct : halp::knob_f32<"BITS", halp::range{.min = .1, .max = 1., .init = 1.}>
{
using mapper = log_map;
} bits;
struct : halp::knob_f32<"FREQ", halp::range{.min = .4, .max = 200., .init = 5.}>
{
using mapper = log_map;
} freq;
halp::knob_f32<"DEPTH", halp::range{.min = 0., .max = 1., .init = 0.}> depth;
halp::knob_f32<"AM/RING/FM", halp::range{.min = 0., .max = 2., .init = 0.}> am_fm;
} inputs;
struct
{
halp::dynamic_audio_bus<"Output", double> audio;
} outputs;
using setup = halp::setup;
void prepare(setup info);
// 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};
double
previous_rate{1},
previous_bits{1},
previous_depth{0},
previous_am_fm{0},
am_amp{0},
fm_amp{0};
std::vector<int> skipped_frames;
std::vector<float> phases;
gam::LFO<gam::phsInc::Loop, halp::compat::gamma_domain> lfo{5.};
std::vector<gam::Delay<double,
gam::ipl::Linear,
halp::compat::gamma_domain>> fms;
std::vector<gam::OnePole<double,
double,
halp::compat::gamma_domain>> lpfs;
void set_bit_factor();
double crush(const double& f);
};
} // namespace Ottobit