From dd3d52c1f6e690673ed0f3668647cdc9163f5d6c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 23 Nov 2017 17:08:11 +0100 Subject: [PATCH] ramp to values to avoid audio glitches --- nanofun.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/nanofun.js b/nanofun.js index bde7c13..b8dcaf9 100644 --- a/nanofun.js +++ b/nanofun.js @@ -416,7 +416,8 @@ var nanofun = function() { $('#master-gain').on('change', function() { var fraction = parseInt(this.value) / parseInt(127); - self.masterGainNode.gain.value = fraction * fraction; + var now = self.audioCtx.currentTime; + self.masterGainNode.gain.exponentialRampToValueAtTime(fraction * fraction, now + 0.015); }); $('#delay').on('change', function() { @@ -424,13 +425,15 @@ var nanofun = function() { if (value == 0) { self.delay.disconnect(); } else { - self.delay.delayTime.value = value; + var now = self.audioCtx.currentTime; + self.delay.delayTime.exponentialRampToValueAtTime(value, now + 0.015); self.delay.connect(self.audioCtx.destination); } }); $('#feedback').on('change', function() { - self.feedback.gain.value = this.value; + var now = self.audioCtx.currentTime; + self.feedback.gain.exponentialRampToValueAtTime(this.value, now + 0.015); }); $('#filter').on('change', function() { @@ -440,7 +443,8 @@ var nanofun = function() { $('.touch-gain').on('change', function() { var fraction = parseInt(this.value) / parseInt(127); var touchIdx = parseInt($(this).parent().data('touch')); - self.touchGainNodes[touchIdx].gain.value = fraction * fraction; + var now = self.audioCtx.currentTime; + self.touchGainNodes[touchIdx].gain.exponentialRampToValueAtTime(fraction * fraction, now + 0.015); }); self.time_interval_id = setInterval(function() { -- 2.39.2