(function ()
{
  var onDOMContentLoaded = function ()
  {
    window.AudioContext = window.AudioContext || window.webkitAudioContext;
    var context = new AudioContext();
    context.createScriptProcessor = context.createScriptProcessor || context.createJavaScriptNode;
    var processor = context.createScriptProcessor(4096, 1, 1);

    var osc = context.createOscillator();
    osc.start = osc.start || osc.noteOn;
    osc.stop = osc.stop || osc.noteOff;
    osc.connect(processor);
    processor.connect(context.destination);
    osc.start(0);

    var volume = 0.3;
    processor.onaudioprocess = function (event)
    {
        var inputBuffer = event.inputBuffer;
        var outputBuffer = event.outputBuffer;
		console.log(context.sampleRate);

        for (var channel = 0; channel < outputBuffer.numberOfChannels; channel++)
        {
            var input  = event.inputBuffer.getChannelData(channel);
            var output = event.outputBuffer.getChannelData(channel);
            for (var sample_i=0; sample_i<this.bufferSize; sample_i++)
            {
                output[sample_i] = volume * (Math.random() - 0.5);
            }
        }
    }
  }

  if ((document.readyState === "interactive") || (document.readyState === "complete"))
  {
      onDOMContentLoaded();
  }
  else
  {
      document.addEventListener("DOMContentLoaded", onDOMContentLoaded, true);
  }

})();

@@ -554,22 +554,75 @@
 var 
-volume = 0.3;%0A
+main = function ()%0A    %7B%0A%09  var oscillator = genOscillator(440);%0A  
     
@@ -673,54 +673,11 @@
     
-%7B%0A        var inputBuffer = event.inputBuffer;
+  %7B
 %0A   
@@ -724,44 +724,8 @@
 er;%0A
-%09%09console.log(context.sampleRate);%0A%0A
     
@@ -816,76 +816,8 @@
   %7B%0A
-            var input  = event.inputBuffer.getChannelData(channel);%0A
     
@@ -906,26 +906,20 @@
 var 
-sample_i=0; sample
+buf_i=0; buf
 _i%3Ct
@@ -934,22 +934,19 @@
 erSize; 
-sample
+buf
 _i++)%0A  
@@ -984,81 +984,359 @@
 put%5B
-sample_i%5D = volume * (Math.random() - 0.5);%0A            %7D%0A        %7D%0A    %7D
+buf_i%5D = oscillator();%0A            %7D%0A        %7D%0A      %7D%0A    %7D%0A%0A%09var genOscillator = function (freq)%0A%09%7B%0A%09%09var dt = 1.0 / context.sampleRate;%0A%09%09var k = 2.0 * Math.PI * freq;%0A%09%09var T = 1.0 / freq;%0A%09%09var t = 0.0;%0A%0A%09%09var _oscillator = function ()%0A%09%09%7B%0A%09%09%09var ret = (Math.random() - 0.5); // %5B-0.5:0.5)%0A%09%09%09return ret;%0A%09%09%7D%0A%09%09return _oscillator;%0A%09%7D%0A%0A    main();
 %0A  %7D
@@ -1557,12 +1557,13 @@
 %0A  %7D%0A%0A%7D)();%0A
+%0A

improve sample1