pnpm dlx shadcn@latest add @audio-ui/simulated-levels
import { createSimulatedLevels } from "@/lib/simulated-levels";| Files | lib/simulated-levels.ts |
|---|---|
| Depends on | Nothing |
| npm | Nothing |
| Used by | meter-svelte-demo, meter-vue-demo, meter-web-demo, use-simulated-levels |
| Export | Kind | What it is |
|---|---|---|
SimulatedFrame | interface | |
createSimulatedLevels | function | Levels that move on their own, in the shape a Meter paints from: a random walk per channel with a peak that holds for a moment and then falls, like a real signal's. |
Usage
Levels that move on their own, in the shape a Meter paints from: a random walk per channel, with a peak that holds and then falls like a real signal's. For a meter shown without sound, such as a preview that does not ask for the microphone. useSimulatedLevels is the React hook over it.
import { createSimulatedLevels } from "@/lib/simulated-levels";
const simulated = createSimulatedLevels(2, { max: -6, min: -48 });
// `source` is what a Meter takes; `run()` moves it until the function it returns is called.
const stop = simulated.run();source is a live source, { getSnapshot, subscribe }: each frame costs no render in any framework. min and max keep the levels between two values in dB, for a meter with a narrower scale.