Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class AudioParam

  1. Object
  2. 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.

Methods

public float getDefaultValue()The value used when nothing is scheduled.
public float getMinValue()The lowest value the parameter can take.
public float getMaxValue()The highest value the parameter can take.
public AutomationRate getAutomationRate()The automation rate.
public void setAutomationRate(AutomationRate rate)Sets the automation rate.
public float getValue()The intrinsic value at the context’s current time: the automation timeline, without the contribution of connected nodes.
public void setValue(float value)Sets the value now, the same as setValueAtTime(value, context.getCurrentTime()).
public AudioParam setValueAtTime(float value, double startTime)Changes the value at startTime.
public AudioParam linearRampToValueAtTime(float value, double endTime)Ramps linearly from the previous scheduled value to value, reaching it at endTime.
public AudioParam exponentialRampToValueAtTime(float value, double endTime)Ramps exponentially from the previous scheduled value to value, reaching it at endTime.
public AudioParam setTargetAtTime(float target, double startTime, double timeConstant)Starts an exponential approach to target at startTime.
public AudioParam setValueCurveAtTime(float[] values, double startTime, double duration)Follows values from startTime for duration seconds, linearly interpolating between them, then holds the last one.
public AudioParam cancelScheduledValues(double cancelTime)Removes every event scheduled at or after cancelTime.
public AudioParam cancelAndHoldAtTime(double cancelTime)Like cancelScheduledValues(double), but the value the timeline would have had at cancelTime is held from then on, so a ramp in progress stops where it was rather than jumping back.

Inherited methods

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

public AutomationRate getAutomationRate()
The automation rate.

Returns

whether the value is computed per sample or per render quantum

setAutomationRate

public void setAutomationRate(AutomationRate rate)
Sets the automation rate.

Parameters

rate AutomationRate
the new rate

Throws

IllegalStateException
for a parameter whose rate the specification fixes, such as AudioBufferSourceNode.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 float
the new value

setValueAtTime

public AudioParam setValueAtTime(float value, double startTime)
Changes the value at startTime.

Parameters

value float
the new value
startTime double
when, in context seconds

Returns

this parameter

linearRampToValueAtTime

public AudioParam linearRampToValueAtTime(float value, double endTime)
Ramps linearly from the previous scheduled value to value, reaching it at endTime.

Parameters

value float
the value to reach
endTime double
when it is reached

Returns

this parameter

exponentialRampToValueAtTime

public AudioParam exponentialRampToValueAtTime(float value, double endTime)
Ramps exponentially from the previous scheduled value to value, reaching it at endTime. If the previous value is 0 or of the other sign the value holds until endTime, as the specification requires.

Parameters

value float
the value to reach; must not be 0
endTime double
when it is reached

Returns

this parameter

setTargetAtTime

public AudioParam setTargetAtTime(float target, double startTime, double timeConstant)
Starts an exponential approach to target at startTime. After timeConstant seconds about 63% of the distance has been covered.

Parameters

target float
the value approached
startTime double
when the approach starts
timeConstant double
the time constant in seconds, 0 or more; 0 jumps

Returns

this parameter

setValueCurveAtTime

public AudioParam setValueCurveAtTime(float[] values, double startTime, double duration)
Follows values from startTime for duration seconds, linearly interpolating between them, then holds the last one.

Parameters

values float[]
at least two values; copied
startTime double
when the curve starts
duration double
how long it lasts, more than 0

Returns

this parameter

cancelScheduledValues

public AudioParam cancelScheduledValues(double cancelTime)
Removes every event scheduled at or after cancelTime.

Parameters

cancelTime double
the first time to clear

Returns

this parameter

cancelAndHoldAtTime

public AudioParam cancelAndHoldAtTime(double cancelTime)
Like cancelScheduledValues(double), but the value the timeline would have had at cancelTime is held from then on, so a ramp in progress stops where it was rather than jumping back.

Parameters

cancelTime double
when to hold

Returns

this parameter