ScriptProcessorNode

备注: 这个特性在 2014 年 8 月 29 日发布的 Web Audio API 规范中已经标记为不推荐,将很快会被Audio Workers代替。

ScriptProcessorNode 接口允许使用 JavaScript 生成、处理、分析音频。它是一个 AudioNode,连接着两个缓冲区音频处理模块,其中一个缓冲区包含输入音频数据,另外一个包含处理后的输出音频数据。实现了 AudioProcessingEvent (en-US) 接口的一个事件,每当输入缓冲区有新的数据时,事件将被发送到该对象,并且事件将在数据填充到输出缓冲区后结束。

The ScriptProcessorNode stores the input in a buffer, send the audioprocess event. The EventHandler takes the input buffer and fill the output buffer which is sent to the output by the ScriptProcessorNode.

输入和输出缓冲区大小在创建时定义,当 AudioContext.createScriptProcessor() 方法被调用时 (都是由 AudioContext.createScriptProcessor()bufferSize 参数定义). 缓冲区大小必须是在 25616384 之间的 2 的次幂,为 256, 512, 1024, 2048, 4096, 8192 或者 16384. Small numbers lower the latency, but large number may be necessary to avoid audio breakup and glitches.

If the buffer size is not defined, which is recommended, the browser will pick one that its heuristic deems appropriate.

Number of inputs 1
Number of outputs 1
Channel count mode "max"
Channel count 2 (not used in the default count mode)
Channel interpretation "speakers"

属性

从上一级继承属性,AudioNode

ScriptProcessorNode.bufferSize (en-US) 只读

返回一个表示输入和输出缓冲区大小的整数。它的值可以是在25616384 之间的 2 的次幂。

事件句柄

ScriptProcessorNode.onaudioprocess (en-US)

Represents the event handler to be called.

方法

No specific methods; inherits methods from its parent, AudioNode.

示例

参见 BaseAudioContext.createScriptProcessor() 以获取示例代码。

规范

自 2014 年 8 月 29 日 Web Audio API 规范发布以来,此特性已被弃用。它不再有望成为标准。

它已被 AudioWorklet (en-US)AudioWorkletNode 接口所取代。

浏览器兼容性

BCD tables only load in the browser

参见