JSPM

audio-frequency-to-index

2.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1159
  • Score
    100M100P100Q113472F
  • License MIT

convert a Hz frequency to an index for WebAudio

Package Exports

  • audio-frequency-to-index

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (audio-frequency-to-index) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

audio-frequency-to-index

stable

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 = require('audio-frequency-to-index')
const sampleRate = audioContext.sampleRate // 44100
const length = analyserNode.frequencyBinCount // 1024

const index = freq2index(400, sampleRate, length)
//=> 19

Usage

NPM

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.