Web-audio-api: ScriptProcessor node does not work if output is not connected

Created on 25 Jul 2014  路  8Comments  路  Source: WebAudio/web-audio-api

I've found this issue in the Chromium bugs, but couldn't find a reference to it here.

I'm not sure if this is the official bug list for Web Audio and/or the specification, but it would be valuable to be able to act on the data from a ScriptProcessorNode without needing to pipe it to a destination node, and I did not see the issue on this list yet.

Currently, setting the numberOfOutputChannels to 0 when creating the node and not connecting it to a destination causes it to not raise events or pipe audio:

var context = new AudioContext();
var processor = context.createScriptProcessor(4096, 1, 0);
var source;

// event is never raised
processor.onaudioprocess = function(e) {
  console.log('Processing audio');
};

navigator.webkitGetUserMedia({audio: true},
  function(stream) {
    source = context.createMediaStreamSource(stream);
    source.connect(processor);
    // only functions with code below, when processor is created as: createScriptProcessor(4096, 1, 1)
    // processor.connect(context.destination);
  },  
  function() {
    console.error('Failed to instantiate audio stream.');
  }
);

Does anyone know if this is planned for the future, or already known?


_I'm working in Chrome 36.0.1985.125 (Official Build 283153) on a Mac OS X_

Most helpful comment

Here is the fix:

MicTest.prototype = {
  run: function() {
    if (typeof audioContext === 'undefined') {
      this.test.reportError('WebAudio is not supported, test cannot run.');
      this.test.done();
    } else {

      // https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#webaudio
      // https://github.com/webrtc/testrtc/issues/267
      // https://github.com/WebAudio/web-audio-api/issues/345
      console.log('audioContext.state', audioContext.state);
      if (audioContext.state === 'suspended') {
          audioContext.resume();
      }

      doGetUserMedia(this.constraints, this.gotStream.bind(this));
    }
  },

All 8 comments

This is a Chrome/Blink/Webkit bug, not a spec issue. It should work as you describe.

Is this Chrome/Blink/Webkit bug tracked somewhere, @cwilso? I am still seeing this behavior in Chrome 57. Have to hook up a destination in order for the scriptProcessor to be triggered. Weird for audio input analysis use cases.

Thanks, starred.

Yes - see first line of the OP. https://bugs.chromium.org/p/chromium/issues/detail?id=327649

It has been a long time. Anyone know how to nofity the chromium team to fix? Very much thanks.

This will not be fixed - the chromium team stated in the issue that ScriptProcessor is now deprecated. See comment 15 on the chromium issue.

See also the somewhat related issue #1578

Here is the fix:

MicTest.prototype = {
  run: function() {
    if (typeof audioContext === 'undefined') {
      this.test.reportError('WebAudio is not supported, test cannot run.');
      this.test.done();
    } else {

      // https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#webaudio
      // https://github.com/webrtc/testrtc/issues/267
      // https://github.com/WebAudio/web-audio-api/issues/345
      console.log('audioContext.state', audioContext.state);
      if (audioContext.state === 'suspended') {
          audioContext.resume();
      }

      doGetUserMedia(this.constraints, this.gotStream.bind(this));
    }
  },
Was this page helpful?
0 / 5 - 0 ratings

Related issues

echolevel picture echolevel  路  7Comments

rickygraham picture rickygraham  路  10Comments

olivierthereaux picture olivierthereaux  路  20Comments

mounirlamouri picture mounirlamouri  路  10Comments

cyrta picture cyrta  路  17Comments