score-avnd-senior/Ottobit/OttobitModel.hpp

71 lines
1.4 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-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>
namespace Meris
2024-09-30 18:50:58 +01:00
{
class Ottobit
{
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-09-30 22:30:26 +01:00
halp_meta(name, "Ottobit")
2024-09-30 18:50:58 +01:00
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;
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-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:
// 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);
2024-09-30 18:50:58 +01:00
};
}