Skip to content

Commit

Permalink
Fix issue #21 Allow control each input level independently
Browse files Browse the repository at this point in the history
  • Loading branch information
brummer10 committed Sep 1, 2024
1 parent b261dab commit 2b94dfb
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 68 deletions.
Binary file modified Ratatouille.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 24 additions & 19 deletions Ratatouille/Ratatouille.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/


#define CONTROLS 7
#define CONTROLS 8

#define GUI_ELEMENTS 0

Expand Down Expand Up @@ -285,8 +285,8 @@ void plugin_value_changed(X11_UI *ui, Widget_t *w, PortIndex index) {
}

void plugin_set_window_size(int *w,int *h,const char * plugin_uri) {
(*w) = 500; //set initial width of main window
(*h) = 429; //set initial height of main window
(*w) = 610; //set initial width of main window
(*h) = 419; //set initial height of main window
}

const char* plugin_set_name() {
Expand Down Expand Up @@ -325,73 +325,78 @@ void plugin_create_controller_widgets(X11_UI *ui, const char * plugin_uri) {
asprintf(&ps->ir1.filepicker->filter ,"%s", ".wav");
ps->ir1.filepicker->use_filter = 1;

ps->ma.filebutton = add_lv2_file_button (ps->ma.filebutton, ui->win, -1, "Neural Model", ui, 40, 258, 25, 25);
ps->ma.filebutton = add_lv2_file_button (ps->ma.filebutton, ui->win, -1, "Neural Model", ui, 40, 248, 25, 25);
ps->ma.filebutton->parent_struct = (void*)&ps->ma;
ps->ma.filebutton->func.user_callback = file_load_response;

ps->mb.filebutton = add_lv2_file_button (ps->mb.filebutton, ui->win, -2, "Neural Model", ui, 40, 298, 25, 25);
ps->mb.filebutton = add_lv2_file_button (ps->mb.filebutton, ui->win, -2, "Neural Model", ui, 40, 288, 25, 25);
ps->mb.filebutton->parent_struct = (void*)&ps->mb;
ps->mb.filebutton->func.user_callback = file_load_response;

ps->ir.filebutton = add_lv2_irfile_button (ps->ir.filebutton, ui->win, -3, "IR File", ui, 40, 338, 25, 25);
ps->ir.filebutton = add_lv2_irfile_button (ps->ir.filebutton, ui->win, -3, "IR File", ui, 40, 328, 25, 25);
ps->ir.filebutton->parent_struct = (void*)&ps->ir;
ps->ir.filebutton->func.user_callback = file_load_response;

ps->ir1.filebutton = add_lv2_irfile_button (ps->ir1.filebutton, ui->win, -4, "IR File", ui, 40, 378, 25, 25);
ps->ir1.filebutton = add_lv2_irfile_button (ps->ir1.filebutton, ui->win, -4, "IR File", ui, 40, 368, 25, 25);
ps->ir1.filebutton->parent_struct = (void*)&ps->ir1;
ps->ir1.filebutton->func.user_callback = file_load_response;

ui->widget[0] = add_lv2_knob (ui->widget[0], ui->win, 2, "Input", ui, 35, 85, 100, 120);
ui->widget[0] = add_lv2_knob (ui->widget[0], ui->win, 2, "Input(A)", ui, 35, 90, 90, 110);
set_adjustment(ui->widget[0]->adj, 0.0, 0.0, -20.0, 20.0, 0.2, CL_CONTINUOS);
set_widget_color(ui->widget[0], 0, 0, 0.259, 0.518, 0.894, 1.0);
set_widget_color(ui->widget[0], 0, 3, 0.686, 0.729, 0.773, 1.0);

ui->widget[2] = add_lv2_knob (ui->widget[2], ui->win, 4, "Blend", ui, 135, 95, 80, 110);
ui->widget[7] = add_lv2_knob (ui->widget[7], ui->win, 11, "Input(B)", ui, 125, 90, 90, 110);
set_adjustment(ui->widget[7]->adj, 0.0, 0.0, -20.0, 20.0, 0.2, CL_CONTINUOS);
set_widget_color(ui->widget[7], 0, 0, 0.259, 0.518, 0.894, 1.0);
set_widget_color(ui->widget[7], 0, 3, 0.686, 0.729, 0.773, 1.0);

ui->widget[2] = add_lv2_knob (ui->widget[2], ui->win, 4, "Blend(A|B)", ui, 215, 90, 90, 110);
set_adjustment(ui->widget[2]->adj, 0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
set_widget_color(ui->widget[2], 0, 0, 0.259, 0.518, 0.894, 1.0);
set_widget_color(ui->widget[2], 0, 3, 0.686, 0.729, 0.773, 1.0);

ui->widget[4] = add_lv2_knob (ui->widget[4], ui->win, 8, "Delay", ui, 215, 100, 70, 105);
set_adjustment(ui->widget[4]->adj, 0.0, 0.0, 0.0, 4096.0, 16.0, CL_CONTINUOS);
ui->widget[4] = add_lv2_knob (ui->widget[4], ui->win, 8, "Delay(Δ)", ui, 305, 90, 90, 110);
set_adjustment(ui->widget[4]->adj, 0.0, 0.0, -4096.0, 4096.0, 16.0, CL_CONTINUOS);
set_widget_color(ui->widget[4], 0, 0, 0.259, 0.518, 0.894, 1.0);
set_widget_color(ui->widget[4], 0, 3, 0.686, 0.729, 0.773, 1.0);

ui->widget[3] = add_lv2_knob (ui->widget[3], ui->win, 7, "Mix (IR)", ui, 285, 95, 80, 110);
ui->widget[3] = add_lv2_knob (ui->widget[3], ui->win, 7, "Mix (IR)", ui, 395, 90, 90, 110);
set_adjustment(ui->widget[3]->adj, 0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
set_widget_color(ui->widget[3], 0, 0, 0.259, 0.518, 0.894, 1.0);
set_widget_color(ui->widget[3], 0, 3, 0.686, 0.729, 0.773, 1.0);

ui->widget[1] = add_lv2_knob (ui->widget[1], ui->win, 3, "Output ", ui, 365, 85, 100, 120);
ui->widget[1] = add_lv2_knob (ui->widget[1], ui->win, 3, "Output ", ui, 485, 90, 90, 110);
set_adjustment(ui->widget[1]->adj, 0.0, 0.0, -20.0, 20.0, 0.2, CL_CONTINUOS);
set_widget_color(ui->widget[1], 0, 0, 0.259, 0.518, 0.894, 1.0);
set_widget_color(ui->widget[1], 0, 3, 0.686, 0.729, 0.773, 1.0);

ps->ma.fbutton = add_lv2_button(ps->ma.fbutton, ui->win, "", ui, 435, 254, 22, 30);
ps->ma.fbutton = add_lv2_button(ps->ma.fbutton, ui->win, "", ui, 545, 244, 22, 30);
ps->ma.fbutton->parent_struct = (void*)&ps->ma;
combobox_set_pop_position(ps->ma.fbutton, 0);
combobox_add_entry(ps->ma.fbutton, "None");
ps->ma.fbutton->func.value_changed_callback = file_menu_callback;

ps->mb.fbutton = add_lv2_button(ps->mb.fbutton, ui->win, "", ui, 435, 294, 22, 30);
ps->mb.fbutton = add_lv2_button(ps->mb.fbutton, ui->win, "", ui, 545, 284, 22, 30);
ps->mb.fbutton->parent_struct = (void*)&ps->mb;
combobox_set_pop_position(ps->mb.fbutton, 0);
combobox_add_entry(ps->mb.fbutton, "None");
ps->mb.fbutton->func.value_changed_callback = file_menu_callback;

ps->ir.fbutton = add_lv2_button(ps->ir.fbutton, ui->win, "", ui, 435, 334, 22, 30);
ps->ir.fbutton = add_lv2_button(ps->ir.fbutton, ui->win, "", ui, 545, 324, 22, 30);
ps->ir.fbutton->parent_struct = (void*)&ps->ir;
combobox_set_pop_position(ps->ir.fbutton, 0);
combobox_add_entry(ps->ir.fbutton, "None");
ps->ir.fbutton->func.value_changed_callback = file_menu_callback;

ps->ir1.fbutton = add_lv2_button(ps->ir1.fbutton, ui->win, "", ui, 435, 374, 22, 30);
ps->ir1.fbutton = add_lv2_button(ps->ir1.fbutton, ui->win, "", ui, 545, 364, 22, 30);
ps->ir1.fbutton->parent_struct = (void*)&ps->ir1;
combobox_set_pop_position(ps->ir1.fbutton, 0);
combobox_add_entry(ps->ir1.fbutton, "None");
ps->ir1.fbutton->func.value_changed_callback = file_menu_callback;

ui->widget[5] = add_lv2_toggle_button (ui->widget[5], ui->win, 9, "", ui, 70, 338, 25, 25);
ui->widget[6] = add_lv2_toggle_button (ui->widget[6], ui->win, 10, "", ui, 70, 378, 25, 25);
ui->widget[5] = add_lv2_toggle_button (ui->widget[5], ui->win, 9, "", ui, 70, 328, 25, 25);
ui->widget[6] = add_lv2_toggle_button (ui->widget[6], ui->win, 10, "", ui, 70, 368, 25, 25);
}

void plugin_cleanup(X11_UI *ui) {
Expand Down
55 changes: 43 additions & 12 deletions Ratatouille/Ratatouille.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ class Xratatouille
float* input0;
float* output0;
float* _inputGain;
float* _inputGain1;
float* _outputGain;
float* _blend;
float* _mix;
float* _delay;
float* _bufb;
float* _normA;
float* _normB;
Expand All @@ -130,6 +132,7 @@ class Xratatouille
double fRec3[2];
double fRec2[2];
double fRec1[2];
double fRec4[2];
uint32_t bufsize;
uint32_t s_rate;
bool doit;
Expand Down Expand Up @@ -243,8 +246,13 @@ Xratatouille::Xratatouille() :
rt_policy(0),
input0(NULL),
output0(NULL),
_inputGain(0),
_inputGain1(0),
_outputGain(0),
_blend(0),
_mix(0),
_delay(0),
_bufb(0),
_normA(0),
_normB(0) {
xrworker.start();
Expand Down Expand Up @@ -321,6 +329,7 @@ void Xratatouille::init_dsp_(uint32_t rate)
for (int l0 = 0; l0 < 2; l0 = l0 + 1) fRec3[l0] = 0.0;
for (int l0 = 0; l0 < 2; l0 = l0 + 1) fRec2[l0] = 0.0;
for (int l0 = 0; l0 < 2; l0 = l0 + 1) fRec1[l0] = 0.0;
for (int l0 = 0; l0 < 2; l0 = l0 + 1) fRec4[l0] = 0.0;
}

// connect the Ports used by the plug-in class
Expand Down Expand Up @@ -352,12 +361,18 @@ void Xratatouille::connect_(uint32_t port,void* data)
case 7:
_mix = static_cast<float*>(data);
break;
case 8:
_delay = static_cast<float*>(data);
break;
case 9:
_normA = static_cast<float*>(data);
break;
case 10:
_normB = static_cast<float*>(data);
break;
case 11:
_inputGain1 = static_cast<float*>(data);
break;
default:
break;
}
Expand All @@ -370,8 +385,11 @@ void Xratatouille::activate_f()

void Xratatouille::clean_up()
{
for (int l0 = 0; l0 < 2; l0 = l0 + 1) fRec0[l0] = 0.0;
for (int l0 = 0; l0 < 2; l0 = l0 + 1) fRec3[l0] = 0.0;
for (int l0 = 0; l0 < 2; l0 = l0 + 1) fRec2[l0] = 0.0;
for (int l0 = 0; l0 < 2; l0 = l0 + 1) fRec1[l0] = 0.0;
for (int l0 = 0; l0 < 2; l0 = l0 + 1) fRec4[l0] = 0.0;
// delete the internal DSP mem
}

Expand Down Expand Up @@ -672,26 +690,41 @@ void Xratatouille::run_dsp_(uint32_t n_samples)

// get controller values from host
double fSlow0 = 0.0010000000000000009 * std::pow(1e+01, 0.05 * double(*(_inputGain)));
double fSlow4 = 0.0010000000000000009 * std::pow(1e+01, 0.05 * double(*(_inputGain1)));
double fSlow3 = 0.0010000000000000009 * std::pow(1e+01, 0.05 * double(*(_outputGain)));
double fSlow2 = 0.0010000000000000009 * double(*(_blend));
double fSlow1 = 0.0010000000000000009 * double(*(_mix));

if (_neuralA.load(std::memory_order_acquire) || _neuralB.load(std::memory_order_acquire)) {
// input volume
// internal buffer
float bufa[n_samples];
memcpy(bufa, output0, n_samples*sizeof(float));
float bufb[n_samples];
memcpy(bufb, output0, n_samples*sizeof(float));
bufsize = n_samples;

// process delta delay
if (*(_delay) < 0) cdelay->compute(n_samples, bufa, bufa);
else cdelay->compute(n_samples, bufb, bufb);

// process input volume slot A
if (_neuralA.load(std::memory_order_acquire)) {
for (int i0 = 0; i0 < n_samples; i0 = i0 + 1) {
fRec0[0] = fSlow0 + 0.999 * fRec0[1];
output0[i0] = float(double(output0[i0]) * fRec0[0]);
bufa[i0] = float(double(bufa[i0]) * fRec0[0]);
fRec0[1] = fRec0[0];
}
}

float bufa[n_samples];
memcpy(bufa, output0, n_samples*sizeof(float));
float bufb[n_samples];
memcpy(bufb, output0, n_samples*sizeof(float));
bufsize = n_samples;
// process input volume slot B
if (_neuralB.load(std::memory_order_acquire)) {
for (int i0 = 0; i0 < n_samples; i0 = i0 + 1) {
fRec4[0] = fSlow4 + 0.999 * fRec4[1];
bufb[i0] = float(double(bufb[i0]) * fRec4[0]);
fRec4[1] = fRec4[0];
}
}

// process slot B in parallel
// process slot B in parallel thread
_bufb = bufb;
if (_neuralB.load(std::memory_order_acquire) && pro.getProcess()) {
pro.setProcessor(0);
Expand All @@ -710,8 +743,6 @@ void Xratatouille::run_dsp_(uint32_t n_samples)
pro.processWait();
}

cdelay->compute(n_samples, bufb, bufb);

// mix output when needed
if (_neuralA.load(std::memory_order_acquire) && _neuralB.load(std::memory_order_acquire)) {
for (int i0 = 0; i0 < n_samples; i0 = i0 + 1) {
Expand Down Expand Up @@ -741,7 +772,7 @@ void Xratatouille::run_dsp_(uint32_t n_samples)
memcpy(bufa, output0, n_samples*sizeof(float));
memcpy(bufb, output0, n_samples*sizeof(float));

// process conv1 in parallel
// process conv1 in parallel thread
_bufb = bufb;
if (!_execute.load(std::memory_order_acquire) && conv1.is_runnable()) {
if (pro.getProcess()) {
Expand Down
11 changes: 10 additions & 1 deletion Ratatouille/Ratatouille.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ A Neural Model loader and mixer
lv2:name "Delay" ;
lv2:portProperty lv2:integer ;
lv2:default 0.000000 ;
lv2:minimum 0.000000 ;
lv2:minimum -4096.000000 ;
lv2:maximum 4096.000000 ;
], [
a lv2:InputPort ,
Expand All @@ -178,6 +178,15 @@ A Neural Model loader and mixer
lv2:default 0.0 ;
lv2:minimum 0.0 ;
lv2:maximum 1.0 ;
], [
a lv2:InputPort ,
lv2:ControlPort ;
lv2:index 11 ;
lv2:symbol "Knob5" ;
lv2:name "input1" ;
lv2:default 0.000000 ;
lv2:minimum -20.000000 ;
lv2:maximum 20.000000 ;
] .

<urn:brummer:ratatouille_ui>
Expand Down
2 changes: 1 addition & 1 deletion Ratatouille/cdelay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ inline void Dsp::init(uint32_t sample_rate)

void Dsp::compute(int count, float *input0, float *output0)
{
double fSlow0 = 0.0010000000000000009 * double(*(fHslider0_));
double fSlow0 = 0.0010000000000000009 * std::fabs(*(fHslider0_));
for (int i0 = 0; i0 < count; i0 = i0 + 1) {
double fTemp0 = double(input0[i0]);
fVec0[IOTA0 & 16383] = fTemp0;
Expand Down
Loading

0 comments on commit 2b94dfb

Please sign in to comment.