title: Making an impulse with a JavaScriptNode (Web Audio API)
body: <p>I'm working with the Web Audio API, and I'm trying to make a JavaScriptNode that outputs an impulse.  That is, I want a node that will output a 1 followed by a whole bunch of zeros, and nothing else.</p>
  
  <p>I thought the code below would be a sensible way to do this.  I initialize a variable called "timeForAnImpulse" to true and use this variable to trigger an impulsive output on the audio callback.  In the callback, I then set "timeForAnImpulse" to false.</p>
  
  <p>This seems like it should work, but it doesn't.  Instead of a single impulse, I get an impulse train (a 1 at the start of each buffer). Any idea what I'm doing wrong?</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  window.onload = init;
  
      function impulseNodeCB(evt){
  
          if(timeForAnImpulse){
              var buf = evt.outputBuffer.getChannelData(0);
              buf[0] = 1;
              timeForAnImpulse = false;
          }
      }
  
      var timeForAnImpulse = true;
  
      function init() {
          var context = new webkitAudioContext();
          impulseNode = context.createJavaScriptNode(2048,0,1);
          impulseNode.onaudioprocess = impulseNodeCB;
          impulseNode.connect(context.destination);   
      }
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  </code></pre>