@codexo/exojs-audio-fx 0.19.1 → 0.20.0

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.
Files changed (127) hide show
  1. package/README.md +7 -53
  2. package/index.d.ts +1 -0
  3. package/index.js +1 -0
  4. package/package.json +12 -20
  5. package/dist/esm/AudioAnalyser.d.ts +0 -123
  6. package/dist/esm/AudioAnalyser.d.ts.map +0 -1
  7. package/dist/esm/AudioAnalyser.js +0 -295
  8. package/dist/esm/AudioAnalyser.js.map +0 -1
  9. package/dist/esm/AudioTap.d.ts +0 -33
  10. package/dist/esm/AudioTap.d.ts.map +0 -1
  11. package/dist/esm/AudioTap.js +0 -126
  12. package/dist/esm/AudioTap.js.map +0 -1
  13. package/dist/esm/BeatDetector.d.ts +0 -291
  14. package/dist/esm/BeatDetector.d.ts.map +0 -1
  15. package/dist/esm/BeatDetector.js +0 -365
  16. package/dist/esm/BeatDetector.js.map +0 -1
  17. package/dist/esm/PcmStreamSource.d.ts +0 -132
  18. package/dist/esm/PcmStreamSource.d.ts.map +0 -1
  19. package/dist/esm/PcmStreamSource.js +0 -313
  20. package/dist/esm/PcmStreamSource.js.map +0 -1
  21. package/dist/esm/ReadyGate.d.ts +0 -25
  22. package/dist/esm/ReadyGate.d.ts.map +0 -1
  23. package/dist/esm/ReadyGate.js +0 -69
  24. package/dist/esm/ReadyGate.js.map +0 -1
  25. package/dist/esm/dsp/fft.d.ts +0 -22
  26. package/dist/esm/dsp/fft.d.ts.map +0 -1
  27. package/dist/esm/dsp/mel.d.ts +0 -43
  28. package/dist/esm/dsp/mel.d.ts.map +0 -1
  29. package/dist/esm/dsp/mel.js +0 -61
  30. package/dist/esm/dsp/mel.js.map +0 -1
  31. package/dist/esm/dsp/tempogram.d.ts +0 -192
  32. package/dist/esm/dsp/tempogram.d.ts.map +0 -1
  33. package/dist/esm/effects/AutoWahEffect.d.ts +0 -127
  34. package/dist/esm/effects/AutoWahEffect.d.ts.map +0 -1
  35. package/dist/esm/effects/AutoWahEffect.js +0 -209
  36. package/dist/esm/effects/AutoWahEffect.js.map +0 -1
  37. package/dist/esm/effects/BitCrusherEffect.d.ts +0 -64
  38. package/dist/esm/effects/BitCrusherEffect.d.ts.map +0 -1
  39. package/dist/esm/effects/BitCrusherEffect.js +0 -76
  40. package/dist/esm/effects/BitCrusherEffect.js.map +0 -1
  41. package/dist/esm/effects/ChorusEffect.d.ts +0 -60
  42. package/dist/esm/effects/ChorusEffect.d.ts.map +0 -1
  43. package/dist/esm/effects/ChorusEffect.js +0 -139
  44. package/dist/esm/effects/ChorusEffect.js.map +0 -1
  45. package/dist/esm/effects/CompressorEffect.d.ts +0 -55
  46. package/dist/esm/effects/CompressorEffect.d.ts.map +0 -1
  47. package/dist/esm/effects/CompressorEffect.js +0 -103
  48. package/dist/esm/effects/CompressorEffect.js.map +0 -1
  49. package/dist/esm/effects/ConvolutionEffect.d.ts +0 -118
  50. package/dist/esm/effects/ConvolutionEffect.d.ts.map +0 -1
  51. package/dist/esm/effects/ConvolutionEffect.js +0 -207
  52. package/dist/esm/effects/ConvolutionEffect.js.map +0 -1
  53. package/dist/esm/effects/DelayEffect.d.ts +0 -35
  54. package/dist/esm/effects/DelayEffect.d.ts.map +0 -1
  55. package/dist/esm/effects/DelayEffect.js +0 -104
  56. package/dist/esm/effects/DelayEffect.js.map +0 -1
  57. package/dist/esm/effects/DistortionEffect.d.ts +0 -116
  58. package/dist/esm/effects/DistortionEffect.d.ts.map +0 -1
  59. package/dist/esm/effects/DistortionEffect.js +0 -189
  60. package/dist/esm/effects/DistortionEffect.js.map +0 -1
  61. package/dist/esm/effects/DuckingEffect.d.ts +0 -44
  62. package/dist/esm/effects/DuckingEffect.d.ts.map +0 -1
  63. package/dist/esm/effects/DuckingEffect.js +0 -89
  64. package/dist/esm/effects/DuckingEffect.js.map +0 -1
  65. package/dist/esm/effects/EqualizerEffect.d.ts +0 -50
  66. package/dist/esm/effects/EqualizerEffect.d.ts.map +0 -1
  67. package/dist/esm/effects/EqualizerEffect.js +0 -119
  68. package/dist/esm/effects/EqualizerEffect.js.map +0 -1
  69. package/dist/esm/effects/FlangerEffect.d.ts +0 -107
  70. package/dist/esm/effects/FlangerEffect.d.ts.map +0 -1
  71. package/dist/esm/effects/FlangerEffect.js +0 -178
  72. package/dist/esm/effects/FlangerEffect.js.map +0 -1
  73. package/dist/esm/effects/GranularEffect.d.ts +0 -67
  74. package/dist/esm/effects/GranularEffect.d.ts.map +0 -1
  75. package/dist/esm/effects/GranularEffect.js +0 -104
  76. package/dist/esm/effects/GranularEffect.js.map +0 -1
  77. package/dist/esm/effects/LimiterEffect.d.ts +0 -129
  78. package/dist/esm/effects/LimiterEffect.d.ts.map +0 -1
  79. package/dist/esm/effects/LimiterEffect.js +0 -185
  80. package/dist/esm/effects/LimiterEffect.js.map +0 -1
  81. package/dist/esm/effects/PhaserEffect.d.ts +0 -126
  82. package/dist/esm/effects/PhaserEffect.d.ts.map +0 -1
  83. package/dist/esm/effects/PhaserEffect.js +0 -213
  84. package/dist/esm/effects/PhaserEffect.js.map +0 -1
  85. package/dist/esm/effects/PingPongDelayEffect.d.ts +0 -83
  86. package/dist/esm/effects/PingPongDelayEffect.d.ts.map +0 -1
  87. package/dist/esm/effects/PingPongDelayEffect.js +0 -171
  88. package/dist/esm/effects/PingPongDelayEffect.js.map +0 -1
  89. package/dist/esm/effects/PitchShiftEffect.d.ts +0 -46
  90. package/dist/esm/effects/PitchShiftEffect.d.ts.map +0 -1
  91. package/dist/esm/effects/PitchShiftEffect.js +0 -64
  92. package/dist/esm/effects/PitchShiftEffect.js.map +0 -1
  93. package/dist/esm/effects/ReverbEffect.d.ts +0 -37
  94. package/dist/esm/effects/ReverbEffect.d.ts.map +0 -1
  95. package/dist/esm/effects/ReverbEffect.js +0 -112
  96. package/dist/esm/effects/ReverbEffect.js.map +0 -1
  97. package/dist/esm/effects/RingModulatorEffect.d.ts +0 -95
  98. package/dist/esm/effects/RingModulatorEffect.d.ts.map +0 -1
  99. package/dist/esm/effects/RingModulatorEffect.js +0 -152
  100. package/dist/esm/effects/RingModulatorEffect.js.map +0 -1
  101. package/dist/esm/effects/TremoloEffect.d.ts +0 -108
  102. package/dist/esm/effects/TremoloEffect.d.ts.map +0 -1
  103. package/dist/esm/effects/TremoloEffect.js +0 -192
  104. package/dist/esm/effects/TremoloEffect.js.map +0 -1
  105. package/dist/esm/effects/VocoderEffect.d.ts +0 -45
  106. package/dist/esm/effects/VocoderEffect.d.ts.map +0 -1
  107. package/dist/esm/effects/VocoderEffect.js +0 -68
  108. package/dist/esm/effects/VocoderEffect.js.map +0 -1
  109. package/dist/esm/index.d.ts +0 -25
  110. package/dist/esm/index.d.ts.map +0 -1
  111. package/dist/esm/index.js +0 -24
  112. package/dist/esm/worklets/beat-detector.worklet.js +0 -6
  113. package/dist/esm/worklets/beat-detector.worklet.js.map +0 -1
  114. package/dist/esm/worklets/bit-crusher.worklet.js +0 -6
  115. package/dist/esm/worklets/bit-crusher.worklet.js.map +0 -1
  116. package/dist/esm/worklets/disposable-processor.d.ts +0 -13
  117. package/dist/esm/worklets/disposable-processor.d.ts.map +0 -1
  118. package/dist/esm/worklets/ducking.worklet.js +0 -6
  119. package/dist/esm/worklets/ducking.worklet.js.map +0 -1
  120. package/dist/esm/worklets/granular.worklet.js +0 -6
  121. package/dist/esm/worklets/granular.worklet.js.map +0 -1
  122. package/dist/esm/worklets/pcm-stream.worklet.js +0 -6
  123. package/dist/esm/worklets/pcm-stream.worklet.js.map +0 -1
  124. package/dist/esm/worklets/pitch-shift.worklet.js +0 -6
  125. package/dist/esm/worklets/pitch-shift.worklet.js.map +0 -1
  126. package/dist/esm/worklets/vocoder.worklet.js +0 -6
  127. package/dist/esm/worklets/vocoder.worklet.js.map +0 -1
