Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. AudioParam

AudioParam

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

* Some parts of this feature may have varying levels of support.

The Web Audio API'sAudioParam interface represents an audio-related parameter, usually a parameter of anAudioNode (such asGainNode.gain).

AnAudioParam 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.

EachAudioParam has a list of events, initially empty, that define when and how values change. When this list is not empty, changes using theAudioParam.value attributes are ignored. This list of events allows us to schedule changes that have to happen at very precise times, using arbitrary timeline-based automation curves. The time used is the one defined inAudioContext.currentTime.

AudioParam types

There are twoAudioParam kinds:a-rate andk-rate parameters. EachAudioNode defines which of its parameters area-rate ork-rate in the spec.

a-rate

Ana-rateAudioParam takes the current audio parameter value for eachsample frame of the audio signal.

k-rate

Ak-rateAudioParam uses the same initial audio parameter value for the whole block processed; that is, 128 sample frames. In other words, the same value applies to every frame in the audio as it's processed by the node.

Instance properties

AudioParam.defaultValueRead only

Represents the initial value of the attribute as defined by the specificAudioNode creating theAudioParam.

AudioParam.maxValueRead only

Represents the maximum possible value for the parameter's nominal (effective) range.

AudioParam.minValueRead only

Represents the minimum possible value for the parameter's nominal (effective) range.

AudioParam.value

Represents the parameter's current value as of the current time; initially set to the value ofdefaultValue.

Instance methods

AudioParam.setValueAtTime()

Schedules an instant change to the value of theAudioParam at a precise time, as measured againstAudioContext.currentTime. The new value is given by thevalue parameter.

AudioParam.linearRampToValueAtTime()

Schedules a gradual linear change in the value of theAudioParam. The change starts at the time specified for theprevious event, follows a linear ramp to the new value given in thevalue parameter, and reaches the new value at the time given in theendTime parameter.

AudioParam.exponentialRampToValueAtTime()

Schedules a gradual exponential change in the value of theAudioParam. The change starts at the time specified for theprevious event, follows an exponential ramp to the new value given in thevalue parameter, and reaches the new value at the time given in theendTime parameter.

AudioParam.setTargetAtTime()

Schedules the start of a change to the value of theAudioParam. The change starts at the time specified instartTime and exponentially moves towards the value given by thetarget parameter. The exponential decay rate is defined by thetimeConstant parameter, which is a time measured in seconds.

AudioParam.setValueCurveAtTime()

Schedules the values of theAudioParam to follow a set of values, defined by an array of floating-point numbers scaled to fit into the given interval, starting at a given start time and spanning a given duration of time.

AudioParam.cancelScheduledValues()

Cancels all scheduled future changes to theAudioParam.

AudioParam.cancelAndHoldAtTime()

Cancels all scheduled future changes to theAudioParam but holds its value at a given time until further changes are made using other methods.

Examples

First, a basic example showing aGainNode having itsgain value set.gain is an example of ana-rateAudioParam, as the value can potentially be set differently for each sample frame of the audio.

js
const audioCtx = new AudioContext();const gainNode = audioCtx.createGain();gainNode.gain.value = 0;

Next, an example showing aDynamicsCompressorNode having some param values manipulated. These are examples ofk-rateAudioParam types, as the values are set for the entire audio block at once.

js
const compressor = audioCtx.createDynamicsCompressor();compressor.threshold.setValueAtTime(-50, audioCtx.currentTime);compressor.knee.setValueAtTime(40, audioCtx.currentTime);compressor.ratio.setValueAtTime(12, audioCtx.currentTime);compressor.attack.setValueAtTime(0, audioCtx.currentTime);compressor.release.setValueAtTime(0.25, audioCtx.currentTime);

Specifications

Specification
Web Audio API
# AudioParam

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp