Old 09-04-2021, 01:48 PM   #1
fsynth
Human being with feelings
 
Join Date: Sep 2020
Posts: 119
Default Smooth a control automated by MIDI CC

Hello all

I found a simple volume JSfx that goes from -inf to 0dbfs, exactly what I need.
I would like to use as a real time volume pedal for guitar using a MIDI controller.
Only problem I am having is its stepped and clicks when controlled by a MIDI CC.
Is there any way to smooth the control internally in the code?

Any help would be greatly appreciated, below is the code for the plugin.


desc: volume reducer
slider1:1<0,1,0.0078125>adjustment
slider2:0.7<-1,1,0.1>curve

redraw = 1;

@slider
f = slider1;
k = pow(2, slider2*2);
gain = f ? pow(f, k) : 0;
redraw = 1;

@sample
spl0=spl0*gain;
spl1=spl1*gain;

@gfx 240 400
gfx_a = 1;
redraw ? (
MARGIN = 10;
NUMPOINTS = 128;
MARKSIZE = 6;
// Draw curve
gfx_r = gfx_b = 0; gfx_g = 1;
xdelta = (gfx_w - MARGIN*2)/NUMPOINTS;
gfx_x = MARGIN;
gfx_y = gfx_h - MARGIN;
i = 1;
loop(NUMPOINTS,
ff = pow((i/NUMPOINTS), k);
y = (1 - ff) * (gfx_h - MARGIN*2) + MARGIN;
gfx_lineto(gfx_x + xdelta, y, 1);
i += 1;
);
// Draw mark
gfx_r = gfx_b = gfx_g = 1; gfx_a = 0.9;
gfx_x = f * (gfx_w - MARGIN*2) + MARGIN - MARKSIZE/2;
gfx_y = (1 - gain) * (gfx_h - MARGIN*2) + MARGIN - MARKSIZE/2;
gfx_rectto(gfx_x + MARKSIZE, gfx_y + MARKSIZE);
// Print dB
gfx_r = gfx_b = 0; gfx_g = 1; gfx_a = 1;
gfx_x = MARGIN + 3;
gfx_y = gfx_texth + 3;
f ? (
db = k * log10(f) * 10;
db >= 0 ? gfx_drawchar($' ');
gfx_drawnumber(db, 1);
gfx_drawchar($' ');
gfx_drawchar($'d');
gfx_drawchar($'B');
) : (
gfx_drawchar($'-');
gfx_drawchar($'i');
gfx_drawchar($'n');
gfx_drawchar($'f');
);
// redraw = 0;
);
fsynth is offline   Reply With Quote
Old 09-07-2021, 08:32 AM   #2
fsynth
Human being with feelings
 
Join Date: Sep 2020
Posts: 119
Default

Ahhh! bummer no one can help?
I know a low pass filter with a very low frequency can smooth a control (BUT)
I have zero knowledge of DSP, used many times in SynthEdit to smooth a control.
But that was just wiring pre-built DSP modules.

HELP PLEASE
fsynth is offline   Reply With Quote
Old 09-14-2021, 10:41 PM   #3
Time Waster
Human being with feelings
 
Time Waster's Avatar
 
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 1,643
Default

If you start a new JSFX in a recent version of REAPER, the volume smoothing code is already there as the example code. The example smooths any change in a volume slider value over one block. You should be able to do something similar with a change in CC value. There many ways to do it but linear interpolation usually works OK. I suggest experimenting with how many samples over which you to smooth the change, as the fewer the better for latency.
__________________
Mal, aka The Wasters of Time
Mal's JSFX: ReaRack2 Modular Synth

Last edited by Time Waster; 09-14-2021 at 10:50 PM.
Time Waster is offline   Reply With Quote
Old 09-15-2021, 12:40 AM   #4
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,652
Default

Here's a verion with a simple 1st order low-pass filter as a smoother. I've also added @init, so the initial redraw = 1 is actually executed.

Code:
desc: volume reducer
slider1:1<0,1,0.0078125>adjustment
slider2:0.7<-1,1,0.1>curve

@init
redraw = 1;

smooth_time = 0.0165; // 16.5 ms
lp_coeff = 1 - exp(-5 / (smooth_time * srate));
lp_out = 1;

@slider
f = slider1;
k = pow(2, slider2*2);
gain = f ? pow(f, k) : 0;
redraw = 1;

@sample
lp_out += (gain - lp_out) * lp_coeff;
spl0=spl0*lp_out;
spl1=spl1*lp_out;

