Thread: Mute JS
View Single Post
Old 07-27-2015, 08:04 PM   #8
SaulT
Human being with feelings
 
Join Date: Oct 2013
Location: Seattle, WA
Posts: 819
Default

Huh.... smoothing, you say?

Not perfect, but it works, with variable fade in/fade out times.

Code:
desc:mute
slider1:0<0,1,1{mute off,mute on}>mute
slider2:10<1,500,1>fade in
slider3:10<1,500,1>fade out

@init
function singlepole(in,target,coeff) ( in*coeff + target*(1-coeff); );
gain = state = target_gain = slider1;


@slider
fade_in = exp(-1/(slider2/1000*srate));
fade_out = exp(-1/(slider3/1000*srate));

state = slider1;
state != ostate ? (

  state > ostate ? (
    target_gain = slider1;
    cur_coeff = fade_in;
    );

  state < ostate ? (
    target_gain = slider1;
    cur_coeff = fade_out;
    );
  );

ostate = state;

@sample
gain = vol.singlepole(gain,target_gain,cur_coeff);

spl0 *= gain;
spl1 *= gain;
SaulT is offline   Reply With Quote