Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 930593 of ScriptProcessorNode

  • Revision slug: Web/API/ScriptProcessorNode
  • Revision title: ScriptProcessorNode
  • Revision id: 930593
  • Created:
  • Creator: Sebastianz
  • Is current revision? No
  • Comment Replaced list for properties by table (bug 1212752)

Revision Content

{{APIRef("Web Audio API")}}

Note: As of the August 29 2014 Web Audio API spec publication, this feature has been marked as deprecated, and is soon to be replaced by Audio Workers.

The ScriptProcessorNode interface allows the generation, processing, or analyzing of audio using JavaScript. It is an {{domxref("AudioNode")}} audio-processing module that is linked to two buffers, one containing the input audio data, one containing the processed output audio data. An event, implementing the {{domxref("AudioProcessingEvent")}} interface, is sent to the object each time the input buffer contains new data, and the event handler terminates when it has filled the output buffer with data.

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.

The size of the input and output buffer are defined at the creation time, when the {{domxref("AudioContext.createScriptProcessor()")}} method is called (both are defined by {{domxref("AudioContext.createScriptProcessor()")}}'s bufferSize parameter). The buffer size must be a power of 2 between 256 and 16384, that is 256, 512, 1024, 2048, 4096, 8192 or 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"

Properties

Inherits properties from its parent, {{domxref("AudioNode")}}.

{{domxref("ScriptProcessorNode.bufferSize")}} {{readonlyInline}}
Returns an integer representing both the input and output buffer size. Its value can be a power of 2 value in the range 25616384.

Event handlers

{{domxref("ScriptProcessorNode.onaudioprocess")}}
Represents the {{domxref("EventHandler")}} to be called.

Methods

No specific methods; inherits methods from its parent, {{domxref("AudioNode")}}.

Example

{{page("/en-US/docs/Web/API/AudioContext.createScriptProcessor","Example")}}

Specifications

Specification Status Comment
{{SpecName('Web Audio API', '#the-scriptprocessornode-interface---deprecated', 'ScriptProcessorNode')}} {{Spec2('Web Audio API')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 14 {{property_prefix("webkit")}} {{CompatGeckoDesktop(25)}} {{CompatNo}} 15 {{property_prefix("webkit")}}
22 (unprefixed)
6 {{property_prefix("webkit")}}
Feature Android Chrome Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support {{CompatNo}} 28 {{property_prefix("webkit")}} {{CompatGeckoMobile(25)}} 1.2 {{CompatNo}} {{CompatNo}} 6 {{property_prefix("webkit")}}

See also

Revision Source

<p>{{APIRef("Web Audio API")}}</p>

<div class="note">
<p><strong>Note</strong>: As of the August 29 2014 Web Audio API spec publication, this feature has been marked as deprecated, and is soon to be replaced by <a href="/en-US/docs/Web/API/Web_Audio_API#Audio_Workers">Audio Workers</a>.</p>
</div>

<div>
<p>The <code>ScriptProcessorNode</code> interface allows the generation, processing, or analyzing of audio using JavaScript. It is an {{domxref("AudioNode")}} audio-processing module that is linked to two buffers, one containing the input audio data, one containing the processed output audio data. An event, implementing the {{domxref("AudioProcessingEvent")}} interface, is sent to the object each time the input buffer contains new data, and the event handler terminates when it has filled the output buffer with data.</p>
</div>

<p><img alt="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." src="https://mdn.mozillademos.org/files/5157/WebAudioScriptProcessingNode.png" style="display:block; height:174px; margin:0px auto; width:306px" /></p>

<p>The size of the input and output buffer are defined at the creation time, when the {{domxref("AudioContext.createScriptProcessor()")}} method is called (both are defined by {{domxref("AudioContext.createScriptProcessor()")}}'s <code>bufferSize</code> parameter). The buffer size must be a power of 2 between <code>256</code> and <code>16384</code>, that is <code>256</code>, <code>512</code>, <code>1024</code>, <code>2048</code>, <code>4096</code>, <code>8192</code> or <code>16384</code>. Small numbers lower the <em>latency</em>, but large number may be necessary to avoid audio breakup and glitches.</p>

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

<table class="properties">
 <tbody>
  <tr>
   <th scope="row">Number of inputs</th>
   <td><code>1</code></td>
  </tr>
  <tr>
   <th scope="row">Number of outputs</th>
   <td><code>1</code></td>
  </tr>
  <tr>
   <th scope="row">Channel count mode</th>
   <td><code>"max"</code></td>
  </tr>
  <tr>
   <th scope="row">Channel count</th>
   <td><code>2</code> (not used in the default count mode)</td>
  </tr>
  <tr>
   <th scope="row">Channel interpretation</th>
   <td><code>"speakers"</code></td>
  </tr>
 </tbody>
</table>

<h2 id="Properties">Properties</h2>

<p><em>Inherits properties from its parent, </em><em>{{domxref("AudioNode")}}</em>.</p>

<dl>
 <dt>{{domxref("ScriptProcessorNode.bufferSize")}} {{readonlyInline}}</dt>
 <dd>Returns an integer representing both the input and output buffer size. Its value can be a power of 2 value in the range <code>256</code>–<code>16384</code>.</dd>
</dl>

<h3 id="Event_handlers">Event handlers</h3>

<dl>
 <dt>{{domxref("ScriptProcessorNode.onaudioprocess")}}</dt>
 <dd>Represents the {{domxref("EventHandler")}} to be called.</dd>
</dl>

<h2 id="Methods">Methods</h2>

<p><em>No specific methods; inherits methods from its parent, </em><em>{{domxref("AudioNode")}}</em>.</p>

<h2 id="Example">Example</h2>

<p>{{page("/en-US/docs/Web/API/AudioContext.createScriptProcessor","Example")}}</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Web Audio API', '#the-scriptprocessornode-interface---deprecated', 'ScriptProcessorNode')}}</td>
   <td>{{Spec2('Web Audio API')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>14 {{property_prefix("webkit")}}</td>
   <td>{{CompatGeckoDesktop(25)}}</td>
   <td>{{CompatNo}}</td>
   <td>15&nbsp;{{property_prefix("webkit")}}<br />
    22 (unprefixed)</td>
   <td>6 {{property_prefix("webkit")}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Firefox OS</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>28&nbsp;{{property_prefix("webkit")}}</td>
   <td>{{CompatGeckoMobile(25)}}</td>
   <td>1.2</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>6&nbsp;{{property_prefix("webkit")}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/Web_Audio_API/Using_Web_Audio_API">Using the Web Audio API</a></li>
</ul>
Revert to this revision