Skip to main content

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

The above method schedules an instant change to the value at given startTime.

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

Errors:

Error typeDescription
RangeErrorstartTime is negative number.

Returns AudioParam.

linearRampToValueAtTime

The above method 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.

ParametersTypeDescription
valuenumberA float representing the value the AudioParam will ramp to by given time.
endTimenumberThe time, in seconds, at which the value ramp will end.

Errors

Error typeDescription
RangeErrorendTime is negative number.

Returns AudioParam.

exponentialRampToValueAtTime

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

ParametersTypeDescription
valuenumberA float representing the value the AudioParam will ramp to by given time.
endTimenumberThe time, in seconds, at which the value ramp will end.

Errors

Error typeDescription
RangeErrorendTime is negative number.

Returns AudioParam.

setTargetAtTime

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

ParametersTypeDescription
targetnumberA float representing the value to which the AudioParam will start transitioning.
startTimenumberThe time, in seconds, at which exponential transition will begin.
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.

Returns AudioParam.

setValueCurveAtTime

The above method schedules the parameters's value change following a curve defined by given array.

ParametersTypeDescription
valuesFloat32ArrayThe array of values defining a curve, which change will follow.
startTimenumberThe time, in seconds, at which change will begin.
durationnumberA double representing total time over which the change will happen.

Errors

Error typeDescription
RangeErrorstartTime is negative number.

Returns AudioParam.

cancelScheduledValues

The above method cancels all scheduled changes after given cancel time.

ParametersTypeDescription
cancelTimenumberThe time, in seconds, after which all scheduled changes will be cancelled.

Errors

Error typeDescription
RangeErrorcancelTime is negative number.

Returns AudioParam.

cancelAndHoldAtTime

The above method cancels all scheduled changes after given cancel time, but holds its value at given cancel time until further changes appear.

ParametersTypeDescription
cancelTimenumberThe time, in seconds, after which all scheduled changes will be cancelled.

Errors

Error typeDescription
RangeErrorcancelTime is negative number.

Returns AudioParam.

Remarks

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