@gfx 240 400 
gfx_a = 1;
redraw ? (
MARGIN = 10;
NUMPOINTS = 128;
MARKSIZE = 6;
// Draw curve
gfx_r = gfx_b = 0; gfx_g = 1;
xdelta = (gfx_w - MARGIN*2)/NUMPOINTS;
gfx_x = MARGIN;
gfx_y = gfx_h - MARGIN;
i = 1;
loop(NUMPOINTS,
ff = pow((i/NUMPOINTS), k);
y = (1 - ff) * (gfx_h - MARGIN*2) + MARGIN;
gfx_lineto(gfx_x + xdelta, y, 1);
i += 1;
);
// Draw mark
gfx_r = gfx_b = gfx_g = 1; gfx_a = 0.9;
gfx_x = f * (gfx_w - MARGIN*2) + MARGIN - MARKSIZE/2;
gfx_y = (1 - gain) * (gfx_h - MARGIN*2) + MARGIN - MARKSIZE/2;
gfx_rectto(gfx_x + MARKSIZE, gfx_y + MARKSIZE);
// Print dB
gfx_r = gfx_b = 0; gfx_g = 1; gfx_a = 1;
gfx_x = MARGIN + 3;
gfx_y = gfx_texth + 3;
f ? (
db = k * log10(f) * 10;
db >= 0 ? gfx_drawchar($' ');
gfx_drawnumber(db, 1);
gfx_drawchar($' ');
gfx_drawchar($'d');
gfx_drawchar($'B');
) : (
gfx_drawchar($'-');
gfx_drawchar($'i');
gfx_drawchar($'n');
gfx_drawchar($'f');
);
// redraw = 0;
);
Tale is offline   Reply With Quote
Old 09-15-2021, 08:19 AM   #5
fsynth
Human being with feelings
 
Join Date: Sep 2020
Posts: 119
Default

Quote:
Originally Posted by Tale View Post
Here's a verion with a simple 1st order low-pass filter as a smoother. I've also added @init, so the initial redraw = 1 is actually executed.

Code:
desc: volume reducer
slider1:1<0,1,0.0078125>adjustment
slider2:0.7<-1,1,0.1>curve

@init
redraw = 1;

smooth_time = 0.0165; // 16.5 ms
lp_coeff = 1 - exp(-5 / (smooth_time * srate));
lp_out = 1;

@slider
f = slider1;
k = pow(2, slider2*2);
gain = f ? pow(f, k) : 0;
redraw = 1;

@sample
lp_out += (gain - lp_out) * lp_coeff;
spl0=spl0*lp_out;
spl1=spl1*lp_out;

@gfx 240 400 
gfx_a = 1;
redraw ? (
MARGIN = 10;
NUMPOINTS = 128;
MARKSIZE = 6;
// Draw curve
gfx_r = gfx_b = 0; gfx_g = 1;
xdelta = (gfx_w - MARGIN*2)/NUMPOINTS;
gfx_x = MARGIN;
gfx_y = gfx_h - MARGIN;
i = 1;
loop(NUMPOINTS,
ff = pow((i/NUMPOINTS), k);
y = (1 - ff) * (gfx_h - MARGIN*2) + MARGIN;
gfx_lineto(gfx_x + xdelta, y, 1);
i += 1;
);
// Draw mark
gfx_r = gfx_b = gfx_g = 1; gfx_a = 0.9;
gfx_x = f * (gfx_w - MARGIN*2) + MARGIN - MARKSIZE/2;
gfx_y = (1 - gain) * (gfx_h - MARGIN*2) + MARGIN - MARKSIZE/2;
gfx_rectto(gfx_x + MARKSIZE, gfx_y + MARKSIZE);
// Print dB
gfx_r = gfx_b = 0; gfx_g = 1; gfx_a = 1;
gfx_x = MARGIN + 3;
gfx_y = gfx_texth + 3;
f ? (
db = k * log10(f) * 10;
db >= 0 ? gfx_drawchar($' ');
gfx_drawnumber(db, 1);
gfx_drawchar($' ');
gfx_drawchar($'d');
gfx_drawchar($'B');
) : (
gfx_drawchar($'-');
gfx_drawchar($'i');
gfx_drawchar($'n');
gfx_drawchar($'f');
);
// redraw = 0;
);
Thank you so much for taking the time to help.
I really need to spend some time to understand DSP and JsFx.
Using this in a RPi4 so can not use a non ARM VST.
Can't wait until the work day is done so I can install.

Again Thank you for the time and help.
fsynth is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 11:34 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.