[dsp] housekeeping and out_frame

This commit is contained in:
thibaud keller 2024-10-20 23:37:37 +01:00
parent 1970b5c624
commit 2b807fd789
2 changed files with 33 additions and 15 deletions

View file

@ -6,28 +6,44 @@ namespace Ottobit
{
void Senior::operator()(tick t)
{
// Only compute skipped_frames when the control changes
// Only compute skipped_frames when control changes
if (inputs.s_rate != previous_rate)
{
step_size = (1. - inputs.s_rate) * RATE;
previous_rate = inputs.s_rate;
}
// Only compute bit_factor when the control changes
if (inputs.bits != previous_bits)
{
set_bit_factor();
previous_bits = inputs.bits;
}
if (inputs.depth != previous_depth ||
inputs.am_fm != previous_am_fm)
{
if (inputs.am_fm < 1.f)
am_amp = (inputs.am_fm * 0.5) + (inputs.depth * 0.5);
else
{
am_amp = 2 - inputs.am_fm;
fm_amp = inputs.am_fm - 1;
}
previous_depth = inputs.depth;
previous_am_fm = inputs.am_fm;
}
// Process the input buffer
for(int i{0}; i < inputs.audio.channels; i++)
{
auto* in = inputs.audio[i];
auto* out = outputs.audio[i % outputs.audio.channels];
// Init current_frame for each channel
double current_frame{crush(in[i])};
// Init current_frame and out_frame for each channel
double current_frame{crush(in[0])};
double out_frame{current_frame};
for(int j{0}; j < t.frames; j++)
{
@ -39,28 +55,25 @@ void Senior::operator()(tick t)
current_frame = crush(in[j]);
}
if (!inputs.depth)
out[j] = current_frame;
else
if (inputs.depth)
{
lfo.set(inputs.freq, phases[i], 0);
if (inputs.am_fm < 1.f)
{
double amp = (inputs.am_fm * 0.5) + (inputs.depth * 0.5);
out[j] = current_frame * ((lfo.cos() * amp) + (1 - amp));
}
out_frame = current_frame * (lfo.cos() * am_amp + (1 - am_amp));
else
{
double amp = lfo.cos() * inputs.depth;
fms[i].delay(amp * .0025 + 1);
double am = current_frame * (amp + (1 - inputs.depth));
double am = current_frame * (amp + 1 - inputs.depth);
double fm = fms[i](current_frame);
out[j] = (am * (2 - inputs.am_fm)) + (fm * (inputs.am_fm - 1));
out_frame = am * am_amp + fm * fm_amp;
}
phases[i] = lfo.phase();
}
out[j] = out_frame;
}
}
}

View file

@ -91,8 +91,13 @@ private:
int bit_factor, step_size{0};
double previous_bits{BITS},
previous_rate{1};
double
previous_bits{BITS},
previous_rate{1},
previous_depth{0},
previous_am_fm{0},
am_amp{0},
fm_amp{0};
std::vector<float> phases;
std::vector<int> skipped_frames;