score-avnd-senior/Ottobit/OttobitModel.cpp

40 lines
779 B
C++
Raw Normal View History

2024-09-30 18:50:58 +01:00
#include "Ottobit.hpp"
namespace Example
{
2024-09-30 22:30:26 +01:00
void Ottobit::operator()(tick t)
2024-09-30 18:50:58 +01:00
{
2024-09-30 22:30:26 +01:00
// Only compute bit factor when the control changes
if (inputs.bits != previous_bits)
{
set_bit_factor();
previous_bits = inputs.bits;
}
2024-09-30 18:50:58 +01:00
// 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++)
{
2024-09-30 22:30:26 +01:00
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;
2024-09-30 18:50:58 +01:00
}
}
}
2024-09-30 22:30:26 +01:00
void Ottobit::set_bit_factor()
{
bit_factor = pow(2, inputs.bits) - 1;
}
2024-09-30 18:50:58 +01:00
}