mozilla

Revision 469143 of AudioBuffer

  • Revision slug: Web/API/AudioBuffer
  • Revision title: AudioBuffer
  • Revision id: 469143
  • Created:
  • Creator: tregagnon
  • Is current revision? No
  • Comment

Revision Content

{{WebAudioRef}}

{{SeeCompatTable}}

The AudioBuffer interface represents an audio asset residing in memory. The buffer contains data in the following format:  non-interleaved IEEE 32-bit linear PCM with a nominal range between -1 and +1. It may contain several channels.

Objects of these types are designed to hold small audio snippets, typically less than 45s. For longer sounds, objects implementing the {{domxref("MediaAudioElementSourceNode")}} are more suitable.

Properties

{{domxref("AudioBuffer.sampleRate")}} {{readonlyInline}}
Returns a float representing the sample rate, samples per second, of the PCM data stored in the buffer.
{{domxref("AudioBuffer.length")}} {{readonlyInline}}
Returns an integer representing the length, in sample-frames, of the PCM data stored in the buffer.
{{domxref("AudioBuffer.duration")}} {{readonlyInline}}
Returns a double representing the duration, in seconds, of the PCM data stored in the buffer.
{{domxref("AudioBuffer.numberOfChannels")}} {{readonlyInline}}
Returns an integer representing the number of discrete audio channels described by the PCM data stored in the buffer.

Methods

{{domxref("AudioBuffer.getChannelData()")}}
Returns a {{domxref("Float32Array")}} containing the PCM data associated with the channel, defined by the channel parameter (with 0 representing the first channel). If channel is greater or equal to AudioBuffer.numberOfChannels, an exception is raised.

Examples

 

Specifications

Specification Status Comment
{{SpecName('Web Audio API', '#AudioBuffer-section', 'AudioBuffer')}} {{Spec2('Web Audio API')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatVersionUnknown}}{{property_prefix("webkit")}} Activated on Nightly only {{CompatNo}} {{CompatNo}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatNo}} Activated on Nightly only {{CompatNo}} {{CompatNo}} {{CompatUnknown}}

See also

  • Using Web Audio

Revision Source

<p>{{WebAudioRef}}</p>
<p>{{SeeCompatTable}}</p>
<p>The <code><strong>AudioBuffer</strong></code> interface represents an audio asset residing in memory. The buffer contains data in the following format:&nbsp; non-interleaved IEEE 32-bit linear PCM with a nominal range between -1 and +1. It may contain several channels.</p>
<p>Objects of these types are designed to hold small audio snippets, typically less than 45s. For longer sounds, objects implementing the {{domxref("MediaAudioElementSourceNode")}} are more suitable.</p>
<h2 id="Properties">Properties</h2>
<dl>
  <dt>
    {{domxref("AudioBuffer.sampleRate")}} {{readonlyInline}}</dt>
  <dd>
    Returns a float representing the sample rate, samples per second, of the PCM data stored in the buffer.</dd>
  <dt>
    {{domxref("AudioBuffer.length")}} {{readonlyInline}}</dt>
  <dd>
    Returns an integer representing the length, in sample-frames, of the PCM data stored in the buffer.</dd>
  <dt>
    {{domxref("AudioBuffer.duration")}} {{readonlyInline}}</dt>
  <dd>
    Returns a double representing the duration, in seconds, of the PCM data stored in the buffer.</dd>
  <dt>
    {{domxref("AudioBuffer.numberOfChannels")}} {{readonlyInline}}</dt>
  <dd>
    Returns an integer representing the number of discrete audio channels described by the PCM data stored in the buffer.</dd>
</dl>
<h2 id="Methods">Methods</h2>
<dl>
  <dt>
    {{domxref("AudioBuffer.getChannelData()")}}</dt>
  <dd>
    Returns a {{domxref("Float32Array")}} containing the PCM data associated with the channel, defined by the <code>channel</code> parameter (with 0 representing the first channel). If <code>channel</code> is greater or equal to <code>AudioBuffer.numberOfChannels,</code> an exception is raised.</dd>
</dl>
<h2 id="Examples">Examples</h2>
<p>&nbsp;</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', '#AudioBuffer-section', 'AudioBuffer')}}</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>{{CompatVersionUnknown}}{{property_prefix("webkit")}}</td>
        <td>Activated on Nightly only</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatUnknown}}</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>IE Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatNo}}</td>
        <td>Activated on Nightly only</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
  <li>Using Web Audio</li>
</ul>
Revert to this revision