This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

createScriptProcessor

Summary

Creates a ScriptProcessorNode for direct audio processing using JavaScript. An exception will be thrown if bufferSize or numberOfInputChannels or numberOfOutputChannels are outside the valid range.

Method of apis/webaudio/AudioContextapis/webaudio/AudioContext

Syntax

var  = AudioContext.createScriptProcessor(bufferSize, numberOfInputChannels, numberOfOutputChannels);

Parameters

bufferSize

Data-type
unsigned long

Determines the buffer size in units of sample-frames. It must be one of the following values: 256, 512, 1024, 2048, 4096, 8192, 16384. This value controls how frequently the onaudioprocess event handler is called and how many sample-frames need to be processed each call. Lower values for bufferSize will result in a lower (better) latency. Higher values will be necessary to avoid audio breakup and glitches. The value chosen must carefully balance between latency and audio quality.

numberOfInputChannels

Data-type
unsigned long

(Optional)

Defaults to 2; determines the number of channels for this node’s input. Values of up to 32 must be supported.

numberOfOutputChannels

Data-type
unsigned long

(Optional)

Defaults to 2; determines the number of channels for this node’s output. Values of up to 32 must be supported.

Return Value

Returns an object of type

ScriptProcessorNode

Examples

var audioCtx = new AudioContext();
myScriptProcessor = audioCtx.createScriptProcessor(1024, 1, 1);

Related specifications

W3C Web Audio API
W3C Editor’s Draft