score-avnd-senior/Senior/SeniorModel.hpp

90 lines
2 KiB
C++
Raw Normal View History

2024-09-30 18:50:58 +01:00
#pragma once
2024-09-30 22:30:26 +01:00
#include <cmath>
2024-10-06 23:26:13 +01:00
#include <ranges>
2024-09-30 22:30:26 +01:00
2024-10-06 23:26:13 +01:00
#include <Gamma/Oscillator.h>
#include <Gamma/Delay.h>
#include <halp/compat/gamma.hpp>
2024-09-30 18:50:58 +01:00
#include <halp/audio.hpp>
#include <halp/controls.hpp>
2024-09-30 22:30:26 +01:00
#include <halp/mappers.hpp>
2024-09-30 18:50:58 +01:00
#include <halp/meta.hpp>
2024-10-06 23:26:13 +01:00
namespace Ottobit
2024-09-30 18:50:58 +01:00
{
2024-10-06 23:26:13 +01:00
class Senior
2024-09-30 18:50:58 +01:00
{
2024-09-30 22:30:26 +01:00
#define BITS 16
2024-10-01 00:43:19 +01:00
#define RATE 64
2024-09-30 22:30:26 +01:00
2024-09-30 18:50:58 +01:00
public:
2024-10-06 23:26:13 +01:00
halp_meta(name, "Senior")
2024-09-30 18:50:58 +01:00
halp_meta(category, "Audio")
2024-10-06 23:26:13 +01:00
halp_meta(c_name, "senior")
2024-09-30 18:50:58 +01:00
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;
2024-09-30 22:30:26 +01:00
struct : halp::knob_f32<"Bits", halp::range{.min = 3, .max = BITS, .init = BITS}>
{
using mapper = halp::log_mapper<std::ratio<95, 100>>;
} bits;
2024-10-01 00:43:19 +01:00
halp::knob_f32<"Rate", halp::range{.min = .1, .max = 1., .init = 1.}> rate;
2024-09-30 18:50:58 +01:00
} inputs;
struct
{
halp::dynamic_audio_bus<"Output", double> audio;
} outputs;
using setup = halp::setup;
2024-09-30 22:30:26 +01:00
void prepare(setup info)
2024-09-30 18:50:58 +01:00
{
// Initialization, this method will be called with buffer size, etc.
2024-09-30 22:30:26 +01:00
set_bit_factor();
skipped_frames.resize(info.input_channels);
2024-10-06 23:26:13 +01:00
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);
}
2024-09-30 18:50:58 +01:00
}
// Do our processing for N samples
using tick = halp::tick;
// Defined in the .cpp
2024-09-30 22:30:26 +01:00
void operator()(tick t);
2024-09-30 18:50:58 +01:00
// 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};
2024-10-06 23:26:13 +01:00
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);
2024-09-30 18:50:58 +01:00
};
}