Skip to content

API Reference


API Reference ​

Functions ​

FunctionDescription
getBiquadFilterCreates a biquad lowpass filter for audio processing.
analyzeFullBufferDetects the tempo of a whole decoded file at once.
createRealtimeBpmAnalyzerCreates a real-time BPM analyzer for live audio.

Classes ​

ClassDescription
BpmAnalyzerReal-time BPM analyzer: the AudioNode-like EventTarget that createRealtimeBpmAnalyzer returns.

Type Aliases ​

Type AliasDescription
EngineNameThe tempo engine. May grow in a minor release, like every exported union but Status: give a switch over it a default branch.
EngineOptionThe realtime engine option: a bare name, or a name with the settings only that engine understands. Realtime and offline take different settings, so each has its own type and none is accepted where it does nothing. An object takes name and that engine's settings only: restartAfterSeconds for peaks, mode for tempogram. Any other key, such as lowpass (realtime peaks has a fixed lowpass inside analyzer.input) or a typo, makes the factory's promise reject with a TypeError that names it, whatever its value. null or undefined means the default, tempogram.
LowpassOptionThe lowpass settings: the offline engine: {name: 'peaks', lowpass}, getBiquadFilter and Node's applyLowpass take the same ones. null or undefined means the defaults. Anything else that is not an object, an array included, throws a TypeError that names its type. No key but frequency and q is accepted: another throws a TypeError that names it, whatever its value, undefined included. That covers the 5.x names frequencyValue and qualityValue, the DOM's Q, detune, type and gain, which TypeScript lets through from a BiquadFilterOptions, and typos. Each setting is a finite number: another type throws a TypeError, and NaN or an infinity a RangeError, as does a value outside its range.
OfflineEngineOptionThe offline engine option. Realtime peaks has a fixed lowpass inside analyzer.input, so only offline takes lowpass settings. The object form is peaks only, and takes name and lowpass only: any other key, such as restartAfterSeconds or a typo, makes the promise reject with a TypeError that names it, whatever its value. null or undefined means the default, tempogram.
TempoRangeRange every tempo is reported in, in BPM. max must be at least twice min, so every tempo has an octave inside it. max must be at most 2^31 - 1, so a whole BPM fits a signed 32-bit integer, and max / min must be a finite number; a value past either bound is refused with a RangeError. Default 90 to 180, the range Reading.confidence was measured on: any other range gives every reading confidence null, and an explicit {min: 90, max: 180} is the default. Any key other than min and max is refused with a TypeError that names it.
AnalyzerOptionsOptions for the realtime analyzer. createRealtimeBpmAnalyzer checks them before it loads the processor: for an invalid value, the promise it returns rejects with a RangeError or a TypeError. It takes these keys only: any other own key, a typo included, rejects with a TypeError that names it, whatever its value.
OfflineOptionsOptions for whole-buffer analysis, in the browser and in Node. Only these two keys: any other own key, a typo or a realtime option included, rejects with a TypeError that names it, whatever its value.
CandidateRelationHow a candidate's tempo relates to the reading's tempo. May grow in a minor release.
CandidateAnother tempo the engine considered.
AudioSpanThe audio a reading covers, in seconds of analysed audio since the epoch began (since the analyzer started or since the last reset()). Lost live input counted as silence is included, so this is audio time, not wall time. from <= to, and to never decreases within an epoch.
ReadingOne measurement: the tempo the engine reports for a span of audio.
OfflineResultWhole-buffer result: the same Reading realtime emits, or null when no tempo was found. audio spans the analysed buffer.
AnalyzerErrorNameError names, after the DOM's ...Error names. May grow in a minor release. Serialisable through postMessage: never an Error instance. The detail is in message, which has no stable format.
AnalyzerError-
StatusThe analyzer's status, the discriminant of AnalyzerState. The one closed union: a new status would change what the existing ones mean, so it waits for a major release, and an exhaustive switch over it is safe.
ListeningReasonWhy the analyzer is listening, so a late subscriber can tell a fresh start from a lost pulse or lost input. May grow in a minor release.
AnalyzerStateWhat the analyzer is doing now: a snapshot, like AudioContext.state. An object rather than a string, because each status carries its own fields.
EngineReasonReasons the engine gives, inside a worklet message. May grow in a minor release.
CallerReasonReasons that come from the caller: reset() and stop().
StateChangeReasonEvery reason a statechange can carry. May grow in a minor release: branch on to.status, which is closed, and treat an unknown reason as informational.
StateChangePayload of statechange. to is the object analyzer.state holds at dispatch. A reset() while listening is a change too, from listening to listening: the epoch moved.
ProgressPayload of progress: the same number as state.progress.
KickPayload of kick: one kick drum the analyzer heard, as soon as it heard it, whichever engine runs.
DebugInfoEngine detail, only with debug: true. Not part of the contract: its shape changes with any release.
AnalyzerEventMapThe analyzer's events. May grow in a minor release: a new event type is additive, as nobody listens to it yet.
AnalyzerEventType-
ListenOptionsOptions for on(), a subset of AddEventListenerOptions.

Variables ​

RELATION_TOLERANCE ​

ts
const RELATION_TOLERANCE: 0.02 = 0.02;

Defined in: contract/types.ts:162

Relative tolerance for half and double: 0.02 means within 2% of the exact ratio.