The WebAudio API contains an analyser which can be used to extract information from audio such as fast frequency transforms (FFT) of the frequencies.
The 'getByteFrequencyData' method results in a normalised array of values (scaled ) of a length specified (fftSize) and of values between 0 and 255. The default fftSize is 2048.
This array represents equally split frequency bands at half the sample rate (the Nyquist Frequency) with each element of the array corresponding to steps in frequency of:
For example, if the sample rate if 44100 Hz, and the fftSize is 1024, then the array bins are1)http://stackoverflow.com/questions/4364823/how-do-i-obtain-the-frequencies-of-each-value-in-an-fft:
0: 0 * 44100 / 1024 = 0.0 Hz
1: 1 * 44100 / 1024 = 43.1 Hz
2: 2 * 44100 / 1024 = 86.1 Hz
3: 3 * 44100 / 1024 = 129.2 Hz
511L 511 * 44100 / 1024 = 22006.9 Hz
The sample rate can be obtained by the 'sampleRate' property of the audio context being used to play the audio.
Here is a snippet from the W3C draft 2)https://webaudio.github.io/web-audio-api/:
Copies the current frequency data into the passed unsigned byte array. If the array has fewer elements than the
frequencyBinCount, the excess elements will be dropped. If the array has more elements than the
frequencyBinCount, the excess elements will be ignored. The most recent
fftSize frames are used in computing the frequency data.
If another call to
getFloatFrequencyData occurs within the same render quantum as a previous call, the current frequency data is not updated with the same data. Instead, the previously computed data is returned.
References [ + ]