Class AudioParam
A value of an AudioNode that can be scheduled ahead of time and modulated
by other nodes, the Web Audio AudioParam.
The value at any moment is the automation timeline (or the default value
when nothing is scheduled), plus the sum of every node output connected to
the parameter with AudioNode.connect(AudioParam), clamped to
getMinValue() and getMaxValue(). Scheduling methods return the
parameter so calls can be chained:
OfflineAudioContext audio = new OfflineAudioContext(2, 44100, 44100);
GainNode gain = audio.createGain();
double now = audio.getCurrentTime();
gain.getGain().setValueAtTime(0, now)
.linearRampToValueAtTime(1, now + 0.05)
.setTargetAtTime(0.2f, now + 0.05, 0.1);
Times are in the context's time base, BaseAudioContext.getCurrentTime().
Every method may be called from any thread; changes reach the renderer at
its next render quantum.
-
Method Summary
Modifier and TypeMethodDescriptioncancelAndHoldAtTime(double cancelTime) LikecancelScheduledValues(double), but the value the timeline would have had atcancelTimeis held from then on, so a ramp in progress stops where it was rather than jumping back.cancelScheduledValues(double cancelTime) Removes every event scheduled at or aftercancelTime.exponentialRampToValueAtTime(float value, double endTime) Ramps exponentially from the previous scheduled value tovalue, reaching it atendTime.The automation rate.floatThe value used when nothing is scheduled.floatThe highest value the parameter can take.floatThe lowest value the parameter can take.floatgetValue()The intrinsic value at the context's current time: the automation timeline, without the contribution of connected nodes.linearRampToValueAtTime(float value, double endTime) Ramps linearly from the previous scheduled value tovalue, reaching it atendTime.voidSets the automation rate.setTargetAtTime(float target, double startTime, double timeConstant) Starts an exponential approach totargetatstartTime.voidsetValue(float value) Sets the value now, the same assetValueAtTime(value, context.getCurrentTime()).setValueAtTime(float value, double startTime) Changes the value atstartTime.setValueCurveAtTime(float[] values, double startTime, double duration) FollowsvaluesfromstartTimefordurationseconds, linearly interpolating between them, then holds the last one.
-
Method Details
-
getDefaultValue
public float getDefaultValue()The value used when nothing is scheduled.
Returns
the default value
-
getMinValue
public float getMinValue()The lowest value the parameter can take.
Returns
the nominal minimum
-
getMaxValue
public float getMaxValue()The highest value the parameter can take.
Returns
the nominal maximum
-
getAutomationRate
The automation rate.
Returns
whether the value is computed per sample or per render quantum
-
setAutomationRate
Sets the automation rate.
Parameters
rate: the new rate
Throws
IllegalStateException: for a parameter whose rate the specification fixes, such asAudioBufferSourceNode.playbackRate
-
getValue
public float getValue()The intrinsic value at the context's current time: the automation timeline, without the contribution of connected nodes.
Returns
the value
-
setValue
public void setValue(float value) Sets the value now, the same as
setValueAtTime(value, context.getCurrentTime()).Parameters
value: the new value
-
setValueAtTime
Changes the value at
startTime.Parameters
-
value: the new value -
startTime: when, in context seconds
Returns
this parameter
-
-
linearRampToValueAtTime
Ramps linearly from the previous scheduled value to
value, reaching it atendTime.Parameters
-
value: the value to reach -
endTime: when it is reached
Returns
this parameter
-
-
exponentialRampToValueAtTime
Ramps exponentially from the previous scheduled value to
value, reaching it atendTime. If the previous value is 0 or of the other sign the value holds untilendTime, as the specification requires.Parameters
-
value: the value to reach; must not be 0 -
endTime: when it is reached
Returns
this parameter
-
-
setTargetAtTime
Starts an exponential approach to
targetatstartTime. AftertimeConstantseconds about 63% of the distance has been covered.Parameters
-
target: the value approached -
startTime: when the approach starts -
timeConstant: the time constant in seconds, 0 or more; 0 jumps
Returns
this parameter
-
-
setValueCurveAtTime
Follows
valuesfromstartTimefordurationseconds, linearly interpolating between them, then holds the last one.Parameters
-
values: at least two values; copied -
startTime: when the curve starts -
duration: how long it lasts, more than 0
Returns
this parameter
-
-
cancelScheduledValues
Removes every event scheduled at or after
cancelTime.Parameters
cancelTime: the first time to clear
Returns
this parameter
-
cancelAndHoldAtTime
Like
cancelScheduledValues(double), but the value the timeline would have had atcancelTimeis held from then on, so a ramp in progress stops where it was rather than jumping back.Parameters
cancelTime: when to hold
Returns
this parameter
-