Table of Contents

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

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

context BaseAudioContext
options AnalyserOptions

Remarks

-CreateAnalyser(), the equivalent factory method

See also on MDN

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, and 32768. Defaults to 2048.

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 of 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, and 16384.

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 0 dB is the loudest possible sound, -10 dB is a 10th of that, etc. The default value is -30 dB.When getting data from getByteFrequencyData(), any frequencies with an amplitude of maxDecibels or higher will be returned as 255.

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 0 dB is the loudest possible sound, -10 dB is a 10th of that, etc. The default value is -100 dB.When getting data from getByteFrequencyData(), any frequencies with an amplitude of minDecibels or lower will be returned as 0.

NOTE
If a value greater than AnalyserNode.maxDecibels is set, an INDEX_SIZE_ERR exception 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 0 to 1 (0 meaning no time averaging). The default value is 0.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, an INDEX_SIZE_ERR exception 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

array Uint8Array

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

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.

-Using the Web Audio API

See also on MDN

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

array Uint8Array

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

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.

-Using the Web Audio API

See also on MDN

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

array Float32Array

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

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")}}.

-Using the Web Audio API

See also on MDN

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

array Float32Array

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

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.

-Using the Web Audio API

See also on MDN