[model, ui] functional rate reduction
This commit is contained in:
parent
89e8490f08
commit
daa50f8902
3 changed files with 38 additions and 13 deletions
|
@ -4,28 +4,47 @@ namespace Example
|
|||
{
|
||||
void Ottobit::operator()(tick t)
|
||||
{
|
||||
// Only compute bit factor when the control changes
|
||||
// Only compute bit_factor when the control changes
|
||||
if (inputs.bits != previous_bits)
|
||||
{
|
||||
set_bit_factor();
|
||||
previous_bits = inputs.bits;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Process the input buffer
|
||||
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];
|
||||
|
||||
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;
|
||||
}
|
||||
if (skipped_frames <= step_size)
|
||||
skipped_frames++;
|
||||
else
|
||||
current_frame = in[j];
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
out[j] = current_frame;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace Example
|
|||
class Ottobit
|
||||
{
|
||||
#define BITS 16
|
||||
#define RATE 64
|
||||
|
||||
public:
|
||||
halp_meta(name, "Ottobit")
|
||||
|
@ -29,6 +30,7 @@ public:
|
|||
{
|
||||
using mapper = halp::log_mapper<std::ratio<95, 100>>;
|
||||
} bits;
|
||||
halp::knob_f32<"Rate", halp::range{.min = .1, .max = 1., .init = 1.}> rate;
|
||||
} inputs;
|
||||
|
||||
struct
|
||||
|
@ -37,9 +39,13 @@ public:
|
|||
} outputs;
|
||||
|
||||
// Local variables
|
||||
double previous_bits;
|
||||
int bit_factor;
|
||||
double current_frame;
|
||||
int bit_factor,
|
||||
skipped_frames{0},
|
||||
step_size{0};
|
||||
|
||||
double previous_bits{BITS},
|
||||
previous_rate{1},
|
||||
current_frame;
|
||||
|
||||
void set_bit_factor();
|
||||
|
||||
|
@ -47,7 +53,6 @@ public:
|
|||
void prepare(setup info)
|
||||
{
|
||||
// Initialization, this method will be called with buffer size, etc.
|
||||
previous_bits = BITS;
|
||||
set_bit_factor();
|
||||
}
|
||||
|
||||
|
|
|
@ -10,10 +10,11 @@ struct Ottobit::ui
|
|||
using enum halp::layouts;
|
||||
|
||||
halp_meta(name, "Ottobit")
|
||||
halp_meta(layout, vbox)
|
||||
halp_meta(layout, hbox)
|
||||
halp_meta(background, dark)
|
||||
|
||||
halp::label title{"Bits"};
|
||||
halp::item<&ins::bits> bits;
|
||||
|
||||
halp::item<&ins::rate> rate;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue