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 649251 of AudioParam

  • Revision slug: Web/API/AudioParam
  • Revision title: AudioParam
  • Revision id: 649251
  • Created:
  • Creator: chrisdavidmills
  • Is current revision? No
  • Comment

Revision Content

{{APIRef()}}

The AudioParam interface represents an audio-related parameter, usually a parameter of an {{domxref("AudioNode")}} (such as {{ domxref("GainNode.gain") }}). An AudioParam can be set to a specific value or a change in value, and can be scheduled to happen at a specific time and following a specific pattern.

There are two kinds of AudioParam, a-rate and k-rate parameters:

  • An a-rate AudioParam takes the current audio parameter value for each sample frame of the audio signal.
  • A k-rate AudioParam uses the same initial audio parameter value for the whole block processed, that is 128 sample frames.

Each {{domxref("AudioNode")}} defines which of its parameters are a-rate or k-rate in the spec.

Each AudioParam has a list of events, initially empty, that define when and how values change. When this list is not empty, changes using the AudioParam.value attributes are ignored. This list of events allows us to schedule changes that have to happen at very precise times, using arbitrary timelime-based automation curves. The time used is the one defined in {{domxref("AudioContext.currentTime")}}.

Properties

AudioParam Inherits properties from its parent, AudioNode.

{{domxref("AudioParam.value")}}
Represents the parameter's current floating point value; initially set to the value of AudioParam.defaultValue. Though it can be set, any modifications happening while there are automation events scheduled — that is events scheduled using the methods of the AudioParam — are ignored, without raising any exception.
{{domxref("AudioParam.defaultValue")}} {{readonlyInline}}
Represents the initial value of the attributes as defined by the specific {{domxref("AudioNode")}} creating the AudioParam.

Methods

AudioParam Inherits methods from its parent, AudioNode.

{{domxref("AudioParam.setValueAtTime()")}}
Schedules an instant change to the value of the AudioParam at a precise time, as measured against {{domxref("AudioContext.currentTime")}}. The new value is given in the value parameter.
{{domxref("AudioParam.linearRampToValueAtTime()")}}
Schedules a gradual linear change in the value of the AudioParam. The change starts at the time specified for the previous event, follows a linear ramp to the new value given in the value parameter, and reaches the new value at the time given in the endTime parameter.
{{domxref("AudioParam.exponentialRampToValueAtTime()")}}
Schedules a gradual exponential change in the value of the AudioParam. The change starts at the time specified for the previous event, follows an exponential ramp to the new value given in the value parameter, and reaches the new value at the time given in the endTime parameter.
{{domxref("AudioParam.setTargetAtTime()")}}
Schedules the start of a change to the value of the AudioParam. The change starts at the time specified in startTime and exponentially moves towards the value given by the target parameter. The exponential decay rate is defined by the timeConstant parameter.
{{domxref("AudioParam.setValueCurveAtTime()")}}
Schedules the values of the AudioParam to follow a set of values, defined by the values {{domxref("Float32Array")}} scaled to fit into the given interval, starting at startTime, and having a specific duration.
{{domxref("AudioParam.cancelScheduledValues()")}}
Cancels all scheduled future changes to the AudioParam.

Examples

First, a basic example showing a {{domxref("GainNode")}} having its gain value set. gain is an example of an a-rate AudioParam, as the value can potentially be set differently for each sample frame of the audio.

var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioContext();

var gainNode = audioCtx.createGain();
gainNode.gain.value = 0;

Next, an example showing a {{ domxref("BiquadFilterNode") }} having some values set. These are examples of k-rate AudioParam's, as the values are set for the entire audio block at once.

var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioContext();

var biquadFilter = audioCtx.createBiquadFilter();

biquadFilter.type = "lowshelf";
biquadFilter.frequency.value = 1000;
biquadFilter.gain.value = 25;

Specifications

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

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 14 {{property_prefix("webkit")}} 23 {{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")}} 25 1.2 {{CompatNo}} {{CompatNo}} 6 {{property_prefix("webkit")}}

See also

Revision Source

<p>{{APIRef()}}</p>
<div class="summary">
 <p>The <code>AudioParam</code> interface represents an audio-related parameter, usually a parameter of an {{domxref("AudioNode")}} (such as {{ domxref("GainNode.gain") }}). An <code>AudioParam</code> can be set to a specific value or a change in value, and can be scheduled to happen at a specific time and following a specific pattern.</p>
</div>
<p>There are two kinds of <code>AudioParam</code>, <em>a-rate</em> and <em>k-rate</em> parameters:</p>
<ul>
 <li id="a-rate">An <em>a-rate</em> <code>AudioParam</code> takes the current audio parameter value for each <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API#Audio_buffers.3A_frames.2C_samples_and_channels">sample frame</a> of the audio signal.</li>
 <li id="k-rate">A <em>k-rate</em> <code>AudioParam</code> uses the same initial audio parameter value for the whole block processed, that is 128 sample frames.</li>
</ul>
<p>Each {{domxref("AudioNode")}} defines which of its parameters are <em>a-rate</em> or <em>k-rate</em> in the spec.</p>
<p>Each <code>AudioParam</code> has a list of events, initially empty, that define when and how values change. When this list is not empty, changes using the <code>AudioParam.value</code> attributes are ignored. This list of events allows us to schedule changes that have to happen at very precise times, using arbitrary timelime-based automation curves. The time used is the one defined in {{domxref("AudioContext.currentTime")}}.</p>
<h2 id="Properties">Properties</h2>
<p><code>AudioParam</code><em> Inherits properties from its parent, </em><code>AudioNode</code>.</p>
<dl>
 <dt>
  {{domxref("AudioParam.value")}}</dt>
 <dd>
  Represents the parameter's current floating point value; initially set to the value of <code>AudioParam.defaultValue</code>. Though it can be set, any modifications happening while there are automation events scheduled — that is events scheduled using the methods of the <code>AudioParam</code> — are ignored, without raising any exception.</dd>
 <dt>
  {{domxref("AudioParam.defaultValue")}} {{readonlyInline}}</dt>
 <dd>
  Represents the initial value of the attributes as defined by the specific {{domxref("AudioNode")}} creating the <code>AudioParam</code>.</dd>
</dl>
<h2 id="Methods">Methods</h2>
<p>AudioParam<em> Inherits methods from its parent, </em><code>AudioNode</code>.</p>
<dl>
 <dt>
  {{domxref("AudioParam.setValueAtTime()")}}</dt>
 <dd>
  Schedules an instant change to the value of the <code>AudioParam</code> at a precise time, as measured against {{domxref("AudioContext.currentTime")}}. The new value is given in the <code>value</code> parameter.</dd>
 <dt>
  {{domxref("AudioParam.linearRampToValueAtTime()")}}</dt>
 <dd>
  Schedules a gradual linear change in the value of the <code>AudioParam</code>. The change starts at the time specified for the <em>previous</em> event, follows a linear ramp to the new value given in the <code>value</code> parameter, and reaches the new value at the time given in the <code>endTime</code> parameter.</dd>
 <dt>
  {{domxref("AudioParam.exponentialRampToValueAtTime()")}}</dt>
 <dd>
  Schedules a gradual exponential change in the value of the <code>AudioParam</code>. The change starts at the time specified for the <em>previous</em> event, follows an exponential ramp to the new value given in the <code>value</code> parameter, and reaches the new value at the time given in the <code>endTime</code> parameter.</dd>
 <dt>
  {{domxref("AudioParam.setTargetAtTime()")}}</dt>
 <dd>
  Schedules the start of a change to the value of the <code>AudioParam</code>. The change starts at the time specified in <code>startTime</code> and exponentially moves towards the value given by the <code>target</code> parameter. The exponential decay rate is defined by the <code>timeConstant</code> parameter.</dd>
 <dt>
  {{domxref("AudioParam.setValueCurveAtTime()")}}</dt>
 <dd>
  Schedules the values of the <code>AudioParam</code> to follow a set of values, defined by the <code>values</code> {{domxref("Float32Array")}} scaled to fit into the given interval, starting at <code>startTime</code>, and having a specific <code>duration</code>.</dd>
 <dt>
  {{domxref("AudioParam.cancelScheduledValues()")}}</dt>
 <dd>
  Cancels all scheduled future changes to the <code>AudioParam</code>.</dd>
</dl>
<h2 id="Examples">Examples</h2>
<p>First, a basic example showing a {{domxref("GainNode")}} having its <code>gain</code> value set. <code>gain</code> is an example of an a-rate AudioParam, as the value can potentially be set differently for each sample frame of the audio.</p>
<pre class="brush: js;highlight[5]">
var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioContext();

var gainNode = audioCtx.createGain();
gainNode.gain.value = 0;</pre>
<p>Next, an example showing a {{ domxref("BiquadFilterNode") }} having some values set. These are examples of k-rate AudioParam's, as the values are set for the entire audio block at once.</p>
<pre class="brush: js;highlight[6,7,8]">
var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioContext();

var biquadFilter = audioCtx.createBiquadFilter();

biquadFilter.type = "lowshelf";
biquadFilter.frequency.value = 1000;
biquadFilter.gain.value = 25;</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-audioparam-interface', 'AudioParam')}}</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>23</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>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_Audio_API/Using_Web_Audio_API">Using the Web Audio API</a></li>
</ul>
Revert to this revision