Skip to main content
Version: Latest

AudioParam

The AudioParam interface represents audio-related parameter (such as gain property of GainNode`). It can be set to specific value or schedule value change to happen at specific time, and following specific pattern.

a-rate vs k-rate​

  • a-rate - takes the current audio parameter value for each sample frame of the audio signal.
  • k-rate - uses the same initial audio parameter value for the whole block processed.

Properties​

NameTypeDescription
defaultValuenumberInitial value of the parameter.
Read only
minValuenumberMinimum possible value of the parameter.
Read only
maxValuenumberMaximum possible value of the parameter.
Read only
valuenumberCurrent value of the parameter. Initially set to defaultValue.

Methods​

setValueAtTime​

Schedules an instant change to the value at given startTime.

caution

If you need to call this function many times (especially more than 31 times), it is recommended to use the methods described below (such as linearRampToValueAtTime or exponentialRampToValueAtTime), as they are more efficient for continuous changes. For more specific use cases, you can schedule multiple value changes using setValueCurveAtTime.

ParameterTypeDescription
valuenumberA float representing the value the AudioParam will be set at given time
startTimenumberThe time, in seconds, at which the change in value is going to happen. If it's smaller than currentTime, it will be clamped to currentTime.

Errors:​

Error typeDescription
RangeErrorstartTime is negative number.
NotSupportedErrorstartTime falls within the interval [T,T+D)[T, T+D) where TT is the time of previously scheduled setValueCurveAtTime event and DD is its duration.

Returns AudioParam.​

linearRampToValueAtTime​

Schedules a gradual linear change to the new value. The change begins at the time designated for the previous event. It follows a linear ramp to the value, achieving it by the specified endTime.

ParameterTypeDescription
valuenumberA float representing the value, the AudioParam will ramp to by given time.
endTimenumberThe time, in seconds, at which the value ramp will end. If it's smaller than currentTime, it will be clamped to currentTime.

Errors​

Error typeDescription
RangeErrorendTime is negative number.
NotSupportedErrorendTime falls within the interval [T,T+D)[T, T+D) where TT is the time of previously scheduled setValueCurveAtTime event and DD is its duration.

Returns AudioParam.​

exponentialRampToValueAtTime​

Schedules a gradual exponential change to the new value. The change begins at the time designated for the previous event. It follows an exponential ramp to the value, achieving it by the specified endTime.

ParameterTypeDescription
valuenumberA float representing the value the AudioParam will ramp to by given time.
endTimenumberThe time, in seconds, at which the value ramp will end. If it's smaller than currentTime, it will be clamped to currentTime.

Errors​

Error typeDescription
RangeErrorendTime is negative number.
NotSupportedErrorendTime falls within the interval [T,T+D)[T, T+D) where TT is the time of previously scheduled setValueCurveAtTime event and DD is its duration.

Returns AudioParam.​

setTargetAtTime​

Schedules a gradual change to the new value at the start time. This method is useful for decay or release portions of ADSR envelopes.

ParameterTypeDescription
targetnumberA float representing the value to which the AudioParam will start transitioning.
startTimenumberThe time, in seconds, at which exponential transition will begin. If it's smaller than currentTime, it will be clamped to currentTime.
timeConstantnumberA double representing the time-constant value of an exponential approach to the target.

Errors​

Error typeDescription
RangeErrorstartTime is negative number.
RangeErrortimeConstant is negative number.
NotSupportedErrorstartTime falls within the interval [T,T+D)[T, T+D) where TT is the time of previously scheduled setValueCurveAtTime event and DD is its duration.

Returns AudioParam.​

setValueCurveAtTime​

Schedules the parameters's value change following a curve defined by given array.

ParameterTypeDescription
valuesFloat32ArrayThe array of values defining a curve, which change will follow.
startTimenumberThe time, in seconds, at which change will begin. If it's smaller than currentTime, it will be clamped to currentTime.
durationnumberA double representing total time over which the change will happen.

Errors​

Error typeDescription
RangeErrorstartTime is negative number.
NotSupportedErrorthere are already scheduled events that fall within the interval (T,T+D)(T, T+D) where TT is the startTime and DD is the duration.

Returns AudioParam.​

cancelScheduledValues​

Cancels all scheduled changes after given cancel time.

ParameterTypeDescription
cancelTimenumberThe time, in seconds, after which all scheduled changes will be cancelled. If it's smaller than currentTime, it will be clamped to currentTime.

Errors​

Error typeDescription
RangeErrorcancelTime is negative number.

Returns AudioParam.​

cancelAndHoldAtTime​

Cancels all scheduled changes after given cancel time, but holds its value at given cancel time until further changes appear.

ParameterTypeDescription
cancelTimenumberThe time, in seconds, after which all scheduled changes will be cancelled. If it's smaller than currentTime, it will be clamped to currentTime.

Errors​

Error typeDescription
RangeErrorcancelTime is negative number.

Returns AudioParam.​

Remarks​

All time parameters should be in the same time coordinate system as BaseAudioContext.currentTime.