Path: blob/main/files/en-us/web/api/analysernode/getfloatfrequencydata/index.md
6520 views
------{{ APIRef("Web Audio API") }}
The getFloatFrequencyData() method of the {{domxref("AnalyserNode")}} Interface copies the current frequency data into a {{jsxref("Float32Array")}} array passed into it.
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 {{domxref("AnalyserNode.getByteFrequencyData()")}} instead, which works on a {{jsxref("Uint8Array")}}.
Syntax
Parameters
array: The {{jsxref("Float32Array")}} that the frequency domain data will be copied to. For any sample which is silent, the value is
-Infinity. If the array has fewer elements than the {{domxref("AnalyserNode.frequencyBinCount")}}, excess elements are dropped. If it has more elements than needed, excess elements are ignored.
Return value
None ({{jsxref("undefined")}}).
Examples
Drawing a spectrum
The following example shows basic usage of an {{domxref("AudioContext")}} to connect a {{domxref("MediaElementAudioSourceNode")}} to an AnalyserNode. While the audio is playing, we collect the frequency data repeatedly with {{domxref("window.requestAnimationFrame()","requestAnimationFrame()")}} and draw a "winamp bar graph style" to a {{htmlelement("canvas")}} element.
For more complete applied examples/information, check out our Voice-change-O-matic demo (see app.js lines 108–193 for relevant code).
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}