audio-frequency-to-index
Convert a Hz frequency to an index for WebAudio frequency analysis. Also see audio-index-to-frequency.
The value is clamped between [ 0 .. frequencyBinCount ]
. The frequencyBinCount
is the same as ananlyserNode.fftSize / 2
.
const freq2index = const sampleRate = audioContextsampleRate // 44100const length = analyserNodefrequencyBinCount // 1024 const index = //=> 19
Usage
index = frequencyToIndex(frequency, sampleRate, frequencyBinCount)
Converts frequency
(in Hz) to an index
integer using the audioContext.sampleRate
and analyserNode.frequencyBinCount
from the Web Audio API.
License
MIT, see LICENSE.md for details.