@codexo/exojs-audio-fx 0.15.3 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/AudioAnalyser.d.ts +4 -3
- package/dist/esm/AudioAnalyser.d.ts.map +1 -0
- package/dist/esm/AudioAnalyser.js +365 -468
- package/dist/esm/AudioAnalyser.js.map +1 -1
- package/dist/esm/BeatDetector.d.ts +16 -15
- package/dist/esm/BeatDetector.d.ts.map +1 -0
- package/dist/esm/BeatDetector.js +370 -428
- package/dist/esm/BeatDetector.js.map +1 -1
- package/dist/esm/dsp/fft.d.ts +5 -5
- package/dist/esm/dsp/fft.d.ts.map +1 -0
- package/dist/esm/dsp/mel.d.ts +6 -6
- package/dist/esm/dsp/mel.d.ts.map +1 -0
- package/dist/esm/dsp/mel.js +55 -64
- package/dist/esm/dsp/mel.js.map +1 -1
- package/dist/esm/dsp/tempogram.d.ts +60 -20
- package/dist/esm/dsp/tempogram.d.ts.map +1 -0
- package/dist/esm/effects/AutoWahEffect.d.ts +3 -2
- package/dist/esm/effects/AutoWahEffect.d.ts.map +1 -0
- package/dist/esm/effects/AutoWahEffect.js +210 -237
- package/dist/esm/effects/AutoWahEffect.js.map +1 -1
- package/dist/esm/effects/BitCrusherEffect.d.ts +3 -2
- package/dist/esm/effects/BitCrusherEffect.d.ts.map +1 -0
- package/dist/esm/effects/BitCrusherEffect.js +72 -70
- package/dist/esm/effects/BitCrusherEffect.js.map +1 -1
- package/dist/esm/effects/ChorusEffect.d.ts +2 -1
- package/dist/esm/effects/ChorusEffect.d.ts.map +1 -0
- package/dist/esm/effects/ChorusEffect.js +132 -150
- package/dist/esm/effects/ChorusEffect.js.map +1 -1
- package/dist/esm/effects/CompressorEffect.d.ts +2 -1
- package/dist/esm/effects/CompressorEffect.d.ts.map +1 -0
- package/dist/esm/effects/CompressorEffect.js +104 -118
- package/dist/esm/effects/CompressorEffect.js.map +1 -1
- package/dist/esm/effects/ConvolutionEffect.d.ts +10 -5
- package/dist/esm/effects/ConvolutionEffect.d.ts.map +1 -0
- package/dist/esm/effects/ConvolutionEffect.js +208 -189
- package/dist/esm/effects/ConvolutionEffect.js.map +1 -1
- package/dist/esm/effects/DelayEffect.d.ts +1 -0
- package/dist/esm/effects/DelayEffect.d.ts.map +1 -0
- package/dist/esm/effects/DelayEffect.js +105 -109
- package/dist/esm/effects/DelayEffect.js.map +1 -1
- package/dist/esm/effects/DistortionEffect.d.ts +4 -3
- package/dist/esm/effects/DistortionEffect.d.ts.map +1 -0
- package/dist/esm/effects/DistortionEffect.js +190 -195
- package/dist/esm/effects/DistortionEffect.js.map +1 -1
- package/dist/esm/effects/DuckingEffect.d.ts +3 -2
- package/dist/esm/effects/DuckingEffect.d.ts.map +1 -0
- package/dist/esm/effects/DuckingEffect.js +91 -172
- package/dist/esm/effects/DuckingEffect.js.map +1 -1
- package/dist/esm/effects/EqualizerEffect.d.ts +1 -0
- package/dist/esm/effects/EqualizerEffect.d.ts.map +1 -0
- package/dist/esm/effects/EqualizerEffect.js +120 -133
- package/dist/esm/effects/EqualizerEffect.js.map +1 -1
- package/dist/esm/effects/FlangerEffect.d.ts +7 -6
- package/dist/esm/effects/FlangerEffect.d.ts.map +1 -0
- package/dist/esm/effects/FlangerEffect.js +172 -201
- package/dist/esm/effects/FlangerEffect.js.map +1 -1
- package/dist/esm/effects/GranularEffect.d.ts +3 -2
- package/dist/esm/effects/GranularEffect.d.ts.map +1 -0
- package/dist/esm/effects/GranularEffect.js +100 -95
- package/dist/esm/effects/GranularEffect.js.map +1 -1
- package/dist/esm/effects/LimiterEffect.d.ts +1 -0
- package/dist/esm/effects/LimiterEffect.d.ts.map +1 -0
- package/dist/esm/effects/LimiterEffect.js +182 -194
- package/dist/esm/effects/LimiterEffect.js.map +1 -1
- package/dist/esm/effects/PhaserEffect.d.ts +2 -1
- package/dist/esm/effects/PhaserEffect.d.ts.map +1 -0
- package/dist/esm/effects/PhaserEffect.js +214 -254
- package/dist/esm/effects/PhaserEffect.js.map +1 -1
- package/dist/esm/effects/PingPongDelayEffect.d.ts +2 -1
- package/dist/esm/effects/PingPongDelayEffect.d.ts.map +1 -0
- package/dist/esm/effects/PingPongDelayEffect.js +172 -185
- package/dist/esm/effects/PingPongDelayEffect.js.map +1 -1
- package/dist/esm/effects/PitchShiftEffect.d.ts +3 -2
- package/dist/esm/effects/PitchShiftEffect.d.ts.map +1 -0
- package/dist/esm/effects/PitchShiftEffect.js +60 -60
- package/dist/esm/effects/PitchShiftEffect.js.map +1 -1
- package/dist/esm/effects/ReverbEffect.d.ts +2 -1
- package/dist/esm/effects/ReverbEffect.d.ts.map +1 -0
- package/dist/esm/effects/ReverbEffect.js +113 -117
- package/dist/esm/effects/ReverbEffect.js.map +1 -1
- package/dist/esm/effects/RingModulatorEffect.d.ts +4 -3
- package/dist/esm/effects/RingModulatorEffect.d.ts.map +1 -0
- package/dist/esm/effects/RingModulatorEffect.js +153 -161
- package/dist/esm/effects/RingModulatorEffect.js.map +1 -1
- package/dist/esm/effects/TremoloEffect.d.ts +1 -0
- package/dist/esm/effects/TremoloEffect.d.ts.map +1 -0
- package/dist/esm/effects/TremoloEffect.js +193 -201
- package/dist/esm/effects/TremoloEffect.js.map +1 -1
- package/dist/esm/effects/VocoderEffect.d.ts +2 -1
- package/dist/esm/effects/VocoderEffect.d.ts.map +1 -0
- package/dist/esm/effects/VocoderEffect.js +69 -80
- package/dist/esm/effects/VocoderEffect.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +23 -22
- package/dist/esm/worklets/beat-detector.worklet.js +5 -1162
- package/dist/esm/worklets/beat-detector.worklet.js.map +1 -1
- package/dist/esm/worklets/bit-crusher.worklet.js +5 -44
- package/dist/esm/worklets/bit-crusher.worklet.js.map +1 -1
- package/dist/esm/worklets/ducking.worklet.js +6 -0
- package/dist/esm/worklets/ducking.worklet.js.map +1 -0
- package/dist/esm/worklets/granular.worklet.js +5 -97
- package/dist/esm/worklets/granular.worklet.js.map +1 -1
- package/dist/esm/worklets/pitch-shift.worklet.js +5 -128
- package/dist/esm/worklets/pitch-shift.worklet.js.map +1 -1
- package/dist/esm/worklets/vocoder.worklet.js +5 -93
- package/dist/esm/worklets/vocoder.worklet.js.map +1 -1
- package/package.json +6 -6
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/worklets/beat-detector.worklet.d.ts +0 -1
- package/dist/esm/worklets/bit-crusher.worklet.d.ts +0 -1
- package/dist/esm/worklets/granular.worklet.d.ts +0 -1
- package/dist/esm/worklets/pitch-shift.worklet.d.ts +0 -1
- package/dist/esm/worklets/vocoder.worklet.d.ts +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BeatDetector.js","sources":["../../../src/BeatDetector.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAiJA,MAAM,WAAW,GAAG,qBAAqB;AAEzC;;;;;;;;;;;;;;;;;;;;;;;AAuBG;MACU,YAAY,CAAA;;AAEP,IAAA,MAAM,GAAG,IAAI,MAAM,EAAc;AACjC,IAAA,aAAa,GAAG,IAAI,MAAM,EAAoB;AAC9C,IAAA,UAAU,GAAG,IAAI,MAAM,EAAc;AACrC,IAAA,UAAU,GAAG,IAAI,MAAM,EAAa;AACpC,IAAA,eAAe,GAAG,IAAI,MAAM,EAAkB;;;AAI7C,IAAA,QAAQ;;IAGjB,YAAY,GAA4B,IAAI;IAC5C,OAAO,GAAuB,IAAI;IAClC,UAAU,GAAqB,IAAI;IACnC,aAAa,GAAsC,IAAI;IACvD,MAAM,GAAyB,IAAI;IACnC,mBAAmB,GAAyC,IAAI;AACvD,IAAA,oBAAoB,GAAG,CAAC,GAAiB,KAAU;AAClE,QAAA,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC;AACrD,QAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;AAClB,IAAA,CAAC;;IAGO,MAAM,GAAG,CAAC;IAC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AE,eAAe,EAAE,CAAC;gBAChD;AACF,YAAA,CAAC,CAAC;YACF;QACF;AAEA,QAAA,mBAAmB,CAAC,IAAI,CAAC,MAAK;AAC5B,YAAA,IAAI,IAAI,CAAC,OAAO,KAAK,MAAM,IAAI,IAAI,CAAC,YAAY,IAAI,mBAAmB,EAAE,EAAE;gBACzE,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC;YAChD;AACF,QAAA,CAAC,CAAC;IACJ;IAEQ,cAAc,GAAA;QACpB,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,YAAY,EAAE;AACxC,YAAA,IAAI;gBACF,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC;YAC/C;AAAE,YAAA,MAAM;;YAER;QACF;AACA,QAAA,IAAI,CAAC,UAAU,GAAG,IAAI;AAEtB,QAAA,IAAI,IAAI,CAAC,aAAa,EAAE;AACtB,YAAA,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE;AAC/B,YAAA,IAAI,CAAC,aAAa,GAAG,IAAI;QAC3B;IACF;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"BeatDetector.js","names":["beatDetectorWorkletSource","asStream"],"sources":["../../src/BeatDetector.ts"],"sourcesContent":["import { type AudioBus, getAudioContext, isAudioContextReady, onAudioContextReady, registerAudioWorkletProcessor, Signal, type Voice } from '@codexo/exojs';\n\nimport beatDetectorWorkletSource from './worklets/beat-detector.worklet.ts?worklet';\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport type BeatDetectorSource = AudioBus | Voice | MediaStream | AudioNode | null;\n\nexport interface BeatDetectorOptions {\n /** Minimum detectable BPM. Default 50. */\n minBpm?: number;\n /** Maximum detectable BPM. Default 300. */\n maxBpm?: number;\n /** FFT size for onset detection. Default 2048. */\n fftSize?: number;\n /** Hop size in samples between successive FFTs. Default 512. */\n hopSize?: number;\n /**\n * Short tempogram window (seconds) that reacts quickly to a genuine tempo\n * change. Default 2.5. The tracked tempo follows this FAST window only when it\n * disagrees with {@link stableTempoWindowSec} consistently over several\n * analysis hops, so a real DJ drift is tracked without making a steady tempo\n * nervous.\n */\n fastTempoWindowSec?: number;\n /**\n * Long tempogram window (seconds) that holds the tempo grid steady against\n * noise and octave ambiguity. Default 8. Should be ≥ {@link fastTempoWindowSec}\n * and large enough to hold ≳ 2 periods of the slowest tempo; it also sizes the\n * internal flux ring buffer.\n */\n stableTempoWindowSec?: number;\n /**\n * Hops between successive autocorrelation (tempogram) recomputations.\n * Default 15 (~160 ms at 48 kHz with the default 512-sample hop). Lower values\n * react faster to tempo changes at the cost of more CPU.\n */\n acfIntervalHops?: number;\n /**\n * Minimum warm-up (ms) before the first beat may be emitted. Default 400.\n * The detector starts hunting a tempo once this much analysis history exists\n * instead of waiting a full slowest-tempo period, so early {@link BeatInfo}\n * beats (tagged `status: 'provisional'`) arrive with low latency for visual\n * reactivity. A beat is promoted to `status: 'locked'` only once the tempo grid\n * is trustworthy (full analysis window + sustained on-grid tracking). Replaces\n * the former `settlingMs` (default 1500).\n */\n minSettlingMs?: number;\n /**\n * When true (default), early low-confidence beats are emitted tagged\n * `status: 'provisional'` (then promoted to `'locked'`) for snappy visual\n * reactivity. Set false to suppress provisional beats entirely - {@link onBeat}\n * then fires only for `'locked'` beats, matching the pre-provisional behaviour.\n */\n emitProvisionalBeats?: boolean;\n /** Number of mel filterbank bands. Default 24. */\n melBands?: number;\n /**\n * When true (default), the worklet runs parallel 3/4 and 4/4 posteriors and\n * switches active time signature via hysteresis. Set false to lock to 4/4.\n */\n enableTimeSignatureDetection?: boolean;\n /**\n * Optional initial source. Equivalent to constructing then assigning\n * `detector.source = value`; provided for ergonomic one-shot construction.\n * The setter remains usable for runtime source switches.\n */\n source?: BeatDetectorSource;\n /**\n * Half-life in seconds for the {@link BeatDetector.pulse} envelope.\n * Default 0.15 - `pulse` halves every 150ms after each beat.\n */\n pulseHalfLife?: number;\n /**\n * Half-life in seconds for the {@link BeatDetector.barPulse} envelope.\n * Default 0.3 - slower than beat pulse for downbeat-emphasized visuals.\n */\n barPulseHalfLife?: number;\n /**\n * Time window in seconds for {@link BeatDetector.justBeat}. Default 0.03\n * - true for the visual frame(s) within 30ms of a beat onset.\n */\n justBeatWindow?: number;\n}\n\nexport interface BeatInfo {\n /** audioContext.currentTime when the beat occurred. */\n audioTime: number;\n /** BPM at this beat. */\n tempo: number;\n /** Confidence 0..1. */\n confidence: number;\n /** Phase within beat (0 = start). */\n beatPhase: number;\n /** Novelty/onset strength at the beat. */\n energy: number;\n /** Is this beat the first in a bar? */\n isDownbeat: boolean;\n /** Beat position within the bar (1..N). */\n beatInBar: number;\n /**\n * Detection trust level:\n * - `'provisional'` - an early, low-latency beat emitted before the tempo grid\n * is fully settled. Good for visual reactivity (a \"blink\"); may be revised.\n * - `'locked'` - the tempo grid is settled and trustworthy. Safe for\n * sync-critical use. Each stable segment yields exactly one provisional→locked\n * transition.\n */\n status: 'provisional' | 'locked';\n}\n\nexport interface UpcomingBeat {\n audioTime: number;\n tempo: number;\n isDownbeat: boolean;\n beatInBar: number;\n}\n\nexport interface BarInfo {\n audioTime: number;\n tempo: number;\n confidence: number;\n /** Monotonically increasing bar counter since detector start. */\n barNumber: number;\n}\n\nexport interface TimeSignature {\n numerator: number;\n denominator: number;\n}\n\nexport interface TempoCandidate {\n bpm: number;\n /** Peak strength 0..1. */\n score: number;\n}\n\nexport interface BandEnergy {\n low: number;\n mid: number;\n high: number;\n}\n\nconst workletName = 'exojs-beat-detector';\n\n/**\n * Real-time tempo + beat tracker. Splits work between the audio-rendering\n * thread (an AudioWorklet that runs onset detection, tempogram analysis,\n * and parallel 3/4 and 4/4 posterior estimation) and the main thread (this\n * class - receives beats, fires Signals, handles configuration and source\n * routing).\n *\n * Accepts a wide range of {@link BeatDetectorSource}s - a bus, an individual\n * {@link Voice}, a raw MediaStream, or any AudioNode - and exposes a Signal\n * for each notable event:\n * - {@link BeatDetector.onBeat} - every detected beat\n * - {@link BeatDetector.onDownbeat} - first beat of each bar\n * - {@link BeatDetector.onBarStart} - bar boundary\n * - {@link BeatDetector.onTempoChange} - when the tracked BPM changes\n * - {@link BeatDetector.onBeatPredicted} - look-ahead schedule notice\n *\n * Early beats arrive with low latency tagged `status: 'provisional'` (after a\n * short `minSettlingMs` warm-up, default 400 ms) for snappy visual reactivity,\n * then promote to `status: 'locked'` once the tempo grid is trustworthy - a\n * single {@link BeatDetector.onBeat} signal carries both via {@link BeatInfo.status}.\n * Set `emitProvisionalBeats: false` to receive only locked beats. Time-signature\n * detection (3/4 vs 4/4) is on by default; lock to 4/4 by setting\n * `enableTimeSignatureDetection: false`.\n */\nexport class BeatDetector {\n // ---- Signals ----\n public readonly onBeat = new Signal<[BeatInfo]>();\n public readonly onTempoChange = new Signal<[number, number]>();\n public readonly onDownbeat = new Signal<[BeatInfo]>();\n public readonly onBarStart = new Signal<[BarInfo]>();\n public readonly onBeatPredicted = new Signal<[UpcomingBeat]>();\n\n // ---- Options ----\n // enableTimeSignatureDetection not in Required<> since it has a default; keep as full explicit type\n private readonly _options: Required<BeatDetectorOptions>;\n\n // ---- Audio plumbing ----\n private _workletNode: AudioWorkletNode | null = null;\n private _source: BeatDetectorSource = null;\n private _tapSource: AudioNode | null = null;\n private _streamSource: MediaStreamAudioSourceNode | null = null;\n private _ready: Promise<void> | null = null;\n private _pendingSourceSetup: ((ctx: AudioContext) => void) | null = null;\n private readonly _onAudioContextReady = (ctx: AudioContext): void => {\n onAudioContextReady.remove(this._onAudioContextReady);\n this._setup(ctx);\n };\n\n // ---- Cached state from worklet ----\n private _tempo = 0;\n private _beatPhase = 0;\n private _nextBeatTime = 0;\n private _confidence = 0;\n private _gridStability = 0;\n private _tempoCandidates: readonly TempoCandidate[] = [];\n private _rms = 0;\n private _onsetStrength = 0;\n private _bandEnergy: BandEnergy = { low: 0, mid: 0, high: 0 };\n private _barPosition = 1;\n private _barLength = 4;\n private _timeSignature: TimeSignature = { numerator: 4, denominator: 4 };\n private _nextDownbeatTime = 0;\n private _lookahead: readonly UpcomingBeat[] = Object.freeze([]);\n\n /**\n * Half-life in seconds for the {@link pulse} envelope. Mutable; default 0.15.\n * Smaller values give a snappier pulse, larger values a longer afterglow.\n */\n public pulseHalfLife: number;\n\n /** Half-life for the {@link barPulse} envelope. Mutable; default 0.3. */\n public barPulseHalfLife: number;\n\n /** Time window for {@link justBeat}. Mutable; default 0.03 (30ms). */\n public justBeatWindow: number;\n\n public constructor(options?: BeatDetectorOptions) {\n this._options = {\n minBpm: options?.minBpm ?? 50,\n maxBpm: options?.maxBpm ?? 300,\n fftSize: options?.fftSize ?? 2048,\n hopSize: options?.hopSize ?? 512,\n fastTempoWindowSec: options?.fastTempoWindowSec ?? 2.5,\n stableTempoWindowSec: options?.stableTempoWindowSec ?? 8,\n acfIntervalHops: options?.acfIntervalHops ?? 15,\n minSettlingMs: options?.minSettlingMs ?? 400,\n emitProvisionalBeats: options?.emitProvisionalBeats ?? true,\n melBands: options?.melBands ?? 24,\n enableTimeSignatureDetection: options?.enableTimeSignatureDetection ?? true,\n // Visual-state options aren't part of worklet config; cached in the public\n // fields below but kept in the Required<> shape for type completeness.\n source: options?.source ?? null,\n pulseHalfLife: options?.pulseHalfLife ?? 0.15,\n barPulseHalfLife: options?.barPulseHalfLife ?? 0.3,\n justBeatWindow: options?.justBeatWindow ?? 0.03,\n };\n\n this.pulseHalfLife = this._options.pulseHalfLife;\n this.barPulseHalfLife = this._options.barPulseHalfLife;\n this.justBeatWindow = this._options.justBeatWindow;\n\n if (isAudioContextReady()) {\n this._setup(getAudioContext());\n } else {\n onAudioContextReady.add(this._onAudioContextReady);\n }\n\n if (options?.source !== undefined && options.source !== null) {\n this.source = options.source;\n }\n }\n\n // -----------------------------------------------------------------------\n // Source setter (polymorphic tap)\n // -----------------------------------------------------------------------\n\n public get source(): BeatDetectorSource {\n return this._source;\n }\n\n public set source(value: BeatDetectorSource) {\n if (value === this._source) return;\n\n this._disconnectTap();\n this._source = value;\n\n if (value === null) return;\n\n if (isAudioContextReady()) {\n this._pendingSourceSetup = null;\n this._connectSource(value, getAudioContext());\n } else {\n if (this._pendingSourceSetup !== null) {\n onAudioContextReady.remove(this._pendingSourceSetup);\n }\n\n const handler = (ctx: AudioContext): void => {\n onAudioContextReady.remove(handler);\n this._pendingSourceSetup = null;\n this._connectSource(value, ctx);\n };\n\n this._pendingSourceSetup = handler;\n onAudioContextReady.add(handler);\n }\n }\n\n // -----------------------------------------------------------------------\n // Ready promise\n // -----------------------------------------------------------------------\n\n public get ready(): Promise<void> {\n return this._ready ?? Promise.resolve();\n }\n\n // -----------------------------------------------------------------------\n // Stage 1 state accessors\n // -----------------------------------------------------------------------\n\n public get tempo(): number {\n return this._tempo;\n }\n public get beatPhase(): number {\n return this._beatPhase;\n }\n public get nextBeatTime(): number {\n return this._nextBeatTime;\n }\n public get confidence(): number {\n return this._confidence;\n }\n public get gridStability(): number {\n return this._gridStability;\n }\n public get rms(): number {\n return this._rms;\n }\n public get onsetStrength(): number {\n return this._onsetStrength;\n }\n public get bandEnergy(): BandEnergy {\n return this._bandEnergy;\n }\n\n public get tempoCandidates(): readonly TempoCandidate[] {\n return this._tempoCandidates;\n }\n\n // -----------------------------------------------------------------------\n // Stage 2 state accessors\n // -----------------------------------------------------------------------\n\n public get barPosition(): number {\n return this._barPosition;\n }\n public get barLength(): number {\n return this._barLength;\n }\n public get timeSignature(): TimeSignature {\n return this._timeSignature;\n }\n public get nextDownbeatTime(): number {\n return this._nextDownbeatTime;\n }\n\n public get lookahead(): readonly UpcomingBeat[] {\n return this._lookahead;\n }\n\n // -----------------------------------------------------------------------\n // Visual derived state - pure getters for per-frame polling\n // -----------------------------------------------------------------------\n\n /**\n * Seconds elapsed since the most recent beat, derived from {@link beatPhase}\n * and {@link tempo}. Returns 0 when the detector hasn't locked yet.\n */\n public get secondsSinceLastBeat(): number {\n if (this._tempo === 0) return 0;\n return this._beatPhase * (60 / this._tempo);\n }\n\n /**\n * 0..1 envelope, peaks at 1.0 the moment a beat fires and halves every\n * {@link pulseHalfLife} seconds. Drives \"pulse on the beat\" visuals\n * with a single multiplication: `sprite.scale = 1 + clock.pulse * 0.3`.\n */\n public get pulse(): number {\n if (this._tempo === 0) return 0;\n return Math.pow(0.5, this.secondsSinceLastBeat / this.pulseHalfLife);\n }\n\n /**\n * Like {@link pulse} but resets on downbeats and decays per\n * {@link barPulseHalfLife}. Useful for emphasizing the first beat of\n * each bar (e.g. brighter flash on \"1\" vs \"2,3,4\").\n */\n public get barPulse(): number {\n if (this._tempo === 0 || this._barLength === 0) return 0;\n const secondsPerBeat = 60 / this._tempo;\n const lastDownbeat = this._nextDownbeatTime - this._barLength * secondsPerBeat;\n const elapsed = Math.max(0, getAudioContext().currentTime - lastDownbeat);\n return Math.pow(0.5, elapsed / this.barPulseHalfLife);\n }\n\n /**\n * True for the visual frame(s) within {@link justBeatWindow} seconds of\n * a beat onset. Use for one-shot triggers (strobe flash, particle burst,\n * sample retrigger). Default window 30ms covers a typical 60fps frame.\n */\n public get justBeat(): boolean {\n return this._tempo > 0 && this.secondsSinceLastBeat < this.justBeatWindow;\n }\n\n /**\n * Phase 0..1 within a subdivision of the current beat. `division` is the\n * number of subdivisions per beat: 2 for 8th notes, 4 for 16th notes,\n * 3 for triplets. Use to drive sub-beat-resolution effects:\n *\n * const sixteenth = clock.subdivisionPhase(4);\n * if (sixteenth < 0.05) flash();\n */\n public subdivisionPhase(division: number): number {\n if (!Number.isFinite(division) || division <= 0) return 0;\n return (this._beatPhase * division) % 1;\n }\n\n // -----------------------------------------------------------------------\n // Lifecycle\n // -----------------------------------------------------------------------\n\n public destroy(): void {\n onAudioContextReady.remove(this._onAudioContextReady);\n\n if (this._pendingSourceSetup !== null) {\n onAudioContextReady.remove(this._pendingSourceSetup);\n this._pendingSourceSetup = null;\n }\n this._disconnectTap();\n this._workletNode?.disconnect();\n this._workletNode = null;\n this._ready = null;\n this.onBeat.clear();\n this.onTempoChange.clear();\n this.onDownbeat.clear();\n this.onBarStart.clear();\n this.onBeatPredicted.clear();\n }\n\n // -----------------------------------------------------------------------\n // Private helpers - setup\n // -----------------------------------------------------------------------\n\n private _setup(audioContext: AudioContext): void {\n const opts = this._options;\n this._ready = registerAudioWorkletProcessor(audioContext, workletName, beatDetectorWorkletSource).then(() => {\n const node = new AudioWorkletNode(audioContext, workletName, {\n numberOfInputs: 1,\n numberOfOutputs: 0,\n processorOptions: {\n fftSize: opts.fftSize,\n hopSize: opts.hopSize,\n minBpm: opts.minBpm,\n maxBpm: opts.maxBpm,\n melBands: opts.melBands,\n minSettlingMs: opts.minSettlingMs,\n emitProvisionalBeats: opts.emitProvisionalBeats,\n fastTempoWindowSec: opts.fastTempoWindowSec,\n stableTempoWindowSec: opts.stableTempoWindowSec,\n acfIntervalHops: opts.acfIntervalHops,\n enableTimeSignatureDetection: opts.enableTimeSignatureDetection,\n },\n });\n\n this._workletNode = node;\n node.port.onmessage = this._onWorkletMessage.bind(this);\n\n // If a source was set before worklet was ready, connect it now.\n if (this._source !== null) {\n this._connectSource(this._source, audioContext);\n }\n });\n }\n\n private _onWorkletMessage(event: MessageEvent): void {\n const message = event.data as Record<string, unknown>;\n switch (message.type) {\n case 'state':\n this._tempo = (message.tempo as number) ?? 0;\n this._beatPhase = (message.beatPhase as number) ?? 0;\n this._nextBeatTime = (message.nextBeatTime as number) ?? 0;\n this._nextDownbeatTime = (message.nextDownbeatTime as number) ?? 0;\n this._confidence = (message.confidence as number) ?? 0;\n this._gridStability = (message.gridStability as number) ?? 0;\n this._tempoCandidates = Object.freeze((message.tempoCandidates as TempoCandidate[]) ?? []);\n this._rms = (message.rms as number) ?? 0;\n this._onsetStrength = (message.onsetStrength as number) ?? 0;\n this._bandEnergy = (message.bandEnergy as BandEnergy) ?? { low: 0, mid: 0, high: 0 };\n this._barPosition = (message.barPosition as number) ?? 1;\n this._barLength = (message.barLength as number) ?? 4;\n this._timeSignature = (message.timeSignature as TimeSignature) ?? { numerator: 4, denominator: 4 };\n {\n const lookahead = (message.lookahead as UpcomingBeat[]) ?? [];\n this._lookahead = Object.freeze(lookahead);\n if (lookahead.length > 0) {\n this.onBeatPredicted.dispatch(lookahead[0]!);\n }\n }\n break;\n\n case 'beat': {\n const bi: BeatInfo = {\n audioTime: message.audioTime as number,\n tempo: message.tempo as number,\n confidence: message.confidence as number,\n beatPhase: message.beatPhase as number,\n energy: message.energy as number,\n isDownbeat: message.isDownbeat as boolean,\n beatInBar: message.beatInBar as number,\n status: (message.status as 'provisional' | 'locked' | undefined) ?? 'locked',\n };\n this.onBeat.dispatch(bi);\n if (bi.isDownbeat) this.onDownbeat.dispatch(bi);\n break;\n }\n\n case 'tempoChange':\n this.onTempoChange.dispatch(message.newTempo as number, message.oldTempo as number);\n break;\n\n case 'barStart': {\n const info: BarInfo = {\n audioTime: message.audioTime as number,\n tempo: message.tempo as number,\n confidence: message.confidence as number,\n barNumber: message.barNumber as number,\n };\n this.onBarStart.dispatch(info);\n break;\n }\n }\n }\n\n // -----------------------------------------------------------------------\n // Private helpers - source tap\n // -----------------------------------------------------------------------\n\n private _connectSource(source: BeatDetectorSource, audioContext: AudioContext): void {\n if (!this._workletNode) return;\n\n const tap = this._resolveToAudioNode(source, audioContext);\n if (!tap) {\n this._deferConnectionViaBus(source);\n return;\n }\n\n this._tapSource = tap;\n tap.connect(this._workletNode, 0, 0);\n }\n\n private _resolveToAudioNode(source: BeatDetectorSource, audioContext: AudioContext): AudioNode | null {\n if (source === null) return null;\n\n // MediaStream - duck-type via getTracks\n const asStream = source as Partial<{ getTracks: unknown }>;\n if (typeof asStream.getTracks === 'function') {\n if (this._streamSource) {\n this._streamSource.disconnect();\n this._streamSource = null;\n }\n const msNode = audioContext.createMediaStreamSource(source as MediaStream);\n this._streamSource = msNode;\n return msNode;\n }\n\n // AudioBus - has _getOutputNode (checked before raw AudioNode)\n const asBus = source as Partial<{ _getOutputNode: () => AudioNode | null }>;\n if (typeof asBus._getOutputNode === 'function') {\n return asBus._getOutputNode();\n }\n\n // Voice - tap its output node\n const asVoice = source as Partial<{ output: AudioNode }>;\n if ('output' in asVoice && asVoice.output) {\n return asVoice.output;\n }\n\n // Raw AudioNode - duck-type: has connect & disconnect\n const asNode = source as Partial<{ connect: unknown; disconnect: unknown }>;\n if (typeof asNode.connect === 'function' && typeof asNode.disconnect === 'function') {\n return source as unknown as AudioNode;\n }\n\n return null;\n }\n\n private _deferConnectionViaBus(source: BeatDetectorSource): void {\n const asBus = source as Partial<{ onceSetup: (callback: () => void) => void }>;\n if (typeof asBus.onceSetup === 'function') {\n asBus.onceSetup(() => {\n if (this._source === source && this._workletNode && isAudioContextReady()) {\n this._connectSource(source, getAudioContext());\n }\n });\n return;\n }\n\n onAudioContextReady.once(() => {\n if (this._source === source && this._workletNode && isAudioContextReady()) {\n this._connectSource(source, getAudioContext());\n }\n });\n }\n\n private _disconnectTap(): void {\n if (this._tapSource && this._workletNode) {\n try {\n this._tapSource.disconnect(this._workletNode);\n } catch {\n // Ignore\n }\n }\n this._tapSource = null;\n\n if (this._streamSource) {\n this._streamSource.disconnect();\n this._streamSource = null;\n }\n }\n}\n"],"mappings":";;;;AAiJA,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;AA0BpB,IAAa,eAAb,MAA0B;CAExB,AAAgB,SAAS,IAAI,OAAmB;CAChD,AAAgB,gBAAgB,IAAI,OAAyB;CAC7D,AAAgB,aAAa,IAAI,OAAmB;CACpD,AAAgB,aAAa,IAAI,OAAkB;CACnD,AAAgB,kBAAkB,IAAI,OAAuB;CAI7D,AAAiB;CAGjB,AAAQ,eAAwC;CAChD,AAAQ,UAA8B;CACtC,AAAQ,aAA+B;CACvC,AAAQ,gBAAmD;CAC3D,AAAQ,SAA+B;CACvC,AAAQ,sBAA4D;CACpE,AAAiB,wBAAwB,QAA4B;EACnE,oBAAoB,OAAO,KAAK,oBAAoB;EACpD,KAAK,OAAO,GAAG;CACjB;CAGA,AAAQ,SAAS;CACjB,AAAQ,aAAa;CAC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tE,KAAK,eAAe,QAAQ,gBAAgB,CAAC;GAEjD,CAAC;GACD;EACF;EAEA,oBAAoB,WAAW;GAC7B,IAAI,KAAK,YAAY,UAAU,KAAK,gBAAgB,oBAAoB,GACtE,KAAK,eAAe,QAAQ,gBAAgB,CAAC;EAEjD,CAAC;CACH;CAEA,AAAQ,iBAAuB;EAC7B,IAAI,KAAK,cAAc,KAAK,cAC1B,IAAI;GACF,KAAK,WAAW,WAAW,KAAK,YAAY;EAC9C,QAAQ,CAER;EAEF,KAAK,aAAa;EAElB,IAAI,KAAK,eAAe;GACtB,KAAK,cAAc,WAAW;GAC9B,KAAK,gBAAgB;EACvB;CACF;AACF"}
|
package/dist/esm/dsp/fft.d.ts
CHANGED
|
@@ -5,18 +5,18 @@
|
|
|
5
5
|
* After the call, real[i] and imag[i] hold the complex spectrum.
|
|
6
6
|
* A Hann window is applied to the input before the transform.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* source string because AudioWorklets cannot import modules.
|
|
8
|
+
* The beat-detector worklet imports these directly; its build bundles them in.
|
|
10
9
|
*/
|
|
11
10
|
/** Apply a Hann window in-place to `real`. `imag` is zeroed. */
|
|
12
|
-
export declare
|
|
11
|
+
export declare const hannWindow: (real: Float32Array, imag: Float32Array) => void;
|
|
13
12
|
/**
|
|
14
13
|
* In-place FFT. `real` and `imag` must have the same length (power of 2).
|
|
15
14
|
* A Hann window is applied to `real` before the transform; `imag` is zeroed.
|
|
16
15
|
*/
|
|
17
|
-
export declare
|
|
16
|
+
export declare const fft: (real: Float32Array, imag: Float32Array) => void;
|
|
18
17
|
/**
|
|
19
18
|
* Compute magnitude spectrum from complex FFT output.
|
|
20
19
|
* Returns a Float32Array of length `n/2` (positive frequencies only).
|
|
21
20
|
*/
|
|
22
|
-
export declare
|
|
21
|
+
export declare const magnitudeSpectrum: (real: Float32Array, imag: Float32Array) => Float32Array;
|
|
22
|
+
//# sourceMappingURL=fft.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fft.d.ts","sourceRoot":"","sources":["../../../src/dsp/fft.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,gEAAgE;AAChE,eAAO,MAAM,UAAU,GAAI,MAAM,YAAY,EAAE,MAAM,YAAY,KAAG,IAOnE,CAAC;AAuBF;;;GAGG;AACH,eAAO,MAAM,GAAG,GAAI,MAAM,YAAY,EAAE,MAAM,YAAY,KAAG,IAsB5D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,YAAY,EAAE,MAAM,YAAY,KAAG,YAO1E,CAAC"}
|
package/dist/esm/dsp/mel.d.ts
CHANGED
|
@@ -5,13 +5,12 @@
|
|
|
5
5
|
* on the mel scale. Each filter is a typed array of weights for the FFT
|
|
6
6
|
* magnitude bins.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* string (worklets cannot import modules).
|
|
8
|
+
* The beat-detector worklet imports these directly; its build bundles them in.
|
|
10
9
|
*/
|
|
11
10
|
/** Convert Hz to mel. */
|
|
12
|
-
export declare
|
|
11
|
+
export declare const hzToMel: (hz: number) => number;
|
|
13
12
|
/** Convert mel to Hz. */
|
|
14
|
-
export declare
|
|
13
|
+
export declare const melToHz: (mel: number) => number;
|
|
15
14
|
export interface MelBand {
|
|
16
15
|
/** Index of the FFT bin where this filter starts (weight 0). */
|
|
17
16
|
readonly startBin: number;
|
|
@@ -31,7 +30,7 @@ export interface MelBand {
|
|
|
31
30
|
* @param fftSize Number of FFT points (e.g., 2048).
|
|
32
31
|
* @param sampleRate Audio sample rate in Hz (e.g., 48000).
|
|
33
32
|
*/
|
|
34
|
-
export declare
|
|
33
|
+
export declare const buildMelFilterbank: (bandCount: number, fMin: number, fMax: number, fftSize: number, sampleRate: number) => MelBand[];
|
|
35
34
|
/**
|
|
36
35
|
* Compute mel band energies from a magnitude spectrum.
|
|
37
36
|
*
|
|
@@ -40,4 +39,5 @@ export declare function buildMelFilterbank(bandCount: number, fMin: number, fMax
|
|
|
40
39
|
* @param out Optional pre-allocated output array of length `bands.length`.
|
|
41
40
|
* @returns Log-compressed mel band energies.
|
|
42
41
|
*/
|
|
43
|
-
export declare
|
|
42
|
+
export declare const computeMelBands: (mag: Float32Array, bands: readonly MelBand[], out?: Float32Array) => Float32Array;
|
|
43
|
+
//# sourceMappingURL=mel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mel.d.ts","sourceRoot":"","sources":["../../../src/dsp/mel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,yBAAyB;AACzB,eAAO,MAAM,OAAO,GAAI,IAAI,MAAM,KAAG,MAAyC,CAAC;AAE/E,yBAAyB;AACzB,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,KAAG,MAA8C,CAAC;AAErF,MAAM,WAAW,OAAO;IACtB,gEAAgE;IAChE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,4CAA4C;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,8DAA8D;IAC9D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,kFAAkF;IAClF,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;CAChC;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAAI,WAAW,MAAM,EAAE,MAAM,MAAM,EAAE,MAAM,MAAM,EAAE,SAAS,MAAM,EAAE,YAAY,MAAM,KAAG,OAAO,EA2C9H,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,YAAY,EAAE,OAAO,SAAS,OAAO,EAAE,EAAE,MAAM,YAAY,KAAG,YAWlG,CAAC"}
|
package/dist/esm/dsp/mel.js
CHANGED
|
@@ -1,70 +1,61 @@
|
|
|
1
|
+
//#region src/dsp/mel.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
3
|
+
* Mel-scale filterbank generator.
|
|
4
|
+
*
|
|
5
|
+
* Generates `numBands` triangular filters log-spaced from `fMin` to `fMax` Hz
|
|
6
|
+
* on the mel scale. Each filter is a typed array of weights for the FFT
|
|
7
|
+
* magnitude bins.
|
|
8
|
+
*
|
|
9
|
+
* The beat-detector worklet imports these directly; its build bundles them in.
|
|
10
|
+
*/
|
|
11
11
|
/** Convert Hz to mel. */
|
|
12
|
-
|
|
13
|
-
return 2595 * Math.log10(1 + hz / 700);
|
|
14
|
-
}
|
|
12
|
+
const hzToMel = (hz) => 2595 * Math.log10(1 + hz / 700);
|
|
15
13
|
/** Convert mel to Hz. */
|
|
16
|
-
|
|
17
|
-
return 700 * (Math.pow(10, mel / 2595) - 1);
|
|
18
|
-
}
|
|
14
|
+
const melToHz = (mel) => 700 * (Math.pow(10, mel / 2595) - 1);
|
|
19
15
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
bands.push({ startBin, peakBin, endBin, weights });
|
|
65
|
-
}
|
|
66
|
-
return bands;
|
|
67
|
-
}
|
|
16
|
+
* Build a mel filterbank.
|
|
17
|
+
*
|
|
18
|
+
* @param numBands Number of mel bands (default 24).
|
|
19
|
+
* @param fMin Lowest frequency in Hz (default 80).
|
|
20
|
+
* @param fMax Highest frequency in Hz (default 8000).
|
|
21
|
+
* @param fftSize Number of FFT points (e.g., 2048).
|
|
22
|
+
* @param sampleRate Audio sample rate in Hz (e.g., 48000).
|
|
23
|
+
*/
|
|
24
|
+
const buildMelFilterbank = (bandCount, fMin, fMax, fftSize, sampleRate) => {
|
|
25
|
+
const binCount = fftSize >> 1;
|
|
26
|
+
const nyquist = sampleRate / 2;
|
|
27
|
+
const melMin = hzToMel(fMin);
|
|
28
|
+
const melMax = hzToMel(fMax);
|
|
29
|
+
const melPoints = new Float32Array(bandCount + 2);
|
|
30
|
+
for (let i = 0; i < bandCount + 2; i++) melPoints[i] = melMin + (melMax - melMin) * i / (bandCount + 1);
|
|
31
|
+
const binPoints = new Float32Array(bandCount + 2);
|
|
32
|
+
for (let i = 0; i < bandCount + 2; i++) {
|
|
33
|
+
const hz = melToHz(melPoints[i]);
|
|
34
|
+
binPoints[i] = Math.round(hz / nyquist * (binCount - 1));
|
|
35
|
+
}
|
|
36
|
+
const bands = [];
|
|
37
|
+
for (let b = 0; b < bandCount; b++) {
|
|
38
|
+
const startBin = Math.max(0, Math.min(binCount - 1, binPoints[b]));
|
|
39
|
+
const peakBin = Math.max(0, Math.min(binCount - 1, binPoints[b + 1]));
|
|
40
|
+
const endBin = Math.max(0, Math.min(binCount - 1, binPoints[b + 2]));
|
|
41
|
+
const len = endBin - startBin + 1;
|
|
42
|
+
const weights = new Float32Array(len);
|
|
43
|
+
for (let i = 0; i < len; i++) {
|
|
44
|
+
const bin = startBin + i;
|
|
45
|
+
if (bin <= peakBin && peakBin > startBin) weights[i] = (bin - startBin) / (peakBin - startBin);
|
|
46
|
+
else if (bin > peakBin && endBin > peakBin) weights[i] = (endBin - bin) / (endBin - peakBin);
|
|
47
|
+
else weights[i] = 1;
|
|
48
|
+
}
|
|
49
|
+
bands.push({
|
|
50
|
+
startBin,
|
|
51
|
+
peakBin,
|
|
52
|
+
endBin,
|
|
53
|
+
weights
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return bands;
|
|
57
|
+
};
|
|
68
58
|
|
|
59
|
+
//#endregion
|
|
69
60
|
export { buildMelFilterbank, hzToMel, melToHz };
|
|
70
|
-
//# sourceMappingURL=mel.js.map
|
|
61
|
+
//# sourceMappingURL=mel.js.map
|
package/dist/esm/dsp/mel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mel.js","sources":["
|
|
1
|
+
{"version":3,"file":"mel.js","names":[],"sources":["../../../src/dsp/mel.ts"],"sourcesContent":["/**\n * Mel-scale filterbank generator.\n *\n * Generates `numBands` triangular filters log-spaced from `fMin` to `fMax` Hz\n * on the mel scale. Each filter is a typed array of weights for the FFT\n * magnitude bins.\n *\n * The beat-detector worklet imports these directly; its build bundles them in.\n */\n\n/** Convert Hz to mel. */\nexport const hzToMel = (hz: number): number => 2595 * Math.log10(1 + hz / 700);\n\n/** Convert mel to Hz. */\nexport const melToHz = (mel: number): number => 700 * (Math.pow(10, mel / 2595) - 1);\n\nexport interface MelBand {\n /** Index of the FFT bin where this filter starts (weight 0). */\n readonly startBin: number;\n /** Index of the peak FFT bin (weight 1). */\n readonly peakBin: number;\n /** Index of the FFT bin where this filter ends (weight 0). */\n readonly endBin: number;\n /** Pre-computed triangular weights, indexed from startBin..endBin (inclusive). */\n readonly weights: Float32Array;\n}\n\n/**\n * Build a mel filterbank.\n *\n * @param numBands Number of mel bands (default 24).\n * @param fMin Lowest frequency in Hz (default 80).\n * @param fMax Highest frequency in Hz (default 8000).\n * @param fftSize Number of FFT points (e.g., 2048).\n * @param sampleRate Audio sample rate in Hz (e.g., 48000).\n */\nexport const buildMelFilterbank = (bandCount: number, fMin: number, fMax: number, fftSize: number, sampleRate: number): MelBand[] => {\n const binCount = fftSize >> 1; // positive frequencies\n const nyquist = sampleRate / 2;\n\n // Equally-spaced mel points: bandCount+2 points spanning fMin..fMax\n const melMin = hzToMel(fMin);\n const melMax = hzToMel(fMax);\n const melPoints = new Float32Array(bandCount + 2);\n for (let i = 0; i < bandCount + 2; i++) {\n melPoints[i] = melMin + ((melMax - melMin) * i) / (bandCount + 1);\n }\n\n // Convert mel points to FFT bin indices\n const binPoints = new Float32Array(bandCount + 2);\n for (let i = 0; i < bandCount + 2; i++) {\n const hz = melToHz(melPoints[i]!);\n binPoints[i] = Math.round((hz / nyquist) * (binCount - 1));\n }\n\n const bands: MelBand[] = [];\n for (let b = 0; b < bandCount; b++) {\n const startBin = Math.max(0, Math.min(binCount - 1, binPoints[b]!));\n const peakBin = Math.max(0, Math.min(binCount - 1, binPoints[b + 1]!));\n const endBin = Math.max(0, Math.min(binCount - 1, binPoints[b + 2]!));\n\n const len = endBin - startBin + 1;\n const weights = new Float32Array(len);\n for (let i = 0; i < len; i++) {\n const bin = startBin + i;\n if (bin <= peakBin && peakBin > startBin) {\n weights[i] = (bin - startBin) / (peakBin - startBin);\n } else if (bin > peakBin && endBin > peakBin) {\n weights[i] = (endBin - bin) / (endBin - peakBin);\n } else {\n // Degenerate: startBin === peakBin === endBin\n weights[i] = 1;\n }\n }\n\n bands.push({ startBin, peakBin, endBin, weights });\n }\n\n return bands;\n};\n\n/**\n * Compute mel band energies from a magnitude spectrum.\n *\n * @param mag FFT magnitude spectrum (length = fftSize/2).\n * @param bands Filterbank from `buildMelFilterbank`.\n * @param out Optional pre-allocated output array of length `bands.length`.\n * @returns Log-compressed mel band energies.\n */\nexport const computeMelBands = (mag: Float32Array, bands: readonly MelBand[], out?: Float32Array): Float32Array => {\n const result = out ?? new Float32Array(bands.length);\n for (let b = 0; b < bands.length; b++) {\n const { startBin, weights } = bands[b]!;\n let energy = 0;\n for (let i = 0; i < weights.length; i++) {\n energy += mag[startBin + i]! * weights[i]!;\n }\n result[b] = Math.log(1 + energy);\n }\n return result;\n};\n"],"mappings":";;;;;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AM,SAAS,QAAQ,SAAS;QAGxC,QAAQ,KAAK;EAEjB;EAEA,MAAM,KAAK;GAAE;GAAU;GAAS;GAAQ;EAAQ,CAAC;CACnD;CAEA,OAAO;AACT"}
|
|
@@ -5,15 +5,16 @@
|
|
|
5
5
|
* this module computes the autocorrelation function (ACF) over a sliding window and
|
|
6
6
|
* selects the musically-correct tempo from the resulting periodicity peaks.
|
|
7
7
|
*
|
|
8
|
-
* The
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* The beat-detector worklet imports these functions directly; its bundle inlines them,
|
|
9
|
+
* so there is one implementation. The worklet drives them from its own scratch buffers
|
|
10
|
+
* rather than calling `computeTempoCandidates` - the audio thread cannot afford the
|
|
11
|
+
* per-call allocation that convenience wrapper makes - which is why the allocating
|
|
12
|
+
* entry points here are thin shells around out-parameter primitives.
|
|
12
13
|
*
|
|
13
14
|
* Octave disambiguation (the core fix)
|
|
14
15
|
* ------------------------------------
|
|
15
16
|
* The ACF of a periodic onset train peaks at the beat lag `p` AND at every sub-harmonic
|
|
16
|
-
* lag `2p, 3p,
|
|
17
|
+
* lag `2p, 3p, ...` (every other beat also correlates). A naive "biggest peak" or additive
|
|
17
18
|
* harmonic-comb picker therefore drifts down to the lowest in-range sub-harmonic. Three
|
|
18
19
|
* mechanisms cooperate here to lock the true fundamental instead:
|
|
19
20
|
*
|
|
@@ -24,9 +25,9 @@
|
|
|
24
25
|
* (`f`, `f/2`, `f/3` → lags `p, 2p, 3p`) MINUS a penalty for energy at its
|
|
25
26
|
* SUPER-harmonics (`2f`, `3f` → lags `p/2, p/3`). A true fundamental has no
|
|
26
27
|
* super-harmonic energy, so it keeps its full comb; a sub-harmonic candidate is
|
|
27
|
-
* demoted because its super-harmonic (the real beat) is strong.
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* demoted because its super-harmonic (the real beat) is strong. Metrical support
|
|
29
|
+
* therefore reinforces the fundamental rather than a lone sub-harmonic peak, over
|
|
30
|
+
* the `{f/2, f, 2f, 3f}` family. [scoreTempoHypotheses]
|
|
30
31
|
*
|
|
31
32
|
* The super-harmonic penalty is SUBDIVISION-AWARE: a candidate `kf` (k = 2, 3) only
|
|
32
33
|
* demotes `f` when `kf` could itself be the beat, i.e. `kf` lies within the tempo
|
|
@@ -37,7 +38,7 @@
|
|
|
37
38
|
* demoted in favour of an unrelated in-band multiple (180 → 120). Pure clicktracks
|
|
38
39
|
* are unaffected: they have no super-harmonic energy, so the gate changes nothing.
|
|
39
40
|
* 3. A soft log-Gaussian tempo prior centred on ~140 BPM breaks residual ties toward
|
|
40
|
-
* the musical core (100
|
|
41
|
+
* the musical core (100-200 BPM) without hard-clamping the edges. [tempoPrior]
|
|
41
42
|
*/
|
|
42
43
|
export interface TempoCandidateResult {
|
|
43
44
|
/** BPM value. */
|
|
@@ -47,7 +48,7 @@ export interface TempoCandidateResult {
|
|
|
47
48
|
/** ACF lag in hops that produced this peak. */
|
|
48
49
|
lag: number;
|
|
49
50
|
}
|
|
50
|
-
/** Tuning knobs for tempo-candidate scoring. Internal constants for now
|
|
51
|
+
/** Tuning knobs for tempo-candidate scoring. Internal constants for now. */
|
|
51
52
|
export interface TempoScoringOptions {
|
|
52
53
|
/** Lowest BPM accepted as a candidate. */
|
|
53
54
|
minBpm?: number;
|
|
@@ -60,7 +61,7 @@ export interface TempoScoringOptions {
|
|
|
60
61
|
/** Number of candidates to return. */
|
|
61
62
|
topK?: number;
|
|
62
63
|
}
|
|
63
|
-
/** Prior centre
|
|
64
|
+
/** Prior centre - geometric mean of the 100-200 BPM "precise" band. */
|
|
64
65
|
export declare const defaultPriorMu = 140;
|
|
65
66
|
/** Prior width: ≈ ±1 octave at ~0.6 weight. */
|
|
66
67
|
export declare const defaultPriorSigma: number;
|
|
@@ -70,6 +71,13 @@ export declare const defaultPriorSigma: number;
|
|
|
70
71
|
* its peak can round just outside the band and be discarded.
|
|
71
72
|
*/
|
|
72
73
|
export declare const candidateEdgeTolerance = 0.05;
|
|
74
|
+
/** Periodicity-comb weights for a candidate's own sub-multiples (f, f/2, f/3). */
|
|
75
|
+
export declare const combWeightFundamental = 1;
|
|
76
|
+
export declare const combWeightHalf = 0.5;
|
|
77
|
+
export declare const combWeightThird = 0.3;
|
|
78
|
+
/** Super-harmonic penalty weights (2f, 3f) - strong evidence the candidate is a sub-harmonic. */
|
|
79
|
+
export declare const combPenaltyDouble = 1;
|
|
80
|
+
export declare const combPenaltyTriple = 0.5;
|
|
73
81
|
/**
|
|
74
82
|
* The ACF is computed down to a shorter lag than the candidate band needs, so that
|
|
75
83
|
* (a) a high-BPM fundamental whose lag lands on `minLag` is an interior peak with its
|
|
@@ -77,7 +85,7 @@ export declare const candidateEdgeTolerance = 0.05;
|
|
|
77
85
|
* (a sub-harmonic candidate's real beat). One third of `minLag` reaches the 3f lag of a
|
|
78
86
|
* candidate at maxBpm.
|
|
79
87
|
*/
|
|
80
|
-
export declare
|
|
88
|
+
export declare const acfExtendedMinLag: (minLag: number) => number;
|
|
81
89
|
/**
|
|
82
90
|
* Compute the normalised autocorrelation function over a novelty curve.
|
|
83
91
|
*
|
|
@@ -91,7 +99,38 @@ export declare function acfExtendedMinLag(minLag: number): number;
|
|
|
91
99
|
* @param maxLag Maximum lag in hops (inclusive).
|
|
92
100
|
* @returns ACF array indexed by lag (index 0 = lag minLag).
|
|
93
101
|
*/
|
|
94
|
-
export declare
|
|
102
|
+
export declare const computeAcf: (flux: Float32Array, minLag: number, maxLag: number) => Float32Array;
|
|
103
|
+
/**
|
|
104
|
+
* {@link computeAcf} writing into a caller-owned buffer.
|
|
105
|
+
*
|
|
106
|
+
* Separate from the allocating form because the AudioWorklet calls this once per ACF hop
|
|
107
|
+
* on the audio thread, where a per-call `Float32Array` is unaffordable, and because it
|
|
108
|
+
* reads only the first `n` entries of a longer scratch buffer instead of the whole array.
|
|
109
|
+
*
|
|
110
|
+
* @param flux Novelty scratch buffer; only `flux[0..n-1]` is read (oldest first).
|
|
111
|
+
* @param n Number of valid novelty values in `flux`.
|
|
112
|
+
* @param minLag Minimum lag in hops (inclusive).
|
|
113
|
+
* @param maxLag Maximum lag in hops (inclusive).
|
|
114
|
+
* @param out Receives `maxLag - minLag + 1` values, indexed by lag from `minLag`.
|
|
115
|
+
*/
|
|
116
|
+
export declare const computeAcfInto: (flux: Float32Array, n: number, minLag: number, maxLag: number, out: Float32Array) => void;
|
|
117
|
+
/**
|
|
118
|
+
* Sample the ACF at an arbitrary (possibly fractional) lag with linear interpolation.
|
|
119
|
+
* Returns 0 outside the computed lag range and clamps negative correlation to 0 so
|
|
120
|
+
* anti-correlated harmonics never contribute to (or subtract spuriously from) a comb.
|
|
121
|
+
*/
|
|
122
|
+
export declare const acfAtLag: (acf: Float32Array, minLag: number, lag: number) => number;
|
|
123
|
+
/**
|
|
124
|
+
* Sub-lag peak refinement. Fit a parabola through the three samples around an interior
|
|
125
|
+
* local maximum (acf[i-1], acf[i], acf[i+1]) and return the vertex offset in [-0.5, 0.5].
|
|
126
|
+
*
|
|
127
|
+
* The lag grid is coarse at the top of the BPM band (a 300 BPM beat sits at lag ≈ 18.75
|
|
128
|
+
* hops, ~5 ms / lag), so rounding a peak to its nearest integer lag costs several BPM.
|
|
129
|
+
* Interpolating the vertex recovers sub-hop BPM resolution without shrinking the hop.
|
|
130
|
+
* Returns 0 when the three points are not strictly concave (cannot happen for a genuine
|
|
131
|
+
* strict local maximum, but guards floating-point edge cases).
|
|
132
|
+
*/
|
|
133
|
+
export declare const parabolicPeakOffset: (yPrev: number, yMid: number, yNext: number) => number;
|
|
95
134
|
/**
|
|
96
135
|
* Find all positive local-maxima peaks in the ACF and convert lags to BPM candidates.
|
|
97
136
|
*
|
|
@@ -107,9 +146,9 @@ export declare function computeAcf(flux: Float32Array, minLag: number, maxLag: n
|
|
|
107
146
|
* @param sampleRate Audio sample rate in Hz.
|
|
108
147
|
* @param topK Number of peaks to return (default 3).
|
|
109
148
|
*/
|
|
110
|
-
export declare
|
|
149
|
+
export declare const findTempoPeaks: (acf: Float32Array, minLag: number, hopSize: number, sampleRate: number, topK?: number) => TempoCandidateResult[];
|
|
111
150
|
/** Soft log-Gaussian tempo prior: 1 at `mu`, decaying symmetrically in log-BPM. */
|
|
112
|
-
export declare
|
|
151
|
+
export declare const tempoPrior: (bpm: number, mu?: number, sigma?: number) => number;
|
|
113
152
|
/**
|
|
114
153
|
* Re-score raw ACF peaks into musically-disambiguated tempo candidates.
|
|
115
154
|
*
|
|
@@ -123,13 +162,13 @@ export declare function tempoPrior(bpm: number, mu?: number, sigma?: number): nu
|
|
|
123
162
|
* super-harmonic (the real beat), so it is demoted; the true fundamental has no
|
|
124
163
|
* super-harmonic energy and keeps its full comb.
|
|
125
164
|
*
|
|
126
|
-
* The penalty is gated to be SUBDIVISION-AWARE
|
|
165
|
+
* The penalty is gated to be SUBDIVISION-AWARE: a super-harmonic
|
|
127
166
|
* `kf` only counts against `f` when `kf` is itself a plausible beat (`kf ≤ maxBpm`). Energy
|
|
128
167
|
* at a super-harmonic above the tempo band is a subdivision (e.g. hats on 8th-notes over a
|
|
129
168
|
* 180 BPM kick), not a competing fundamental, and must not demote the true beat. Returns
|
|
130
169
|
* candidates sorted by score.
|
|
131
170
|
*/
|
|
132
|
-
export declare
|
|
171
|
+
export declare const scoreTempoHypotheses: (peaks: TempoCandidateResult[], acf: Float32Array, minLag: number, options?: TempoScoringOptions) => TempoCandidateResult[];
|
|
133
172
|
/**
|
|
134
173
|
* Full tempo-candidate pipeline: ACF → peaks → comb + super-harmonic penalty + prior.
|
|
135
174
|
*
|
|
@@ -141,12 +180,13 @@ export declare function scoreTempoHypotheses(peaks: TempoCandidateResult[], acf:
|
|
|
141
180
|
* @param hopSize Audio samples per hop.
|
|
142
181
|
* @param sampleRate Audio sample rate in Hz.
|
|
143
182
|
*/
|
|
144
|
-
export declare
|
|
183
|
+
export declare const computeTempoCandidates: (flux: Float32Array, minLag: number, maxLag: number, hopSize: number, sampleRate: number, options?: TempoScoringOptions) => TempoCandidateResult[];
|
|
145
184
|
/**
|
|
146
|
-
* True when `bpm` is a metrically-related multiple of `reference`
|
|
185
|
+
* True when `bpm` is a metrically-related multiple of `reference` - a ½×, 2×, 3× or ⅓×
|
|
147
186
|
* octave, OR a 3:2 / 2:3 (dotted ↔ triple) relative. Switching across any of these needs the
|
|
148
187
|
* stronger hysteresis margin: they are the same beat counted at a different metrical level
|
|
149
188
|
* (e.g. 180 BPM kick vs the 120 BPM "dotted" grouping its 8th-note subdivisions create), not
|
|
150
189
|
* a genuine tempo change.
|
|
151
190
|
*/
|
|
152
|
-
export declare
|
|
191
|
+
export declare const isOctaveRelated: (bpm: number, reference: number) => boolean;
|
|
192
|
+
//# sourceMappingURL=tempogram.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tempogram.d.ts","sourceRoot":"","sources":["../../../src/dsp/tempogram.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,MAAM,WAAW,oBAAoB;IACnC,iBAAiB;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,GAAG,EAAE,MAAM,CAAC;CACb;AAED,4EAA4E;AAC5E,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,uEAAuE;AACvE,eAAO,MAAM,cAAc,MAAM,CAAC;AAClC,+CAA+C;AAC/C,eAAO,MAAM,iBAAiB,QAAoB,CAAC;AACnD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,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S,mBAAwB,KAChC,oBAAoB,EA0BtB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,GACjC,MAAM,YAAY,EAClB,QAAQ,MAAM,EACd,QAAQ,MAAM,EACd,SAAS,MAAM,EACf,YAAY,MAAM,EAClB,UAAS,mBAAwB,KAChC,oBAAoB,EAatB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,EAAE,WAAW,MAAM,KAAG,OAWhE,CAAC"}
|
|
@@ -34,7 +34,7 @@ export interface AutoWahEffectOptions {
|
|
|
34
34
|
* bandpass filter, creating the characteristic "wah" sweep driven by the
|
|
35
35
|
* loudness of the input signal.
|
|
36
36
|
*
|
|
37
|
-
* The envelope follower is built entirely from native Web Audio nodes
|
|
37
|
+
* The envelope follower is built entirely from native Web Audio nodes - no
|
|
38
38
|
* `ScriptProcessor` or `AudioWorklet` required:
|
|
39
39
|
*
|
|
40
40
|
* 1. A `WaveShaperNode` rectifier approximates `|x|` (full-wave rectification),
|
|
@@ -51,7 +51,7 @@ export interface AutoWahEffectOptions {
|
|
|
51
51
|
* │ ├── outputGain
|
|
52
52
|
* └─ wahFilter(bandpass) ─── wetGain ──────┘
|
|
53
53
|
*
|
|
54
|
-
* Envelope (control) path
|
|
54
|
+
* Envelope (control) path - parallel off inputGain, sums into wahFilter.frequency:
|
|
55
55
|
* inputGain → rectifier(WaveShaper,|x|) → smoothingLowpass(BiquadFilter,lowpass)
|
|
56
56
|
* → sensitivityGain → wahFilter.frequency (AudioParam)
|
|
57
57
|
* ```
|
|
@@ -125,3 +125,4 @@ export declare class AutoWahEffect extends AudioEffect {
|
|
|
125
125
|
private static _makeRectifierCurve;
|
|
126
126
|
private _setupNodes;
|
|
127
127
|
}
|
|
128
|
+
//# sourceMappingURL=AutoWahEffect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoWahEffect.d.ts","sourceRoot":"","sources":["../../../src/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