var audio = new AudioContext || new webkitAudioContext;

function startTone(audio, freq, type, stop) {
  var osc = audio.createOscillator();
  var gain = audio.createGain();
  var time = audio.currentTime;

  if (freq) {
    osc.frequency.setValueAtTime(freq, time);
  }
  else {
    var freq = osc.frequency.value;
  }

  if (type) {
    osc.type = type;
  }
  else {
    var type = osc.type;
  }

  var gainMod;
  switch (type) {
    case 'sine': gainMod = 2; break;
    case 'triangle': gainMod = 2; break;
    case 'sawtooth': gainMod = 4; break;
    case 'square': gainMod = 5; break;
  }

  gain.connect(audio.destination);
  osc.connect(gain);

  gain.gain.setValueAtTime(0, time);
  gain.gain.linearRampToValueAtTime(Math.pow(1.05, freq / -20) / gainMod, time + 0.01);
  osc.start(time);

  if (stop) {
    gain.gain.linearRampToValueAtTime(0, time + stop);
    osc.stop(time + stop);
  }
  else {
    return { osc: osc, gain: gain };
  }
}

@@ -444,33 +444,44 @@
 ine': gainMod = 
-2
+stop ? 2 : 4
 ; break;%0A    cas
@@ -504,17 +504,28 @@
 inMod = 
-2
+stop ? 2 : 5
 ; break;
@@ -556,17 +556,29 @@
 inMod = 
-4
+stop ? 5 : 20
 ; break;
@@ -607,17 +607,29 @@
 inMod = 
-5
+stop ? 6 : 22
 ; break;
@@ -941,24 +941,24 @@
  %7D%0A  else %7B%0A
-
     return %7B
@@ -988,8 +988,365 @@
 ;%0A  %7D%0A%7D%0A
+%0Afunction stopTone(audio, tone) %7B%0A  var time = audio.currentTime;%0A%0A  if (tone instanceof Array) %7B%0A    for (var i = 0; i %3C tone.length; i++) %7B%0A      tone%5Bi%5D.gain.gain.linearRampToValueAtTime(0, time + 0.2);%0A      tone%5Bi%5D.osc.stop(time + 0.2);%0A    %7D%0A  %7D%0A  else %7B%0A    tone.gain.gain.linearRampToValueAtTime(0, time + 0.2);%0A    tone.osc.stop(time + 0.2);%0A  %7D%0A%7D%0A

Add stopTone for stopping playing oscillators