From 1d6759b13545cceea79800b560d6d4219ef3730f Mon Sep 17 00:00:00 2001 From: Leonard Tirulnikov Date: Sat, 9 Jul 2011 17:11:45 -0400 Subject: [PATCH] Can now change frequency while sample is playing without stutter --- dsp.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dsp.js b/dsp.js index bfee29d..20d28cf 100644 --- a/dsp.js +++ b/dsp.js @@ -935,8 +935,10 @@ Sampler.prototype.generate = function() { }; Sampler.prototype.setFreq = function(frequency) { - this.frequency = frequency; - this.step = this.frequency / this.rootFrequency; + var totalProcessed = this.samplesProcessed * this.step; + this.frequency = frequency; + this.step = this.frequency / this.rootFrequency; + this.samplesProcessed = Math.round(totalProcessed/this.step); }; Sampler.prototype.reset = function() {