From: karim hamidou Date: Wed, 5 Jun 2013 13:03:05 +0000 (+0200) Subject: added a slider. X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;ds=inline;p=minisynth.git added a slider. --- diff --git a/audio.html b/audio.html index 8edd1b8..e1f3f18 100644 --- a/audio.html +++ b/audio.html @@ -17,8 +17,21 @@
+ +
+ Carrier wave type: + + + + + +
+ + + + A4
@@ -33,6 +46,23 @@ var ac = new AudioContext(); + function operator1(j, basefreq, phaseIntensity, phaseFreq) { + return Math.sin(2*Math.PI * basefreq * j / 44100 + phaseIntensity * + Math.cos(2 * Math.PI * phaseFreq * j / 44100)); + } + + function operator2(j, basefreq, phaseIntensity, phaseFreq) { + /* // square wave */ + return Math.cos(2*Math.PI * basefreq * j / 44100 + phaseIntensity * + Math.cos(2 * Math.PI * phaseFreq * j / 44100)) + + Math.cos(2*Math.PI * 3 * basefreq * j / 44100 + phaseIntensity * + Math.cos(2 * Math.PI * phaseFreq * j / 44100)) + + Math.cos(2*Math.PI * 5 * basefreq * j / 44100 + phaseIntensity * + Math.cos(2 * Math.PI * phaseFreq * j / 44100)); + } + + + function createNode(basefreq, phaseFreq, phaseIntensity) { var node = ac.createScriptProcessor(256,1,1); @@ -42,31 +72,26 @@ var n = 0; for (var j=0; j< output.length; j++) { - v = Math.sin(2*Math.PI * basefreq * j / 44100 + phaseIntensity * - Math.cos(2 * Math.PI * phaseFreq * j / 44100)); - output[j] = v; + output[j] = operator2(j, basefreq, phaseIntensity, phaseFreq); } } return node; } - freqTable = { - "87" : "260", // C4, which is mapped to W - "83": "270", // C#4 - "88" : "290", // D4 - } - node = undefined; $("#A4").bind("vmousedown", function() { var modfreq = parseInt($("#modfreq").attr("value")); - node = createNode(440, modfreq, -1.5); + var modamp = parseInt($("#modamp").attr("value")); + node = createNode(880, modamp, modfreq); node.connect(ac.destination); }); $("#A4").bind("vmouseup", function() { - if(typeof(node) != "undefined") + if(typeof(node) != "undefined" && node != null) { node.disconnect(); + node = null; + } }); });