gibber-cc / gibberish

Fast, JavaScript DSP library that creates JIT optimized audio callbacks using code generation techniques
387 stars 35 forks source link

Changing amplitude of Sine produces click #10

Closed hamoid closed 7 years ago

hamoid commented 8 years ago

Hi! Trying to create a multilaptop piece using gibberish here :)

I'm wondering what's the right way to change the volume of a playing Sine to avoid clicks. I noticed that if I update the volume every 5ms on steps of 0.001 it does not produce clicks, but it takes forever to fade the amplitude to the new desired value. If I the jump is too large it clicks.

How could I create a sample accurate value interpolator to achieve this? This way I could say .interpolateToAmp(0.8, 100), to go to amplitude 0.8 in 100 samples. Thank you!

charlieroberts commented 8 years ago

Hello! If you look at the examples on the homepage (http://www.charlie-roberts.com/gibberish) there's one called "lineTest" which shows the basic idea (assign a Line object to frequency) . There are also some other ugens that don't currently have tests. You can look at https://github.com/charlieroberts/Gibberish/blob/master/scripts/envelopes.js to see what's available. I'd experiment with using Ease or Curve if you don't want linear interpolation.

Hope this helps! - Charlie

hamoid commented 8 years ago

Thanks! I had not understood the use of retrigger. So I believe I just need to do this, right?

// start at volume 0
line = new Gibberish.Line(0, 0);
a = new Gibberish.Sine(991, line).connect();

// when pressing the mouse, ramp up the volume to 1.0
line.retrigger(1.0, 44100);

// when releasing the mouse, ramp down the volume 0.0
line.retrigger(0.0, 44100);

The group performance with 11 laptops went well, I'll share documentation :)

charlieroberts commented 7 years ago

Long over due closing of comment... would still love to see any documentation of that performance that you might have!