# audio-frequency-to-index

> convert a Hz frequency to an index for WebAudio

Latest version **2.0.0** (published 2015-11-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install audio-frequency-to-index
pnpm add audio-frequency-to-index
yarn add audio-frequency-to-index
bun add audio-frequency-to-index
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2015-11-25 |
| First published | 2015-11-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | web, audio, webaudio, hz, freq, frequencies, frequency, index, freq2index |

## Links

- npm: https://www.npmjs.com/package/audio-frequency-to-index
- Repository: https://github.com/Jam3/audio-frequency-to-index
- Issues: https://github.com/Jam3/audio-frequency-to-index/issues
- npm.io page: https://npm.io/package/audio-frequency-to-index

## Dependencies (1)

- [clamp](https://npm.io/package/clamp.md) ^1.0.1

## Recent versions

- 2.0.0 (latest) — 2015-11-25
- 1.0.1 — 2015-11-25
- 1.0.0 — 2015-11-25

## README

# audio-frequency-to-index

[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

Convert a Hz frequency to an index for WebAudio frequency analysis. Also see [audio-index-to-frequency](https://www.npmjs.com/package/audio-index-to-frequency).

The value is clamped between `[ 0 .. frequencyBinCount ]`. The `frequencyBinCount` is the same as `ananlyserNode.fftSize / 2`. 

```js
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](https://nodei.co/npm/audio-frequency-to-index.png)](https://www.npmjs.com/package/audio-frequency-to-index)

#### `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](http://github.com/Jam3/audio-frequency-to-index/blob/master/LICENSE.md) for details.

---
_Source: https://npm.io/package/audio-frequency-to-index · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
