score-avnd-senior/Ottobit/OttobitModel.cpp

59 lines
1.2 KiB
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-10-01 00:43:19 +01:00
// Only compute bit_factor when the control changes
2024-09-30 22:30:26 +01:00
if (inputs.bits != previous_bits)
{
set_bit_factor();
previous_bits = inputs.bits;
}
2024-10-01 00:43:19 +01:00
// Only compute skipped_frames when the control changes
if (inputs.rate != previous_rate)
{
step_size = (1. - inputs.rate) * RATE;
previous_rate = inputs.rate;
qDebug() << "step size: " << step_size;
}
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];
2024-10-01 00:43:19 +01:00
// Re-init skipped_frames and current_frame for each channel
skipped_frames = 0;
current_frame = in[0];
2024-09-30 18:50:58 +01:00
for(int j = 0; j < t.frames; j++)
{
2024-10-01 00:43:19 +01:00
if (skipped_frames <= step_size)
skipped_frames++;
else
2024-09-30 22:30:26 +01:00
{
2024-10-01 00:43:19 +01:00
skipped_frames = 0;
if (inputs.bits == BITS)
current_frame = in[j];
else
{
int in_scaled{static_cast<int>((in[j] + 1) * bit_factor)};
current_frame = (static_cast<double>(in_scaled) / bit_factor) - 1;
}
2024-09-30 22:30:26 +01:00
}
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
}