Class AnalyserNode
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The AnalyserNode interface represents a node able to provide real-time frequency and time-domain analysis information. It is an AudioNode that passes the audio stream unchanged from the input to the output, but allows you to take the generated data, process it, and create audio visualizations.
[Value("AnalyserNode")]
public class AnalyserNode : AudioNode
- Inheritance
-
AnalyserNode
- Inherited Members
Remarks
An AnalyserNode has exactly one input and one output. The node works even if the output is not connected.
Constructors
AnalyserNode()
public AnalyserNode()
AnalyserNode(BaseAudioContext, AnalyserOptions)
The AnalyserNode() constructor of the Web Audio API creates a new AnalyserNode object instance.
public AnalyserNode(BaseAudioContext context, AnalyserOptions options = null)
Parameters
contextBaseAudioContextoptionsAnalyserOptions
Remarks
-CreateAnalyser(), the equivalent factory method
Properties
FftSize
The fftSize property of the AnalyserNode interface is an unsigned long value and represents the window size in samples that is used when performing a Fast Fourier Transform (FFT) to get frequency domain data.
[Value("fftSize")]
public ulong FftSize { get; set; }
Property Value
- ulong
An unsigned integer, representing the window size of the FFT, given in number of samples. A higher value will result in more details in the frequency domain but fewer details in the amplitude domain.Must be a power of 2 between 25 and 215, so one of:
32,64,128,256,512,1024,2048,4096,8192,16384, and32768. Defaults to2048.
Remarks
FrequencyBinCount
The frequencyBinCount read-only property of the AnalyserNode interface contains the total number of data points available to AudioContext SampleRate. This is half of the value of the FftSize. The two methods' indices have a linear relationship with the frequencies they represent, between 0 and the Nyquist frequency.
[Value("frequencyBinCount")]
public ulong FrequencyBinCount { get; }
Property Value
- ulong
An unsigned integer, equal to the number of values that GetByteFrequencyData(Uint8Array) and GetFloatFrequencyData(Float32Array) copy into the provided
TypedArray.For technical reasons related to how the Fast Fourier transform is defined, it is always half the value of FftSize. Therefore, it will be one of16,32,64,128,256,512,1024,2048,4096,8192, and16384.
Remarks
MaxDecibels
The maxDecibels property of the AnalyserNode interface is a double value representing the maximum power value in the scaling range for the FFT analysis data, for conversion to unsigned byte values — basically, this specifies the maximum value for the range of results when using getByteFrequencyData().
[Value("maxDecibels")]
public Number MaxDecibels { get; set; }
Property Value
- Number
A double, representing the maximum decibel value for scaling the FFT analysis data, where
0dB is the loudest possible sound,-10dB is a 10th of that, etc. The default value is-30dB.When getting data fromgetByteFrequencyData(), any frequencies with an amplitude ofmaxDecibelsor higher will be returned as255.
Remarks
MinDecibels
The minDecibels property of the AnalyserNode interface is a double value representing the minimum power value in the scaling range for the FFT analysis data, for conversion to unsigned byte values — basically, this specifies the minimum value for the range of results when using getByteFrequencyData().
[Value("minDecibels")]
public Number MinDecibels { get; set; }
Property Value
- Number
A double, representing the minimum decibel value for scaling the FFT analysis data, where
0dB is the loudest possible sound,-10dB is a 10th of that, etc. The default value is-100dB.When getting data fromgetByteFrequencyData(), any frequencies with an amplitude ofminDecibelsor lower will be returned as0.NOTE
If a value greater thanAnalyserNode.maxDecibelsis set, anINDEX_SIZE_ERRexception is thrown.
Remarks
SmoothingTimeConstant
The smoothingTimeConstant property of the AnalyserNode interface is a double value representing the averaging constant with the last analysis frame. It's basically an average between the current buffer and the last buffer the AnalyserNode processed, and results in a much smoother set of value changes over time.
[Value("smoothingTimeConstant")]
public Number SmoothingTimeConstant { get; set; }
Property Value
- Number
A double within the range
0to1(0meaning no time averaging). The default value is0.8.If 0 is set, there is no averaging done, whereas a value of 1 means "overlap the previous and current buffer quite a lot while computing the value", which essentially smooths the changes across GetFloatFrequencyData(Float32Array)/GetByteFrequencyData(Uint8Array) calls.In technical terms, we apply a Blackman window and smooth the values over time. The default value is good enough for most cases.NOTE
If a value outside the range 0–1 is set, anINDEX_SIZE_ERRexception is thrown.
Remarks
Methods
GetByteFrequencyData(Uint8Array)
The getByteFrequencyData() method of the AnalyserNode interface copies the current frequency data into a {{jsxref("Uint8Array")}} (unsigned byte array) passed into it.
[Value("getByteFrequencyData")]
public GlobalObject.Undefined GetByteFrequencyData(Uint8Array array)
Parameters
arrayUint8Array
Returns
Remarks
The frequency data is composed of integers on a scale from 0 to 255.
Each item in the array represents the decibel value for a specific frequency. The frequencies are spread linearly from 0 to 1/2 of the sample rate. For example, for 48000 sample rate, the last item of the array will represent the decibel value for 24000 Hz.
If the array has fewer elements than the FrequencyBinCount, excess elements are dropped. If it has more elements than needed, excess elements are ignored.
GetByteTimeDomainData(Uint8Array)
The getByteTimeDomainData() method of the AnalyserNode Interface copies the current waveform, or time-domain, data into a {{jsxref("Uint8Array")}} (unsigned byte array) passed into it.
[Value("getByteTimeDomainData")]
public GlobalObject.Undefined GetByteTimeDomainData(Uint8Array array)
Parameters
arrayUint8Array
Returns
Remarks
If the array has fewer elements than the FftSize, excess elements are dropped. If it has more elements than needed, excess elements are ignored.
GetFloatFrequencyData(Float32Array)
The getFloatFrequencyData() method of the AnalyserNode Interface copies the current frequency data into a {{jsxref("Float32Array")}} array passed into it.
[Value("getFloatFrequencyData")]
public GlobalObject.Undefined GetFloatFrequencyData(Float32Array array)
Parameters
arrayFloat32Array
Returns
Remarks
Each item in the array represents the decibel value for a specific frequency. The frequencies are spread linearly from 0 to 1/2 of the sample rate. For example, for a 48000 Hz sample rate, the last item of the array will represent the decibel value for 24000 Hz.
If you need higher performance and don't care about precision, you can use GetByteFrequencyData(Uint8Array) instead, which works on a {{jsxref("Uint8Array")}}.
GetFloatTimeDomainData(Float32Array)
The getFloatTimeDomainData() method of the AnalyserNode Interface copies the current waveform, or time-domain, data into a {{jsxref("Float32Array")}} array passed into it. Each array value is a sample, the magnitude of the signal at a particular time.
[Value("getFloatTimeDomainData")]
public GlobalObject.Undefined GetFloatTimeDomainData(Float32Array array)
Parameters
arrayFloat32Array
Returns
Remarks
The waveform is represented as PCM data, which has a nominal range of -1.0 to 1.0, but values can exceed the range such as when down-mixing stereo to mono.