score-avnd-senior/Ottobit/OttobitModel.cpp

39 lines
779 B
C++

#include "Ottobit.hpp"
namespace Example
{
void Ottobit::operator()(tick t)
{
// Only compute bit factor when the control changes
if (inputs.bits != previous_bits)
{
set_bit_factor();
previous_bits = inputs.bits;
}
// Process the input buffer
for(int i = 0; i < inputs.audio.channels; i++)
{
auto* in = inputs.audio[i];
auto* out = outputs.audio[i];
for(int j = 0; j < t.frames; j++)
{
if (inputs.bits != BITS)
{
int in_scaled{static_cast<int>((in[j] + 1) * bit_factor)};
current_frame = (static_cast<double>(in_scaled) / bit_factor) - 1;
}
else
current_frame = in[j];
out[j] = current_frame;
}
}
}
void Ottobit::set_bit_factor()
{
bit_factor = pow(2, inputs.bits) - 1;
}
}