Web/API/ScriptProcessorNode/audioprocess event

From Get docs

DeprecatedThis feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.


The audioprocess event of the ScriptProcessorNode interface is fired when an input buffer of a script processor is ready to be processed.

Bubbles No
Cancelable No
Default action None
Interface AudioProcessingEvent
Event handler property ScriptProcessorNode.onaudioprocess

Examples

scriptNode.addEventListener('audioprocess', function(audioProcessingEvent) {
  // The input buffer is a song we loaded earlier
  var inputBuffer = audioProcessingEvent.inputBuffer;

  // The output buffer contains the samples that will be modified and played
  var outputBuffer = audioProcessingEvent.outputBuffer;

  // Loop through the output channels (in this case there is only one)
  for (var channel = 0; channel < outputBuffer.numberOfChannels; channel++) {
    var inputData = inputBuffer.getChannelData(channel);
    var outputData = outputBuffer.getChannelData(channel);

    // Loop through the 4096 samples
    for (var sample = 0; sample < inputBuffer.length; sample++) {
      // make output equal to the same as the input
      outputData[sample] = inputData[sample];

      // add noise to each output sample
      outputData[sample] += ((Math.random() * 2) - 1) * 0.2;         
    }
  }
})

You could also set up the event handler using the ScriptProcessorNode.onaudioprocess property:

scriptNode.onaudioprocess = function(audioProcessingEvent) {
  ...
}

Specifications

Specification Status Comment
Web Audio APIThe definition of 'AudioProcessingEvent' in that specification. Working Draft  

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet

audioprocess event

Deprecated'

Chrome Full support 14

Prefixed'

Full support 14

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Edge

Full support 12

Firefox

Full support 25

IE

No support No

Opera Full support 22


Full support 22


Full support 15

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Safari Full support 6

Prefixed'

Full support 6

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support 25

Opera Android Full support 22


Full support 22


Full support 14

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Safari iOS Full support 6

Prefixed'

Full support 6

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Samsung Internet Android

Full support Yes

Legend

Full support  
Full support
No support  
No support
Deprecated. Not for use in new websites.'
Deprecated. Not for use in new websites.
Requires a vendor prefix or different name for use.'
Requires a vendor prefix or different name for use.


See also