@@ -1,126 +0,0 @@
1
- import { getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
2
-
3
- //#region src/AudioTap.ts
4
- /**
5
- * Feeds one source into one analysis node as a parallel branch, leaving the
6
- * source's own routing alone. Keeps that connection through a locked
7
- * AudioContext, a bus that has not built its nodes yet, a target that only
8
- * arrives later (a loading worklet) and source changes.
9
- *
10
- * Shared by `AudioAnalyser` and `BeatDetector`, which differ only in the node
11
- * they feed.
12
- */
13
- var AudioTap = class {
14
- _source = null;
15
- _target = null;
16
- _tapNode = null;
17
- _streamSource = null;
18
- _pendingSourceSetup = null;
19
- _cancelDeferredRetry = null;
20
- get source() {
21
- return this._source;
22
- }
23
- set source(value) {
24
- if (value === this._source) return;
25
- this._disconnect();
26
- this._cancelDeferred();
27
- this._source = value;
28
- if (value === null) return;
29
- if (isAudioContextReady()) {
30
- this._cancelPendingSetup();
31
- this._connect(value, getAudioContext());
32
- } else {
33
- this._cancelPendingSetup();
34
- const handler = (context) => {
35
- onAudioContextReady.remove(handler);
36
- this._pendingSourceSetup = null;
37
- this._connect(value, context);
38
- };
39
- this._pendingSourceSetup = handler;
40
- onAudioContextReady.add(handler);
41
- }
42
- }
43
- /** Sets the node the source feeds and connects a source assigned before it existed. */
44
- attach(target, context) {
45
- this._target = target;
46
- if (this._source !== null) this._connect(this._source, context);
47
- }
48
- /** Disconnects the tap, cancels pending setup and forgets source and target. */
49
- destroy() {
50
- this._cancelPendingSetup();
51
- this._cancelDeferred();
52
- this._disconnect();
53
- this._target = null;
54
- this._source = null;
55
- }
56
- _connect(source, context) {
57
- if (!this._target) return;
58
- const tap = this._resolve(source, context);
59
- if (!tap) {
60
- this._deferUntilBusSetup(source);
61
- return;
62
- }
63
- this._tapNode = tap;
64
- tap.connect(this._target, 0, 0);
65
- }
66
- _resolve(source, context) {
67
- if (source === null) return null;
68
- if (typeof source.getTracks === "function") {
69
- if (this._streamSource) {
70
- this._streamSource.disconnect();
71
- this._streamSource = null;
72
- }
73
- const streamSource = context.createMediaStreamSource(source);
74
- this._streamSource = streamSource;
75
- return streamSource;
76
- }
77
- const asBus = source;
78
- if (typeof asBus.getOutputNode === "function") return asBus.getOutputNode();
79
- const asVoice = source;
80
- if ("output" in asVoice && asVoice.output) return asVoice.output;
81
- const asNode = source;
82
- if (typeof asNode.connect === "function" && typeof asNode.disconnect === "function") return source;
83
- return null;
84
- }
85
- _deferUntilBusSetup(source) {
86
- this._cancelDeferred();
87
- const retry = () => {
88
- this._cancelDeferred();
89
- if (this._source === source && this._target && isAudioContextReady()) this._connect(source, getAudioContext());
90
- };
91
- const asBus = source;
92
- if (typeof asBus.onceSetup === "function") {
93
- let dispose = null;
94
- this._cancelDeferredRetry = () => dispose?.();
95
- dispose = asBus.onceSetup(retry);
96
- return;
97
- }
98
- onAudioContextReady.add(retry);
99
- this._cancelDeferredRetry = () => onAudioContextReady.remove(retry);
100
- }
101
- _cancelDeferred() {
102
- const cancel = this._cancelDeferredRetry;
103
- this._cancelDeferredRetry = null;
104
- cancel?.();
105
- }
106
- _disconnect() {
107
- if (this._tapNode && this._target) try {
108
- this._tapNode.disconnect(this._target);
109
- } catch {}
110
- this._tapNode = null;
111
- if (this._streamSource) {
112
- this._streamSource.disconnect();
113
- this._streamSource = null;
114
- }
115
- }
116
- _cancelPendingSetup() {
117
- if (this._pendingSourceSetup !== null) {
118
- onAudioContextReady.remove(this._pendingSourceSetup);
119
- this._pendingSourceSetup = null;
120
- }
121
- }
122
- };
123
-
124
- //#endregion
125
- export { AudioTap };
126
- //# sourceMappingURL=AudioTap.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AudioTap.js","names":["asStream"],"sources":["../../src/AudioTap.ts"],"sourcesContent":["import { type AudioBus, getAudioContext, isAudioContextReady, onAudioContextReady, type Voice } from '@codexo/exojs';\n\n/** What an analysis tap can listen to. */\nexport type AudioTapSource = AudioBus | Voice | MediaStream | AudioNode | null;\n\n/**\n * Feeds one source into one analysis node as a parallel branch, leaving the\n * source's own routing alone. Keeps that connection through a locked\n * AudioContext, a bus that has not built its nodes yet, a target that only\n * arrives later (a loading worklet) and source changes.\n *\n * Shared by `AudioAnalyser` and `BeatDetector`, which differ only in the node\n * they feed.\n */\nexport class AudioTap {\n private _source: AudioTapSource = null;\n private _target: AudioNode | null = null;\n private _tapNode: AudioNode | null = null;\n private _streamSource: MediaStreamAudioSourceNode | null = null;\n private _pendingSourceSetup: ((context: AudioContext) => void) | null = null;\n // A deferred retry for a source whose bus has not built its nodes yet. Kept\n // so a source change or destroy can unregister it instead of leaving the old\n // source referenced until that bus is set up or destroyed.\n private _cancelDeferredRetry: (() => void) | null = null;\n\n public get source(): AudioTapSource {\n return this._source;\n }\n\n public set source(value: AudioTapSource) {\n if (value === this._source) return;\n\n this._disconnect();\n this._cancelDeferred();\n this._source = value;\n\n if (value === null) return;\n\n if (isAudioContextReady()) {\n this._cancelPendingSetup();\n this._connect(value, getAudioContext());\n } else {\n this._cancelPendingSetup();\n\n const handler = (context: AudioContext): void => {\n onAudioContextReady.remove(handler);\n this._pendingSourceSetup = null;\n this._connect(value, context);\n };\n\n this._pendingSourceSetup = handler;\n onAudioContextReady.add(handler);\n }\n }\n\n /** Sets the node the source feeds and connects a source assigned before it existed. */\n public attach(target: AudioNode, context: AudioContext): void {\n this._target = target;\n\n if (this._source !== null) {\n this._connect(this._source, context);\n }\n }\n\n /** Disconnects the tap, cancels pending setup and forgets source and target. */\n public destroy(): void {\n this._cancelPendingSetup();\n this._cancelDeferred();\n this._disconnect();\n this._target = null;\n this._source = null;\n }\n\n private _connect(source: AudioTapSource, context: AudioContext): void {\n if (!this._target) return;\n\n const tap = this._resolve(source, context);\n\n if (!tap) {\n this._deferUntilBusSetup(source);\n\n return;\n }\n\n this._tapNode = tap;\n tap.connect(this._target, 0, 0);\n }\n\n private _resolve(source: AudioTapSource, context: AudioContext): AudioNode | null {\n if (source === null) return null;\n\n // MediaStream - duck-typed via getTracks, since jsdom has no MediaStream.\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 streamSource = context.createMediaStreamSource(source as MediaStream);\n this._streamSource = streamSource;\n return streamSource;\n }\n\n // AudioBus - checked before the raw-node case, since a bus also looks node-like.\n const asBus = source as Partial<{ getOutputNode: () => AudioNode | null }>;\n if (typeof asBus.getOutputNode === 'function') {\n return asBus.getOutputNode();\n }\n\n const asVoice = source as Partial<{ output: AudioNode }>;\n if ('output' in asVoice && asVoice.output) {\n return asVoice.output;\n }\n\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 _deferUntilBusSetup(source: AudioTapSource): void {\n this._cancelDeferred();\n\n const retry = (): void => {\n this._cancelDeferred();\n if (this._source === source && this._target && isAudioContextReady()) {\n this._connect(source, getAudioContext());\n }\n };\n const asBus = source as Partial<{ onceSetup: (callback: () => void) => () => void }>;\n\n if (typeof asBus.onceSetup === 'function') {\n // Assigned before the call can run `retry`: a bus that is already set up\n // invokes it synchronously, and its own cancel must find nothing to undo.\n let dispose: (() => void) | null = null;\n this._cancelDeferredRetry = () => dispose?.();\n dispose = asBus.onceSetup(retry);\n\n return;\n }\n\n onAudioContextReady.add(retry);\n this._cancelDeferredRetry = () => onAudioContextReady.remove(retry);\n }\n\n private _cancelDeferred(): void {\n const cancel = this._cancelDeferredRetry;\n\n this._cancelDeferredRetry = null;\n cancel?.();\n }\n\n private _disconnect(): void {\n if (this._tapNode && this._target) {\n try {\n this._tapNode.disconnect(this._target);\n } catch {\n // Already disconnected.\n }\n }\n this._tapNode = null;\n\n if (this._streamSource) {\n this._streamSource.disconnect();\n this._streamSource = null;\n }\n }\n\n private _cancelPendingSetup(): void {\n if (this._pendingSourceSetup !== null) {\n onAudioContextReady.remove(this._pendingSourceSetup);\n this._pendingSourceSetup = null;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAcA,IAAa,WAAb,MAAsB;CACpB,AAAQ,UAA0B;CAClC,AAAQ,UAA4B;CACpC,AAAQ,WAA6B;CACrC,AAAQ,gBAAmD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AgB;GACrB,OAAO;EACT;EAGA,MAAM,QAAQ;EACd,IAAI,OAAO,MAAM,kBAAkB,YACjC,OAAO,MAAM,cAAc;EAG7B,MAAM,UAAU;EAChB,IAAI,YAAY,WAAW,QAAQ,QACjC,OAAO,QAAQ;EAGjB,MAAM,SAAS;EACf,IAAI,OAAO,OAAO,YAAY,cAAc,OAAO,OAAO,eAAe,YACvE,OAAO;EAGT,OAAO;CACT;CAEA,AAAQ,oBAAoB,QAA8B;EACxD,KAAK,gBAAgB;EAErB,MAAM,cAAoB;GACxB,KAAK,gBAAgB;GACrB,IAAI,KAAK,YAAY,UAAU,KAAK,WAAW,oBAAoB,GACjE,KAAK,SAAS,QAAQ,gBAAgB,CAAC;EAE3C;EACA,MAAM,QAAQ;EAEd,IAAI,OAAO,MAAM,cAAc,YAAY;GAGzC,IAAI,UAA+B;GACnC,KAAK,6BAA6B,UAAU;GAC5C,UAAU,MAAM,UAAU,KAAK;GAE/B;EACF;EAEA,oBAAoB,IAAI,KAAK;EAC7B,KAAK,6BAA6B,oBAAoB,OAAO,KAAK;CACpE;CAEA,AAAQ,kBAAwB;EAC9B,MAAM,SAAS,KAAK;EAEpB,KAAK,uBAAuB;EAC5B,SAAS;CACX;CAEA,AAAQ,cAAoB;EAC1B,IAAI,KAAK,YAAY,KAAK,SACxB,IAAI;GACF,KAAK,SAAS,WAAW,KAAK,OAAO;EACvC,QAAQ,CAER;EAEF,KAAK,WAAW;EAEhB,IAAI,KAAK,eAAe;GACtB,KAAK,cAAc,WAAW;GAC9B,KAAK,gBAAgB;EACvB;CACF;CAEA,AAAQ,sBAA4B;EAClC,IAAI,KAAK,wBAAwB,MAAM;GACrC,oBAAoB,OAAO,KAAK,mBAAmB;GACnD,KAAK,sBAAsB;EAC7B;CACF;AACF"}
@@ -1,291 +0,0 @@
1
- import { type AudioBus, Signal, type Voice } from '@codexo/exojs';
2
- /**
3
- * What to analyse: a bus or voice (the usual case), a `MediaStream` such as a
4
- * microphone, or `null` for none yet. A raw `AudioNode` is Web Audio interop
5
- * for graphs built outside the engine.
6
- */
7
- export type BeatDetectorSource = AudioBus | Voice | MediaStream | AudioNode | null;
8
- export interface BeatDetectorOptions {
9
- /** Minimum detectable BPM. Default 50. */
10
- minBpm?: number;
11
- /** Maximum detectable BPM. Default 300. */
12
- maxBpm?: number;
13
- /** FFT size for onset detection. Default 2048. */
14
- fftSize?: number;
15
- /** Hop size in samples between successive FFTs. Default 512. */
16
- hopSize?: number;
17
- /**
18
- * Short tempogram window (seconds) that reacts quickly to a genuine tempo
19
- * change. Default 2.5. The tracked tempo follows this FAST window only when it
20
- * disagrees with {@link stableTempoWindowSec} consistently over several
21
- * analysis hops, so a real DJ drift is tracked without making a steady tempo
22
- * nervous.
23
- */
24
- fastTempoWindowSec?: number;
25
- /**
26
- * Long tempogram window (seconds) that holds the tempo grid steady against
27
- * noise and octave ambiguity. Default 8. Should be ≥ {@link fastTempoWindowSec}
28
- * and large enough to hold ≳ 2 periods of the slowest tempo; it also sizes the
29
- * internal flux ring buffer.
30
- */
31
- stableTempoWindowSec?: number;
32
- /**
33
- * Hops between successive autocorrelation (tempogram) recomputations.
34
- * Default 15 (~160 ms at 48 kHz with the default 512-sample hop). Lower values
35
- * react faster to tempo changes at the cost of more CPU.
36
- */
37
- acfIntervalHops?: number;
38
- /**
39
- * Minimum warm-up (ms) before the first beat may be emitted. Default 400.
40
- * The detector starts hunting a tempo once this much analysis history exists
41
- * instead of waiting a full slowest-tempo period, so early {@link BeatInfo}
42
- * beats (tagged `status: 'provisional'`) arrive with low latency for visual
43
- * reactivity. A beat is promoted to `status: 'locked'` only once the tempo grid
44
- * is trustworthy (full analysis window + sustained on-grid tracking). Replaces
45
- * the former `settlingMs` (default 1500).
46
- */
47
- minSettlingMs?: number;
48
- /**
49
- * When true (default), early low-confidence beats are emitted tagged
50
- * `status: 'provisional'` (then promoted to `'locked'`) for snappy visual
51
- * reactivity. Set false to suppress provisional beats entirely - {@link onBeat}
52
- * then fires only for `'locked'` beats, matching the pre-provisional behaviour.
53
- */
54
- emitProvisionalBeats?: boolean;
55
- /** Number of mel filterbank bands. Default 24. */
56
- melBands?: number;
57
- /**
58
- * When true (default), the worklet runs parallel 3/4 and 4/4 posteriors and
59
- * switches active time signature via hysteresis. Set false to lock to 4/4.
60
- */
61
- enableTimeSignatureDetection?: boolean;
62
- /**
63
- * Optional initial source. Equivalent to constructing then assigning
64
- * `detector.source = value`; provided for ergonomic one-shot construction.
65
- * The setter remains usable for runtime source switches.
66
- */
67
- source?: BeatDetectorSource;
68
- /**
69
- * Half-life in seconds for the {@link BeatDetector.pulse} envelope.
70
- * Default 0.15 - `pulse` halves every 150ms after each beat.
71
- */
72
- pulseHalfLife?: number;
73
- /**
74
- * Half-life in seconds for the {@link BeatDetector.barPulse} envelope.
75
- * Default 0.3 - slower than beat pulse for downbeat-emphasized visuals.
76
- */
77
- barPulseHalfLife?: number;
78
- /**
79
- * Time window in seconds for {@link BeatDetector.justBeat}. Default 0.03
80
- * - true for the visual frame(s) within 30ms of a beat onset.
81
- */
82
- justBeatWindow?: number;
83
- }
84
- export interface BeatInfo {
85
- /** audioContext.currentTime when the beat occurred. */
86
- audioTime: number;
87
- /** BPM at this beat. */
88
- tempo: number;
89
- /** Confidence 0..1. */
90
- confidence: number;
91
- /** Phase within beat (0 = start). */
92
- beatPhase: number;
93
- /** Novelty/onset strength at the beat. */
94
- energy: number;
95
- /** Is this beat the first in a bar? */
96
- isDownbeat: boolean;
97
- /** Beat position within the bar (1..N). */
98
- beatInBar: number;
99
- /**
100
- * Detection trust level:
101
- * - `'provisional'` - an early, low-latency beat emitted before the tempo grid
102
- * is fully settled. Good for visual reactivity (a "blink"); may be revised.
103
- * - `'locked'` - the tempo grid is settled and trustworthy. Safe for
104
- * sync-critical use. Each stable segment yields exactly one provisional→locked
105
- * transition.
106
- */
107
- status: 'provisional' | 'locked';
108
- }
109
- export interface UpcomingBeat {
110
- audioTime: number;
111
- tempo: number;
112
- isDownbeat: boolean;
113
- beatInBar: number;
114
- }
115
- export interface BarInfo {
116
- audioTime: number;
117
- tempo: number;
118
- confidence: number;
119
- /** Monotonically increasing bar counter since detector start. */
120
- barNumber: number;
121
- }
122
- export interface TimeSignature {
123
- numerator: number;
124
- denominator: number;
125
- }
126
- export interface TempoCandidate {
127
- bpm: number;
128
- /** Peak strength 0..1. */
129
- score: number;
130
- }
131
- export interface BandEnergy {
132
- low: number;
133
- mid: number;
134
- high: number;
135
- }
136
- /**
137
- * Real-time tempo + beat tracker. Splits work between the audio-rendering
138
- * thread (an AudioWorklet that runs onset detection, tempogram analysis,
139
- * and parallel 3/4 and 4/4 posterior estimation) and the main thread (this
140
- * class - receives beats, fires Signals, handles configuration and source
141
- * routing).
142
- *
143
- * Accepts a wide range of {@link BeatDetectorSource}s - a bus, an individual
144
- * {@link Voice}, a raw MediaStream, or any AudioNode - and exposes a Signal
145
- * for each notable event:
146
- * - {@link BeatDetector.onBeat} - every detected beat
147
- * - {@link BeatDetector.onDownbeat} - first beat of each bar
148
- * - {@link BeatDetector.onBarStart} - bar boundary
149
- * - {@link BeatDetector.onTempoChange} - when the tracked BPM changes
150
- * - {@link BeatDetector.onBeatPredicted} - look-ahead schedule notice
151
- *
152
- * Early beats arrive with low latency tagged `status: 'provisional'` (after a
153
- * short `minSettlingMs` warm-up, default 400 ms) for snappy visual reactivity,
154
- * then promote to `status: 'locked'` once the tempo grid is trustworthy - a
155
- * single {@link BeatDetector.onBeat} signal carries both via {@link BeatInfo.status}.
156
- * Set `emitProvisionalBeats: false` to receive only locked beats. Time-signature
157
- * detection (3/4 vs 4/4) is on by default; lock to 4/4 by setting
158
- * `enableTimeSignatureDetection: false`.
159
- */
160
- export declare class BeatDetector {
161
- readonly onBeat: Signal<[BeatInfo]>;
162
- readonly onTempoChange: Signal<[number, number]>;
163
- readonly onDownbeat: Signal<[BeatInfo]>;
164
- readonly onBarStart: Signal<[BarInfo]>;
165
- readonly onBeatPredicted: Signal<[UpcomingBeat]>;
166
- private readonly _options;
167
- private _workletNode;
168
- private readonly _tap;
169
- private readonly _ready;
170
- private _destroyed;
171
- private readonly _onAudioContextReady;
172
- private _tempo;
173
- private _beatPhase;
174
- private _nextBeatTime;
175
- private _confidence;
176
- private _phaseConfidence;
177
- private _gridStability;
178
- private _analysisTime;
179
- private _analysisLatency;
180
- private _tempoCandidates;
181
- private _rms;
182
- private _onsetStrength;
183
- private _bandEnergy;
184
- private _barPosition;
185
- private _barLength;
186
- private _timeSignature;
187
- private _nextDownbeatTime;
188
- private _lookahead;
189
- /**
190
- * Half-life in seconds for the {@link pulse} envelope. Mutable; default 0.15.
191
- * Smaller values give a snappier pulse, larger values a longer afterglow.
192
- */
193
- pulseHalfLife: number;
194
- /** Half-life for the {@link barPulse} envelope. Mutable; default 0.3. */
195
- barPulseHalfLife: number;
196
- /** Time window for {@link justBeat}. Mutable; default 0.03 (30ms). */
197
- justBeatWindow: number;
198
- constructor(options?: BeatDetectorOptions);
199
- get source(): BeatDetectorSource;
200
- set source(value: BeatDetectorSource);
201
- /**
202
- * Resolves once the analysis worklet is loaded and listening. Stays pending
203
- * while the shared AudioContext is locked. Rejects with the load error when
204
- * the worklet cannot load, and with an `AbortError` when the detector is
205
- * destroyed before it became ready.
206
- */
207
- get ready(): Promise<void>;
208
- get tempo(): number;
209
- get beatPhase(): number;
210
- get nextBeatTime(): number;
211
- get confidence(): number;
212
- /**
213
- * How well recent onsets support the beat grid's phase, 0 to 1, or 0 before
214
- * the grid locks.
215
- *
216
- * Distinct from {@link confidence}, which reports how sure the detector is of
217
- * the tempo. A metronomic loop at a wrong-by-an-octave tempo reads high
218
- * confidence and high phase confidence; a rubato passage at a known tempo
219
- * reads high confidence and low phase confidence. Gate anything that must
220
- * land exactly on the beat - a scored hit, a quantised trigger - on this
221
- * rather than on {@link confidence}.
222
- */
223
- get phaseConfidence(): number;
224
- get gridStability(): number;
225
- /**
226
- * The `AudioContext.currentTime` of the newest sample the current state
227
- * describes. 0 until the first state message arrives.
228
- *
229
- * Every timestamp this detector reports - this one, {@link BeatInfo.audioTime},
230
- * {@link nextBeatTime}, {@link lookahead} - is on the audio context's clock,
231
- * so `AudioOutputClock` converts them to the `performance.now()` timeline
232
- * without further correction.
233
- */
234
- get analysisTime(): number;
235
- /**
236
- * Seconds between {@link analysisTime} and the moment the main thread
237
- * received that state, measured rather than assumed.
238
- *
239
- * Covers the analysis hop and the worklet-to-main-thread delivery together,
240
- * and is quantised to the context's render-quantum boundary, so treat it as
241
- * a budget figure rather than an exact age. It says nothing about the output
242
- * path: what a listener hears lags the analysed audio by the output latency
243
- * on top, which `AudioOutputClock` reports.
244
- */
245
- get analysisLatency(): number;
246
- get rms(): number;
247
- get onsetStrength(): number;
248
- get bandEnergy(): BandEnergy;
249
- get tempoCandidates(): readonly TempoCandidate[];
250
- get barPosition(): number;
251
- get barLength(): number;
252
- get timeSignature(): TimeSignature;
253
- get nextDownbeatTime(): number;
254
- get lookahead(): readonly UpcomingBeat[];
255
- /**
256
- * Seconds elapsed since the most recent beat, derived from {@link beatPhase}
257
- * and {@link tempo}. Returns 0 when the detector hasn't locked yet.
258
- */
259
- get secondsSinceLastBeat(): number;
260
- /**
261
- * 0..1 envelope, peaks at 1.0 the moment a beat fires and halves every
262
- * {@link pulseHalfLife} seconds. Drives "pulse on the beat" visuals
263
- * with a single multiplication: `sprite.scale = 1 + clock.pulse * 0.3`.
264
- */
265
- get pulse(): number;
266
- /**
267
- * Like {@link pulse} but resets on downbeats and decays per
268
- * {@link barPulseHalfLife}. Useful for emphasizing the first beat of
269
- * each bar (e.g. brighter flash on "1" vs "2,3,4").
270
- */
271
- get barPulse(): number;
272
- /**
273
- * True for the visual frame(s) within {@link justBeatWindow} seconds of
274
- * a beat onset. Use for one-shot triggers (strobe flash, particle burst,
275
- * sample retrigger). Default window 30ms covers a typical 60fps frame.
276
- */
277
- get justBeat(): boolean;
278
- /**
279
- * Phase 0..1 within a subdivision of the current beat. `division` is the
280
- * number of subdivisions per beat: 2 for 8th notes, 4 for 16th notes,
281
- * 3 for triplets. Use to drive sub-beat-resolution effects:
282
- *
283
- * const sixteenth = clock.subdivisionPhase(4);
284
- * if (sixteenth < 0.05) flash();
285
- */
286
- subdivisionPhase(division: number): number;
287
- destroy(): void;
288
- private _setup;
289
- private _onWorkletMessage;
290
- }
291
- //# sourceMappingURL=BeatDetector.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BeatDetector.d.ts","sourceRoot":"","sources":["../../src/BeatDetector.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EAMb,MAAM,EACN,KAAK,KAAK,EACX,MAAM,eAAe,CAAC;AAUvB;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,KAAK,GAAG,WAAW,GAAG,SAAS,GAAG,IAAI,CAAC;AAEnF,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC;;;;OAIG;IACH,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,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