Class AudioParam
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The Web Audio API's AudioParam interface represents an audio-related parameter, usually a parameter of an AudioNode (such as Gain).
[Value("AudioParam")]
public class AudioParam
- Inheritance
-
AudioParam
- Inherited Members
Remarks
An AudioParam 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.
Each AudioParam has a list of events, initially empty, that define when and how values change. When this list is not empty, changes using the AudioParam.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 in BaseAudioContextcurrentTime.
Constructors
AudioParam()
public AudioParam()
Properties
AutomationRate
[Value("automationRate")]
public AutomationRate AutomationRate { get; set; }
Property Value
DefaultValue
The defaultValue
read-only property of the AudioParam interface represents the initial
value of the attributes as defined by the specific AudioNode creating
the AudioParam.
[Value("defaultValue")]
public Number DefaultValue { get; }
Property Value
Remarks
MaxValue
The maxValue
read-only property of the AudioParam interface represents the maximum
possible value for the parameter's nominal (effective) range.
[Value("maxValue")]
public Number MaxValue { get; }
Property Value
- Number
A floating-point Number indicating the maximum value permitted for the
parameter's nominal range.The default value ofmaxValueis the maximum positive single-precision
floating-point value (+340,282,346,638,528,859,811,704,183,484,516,925,440).
Remarks
MinValue
The minValue
read-only property of the AudioParam interface represents the minimum
possible value for the parameter's nominal (effective) range.
[Value("minValue")]
public Number MinValue { get; }
Property Value
- Number
A floating-point Number indicating the minimum value permitted for the
parameter's nominal range.The default value ofminValueis the minimum negative single-precision
floating-point value (-340,282,346,638,528,859,811,704,183,484,516,925,440).
Remarks
Value
The value property of the AudioParam interface gets or sets the value of this AudioParam at the current time.
Initially, the value is set to DefaultValue.
[Value("value")]
public Number Value { get; set; }
Property Value
- Number
A floating-point Number indicating the parameter's value as of the current time.
This value will be between the values specified by the MinValue and MaxValue properties.The data type used internally to storevalueis a single-precision (32-bit) floating point number, while JavaScript uses 64-bit double-precision floating point numbers.
As a result, the value you read from thevalueproperty may not always exactly equal what you set it to.Consider this example:The log output will befalse, because the playback rate parameter,rate, was converted to the 32-bit floating-point number closest to 5.3, which yields 5.300000190734863.
One solution is to use the MathFround method, which returns the single-precision value equivalent to the 64-bit JavaScript value specified—when settingvalue, like this:In this case, the log output will betrue.Thevalueof anAudioParamcan either be fixed or can vary over time.
This is reflected by thevaluegetter, which returns the value of the parameter as of the audio rendering engine's most recent render quantum, or moment at which audio buffers are processed and updated.
In addition to processing audio buffers, each render quantum updates thevalueof eachAudioParamas needed given the current time and any established time-based parameter value changes.Upon first creating the parameter, its value is set to its default value, given by DefaultValue.
This is the parameter's value at a time of 0.0 seconds, and will remain the parameter's value until the first render quantum in which the value is altered.During each render quantum, the browser does the following things related to managing the value of a parameter:Thus, thevalueof a parameter is maintained to accurately reflect the state of the parameter over time.
Remarks
Setting value has the same effect as calling SetValueAtTime(Number, Number) with the time returned by the AudioContext's BaseAudioContextcurrentTime property.
Methods
CancelAndHoldAtTime(Number)
The cancelAndHoldAtTime() method of the
AudioParam interface cancels all scheduled future changes to theAudioParam but holds its value at a given time until further changes are
made using other methods.
[Value("cancelAndHoldAtTime")]
public AudioParam CancelAndHoldAtTime(Number cancelTime)
Parameters
cancelTimeNumber
Returns
- AudioParam
A reference to the AudioParam it was called on.
Remarks
CancelScheduledValues(Number)
The cancelScheduledValues() method of the AudioParam
Interface cancels all scheduled future changes to the AudioParam.
[Value("cancelScheduledValues")]
public AudioParam CancelScheduledValues(Number cancelTime)
Parameters
cancelTimeNumber
Returns
- AudioParam
A reference to this
AudioParamobject. In some older implementations this
method returns 'undefined'.
Remarks
ExponentialRampToValueAtTime(Number, Number)
The exponentialRampToValueAtTime() method of the AudioParam Interface schedules a gradual exponential change in the value of the AudioParam.
The change starts at the time specified for the previous event, follows an exponential ramp to the new value given in the value parameter, and reaches the new value at the time given in theendTime parameter.
[Value("exponentialRampToValueAtTime")]
public AudioParam ExponentialRampToValueAtTime(Number value, Number endTime)
Parameters
Returns
- AudioParam
A reference to this
AudioParamobject. In some browsers older
implementations of this interface return 'undefined'.
Remarks
NOTE
Exponential ramps are considered more useful when changing
frequencies or playback rates than linear ramps because of the way the human ear
works.
LinearRampToValueAtTime(Number, Number)
The linearRampToValueAtTime() method of the AudioParam
Interface schedules a gradual linear change in the value of theAudioParam. The change starts at the time specified for the
previous 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.
[Value("linearRampToValueAtTime")]
public AudioParam LinearRampToValueAtTime(Number value, Number endTime)
Parameters
Returns
- AudioParam
A reference to this
AudioParamobject. In some browsers older
implementations of this interface return 'undefined'.
Remarks
SetTargetAtTime(Number, Number, Number)
The setTargetAtTime() method of the
AudioParam interface schedules the start of a gradual change to theAudioParam value. This is useful for decay or release portions of ADSR
envelopes.
[Value("setTargetAtTime")]
public AudioParam SetTargetAtTime(Number target, Number startTime, Number timeConstant)
Parameters
Returns
- AudioParam
A reference to this
AudioParamobject. Some older browser implementations
of this interface return 'undefined'.
Remarks
SetValueAtTime(Number, Number)
The setValueAtTime() method of the
AudioParam interface schedules an instant change to theAudioParam value at a precise time, as measured against
BaseAudioContextcurrentTime. The new value is given in the value parameter.
[Value("setValueAtTime")]
public AudioParam SetValueAtTime(Number value, Number startTime)
Parameters
Returns
- AudioParam
A reference to this
AudioParamobject. In some browsers older
implementations of this interface return 'undefined'.
Remarks
SetValueCurveAtTime(List<Number>, Number, Number)
ThesetValueCurveAtTime() method of the
AudioParam interface schedules the parameter's value to change
following a curve defined by a list of values.
[Value("setValueCurveAtTime")]
public AudioParam SetValueCurveAtTime(List<Number> values, Number startTime, Number duration)
Parameters
Returns
- AudioParam
A reference to this
AudioParamobject. Some older browser implementations
of this interface returnundefined.
Remarks
The curve is a linear
interpolation between the sequence of values defined in an array of floating-point
values, which are scaled to fit into the given interval starting atstartTime and a specific duration.