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 666121 of AudioNode

  • Revision slug: Web/API/AudioNode
  • Revision title: AudioNode
  • Revision id: 666121
  • Created:
  • Creator: padenot
  • Is current revision? No
  • Comment

Revision Content

{{APIRef()}}

The AudioNode interface is a generic interface for representing an audio processing module like an audio source (e.g. an HTML {{HTMLElement("audio")}} or {{HTMLElement("video")}} element, an {{domxref("OscillatorNode")}}, etc.), the audio destination, intermediate processing module (e.g. a filter like {{domxref("BiquadFilterNode")}} or {{domxref("ConvolverNode")}}), or volume control (like {{domxref("GainNode")}}).

AudioNodes participating in an AudioContext create a audio routing graph.

An AudioNode has inputs and outputs, each with a given amount of channels. An AudioNode with zero inputs and one or multiple outputs is called a source node. The exactly processing done varies from one AudioNode to another but, in general, a node reads its inputs, does some audio-related processing, and generates new values for its outputs, or simply lets the audio passes through (for example in the {{domxref("AnalyserNode")}}, where the result of the processing is accessed separatly).

Different nodes can be linked together to build a processing graph. Such a graph is contained in an {{domxref("AudioContext")}}. Each AudioNode participates in exactly one such context. In general, processing nodes inherit the properties and methods of AudioNode, but also define their own functionality on top. See the individual node pages for more details, as listed on the Web Audio API homepage.

Note: An AudioNode can be target of events, therefore it implements the {{domxref("EventTarget")}} interface.

Properties

{{domxref("AudioNode.context")}} {{readonlyInline}}
Returns the associated {{domxref("AudioContext")}}, that is the object representing the processing graph the node is participating in.
{{domxref("AudioNode.numberOfInputs")}} {{readonlyInline}}
Returns the number of inputs feeding the node. Source nodes are defined as nodes having a numberOfInputs property with a value of 0.
{{domxref("AudioNode.numberOfOutputs")}} {{readonlyInline}}
Returns the number of outputs coming out of the node. Destination nodes — like {{ domxref("AudioDestinationNode") }} — have a value of 0 for this attribute.
{{domxref("AudioNode.channelCount")}}
Represents an integer used to determine how many channels are used when up-mixing and down-mixing connections to any inputs to the node. Its usage and precise definition depend on the value of {{domxref("AudioNode.channelCountMode")}}.
{{domxref("AudioNode.channelCountMode")}}
Represents an enumerated value describing the way channels must be matched between the node's inputs and outputs.
{{domxref("AudioNode.channelInterpretation")}}
Represents an enumerated value describing the meaning of the channels. This interpretation will define how audio up-mixing and down-mixing will happen.
The possible values are "speakers" or "discrete".

Methods

Also implements methods from the interface {{domxref("EventTarget")}}.

{{domxref("AudioNode.connect(AudioNode)")}}
Allows us to connect one output of this node to one input of another node.
{{domxref("AudioNode.connect(AudioParam)")}}
Allows us to connect one output of this node to one input of an audio parameter.
{{domxref("AudioNode.disconnect()")}}
Allows us to disconnect the current node from another one it is already connected to.

Example

This simple snippet of code shows the creation of some audio nodes, and how the AudioNode properties and methods can be used. You can find examples of such usage on any of the examples linked to on the Web Audio API landing page (for example Violent Theremin.)

var AudioContext = window.AudioContext || window.webkitAudioContext;

var audioCtx = new AudioContext();

var oscillator = audioCtx.createOscillator();
var gainNode = audioCtx.createGain();

oscillator.connect(gainNode);
gainNode.connect(audioCtx.destination);

oscillator.context;
oscillator.numberOfInputs;
oscillator.numberOfOutputs;
oscillator.channelCount;

Specifications

