API Reference / AnalyzerState
Type Alias: AnalyzerState
ts
type AnalyzerState =
| {
status: "listening";
epoch: number;
progress: number;
reason: ListeningReason;
}
| {
status: "settling";
epoch: number;
reading: Reading;
}
| {
status: "locked";
epoch: number;
reading: Reading;
}
| {
status: "stopped";
epoch: number;
error: AnalyzerError | null;
};Defined in: contract/types.ts:307
What the analyzer is doing now: a snapshot, like AudioContext.state. An object rather than a string, because each status carries its own fields.
listening: no reading yet in this stretch of audio.progressruns 0 to 1 toward the first reading, andreasonsays why it is listening.audio-lostlasts until the next reading, and that is how a late subscriber learns live input is being lost.settling: readings are coming but have not agreed long enough to lock.locked: readings agree. Leaving needs more disagreement than entering (hysteresis), so it does not flap. The tempo can still move while locked, with nostatechange: within the unlock band, and when peaks moves its lock to a fuller rung. Show the latestreading, not only the one of the move tolocked.stopped: final.erroris null afterstop(), set after a fatal fault.
Remarks
Guarantees:
- Read it any time. A listener added late reads the current state here: events are never replayed.
- It is updated before any event about it is dispatched, so inside a listener it is already current, for every listener of every event of that step.
- Every snapshot is a new object: compare by reference to see whether anything changed.
epochcountsreset()calls. Messages from an older epoch are dropped, so afterreset()returns, nothing measured before it is ever reported.