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-10-07 22:53:11 +01:00
|
|
|
halp::knob_f32<"SAMPLE RATE", halp::range{.min = .1, .max = 1., .init = 1.}> s_rate;
|
|
|
|
|
|
|
|
using log_map = halp::log_mapper<std::ratio<95, 100>>;
|
|
|
|
struct : halp::knob_f32<"BITS", halp::range{.min = 3, .max = BITS, .init = BITS}>
|
2024-09-30 22:30:26 +01:00
|
|
|
{
|
2024-10-07 22:53:11 +01:00
|
|
|
using mapper = log_map;
|
2024-09-30 22:30:26 +01:00
|
|
|
} bits;
|
2024-10-07 22:53:11 +01:00
|
|
|
struct : halp::knob_f32<"FREQ", halp::range{.min = .4, .max = 200., .init = 5.}>
|
|
|
|
{
|
|
|
|
using mapper = log_map;
|
|
|
|
} freq;
|
|
|
|
struct : halp::knob_f32<"DEPTH", halp::range{.min = .0, .max = 1., .init = 0.}>
|
|
|
|
{
|
|
|
|
using mapper = log_map;
|
|
|
|
}
|
|
|
|
depth;
|
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();
|
2024-10-07 22:53:11 +01:00
|
|
|
lfo.set_sample_rate(info.rate);
|
|
|
|
lfo.freq(5);
|
|
|
|
|
2024-10-02 17:16:34 +01:00
|
|
|
skipped_frames.resize(info.input_channels);
|
2024-10-06 23:26:13 +01:00
|
|
|
fms.resize(info.input_channels);
|
|
|
|
|
2024-10-07 22:53:11 +01:00
|
|
|
for (auto& fm : fms)
|
2024-10-06 23:26:13 +01:00
|
|
|
{
|
|
|
|
fm.set_sample_rate(info.rate);
|
|
|
|
fm.maxDelay(0.1);
|
|
|
|
}
|
2024-10-07 22:53:11 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
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;
|
2024-10-02 17:16:34 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
int bit_factor, step_size{0};
|
|
|
|
|
|
|
|
|
2024-10-07 22:53:11 +01:00
|
|
|
double previous_bits{BITS},
|
|
|
|
previous_rate{1};
|
|
|
|
|
|
|
|
std::vector<float> phases;
|
|
|
|
std::vector<int> skipped_frames;
|
2024-10-02 17:16:34 +01:00
|
|
|
|
2024-10-06 23:26:13 +01:00
|
|
|
std::vector<gam::Delay<double,
|
|
|
|
gam::ipl::Linear,
|
|
|
|
halp::compat::gamma_domain>> fms;
|
|
|
|
|
2024-10-07 22:53:11 +01:00
|
|
|
gam::LFO<gam::phsInc::Loop, halp::compat::gamma_domain> lfo{5.};
|
|
|
|
|
2024-10-02 17:16:34 +01:00
|
|
|
void set_bit_factor();
|
2024-10-07 22:53:11 +01:00
|
|
|
double crush(const double& f);
|
2024-09-30 18:50:58 +01:00
|
|
|
};
|
|
|
|
|
2024-10-07 22:53:11 +01:00
|
|
|
} // namespace Ottobit
|