# synced-rate

> The rate of an oscillator that is either free, in hertz, or synced: one cycle per note value of the host's tempo. The two parameters a device adds for it, and the function that reads the rate.

```bash
npx shadcn@latest add @audio-ui/synced-rate
```

```ts
import { SYNCED_RATE_PARAMETERS, lfoRate } from "@/lib/synced-rate";
```

- Files: `lib/synced-rate.ts`
- Depends on: nothing; npm: `@audio-ui/engine`
- Used by: `auto-pan-device`, `chorus-device`, `phaser-device`, `wah-device`

| Export | Kind | What it is |
| --- | --- | --- |
| `RateState` | interface | The parameters that give an oscillator its rate: free in hertz, or a cycle per note value of the tempo. |
| `SYNCED_RATE_PARAMETERS` | const | The two descriptors a synced rate adds beside the one in hertz: a switch and the note list. |
| `lfoRate` | function | The rate of an oscillator in hertz: the one in the state, or, when it is synced, one cycle for each note value at `tempo`, so `1/4` at 120 BPM is 2 Hz. |

## Usage

A modulation rate in hertz, or a note value that follows the host's tempo: what an auto pan, a chorus or a phaser's LFO runs at.

```ts
import { lfoRate } from "@/lib/synced-rate";

const hertz = lfoRate(state, tempo); // state.sync ? the division at the tempo : state.rateHz
```

The tempo comes from the host's `DeviceContext`, given with each `update`.
