]> khamidou — GitHub mirrors - minisynth.git/commitdiff
added a slider. master
authorkarim hamidou <khamidou@gmail.com>
Wed, 5 Jun 2013 13:03:05 +0000 (15:03 +0200)
committerkarim hamidou <khamidou@gmail.com>
Wed, 5 Jun 2013 13:03:05 +0000 (15:03 +0200)
audio.html

index 8edd1b88576d98249c4a39f553458d212ed0a517..e1f3f186f864c4fe9ab2ecfe3ffaa0494d9b5a58 100644 (file)
         </div>
 
         <div data-role="content">
         </div>
 
         <div data-role="content">
+
+            <fieldset data-role="controlgroup" class="operators" data-type="horizontal">
+                    <legend>Carrier wave type:</legend>
+                    <input type="radio" id="op1" value="sin" />
+                    <label for="op1">Op 1</label>
+
+                    <input type="radio" id="op2" value="2sin" />
+                    <label for="op2">Op 2</label>
+            </fieldset>
+
             <label for="modfreq">Modulator frequency:</label>
             <input type="range" name="slider-1" id="modfreq" value="100" min="0" max="4000" />
             <label for="modfreq">Modulator frequency:</label>
             <input type="range" name="slider-1" id="modfreq" value="100" min="0" max="4000" />
+            <label for="modamp">Modulator amplitude:</label>
+            <input type="range" name="slider-2" id="modamp" value="10" min="0" max="100" />
+
 
             <a data-role="button" id="A4">A4</a> 
         </div>
 
             <a data-role="button" id="A4">A4</a> 
         </div>
 
             var ac = new AudioContext();
 
 
             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);
 
             function createNode(basefreq, phaseFreq, phaseIntensity) {
                 var node = ac.createScriptProcessor(256,1,1);
 
                     var n = 0;
 
                     for (var j=0; j< output.length; j++) {
                     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;
             }
 
                     }
                 }
 
                 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 = 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() { 
                     node.connect(ac.destination);
             });
             $("#A4").bind("vmouseup", function() { 
-                    if(typeof(node) != "undefined")
+                    if(typeof(node) != "undefined" && node != null) {
                         node.disconnect();
                         node.disconnect();
+                        node = null;
+                    }
             });
 
         });
             });
 
         });