Path: blob/main/files/en-us/web/api/analysernode/getbytefrequencydata/index.md
6514 views
------{{ APIRef("Web Audio API") }}
The getByteFrequencyData() method of the {{ domxref("AnalyserNode") }} interface copies the current frequency data into a {{jsxref("Uint8Array")}} (unsigned byte array) passed into it.
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 {{domxref("AnalyserNode.frequencyBinCount")}}, excess elements are dropped. If it has more elements than needed, excess elements are ignored.
Syntax
Parameters
array: The {{jsxref("Uint8Array")}} 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
The following example shows basic usage of an {{domxref("AudioContext")}} to create an AnalyserNode, then {{domxref("window.requestAnimationFrame()","requestAnimationFrame")}} and {{htmlelement("canvas")}} to collect frequency data repeatedly and draw a "winamp bar graph style" output of the current audio input. 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}}