envelope-generator
envelope-generator copied to clipboard
Clicks when starting the envelope
I'm getting clicks at the start of every sound. This is the code I'm using atm, on Firefox 49.0, OS X (El Capitan).
var cumT = this.audioCtx.currentTime;
var oscillator = this.audioCtx.createOscillator();
oscillator.type = 'sine';
oscillator.frequency.value = this.wave.frequency;
var gain = this.audioCtx.createGain();
var volume = this.audioCtx.createGain();
oscillator.connect(gain);
gain.connect(volume);
volume.gain.value = 0.5;
volume.connect(this.audioCtx.destination);
oscillator.start(cumT);
var stopAt = cumT;
for (var t = 0; t < timings.length; t += 1) {
var duration = timings[t] / 1000;
if (duration > 0) {
// oscillator.connect(this.audioCtx.destination);
var env = new Envelope(this.audioCtx, {
// curve: "exponential",
attackTime: 0.03,
// decayTime: 1.0,
sustainLevel: 1.0,
releaseTime: 0.03,
startLevel: 0.0
});
gain.gain.value = 0;
env.connect(gain.gain);
gain.gain.value = 0;
env.start(cumT);
cumT += duration;
// oscillator.stop(cumT);
env.release(cumT);
stopAt = env.getReleaseCompleteTime();
env.stop(stopAt);
} else {
cumT += -duration;
}
}
oscillator.stop(stopAt);
Any idea how to solve this?