Specification Status Comment
{{SpecName('Web Audio API', '#the-audionode-interface', 'AudioNode')}} {{Spec2('Web Audio API')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatChrome(10.0)}}{{property_prefix("webkit")}} {{CompatGeckoDesktop(25.0)}} {{CompatNo}} 15.0{{property_prefix("webkit")}}
22 (unprefixed)
{{CompatVersionUnknown}}
channelCount channelCountMode {{CompatVersionUnknown}} {{property_prefix("webkit")}} {{CompatVersionUnknown}} {{CompatNo}} {{CompatVersionUnknown}} {{CompatNo}}
connect(AudioParam) {{CompatVersionUnknown}} {{property_prefix("webkit")}} {{CompatVersionUnknown}} {{CompatNo}} {{CompatVersionUnknown}} {{CompatNo}}
Feature Android Firefox Mobile (Gecko) Firefox OS (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} 25.0 1.2 {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
channelCount
channelCountMode
{{CompatNo}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
connect(AudioParam) {{CompatNo}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatNo}} {{CompatNo}} {{CompatNo}}

See also

Revision Source

<p>{{APIRef()}}</p>
<p>The <code>AudioNode</code> interface is a generic interface for representing an audio processing module like an audio source (e.g. an HTML {{HTMLElement("audio")}} or {{HTMLElement("video")}} element, an {{domxref("OscillatorNode")}}, etc.), the audio destination, intermediate processing module (e.g. a filter like {{domxref("BiquadFilterNode")}} or {{domxref("ConvolverNode")}}), or volume control (like {{domxref("GainNode")}}).</p>
<p><img alt="AudioNodes participating in an AudioContext create a audio routing graph." src="https://mdn.mozillademos.org/files/5081/WebAudioBasics.png" style="width: 355px; height: 260px; display: block; margin: 0px auto;" /></p>
<p>An <code>AudioNode</code> has inputs and outputs, each with a given amount of <em>channels</em>.<em> </em>An <code>AudioNode</code> with zero inputs and one or multiple outputs is called a <em>source node</em>. The exactly processing done varies from one <code>AudioNode</code> to another but, in general, a node reads its inputs, does some audio-related processing, and generates new values for its outputs, or simply lets the audio passes through (for example in the {{domxref("AnalyserNode")}}, where the result of the processing is accessed separatly).</p>
<p>Different nodes can be linked together to build a <em>processing graph</em>. Such a graph is contained in an {{domxref("AudioContext")}}. Each <code>AudioNode</code> participates in exactly one such context. In general, processing nodes inherit the properties and methods of <code>AudioNode</code>, but also define their own functionality on top. See the individual node pages for more details, as listed on the <a href="/en-US/docs/Web/API/Web_Audio_API">Web Audio API</a> homepage.</p>
<div class="note">
 <p><strong>Note</strong>: An <code>AudioNode</code> can be target of events, therefore it implements the {{domxref("EventTarget")}} interface.</p>
</div>
<h2 id="Properties" style="clear:both">Properties</h2>
<dl>
 <dt>
  {{domxref("AudioNode.context")}} {{readonlyInline}}</dt>
 <dd>
  Returns the associated {{domxref("AudioContext")}}, that is the object representing the processing graph the node is participating in.</dd>
</dl>
<dl>
 <dt>
  {{domxref("AudioNode.numberOfInputs")}} {{readonlyInline}}</dt>
 <dd>
  Returns the number of inputs feeding the node. Source nodes are defined as nodes having a <code>numberOfInputs</code> property with a value of <code>0</code>.</dd>
</dl>
<dl>
 <dt>
  {{domxref("AudioNode.numberOfOutputs")}} {{readonlyInline}}</dt>
 <dd>
  Returns the number of outputs coming out of the node. Destination nodes — like {{ domxref("AudioDestinationNode") }} — have a value of <code>0</code> for this attribute.</dd>
</dl>
<dl>
 <dt>
  {{domxref("AudioNode.channelCount")}}</dt>
 <dd>
  Represents an integer used to determine how many channels are used when <a href="/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API#Up-mixing_and_down-mixing">up-mixing and down-mixing</a> connections to any inputs to the node. Its usage and precise definition depend on the value of {{domxref("AudioNode.channelCountMode")}}.</dd>
</dl>
<dl>
 <dt>
  {{domxref("AudioNode.channelCountMode")}}</dt>
 <dd>
  Represents an enumerated value describing the way channels must be matched between the node's inputs and outputs.</dd>
 <dt>
  {{domxref("AudioNode.channelInterpretation")}}</dt>
 <dd>
  Represents an enumerated value describing the meaning of the channels. This interpretation will define how audio <a href="/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API#Up-mixing_and_down-mixing">up-mixing and down-mixing</a> will happen.<br />
  The possible values are <code>"speakers"</code> or <code>"discrete"</code>.</dd>
</dl>
<h2 id="Methods">Methods</h2>
<p><em>Also implements methods from the interface </em>{{domxref("EventTarget")}}.</p>
<dl>
 <dt>
  {{domxref("AudioNode.connect(AudioNode)")}}</dt>
 <dd>
  Allows us to connect one output of this node to one input of another node.</dd>
 <dt>
  {{domxref("AudioNode.connect(AudioParam)")}}</dt>
 <dd>
  Allows us to connect one output of this node to one input of an audio parameter.</dd>
 <dt>
  {{domxref("AudioNode.disconnect()")}}</dt>
 <dd>
  Allows us to disconnect the current node from another one it is already connected to.</dd>
</dl>
<h2 id="Example">Example</h2>
<p>This simple snippet of code shows the creation of some audio nodes, and how the <code>AudioNode</code> properties and methods can be used. You can find examples of such usage on any of the examples linked to on the <a href="/en-US/docs/Web/API/Web_Audio_API">Web Audio API</a> landing page (for example <a href="https://github.com/mdn/violent-theremin">Violent Theremin</a>.)<span class="p"> </span></p>
<pre class="brush: js;highlight[8,9,11,12,13,14]">
var AudioContext = window.AudioContext || window.webkitAudioContext;

var audioCtx = new AudioContext();

var oscillator = audioCtx.createOscillator();
var gainNode = audioCtx.createGain();

oscillator.connect(gainNode);
gainNode.connect(audioCtx.destination);

oscillator.context;
oscillator.numberOfInputs;
oscillator.numberOfOutputs;
oscillator.channelCount;</pre>
<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-audionode-interface', 'AudioNode')}}</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>{{CompatChrome(10.0)}}{{property_prefix("webkit")}}</td>
    <td>{{CompatGeckoDesktop(25.0)}}</td>
    <td>{{CompatNo}}</td>
    <td>15.0{{property_prefix("webkit")}}<br />
     22 (unprefixed)</td>
    <td>{{CompatVersionUnknown}}</td>
   </tr>
   <tr>
    <td><code>channelCount</code> <code>channelCountMode</code></td>
    <td>{{CompatVersionUnknown}} {{property_prefix("webkit")}}</td>
    <td>{{CompatVersionUnknown}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatVersionUnknown}}</td>
    <td>{{CompatNo}}</td>
   </tr>
   <tr>
    <td><code>connect</code><code>(AudioParam)</code></td>
    <td>{{CompatVersionUnknown}} {{property_prefix("webkit")}}</td>
    <td>{{CompatVersionUnknown}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatVersionUnknown}}</td>
    <td>{{CompatNo}}</td>
   </tr>
  </tbody>
 </table>
</div>
<div id="compat-mobile">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Android</th>
    <th>Firefox Mobile (Gecko)</th>
    <th>Firefox OS (Gecko)</th>
    <th>IE Phone</th>
    <th>Opera Mobile</th>
    <th>Safari Mobile</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>{{CompatUnknown}}</td>
    <td>25.0</td>
    <td>1.2</td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
   </tr>
   <tr>
    <td><code>channelCount</code><br />
     <code>channelCountMode</code></td>
    <td>{{CompatNo}}</td>
    <td>{{CompatVersionUnknown}}</td>
    <td>{{CompatVersionUnknown}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
   </tr>
   <tr>
    <td><code>connect</code><code>(AudioParam)</code></td>
    <td>{{CompatNo}}</td>
    <td>{{CompatVersionUnknown}}</td>
    <td>{{CompatVersionUnknown}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</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