[bits] use gama's rounding + make current_frame multichannel

This commit is contained in:
thibaud keller 2024-10-02 17:16:34 +01:00
parent daa50f8902
commit 8d48c93931
4 changed files with 39 additions and 32 deletions

View file

@ -23,7 +23,7 @@ avnd_score_plugin_add(
Ottobit/OttobitUi.hpp
TARGET ottobit
MAIN_CLASS Ottobit
NAMESPACE Example
NAMESPACE Meris
)
avnd_score_plugin_finalize(

View file

@ -1,6 +1,8 @@
#include <Gamma/scl.h>
#include "Ottobit.hpp"
namespace Example
namespace Meris
{
void Ottobit::operator()(tick t)
{
@ -16,34 +18,25 @@ void Ottobit::operator()(tick t)
{
step_size = (1. - inputs.rate) * RATE;
previous_rate = inputs.rate;
qDebug() << "step size: " << step_size;
}
// Process the input buffer
for(int i = 0; i < inputs.audio.channels; i++)
for(int i{0}; i < inputs.audio.channels; i++)
{
auto* in = inputs.audio[i];
auto* out = outputs.audio[i];
// Re-init skipped_frames and current_frame for each channel
skipped_frames = 0;
current_frame = in[0];
// Init current_frame for each channel
double current_frame{crush_frame(in[0])};
for(int j = 0; j < t.frames; j++)
for(int j{0}; j < t.frames; j++)
{
if (skipped_frames <= step_size)
skipped_frames++;
if (skipped_frames[i] <= step_size)
skipped_frames[i]++;
else
{
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;
}
skipped_frames[i] = 0;
current_frame = crush_frame(in[j]);
}
out[j] = current_frame;
@ -55,4 +48,17 @@ void Ottobit::set_bit_factor()
{
bit_factor = pow(2, inputs.bits) - 1;
}
double Ottobit::crush_frame(const double& f)
{
if (inputs.bits == BITS)
return f;
else
{
// Rounding using static_cast
// return static_cast<double>(static_cast<int>(f * bit_factor)) / bit_factor;
// Close, but prefer Lance Putnama's Gama's use of roundMagic
return gam::scl::round<double>(f * bit_factor) / bit_factor;
}
}
}

View file

@ -7,7 +7,7 @@
#include <halp/mappers.hpp>
#include <halp/meta.hpp>
namespace Example
namespace Meris
{
class Ottobit
@ -38,22 +38,12 @@ public:
halp::dynamic_audio_bus<"Output", double> audio;
} outputs;
// Local variables
int bit_factor,
skipped_frames{0},
step_size{0};
double previous_bits{BITS},
previous_rate{1},
current_frame;
void set_bit_factor();
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
@ -64,6 +54,17 @@ public:
// 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);
};
}

View file

@ -2,7 +2,7 @@
#include <Ottobit/OttobitModel.hpp>
#include <halp/layout.hpp>
namespace Example
namespace Meris
{
struct Ottobit::ui
{