score-avnd-senior/Ottobit/OttobitModel.hpp

70 lines
1.4 KiB
C++

#pragma once
#include <cmath>
#include <halp/audio.hpp>
#include <halp/controls.hpp>
#include <halp/mappers.hpp>
#include <halp/meta.hpp>
namespace Meris
{
class Ottobit
{
#define BITS 16
#define RATE 64
public:
halp_meta(name, "Ottobit")
halp_meta(category, "Audio")
halp_meta(c_name, "ottobit")
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);
}
// 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:
// Local variables
int bit_factor, step_size{0};
std::vector<int> skipped_frames;
double previous_bits{BITS}, previous_rate{1};
void set_bit_factor();
double crush_frame(const double& f);
};
}