JavaScriptNode Tone Generation

Hi Chris Rogers,

Digging a little deeper into the Web Audio spec here to build a few tests.
Enjoying the API so far, it feels nice to work with. It also seems pretty
glitch free (only tried OSX).

I have two questions:

1) Can I download a Linux version from anywhere yet to test? (even if it is
not release-ready)

2) Is there a better way generate simple tones from JavaScript than the
following method?

  var context = new webkitAudioContext(),
    ptr = 0,
    jsProc = context.createJavaScriptNode( 2048 );

  jsProc.onaudioprocess = function( e ){
var outl = event.outputBuffer.getChannelData(0),
  outr = event.outputBuffer.getChannelData(1),
  n = e.inputBuffer.getChannelData(0).length;
 for (var i = 0; i < n; ++i) {
          outl[i] = Math.sin((i+ptr)/40);
          outr[i] = Math.sin((i+ptr)/40);


  var source = context.createBufferSource();
  source.connect( jsProc );
  jsProc.connect( context.destination );

This seems to work, but I am unsure whether this is the ideal method for
generating a simple tone with JavaScript? I'm asking because it feels a
little odd to be using an event from a silent stream to generate the data.

Perhaps I should be thinking of this event as the point in time where the
audio engine calls for the mixing down all buffers connected to the
context.destination, rather than thinking of it as new data being available
to the stream?

-- Alistair

Received on Thursday, 21 April 2011 22:32:59 UTC