[bits] use gama's rounding + make current_frame multichannel
This commit is contained in:
parent
daa50f8902
commit
8d48c93931
4 changed files with 39 additions and 32 deletions
|
@ -23,7 +23,7 @@ avnd_score_plugin_add(
|
||||||
Ottobit/OttobitUi.hpp
|
Ottobit/OttobitUi.hpp
|
||||||
TARGET ottobit
|
TARGET ottobit
|
||||||
MAIN_CLASS Ottobit
|
MAIN_CLASS Ottobit
|
||||||
NAMESPACE Example
|
NAMESPACE Meris
|
||||||
)
|
)
|
||||||
|
|
||||||
avnd_score_plugin_finalize(
|
avnd_score_plugin_finalize(
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
#include <Gamma/scl.h>
|
||||||
|
|
||||||
#include "Ottobit.hpp"
|
#include "Ottobit.hpp"
|
||||||
|
|
||||||
namespace Example
|
namespace Meris
|
||||||
{
|
{
|
||||||
void Ottobit::operator()(tick t)
|
void Ottobit::operator()(tick t)
|
||||||
{
|
{
|
||||||
|
@ -16,34 +18,25 @@ void Ottobit::operator()(tick t)
|
||||||
{
|
{
|
||||||
step_size = (1. - inputs.rate) * RATE;
|
step_size = (1. - inputs.rate) * RATE;
|
||||||
previous_rate = inputs.rate;
|
previous_rate = inputs.rate;
|
||||||
qDebug() << "step size: " << step_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process the input buffer
|
// 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* in = inputs.audio[i];
|
||||||
auto* out = outputs.audio[i];
|
auto* out = outputs.audio[i];
|
||||||
|
|
||||||
// Re-init skipped_frames and current_frame for each channel
|
// Init current_frame for each channel
|
||||||
skipped_frames = 0;
|
double current_frame{crush_frame(in[0])};
|
||||||
current_frame = in[0];
|
|
||||||
|
|
||||||
for(int j = 0; j < t.frames; j++)
|
for(int j{0}; j < t.frames; j++)
|
||||||
{
|
{
|
||||||
if (skipped_frames <= step_size)
|
if (skipped_frames[i] <= step_size)
|
||||||
skipped_frames++;
|
skipped_frames[i]++;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
skipped_frames = 0;
|
skipped_frames[i] = 0;
|
||||||
|
current_frame = crush_frame(in[j]);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out[j] = current_frame;
|
out[j] = current_frame;
|
||||||
|
@ -55,4 +48,17 @@ void Ottobit::set_bit_factor()
|
||||||
{
|
{
|
||||||
bit_factor = pow(2, inputs.bits) - 1;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include <halp/mappers.hpp>
|
#include <halp/mappers.hpp>
|
||||||
#include <halp/meta.hpp>
|
#include <halp/meta.hpp>
|
||||||
|
|
||||||
namespace Example
|
namespace Meris
|
||||||
{
|
{
|
||||||
|
|
||||||
class Ottobit
|
class Ottobit
|
||||||
|
@ -38,22 +38,12 @@ public:
|
||||||
halp::dynamic_audio_bus<"Output", double> audio;
|
halp::dynamic_audio_bus<"Output", double> audio;
|
||||||
} outputs;
|
} 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;
|
using setup = halp::setup;
|
||||||
void prepare(setup info)
|
void prepare(setup info)
|
||||||
{
|
{
|
||||||
// Initialization, this method will be called with buffer size, etc.
|
// Initialization, this method will be called with buffer size, etc.
|
||||||
set_bit_factor();
|
set_bit_factor();
|
||||||
|
skipped_frames.resize(info.input_channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do our processing for N samples
|
// Do our processing for N samples
|
||||||
|
@ -64,6 +54,17 @@ public:
|
||||||
|
|
||||||
// UI is defined in another file to keep things clear.
|
// UI is defined in another file to keep things clear.
|
||||||
struct ui;
|
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);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <Ottobit/OttobitModel.hpp>
|
#include <Ottobit/OttobitModel.hpp>
|
||||||
#include <halp/layout.hpp>
|
#include <halp/layout.hpp>
|
||||||
|
|
||||||
namespace Example
|
namespace Meris
|
||||||
{
|
{
|
||||||
struct Ottobit::ui
|
struct Ottobit::ui
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue