W3C home > Mailing lists > Public > public-audio@w3.org > July to September 2013

ScriptProcessorNode behavior without JavsScript references

From: Raymond Toy <rtoy@google.com>
Date: Tue, 17 Sep 2013 13:48:57 -0700
Message-ID: <CAE3TgXHEE3YYbDw6i02Dm0LsbVgrCFO_BRBn_3OdY7OxCUW+Zg@mail.gmail.com>
To: "public-audio@w3.org" <public-audio@w3.org>
Let's say you create a ScriptProcessorNode and set the onaudioprocess to
generate, say, a sine wave.  Something like the script below.

In this case, all Javascript references to the ScriptProcessorNode and the
corresponding onaudioprocess function are dropped.

What should happen now?  Should you still hear the sine wave?

--
Ray

Sample code:

var MyClass = function () {
  var mAudioContext;

  var mPhase = 0;

  var generateTimeSlice = function (leftBuf, rightBuf) {
    var bufLen = leftBuf.length;
    for (var k = 0; k < bufLen; k++) {
      leftBuf[k] = Math.sin(mPhase);
      rightBuf[k] = Math.sin(mPhase * 1.01);
      mPhase += 0.02;
    }
  };

  this.init = function () {
    mAudioContext = new AudioContext();
    var scriptNode = mAudioContext.createScriptProcessor(4096, 0, 2);
    scriptNode.onaudioprocess = function (event) {
      var leftBuf = event.outputBuffer.getChannelData(0);
      var rightBuf = event.outputBuffer.getChannelData(1);
      generateTimeSlice(leftBuf, rightBuf);
    };

    scriptNode.connect(mAudioContext.destination);
  };
};

var gMyClass = new MyClass();
gMyClass.init();
Received on Tuesday, 17 September 2013 20:49:25 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:50:11 UTC