Skip to content

API Reference


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. progress runs 0 to 1 toward the first reading, and reason says why it is listening. audio-lost lasts 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 no statechange: within the unlock band, and when peaks moves its lock to a fuller rung. Show the latest reading, not only the one of the move to locked.
  • stopped: final. error is null after stop(), 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.
  • epoch counts reset() calls. Messages from an older epoch are dropped, so after reset() returns, nothing measured before it is ever reported.