@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.
- package/README.md +7 -53
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +12 -20
- package/dist/esm/AudioAnalyser.d.ts +0 -123
- package/dist/esm/AudioAnalyser.d.ts.map +0 -1
- package/dist/esm/AudioAnalyser.js +0 -295
- package/dist/esm/AudioAnalyser.js.map +0 -1
- package/dist/esm/AudioTap.d.ts +0 -33
- package/dist/esm/AudioTap.d.ts.map +0 -1
- package/dist/esm/AudioTap.js +0 -126
- package/dist/esm/AudioTap.js.map +0 -1
- package/dist/esm/BeatDetector.d.ts +0 -291
- package/dist/esm/BeatDetector.d.ts.map +0 -1
- package/dist/esm/BeatDetector.js +0 -365
- package/dist/esm/BeatDetector.js.map +0 -1
- package/dist/esm/PcmStreamSource.d.ts +0 -132
- package/dist/esm/PcmStreamSource.d.ts.map +0 -1
- package/dist/esm/PcmStreamSource.js +0 -313
- package/dist/esm/PcmStreamSource.js.map +0 -1
- package/dist/esm/ReadyGate.d.ts +0 -25
- package/dist/esm/ReadyGate.d.ts.map +0 -1
- package/dist/esm/ReadyGate.js +0 -69
- package/dist/esm/ReadyGate.js.map +0 -1
- package/dist/esm/dsp/fft.d.ts +0 -22
- package/dist/esm/dsp/fft.d.ts.map +0 -1
- package/dist/esm/dsp/mel.d.ts +0 -43
- package/dist/esm/dsp/mel.d.ts.map +0 -1
- package/dist/esm/dsp/mel.js +0 -61
- package/dist/esm/dsp/mel.js.map +0 -1
- package/dist/esm/dsp/tempogram.d.ts +0 -192
- package/dist/esm/dsp/tempogram.d.ts.map +0 -1
- package/dist/esm/effects/AutoWahEffect.d.ts +0 -127
- package/dist/esm/effects/AutoWahEffect.d.ts.map +0 -1
- package/dist/esm/effects/AutoWahEffect.js +0 -209
- package/dist/esm/effects/AutoWahEffect.js.map +0 -1
- package/dist/esm/effects/BitCrusherEffect.d.ts +0 -64
- package/dist/esm/effects/BitCrusherEffect.d.ts.map +0 -1
- package/dist/esm/effects/BitCrusherEffect.js +0 -76
- package/dist/esm/effects/BitCrusherEffect.js.map +0 -1
- package/dist/esm/effects/ChorusEffect.d.ts +0 -60
- package/dist/esm/effects/ChorusEffect.d.ts.map +0 -1
- package/dist/esm/effects/ChorusEffect.js +0 -139
- package/dist/esm/effects/ChorusEffect.js.map +0 -1
- package/dist/esm/effects/CompressorEffect.d.ts +0 -55
- package/dist/esm/effects/CompressorEffect.d.ts.map +0 -1
- package/dist/esm/effects/CompressorEffect.js +0 -103
- package/dist/esm/effects/CompressorEffect.js.map +0 -1
- package/dist/esm/effects/ConvolutionEffect.d.ts +0 -118
- package/dist/esm/effects/ConvolutionEffect.d.ts.map +0 -1
- package/dist/esm/effects/ConvolutionEffect.js +0 -207
- package/dist/esm/effects/ConvolutionEffect.js.map +0 -1
- package/dist/esm/effects/DelayEffect.d.ts +0 -35
- package/dist/esm/effects/DelayEffect.d.ts.map +0 -1
- package/dist/esm/effects/DelayEffect.js +0 -104
- package/dist/esm/effects/DelayEffect.js.map +0 -1
- package/dist/esm/effects/DistortionEffect.d.ts +0 -116
- package/dist/esm/effects/DistortionEffect.d.ts.map +0 -1
- package/dist/esm/effects/DistortionEffect.js +0 -189
- package/dist/esm/effects/DistortionEffect.js.map +0 -1
- package/dist/esm/effects/DuckingEffect.d.ts +0 -44
- package/dist/esm/effects/DuckingEffect.d.ts.map +0 -1
- package/dist/esm/effects/DuckingEffect.js +0 -89
- package/dist/esm/effects/DuckingEffect.js.map +0 -1
- package/dist/esm/effects/EqualizerEffect.d.ts +0 -50
- package/dist/esm/effects/EqualizerEffect.d.ts.map +0 -1
- package/dist/esm/effects/EqualizerEffect.js +0 -119
- package/dist/esm/effects/EqualizerEffect.js.map +0 -1
- package/dist/esm/effects/FlangerEffect.d.ts +0 -107
- package/dist/esm/effects/FlangerEffect.d.ts.map +0 -1
- package/dist/esm/effects/FlangerEffect.js +0 -178
- package/dist/esm/effects/FlangerEffect.js.map +0 -1
- package/dist/esm/effects/GranularEffect.d.ts +0 -67
- package/dist/esm/effects/GranularEffect.d.ts.map +0 -1
- package/dist/esm/effects/GranularEffect.js +0 -104
- package/dist/esm/effects/GranularEffect.js.map +0 -1
- package/dist/esm/effects/LimiterEffect.d.ts +0 -129
- package/dist/esm/effects/LimiterEffect.d.ts.map +0 -1
- package/dist/esm/effects/LimiterEffect.js +0 -185
- package/dist/esm/effects/LimiterEffect.js.map +0 -1
- package/dist/esm/effects/PhaserEffect.d.ts +0 -126
- package/dist/esm/effects/PhaserEffect.d.ts.map +0 -1
- package/dist/esm/effects/PhaserEffect.js +0 -213
- package/dist/esm/effects/PhaserEffect.js.map +0 -1
- package/dist/esm/effects/PingPongDelayEffect.d.ts +0 -83
- package/dist/esm/effects/PingPongDelayEffect.d.ts.map +0 -1
- package/dist/esm/effects/PingPongDelayEffect.js +0 -171
- package/dist/esm/effects/PingPongDelayEffect.js.map +0 -1
- package/dist/esm/effects/PitchShiftEffect.d.ts +0 -46
- package/dist/esm/effects/PitchShiftEffect.d.ts.map +0 -1
- package/dist/esm/effects/PitchShiftEffect.js +0 -64
- package/dist/esm/effects/PitchShiftEffect.js.map +0 -1
- package/dist/esm/effects/ReverbEffect.d.ts +0 -37
- package/dist/esm/effects/ReverbEffect.d.ts.map +0 -1
- package/dist/esm/effects/ReverbEffect.js +0 -112
- package/dist/esm/effects/ReverbEffect.js.map +0 -1
- package/dist/esm/effects/RingModulatorEffect.d.ts +0 -95
- package/dist/esm/effects/RingModulatorEffect.d.ts.map +0 -1
- package/dist/esm/effects/RingModulatorEffect.js +0 -152
- package/dist/esm/effects/RingModulatorEffect.js.map +0 -1
- package/dist/esm/effects/TremoloEffect.d.ts +0 -108
- package/dist/esm/effects/TremoloEffect.d.ts.map +0 -1
- package/dist/esm/effects/TremoloEffect.js +0 -192
- package/dist/esm/effects/TremoloEffect.js.map +0 -1
- package/dist/esm/effects/VocoderEffect.d.ts +0 -45
- package/dist/esm/effects/VocoderEffect.d.ts.map +0 -1
- package/dist/esm/effects/VocoderEffect.js +0 -68
- package/dist/esm/effects/VocoderEffect.js.map +0 -1
- package/dist/esm/index.d.ts +0 -25
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -24
- package/dist/esm/worklets/beat-detector.worklet.js +0 -6
- package/dist/esm/worklets/beat-detector.worklet.js.map +0 -1
- package/dist/esm/worklets/bit-crusher.worklet.js +0 -6
- package/dist/esm/worklets/bit-crusher.worklet.js.map +0 -1
- package/dist/esm/worklets/disposable-processor.d.ts +0 -13
- package/dist/esm/worklets/disposable-processor.d.ts.map +0 -1
- package/dist/esm/worklets/ducking.worklet.js +0 -6
- package/dist/esm/worklets/ducking.worklet.js.map +0 -1
- package/dist/esm/worklets/granular.worklet.js +0 -6
- package/dist/esm/worklets/granular.worklet.js.map +0 -1
- package/dist/esm/worklets/pcm-stream.worklet.js +0 -6
- package/dist/esm/worklets/pcm-stream.worklet.js.map +0 -1
- package/dist/esm/worklets/pitch-shift.worklet.js +0 -6
- package/dist/esm/worklets/pitch-shift.worklet.js.map +0 -1
- package/dist/esm/worklets/vocoder.worklet.js +0 -6
- package/dist/esm/worklets/vocoder.worklet.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,59 +1,13 @@
|
|
|
1
1
|
# @codexo/exojs-audio-fx
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Since ExoJS v0.20, import from @codexo/exojs/audio-fx. This package is a compatibility shim for the 0.20 line; no independent feature development.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Every export of this package is the very binding its Core entry exports, so code that still imports `@codexo/exojs-audio-fx` shares one engine instance with code that already imports `@codexo/exojs/audio-fx`. The package contains no implementation of its own and depends on nothing but its `@codexo/exojs` peer.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
| Import | Replace with | Forwards |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `@codexo/exojs-audio-fx` | `@codexo/exojs/audio-fx` | everything |
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## Migrating
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
This helper expects an initialized application with audio already playing on its music bus. It does not load or start a track:
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
import type { Application } from '@codexo/exojs';
|
|
19
|
-
import { AudioAnalyser } from '@codexo/exojs-audio-fx';
|
|
20
|
-
|
|
21
|
-
export const inspectMusic = (app: Application): { read: () => Uint8Array; destroy: () => void } => {
|
|
22
|
-
const analyser = new AudioAnalyser({ source: app.audio.music, fftSize: 1024 });
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
read: () => analyser.getSpectrumLog(undefined, { bands: 16 }),
|
|
26
|
-
destroy: () => analyser.destroy(),
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
Call `read` from the owner's update path and destroy the helper when that owner ends. An analyser taps a live bus or voice, not an unloaded asset descriptor. A silent or muted routing path is not repaired by repeatedly creating analysers.
|
|
32
|
-
|
|
33
|
-
## Externally produced PCM
|
|
34
|
-
|
|
35
|
-
Use `PcmStreamSource` for bounded mono/stereo Float32 streaming into an `AudioBus`. Await readiness, enqueue at the source's sample rate, then explicitly start playback; caller-owned arrays are copied and remain reusable. See [the PCM contract and lifecycle guide](docs/pcm-streaming.md) and [the runnable streaming example](../../examples/audio-fx/pcm-stream.ts) for scheduling, overflow, underrun telemetry, clear and drain.
|
|
36
|
-
|
|
37
|
-
For GPU-generated samples, the [GPU stereo PCM guide](docs/gpu-pcm.md) and [example](../../examples/audio-fx/gpu-pcm-stream.ts) connect bounded readback slots to the source, with explicit byte packing or typed float readback on both rendering backends.
|
|
38
|
-
|
|
39
|
-
## Important boundaries
|
|
40
|
-
|
|
41
|
-
Browser audio needs a real user-gesture path. Worklet-backed processors can have asynchronous initialization and capability requirements; handle failure and teardown rather than assuming construction means readiness.
|
|
42
|
-
|
|
43
|
-
Effects, analyser nodes, detectors, and playing voices have distinct lifetimes. Track caller-created resources with their scene or dispose them at their own boundary. Do not leave a detector connected merely because its visual widget was removed.
|
|
44
|
-
|
|
45
|
-
Beat detection estimates tempo and phase. Polling windows such as `justBeat` are not one-shot events, and asynchronous messages are not hard real-time delivery. A rhythm-game scoring timeline needs an explicit authoritative timing design. Analysis values are not a calibrated acoustic loudness measurement.
|
|
46
|
-
|
|
47
|
-
## Documentation
|
|
48
|
-
|
|
49
|
-
[Audio basics](https://exoridus.github.io/ExoJS/en/guide/audio/audio-basics/) · [Effects and routing](https://exoridus.github.io/ExoJS/en/guide/audio/audio-effects/) · [Beat detection](https://exoridus.github.io/ExoJS/en/guide/audio/beat-detection/) · [Audio-reactive visuals](https://exoridus.github.io/ExoJS/en/guide/audio/audio-reactive-visualization/) · [AudioAnalyser API](https://exoridus.github.io/ExoJS/en/api/audio-analyser/)
|
|
50
|
-
|
|
51
|
-
## Beat evaluation
|
|
52
|
-
|
|
53
|
-
[The synthetic MIR evaluation](docs/mir-evaluation.md) documents reproducible quality and posting-latency measurements, adversarial fixtures, provisional-versus-locked comparisons, and their limits. Run the named evaluation test from the repository root; no external audio dataset is required.
|
|
54
|
-
|
|
55
|
-
[The recorded music corpus](test/fixtures/music/README.md) complements it with five committed CC0 excerpts. Its tests run offline and distinguish unreviewed beat proposals from reviewed references; passing integration checks alone does not establish accuracy on music.
|
|
56
|
-
|
|
57
|
-
## License
|
|
58
|
-
|
|
59
|
-
MIT
|
|
13
|
+
Change each import to the Core entry in the table, then remove this package with `npm uninstall @codexo/exojs-audio-fx`. `@codexo/exojs` already contains the module; there is nothing else to install. The migration guide on the ExoJS site lists every renamed import.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@codexo/exojs/audio-fx';
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@codexo/exojs/audio-fx';
|
package/package.json
CHANGED
|
@@ -1,46 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codexo/exojs-audio-fx",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.20.0",
|
|
4
|
+
"description": "Compatibility shim that forwards to @codexo/exojs/audio-fx. Since ExoJS v0.20, import from @codexo/exojs/audio-fx.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/Exoridus/ExoJS.git",
|
|
8
|
-
"directory": "packages/exojs-audio-fx"
|
|
8
|
+
"directory": "packages/legacy/exojs-audio-fx"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
11
|
"sideEffects": false,
|
|
12
|
-
"main": "./
|
|
13
|
-
"
|
|
14
|
-
"types": "./dist/esm/index.d.ts",
|
|
12
|
+
"main": "./index.js",
|
|
13
|
+
"types": "./index.d.ts",
|
|
15
14
|
"exports": {
|
|
16
15
|
".": {
|
|
17
|
-
"types": "./
|
|
18
|
-
"import": "./
|
|
19
|
-
"default": "./
|
|
16
|
+
"types": "./index.d.ts",
|
|
17
|
+
"import": "./index.js",
|
|
18
|
+
"default": "./index.js"
|
|
20
19
|
},
|
|
21
20
|
"./package.json": "./package.json"
|
|
22
21
|
},
|
|
23
22
|
"files": [
|
|
24
|
-
"
|
|
23
|
+
"index.js",
|
|
24
|
+
"index.d.ts",
|
|
25
25
|
"README.md",
|
|
26
26
|
"LICENSE"
|
|
27
27
|
],
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@codexo/exojs": "0.
|
|
29
|
+
"@codexo/exojs": "0.20.x"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@codexo/exojs
|
|
33
|
-
"@codexo/exojs": "0.19.1"
|
|
32
|
+
"@codexo/exojs": "0.20.0"
|
|
34
33
|
},
|
|
35
34
|
"license": "MIT",
|
|
36
35
|
"publishConfig": {
|
|
37
36
|
"access": "public"
|
|
38
|
-
},
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "tsx ../../scripts/build-extension.ts",
|
|
41
|
-
"build:dev": "tsx ../../scripts/build-extension.ts --dev",
|
|
42
|
-
"typecheck": "exo-tsc --noEmit && exo-tsc --noEmit -p tsconfig.test.json && exo-tsc --noEmit -p tsconfig.worklets.json",
|
|
43
|
-
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
44
|
-
"test": "vitest run --root ../.. --project=exojs-audio-fx"
|
|
45
37
|
}
|
|
46
38
|
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { type AudioBus, 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 AudioAnalyserSource = AudioBus | Voice | MediaStream | AudioNode | null;
|
|
8
|
-
/** Construction options for {@link AudioAnalyser}. */
|
|
9
|
-
export interface AudioAnalyserOptions {
|
|
10
|
-
/** FFT window size; must be a power of two between 32 and 32768. Default 2048. */
|
|
11
|
-
fftSize?: number;
|
|
12
|
-
/** Time-domain smoothing constant in 0..1 applied between successive analyses. Default 0.8. */
|
|
13
|
-
smoothingTimeConstant?: number;
|
|
14
|
-
/** Minimum dBFS rendered by the byte-domain spectrum getters. Default -100. */
|
|
15
|
-
minDecibels?: number;
|
|
16
|
-
/** Maximum dBFS rendered by the byte-domain spectrum getters. Default -30. */
|
|
17
|
-
maxDecibels?: number;
|
|
18
|
-
/**
|
|
19
|
-
* Optional initial source. Equivalent to `analyser.source = value` after
|
|
20
|
-
* construction; provided for ergonomic one-shot construction. The setter
|
|
21
|
-
* remains usable for runtime source switches.
|
|
22
|
-
*/
|
|
23
|
-
source?: AudioAnalyserSource;
|
|
24
|
-
}
|
|
25
|
-
/** Mapping options for {@link AudioAnalyser.getSpectrumMel} and {@link AudioAnalyser.getSpectrumLog}. */
|
|
26
|
-
export interface SpectrumMappingOptions {
|
|
27
|
-
/** Number of output bands. Default 32. */
|
|
28
|
-
bands?: number;
|
|
29
|
-
/** Lower frequency bound in Hz. Default 20. */
|
|
30
|
-
fMin?: number;
|
|
31
|
-
/** Upper frequency bound in Hz. Default 20000 (clamped to nyquist at runtime). */
|
|
32
|
-
fMax?: number;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Lightweight visualisation analyser backed by a Web Audio AnalyserNode.
|
|
36
|
-
*
|
|
37
|
-
* Accepts any of: AudioBus, Voice, MediaStream, AudioNode, or null. The tap is
|
|
38
|
-
* a parallel branch - it does not affect the source's main routing. Tap a bus
|
|
39
|
-
* for a whole submix, or an individual {@link Voice} (its `output` node) for a
|
|
40
|
-
* single playing instance.
|
|
41
|
-
*/
|
|
42
|
-
export declare class AudioAnalyser {
|
|
43
|
-
private _analyser;
|
|
44
|
-
private readonly _options;
|
|
45
|
-
private readonly _tap;
|
|
46
|
-
private readonly _onAudioContextReady;
|
|
47
|
-
private _byteSpectrum;
|
|
48
|
-
private _floatSpectrum;
|
|
49
|
-
private _byteWaveform;
|
|
50
|
-
private _floatWaveform;
|
|
51
|
-
private _melCache;
|
|
52
|
-
private _logCache;
|
|
53
|
-
/**
|
|
54
|
-
* Create an `AudioAnalyser` with the given options. The underlying
|
|
55
|
-
* `AnalyserNode` is created immediately if the `AudioContext` is already
|
|
56
|
-
* running, or deferred until {@link onAudioContextReady} fires.
|
|
57
|
-
*/
|
|
58
|
-
constructor(options?: AudioAnalyserOptions);
|
|
59
|
-
/**
|
|
60
|
-
* The currently tapped audio source, or `null` if none is set.
|
|
61
|
-
* Assigning a new value disconnects the previous tap and connects the new
|
|
62
|
-
* source as a parallel branch without affecting the source's main routing.
|
|
63
|
-
*/
|
|
64
|
-
get source(): AudioAnalyserSource;
|
|
65
|
-
set source(value: AudioAnalyserSource);
|
|
66
|
-
get fftSize(): number;
|
|
67
|
-
/** Number of frequency bins available - half of `fftSize`. */
|
|
68
|
-
get frequencyBinCount(): number;
|
|
69
|
-
get smoothingTimeConstant(): number;
|
|
70
|
-
set smoothingTimeConstant(v: number);
|
|
71
|
-
get minDecibels(): number;
|
|
72
|
-
set minDecibels(v: number);
|
|
73
|
-
get maxDecibels(): number;
|
|
74
|
-
set maxDecibels(v: number);
|
|
75
|
-
/** Fill and return the byte frequency spectrum (0..255 per bin). */
|
|
76
|
-
getSpectrum(into?: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
|
|
77
|
-
/** Fill and return the float frequency spectrum (dB per bin). */
|
|
78
|
-
getSpectrumFloat(into?: Float32Array<ArrayBuffer>): Float32Array<ArrayBuffer>;
|
|
79
|
-
/** Fill and return the byte time-domain waveform (0..255 per sample). */
|
|
80
|
-
getWaveform(into?: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
|
|
81
|
-
/** Fill and return the float time-domain waveform (-1..1 per sample). */
|
|
82
|
-
getWaveformFloat(into?: Float32Array<ArrayBuffer>): Float32Array<ArrayBuffer>;
|
|
83
|
-
/**
|
|
84
|
-
* Return the mean energy of frequency bins in the given Hz range, normalised 0..1.
|
|
85
|
-
* Uses the byte spectrum (0..255), normalised by dividing by 255.
|
|
86
|
-
*/
|
|
87
|
-
getBandEnergy(fromHz: number, toHz: number): number;
|
|
88
|
-
/** Return low (0-250 Hz), mid (250-2 kHz), and high (2 k-20 kHz) band energies (0..1 each). */
|
|
89
|
-
getLowMidHigh(): {
|
|
90
|
-
low: number;
|
|
91
|
-
mid: number;
|
|
92
|
-
high: number;
|
|
93
|
-
};
|
|
94
|
-
/** Return overall RMS energy across all bins, normalised 0..1. */
|
|
95
|
-
getRms(): number;
|
|
96
|
-
/**
|
|
97
|
-
* Mel-scaled spectrum, byte domain (0..255). Output length = `bands`.
|
|
98
|
-
* Each output bin is a triangular-weighted sum of the linear FFT bins
|
|
99
|
-
* underneath it, mel-spaced from `fMin` to `fMax`.
|
|
100
|
-
*/
|
|
101
|
-
getSpectrumMel(into?: Uint8Array<ArrayBuffer>, options?: SpectrumMappingOptions): Uint8Array<ArrayBuffer>;
|
|
102
|
-
/** Mel-scaled spectrum, float domain (dBFS values). Output length = `bands`. */
|
|
103
|
-
getSpectrumMelFloat(into?: Float32Array<ArrayBuffer>, options?: SpectrumMappingOptions): Float32Array<ArrayBuffer>;
|
|
104
|
-
/**
|
|
105
|
-
* Log-scaled spectrum, byte domain (0..255). Output length = `bands`.
|
|
106
|
-
* Bins are spaced so each output covers an equal fraction of the
|
|
107
|
-
* `log2(fMax / fMin)` octave range - useful when you want a
|
|
108
|
-
* frequency-axis visualization where each octave gets the same width.
|
|
109
|
-
*/
|
|
110
|
-
getSpectrumLog(into?: Uint8Array<ArrayBuffer>, options?: SpectrumMappingOptions): Uint8Array<ArrayBuffer>;
|
|
111
|
-
/** Log-scaled spectrum, float domain (dBFS values). Output length = `bands`. */
|
|
112
|
-
getSpectrumLogFloat(into?: Float32Array<ArrayBuffer>, options?: SpectrumMappingOptions): Float32Array<ArrayBuffer>;
|
|
113
|
-
/**
|
|
114
|
-
* Disconnect the analyser tap, release the internal `AnalyserNode`, and
|
|
115
|
-
* cancel any pending setup callbacks. Call when the analyser is no longer
|
|
116
|
-
* needed to avoid memory leaks.
|
|
117
|
-
*/
|
|
118
|
-
destroy(): void;
|
|
119
|
-
private _getMelFilterbank;
|
|
120
|
-
private _getLogRanges;
|
|
121
|
-
private _setupAnalyser;
|
|
122
|
-
}
|
|
123
|
-
//# sourceMappingURL=AudioAnalyser.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AudioAnalyser.d.ts","sourceRoot":"","sources":["../../src/AudioAnalyser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAA6D,KAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AAKrH;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,KAAK,GAA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,CAAC,CAcxH;IAED;;;;;OAKG;IACI,cAAc,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,UAAU,CAAC,WAAW,CAAC,CAc/G;IAED,gFAAgF;IACzE,mBAAmB,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,YAAY,CAAC,WAAW,CAAC,CAcxH;IAMD;;;;OAIG;IACI,OAAO,IAAI,IAAI,CAMrB;IAMD,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,aAAa;IAerB,OAAO,CAAC,cAAc;CASvB"}
|
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
import { AudioTap } from "./AudioTap.js";
|
|
2
|
-
import { buildMelFilterbank } from "./dsp/mel.js";
|
|
3
|
-
import { getAudioContext, isAudioContextReady, onAudioContextReady } from "@codexo/exojs";
|
|
4
|
-
|
|
5
|
-
//#region src/AudioAnalyser.ts
|
|
6
|
-
/**
|
|
7
|
-
* Lightweight visualisation analyser backed by a Web Audio AnalyserNode.
|
|
8
|
-
*
|
|
9
|
-
* Accepts any of: AudioBus, Voice, MediaStream, AudioNode, or null. The tap is
|
|
10
|
-
* a parallel branch - it does not affect the source's main routing. Tap a bus
|
|
11
|
-
* for a whole submix, or an individual {@link Voice} (its `output` node) for a
|
|
12
|
-
* single playing instance.
|
|
13
|
-
*/
|
|
14
|
-
var AudioAnalyser = class {
|
|
15
|
-
_analyser = null;
|
|
16
|
-
_options;
|
|
17
|
-
_tap = new AudioTap();
|
|
18
|
-
_onAudioContextReady = (ctx) => {
|
|
19
|
-
onAudioContextReady.remove(this._onAudioContextReady);
|
|
20
|
-
this._setupAnalyser(ctx);
|
|
21
|
-
};
|
|
22
|
-
_byteSpectrum;
|
|
23
|
-
_floatSpectrum;
|
|
24
|
-
_byteWaveform;
|
|
25
|
-
_floatWaveform;
|
|
26
|
-
_melCache = /* @__PURE__ */ new Map();
|
|
27
|
-
_logCache = /* @__PURE__ */ new Map();
|
|
28
|
-
/**
|
|
29
|
-
* Create an `AudioAnalyser` with the given options. The underlying
|
|
30
|
-
* `AnalyserNode` is created immediately if the `AudioContext` is already
|
|
31
|
-
* running, or deferred until {@link onAudioContextReady} fires.
|
|
32
|
-
*/
|
|
33
|
-
constructor(options) {
|
|
34
|
-
this._options = {
|
|
35
|
-
fftSize: options?.fftSize ?? 2048,
|
|
36
|
-
smoothingTimeConstant: options?.smoothingTimeConstant ?? .8,
|
|
37
|
-
minDecibels: options?.minDecibels ?? -100,
|
|
38
|
-
maxDecibels: options?.maxDecibels ?? -30,
|
|
39
|
-
source: options?.source ?? null
|
|
40
|
-
};
|
|
41
|
-
const binCount = this._options.fftSize >> 1;
|
|
42
|
-
this._byteSpectrum = new Uint8Array(binCount);
|
|
43
|
-
this._floatSpectrum = new Float32Array(binCount);
|
|
44
|
-
this._byteWaveform = new Uint8Array(binCount);
|
|
45
|
-
this._floatWaveform = new Float32Array(binCount);
|
|
46
|
-
if (isAudioContextReady()) this._setupAnalyser(getAudioContext());
|
|
47
|
-
else onAudioContextReady.add(this._onAudioContextReady);
|
|
48
|
-
if (options?.source !== void 0 && options.source !== null) this.source = options.source;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* The currently tapped audio source, or `null` if none is set.
|
|
52
|
-
* Assigning a new value disconnects the previous tap and connects the new
|
|
53
|
-
* source as a parallel branch without affecting the source's main routing.
|
|
54
|
-
*/
|
|
55
|
-
get source() {
|
|
56
|
-
return this._tap.source;
|
|
57
|
-
}
|
|
58
|
-
set source(value) {
|
|
59
|
-
this._tap.source = value;
|
|
60
|
-
}
|
|
61
|
-
get fftSize() {
|
|
62
|
-
return this._options.fftSize;
|
|
63
|
-
}
|
|
64
|
-
/** Number of frequency bins available - half of `fftSize`. */
|
|
65
|
-
get frequencyBinCount() {
|
|
66
|
-
return this._options.fftSize >> 1;
|
|
67
|
-
}
|
|
68
|
-
get smoothingTimeConstant() {
|
|
69
|
-
return this._analyser?.smoothingTimeConstant ?? this._options.smoothingTimeConstant;
|
|
70
|
-
}
|
|
71
|
-
set smoothingTimeConstant(v) {
|
|
72
|
-
this._options.smoothingTimeConstant = v;
|
|
73
|
-
if (this._analyser) this._analyser.smoothingTimeConstant = v;
|
|
74
|
-
}
|
|
75
|
-
get minDecibels() {
|
|
76
|
-
return this._analyser?.minDecibels ?? this._options.minDecibels;
|
|
77
|
-
}
|
|
78
|
-
set minDecibels(v) {
|
|
79
|
-
this._options.minDecibels = v;
|
|
80
|
-
if (this._analyser) this._analyser.minDecibels = v;
|
|
81
|
-
}
|
|
82
|
-
get maxDecibels() {
|
|
83
|
-
return this._analyser?.maxDecibels ?? this._options.maxDecibels;
|
|
84
|
-
}
|
|
85
|
-
set maxDecibels(v) {
|
|
86
|
-
this._options.maxDecibels = v;
|
|
87
|
-
if (this._analyser) this._analyser.maxDecibels = v;
|
|
88
|
-
}
|
|
89
|
-
/** Fill and return the byte frequency spectrum (0..255 per bin). */
|
|
90
|
-
getSpectrum(into) {
|
|
91
|
-
const buf = into ?? this._byteSpectrum;
|
|
92
|
-
if (this._analyser) this._analyser.getByteFrequencyData(buf);
|
|
93
|
-
else buf.fill(0);
|
|
94
|
-
return buf;
|
|
95
|
-
}
|
|
96
|
-
/** Fill and return the float frequency spectrum (dB per bin). */
|
|
97
|
-
getSpectrumFloat(into) {
|
|
98
|
-
const buf = into ?? this._floatSpectrum;
|
|
99
|
-
if (this._analyser) this._analyser.getFloatFrequencyData(buf);
|
|
100
|
-
else buf.fill(0);
|
|
101
|
-
return buf;
|
|
102
|
-
}
|
|
103
|
-
/** Fill and return the byte time-domain waveform (0..255 per sample). */
|
|
104
|
-
getWaveform(into) {
|
|
105
|
-
const buf = into ?? this._byteWaveform;
|
|
106
|
-
if (this._analyser) this._analyser.getByteTimeDomainData(buf);
|
|
107
|
-
else buf.fill(0);
|
|
108
|
-
return buf;
|
|
109
|
-
}
|
|
110
|
-
/** Fill and return the float time-domain waveform (-1..1 per sample). */
|
|
111
|
-
getWaveformFloat(into) {
|
|
112
|
-
const buf = into ?? this._floatWaveform;
|
|
113
|
-
if (this._analyser) this._analyser.getFloatTimeDomainData(buf);
|
|
114
|
-
else buf.fill(0);
|
|
115
|
-
return buf;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Return the mean energy of frequency bins in the given Hz range, normalised 0..1.
|
|
119
|
-
* Uses the byte spectrum (0..255), normalised by dividing by 255.
|
|
120
|
-
*/
|
|
121
|
-
getBandEnergy(fromHz, toHz) {
|
|
122
|
-
if (!this._analyser) return 0;
|
|
123
|
-
const nyquist = getAudioContext().sampleRate / 2;
|
|
124
|
-
const binCount = this.frequencyBinCount;
|
|
125
|
-
const fromBin = Math.max(0, Math.min(binCount - 1, Math.round(fromHz / nyquist * binCount)));
|
|
126
|
-
const toBin = Math.max(0, Math.min(binCount - 1, Math.round(toHz / nyquist * binCount)));
|
|
127
|
-
const lo = Math.min(fromBin, toBin);
|
|
128
|
-
const hi = Math.max(fromBin, toBin);
|
|
129
|
-
const spectrum = this.getSpectrum();
|
|
130
|
-
let sum = 0;
|
|
131
|
-
const count = hi - lo + 1;
|
|
132
|
-
for (let i = lo; i <= hi; i++) sum += spectrum[i];
|
|
133
|
-
return sum / (count * 255);
|
|
134
|
-
}
|
|
135
|
-
/** Return low (0-250 Hz), mid (250-2 kHz), and high (2 k-20 kHz) band energies (0..1 each). */
|
|
136
|
-
getLowMidHigh() {
|
|
137
|
-
return {
|
|
138
|
-
low: this.getBandEnergy(0, 250),
|
|
139
|
-
mid: this.getBandEnergy(250, 2e3),
|
|
140
|
-
high: this.getBandEnergy(2e3, 2e4)
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
/** Return overall RMS energy across all bins, normalised 0..1. */
|
|
144
|
-
getRms() {
|
|
145
|
-
if (!this._analyser) return 0;
|
|
146
|
-
const nyquist = getAudioContext().sampleRate / 2;
|
|
147
|
-
return this.getBandEnergy(0, nyquist);
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Mel-scaled spectrum, byte domain (0..255). Output length = `bands`.
|
|
151
|
-
* Each output bin is a triangular-weighted sum of the linear FFT bins
|
|
152
|
-
* underneath it, mel-spaced from `fMin` to `fMax`.
|
|
153
|
-
*/
|
|
154
|
-
getSpectrumMel(into, options) {
|
|
155
|
-
const bandCount = options?.bands ?? 32;
|
|
156
|
-
const out = into ?? new Uint8Array(bandCount);
|
|
157
|
-
const filterbank = this._getMelFilterbank(bandCount, options?.fMin ?? 20, options?.fMax ?? 2e4);
|
|
158
|
-
if (!this._analyser || filterbank === null) {
|
|
159
|
-
out.fill(0);
|
|
160
|
-
return out;
|
|
161
|
-
}
|
|
162
|
-
this._analyser.getByteFrequencyData(this._byteSpectrum);
|
|
163
|
-
applyFilterbank(this._byteSpectrum, filterbank, out);
|
|
164
|
-
return out;
|
|
165
|
-
}
|
|
166
|
-
/** Mel-scaled spectrum, float domain (dBFS values). Output length = `bands`. */
|
|
167
|
-
getSpectrumMelFloat(into, options) {
|
|
168
|
-
const bandCount = options?.bands ?? 32;
|
|
169
|
-
const out = into ?? new Float32Array(bandCount);
|
|
170
|
-
const filterbank = this._getMelFilterbank(bandCount, options?.fMin ?? 20, options?.fMax ?? 2e4);
|
|
171
|
-
if (!this._analyser || filterbank === null) {
|
|
172
|
-
out.fill(0);
|
|
173
|
-
return out;
|
|
174
|
-
}
|
|
175
|
-
this._analyser.getFloatFrequencyData(this._floatSpectrum);
|
|
176
|
-
applyFilterbank(this._floatSpectrum, filterbank, out);
|
|
177
|
-
return out;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Log-scaled spectrum, byte domain (0..255). Output length = `bands`.
|
|
181
|
-
* Bins are spaced so each output covers an equal fraction of the
|
|
182
|
-
* `log2(fMax / fMin)` octave range - useful when you want a
|
|
183
|
-
* frequency-axis visualization where each octave gets the same width.
|
|
184
|
-
*/
|
|
185
|
-
getSpectrumLog(into, options) {
|
|
186
|
-
const bandCount = options?.bands ?? 32;
|
|
187
|
-
const out = into ?? new Uint8Array(bandCount);
|
|
188
|
-
const ranges = this._getLogRanges(bandCount, options?.fMin ?? 20, options?.fMax ?? 2e4);
|
|
189
|
-
if (!this._analyser || ranges === null) {
|
|
190
|
-
out.fill(0);
|
|
191
|
-
return out;
|
|
192
|
-
}
|
|
193
|
-
this._analyser.getByteFrequencyData(this._byteSpectrum);
|
|
194
|
-
applyLogRanges(this._byteSpectrum, ranges, out);
|
|
195
|
-
return out;
|
|
196
|
-
}
|
|
197
|
-
/** Log-scaled spectrum, float domain (dBFS values). Output length = `bands`. */
|
|
198
|
-
getSpectrumLogFloat(into, options) {
|
|
199
|
-
const bandCount = options?.bands ?? 32;
|
|
200
|
-
const out = into ?? new Float32Array(bandCount);
|
|
201
|
-
const ranges = this._getLogRanges(bandCount, options?.fMin ?? 20, options?.fMax ?? 2e4);
|
|
202
|
-
if (!this._analyser || ranges === null) {
|
|
203
|
-
out.fill(0);
|
|
204
|
-
return out;
|
|
205
|
-
}
|
|
206
|
-
this._analyser.getFloatFrequencyData(this._floatSpectrum);
|
|
207
|
-
applyLogRanges(this._floatSpectrum, ranges, out);
|
|
208
|
-
return out;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Disconnect the analyser tap, release the internal `AnalyserNode`, and
|
|
212
|
-
* cancel any pending setup callbacks. Call when the analyser is no longer
|
|
213
|
-
* needed to avoid memory leaks.
|
|
214
|
-
*/
|
|
215
|
-
destroy() {
|
|
216
|
-
onAudioContextReady.remove(this._onAudioContextReady);
|
|
217
|
-
this._tap.destroy();
|
|
218
|
-
this._analyser?.disconnect();
|
|
219
|
-
this._analyser = null;
|
|
220
|
-
}
|
|
221
|
-
_getMelFilterbank(bands, fMin, fMax) {
|
|
222
|
-
if (!this._analyser) return null;
|
|
223
|
-
const ctx = getAudioContext();
|
|
224
|
-
const fftSize = this._options.fftSize;
|
|
225
|
-
const clampedFmax = Math.min(fMax, ctx.sampleRate / 2);
|
|
226
|
-
const key = `${bands}|${fMin}|${clampedFmax}|${fftSize}`;
|
|
227
|
-
let cached = this._melCache.get(key);
|
|
228
|
-
if (cached === void 0) {
|
|
229
|
-
cached = buildMelFilterbank(bands, fMin, clampedFmax, fftSize, ctx.sampleRate);
|
|
230
|
-
this._melCache.set(key, cached);
|
|
231
|
-
}
|
|
232
|
-
return cached;
|
|
233
|
-
}
|
|
234
|
-
_getLogRanges(bands, fMin, fMax) {
|
|
235
|
-
if (!this._analyser) return null;
|
|
236
|
-
const ctx = getAudioContext();
|
|
237
|
-
const fftSize = this._options.fftSize;
|
|
238
|
-
const clampedFmax = Math.min(fMax, ctx.sampleRate / 2);
|
|
239
|
-
const key = `${bands}|${fMin}|${clampedFmax}|${fftSize}`;
|
|
240
|
-
let cached = this._logCache.get(key);
|
|
241
|
-
if (cached === void 0) {
|
|
242
|
-
cached = buildLogRanges(bands, fMin, clampedFmax, fftSize, ctx.sampleRate);
|
|
243
|
-
this._logCache.set(key, cached);
|
|
244
|
-
}
|
|
245
|
-
return cached;
|
|
246
|
-
}
|
|
247
|
-
_setupAnalyser(audioContext) {
|
|
248
|
-
const node = audioContext.createAnalyser();
|
|
249
|
-
node.fftSize = this._options.fftSize;
|
|
250
|
-
node.minDecibels = this._options.minDecibels;
|
|
251
|
-
node.maxDecibels = this._options.maxDecibels;
|
|
252
|
-
node.smoothingTimeConstant = this._options.smoothingTimeConstant;
|
|
253
|
-
this._analyser = node;
|
|
254
|
-
this._tap.attach(node, audioContext);
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
const buildLogRanges = (bandCount, fMin, fMax, fftSize, sampleRate) => {
|
|
258
|
-
const binCount = fftSize >> 1;
|
|
259
|
-
const nyquist = sampleRate / 2;
|
|
260
|
-
const logMin = Math.log(fMin);
|
|
261
|
-
const logMax = Math.log(fMax);
|
|
262
|
-
const ranges = [];
|
|
263
|
-
for (let b = 0; b < bandCount; b++) {
|
|
264
|
-
const lowHz = Math.exp(logMin + (logMax - logMin) * b / bandCount);
|
|
265
|
-
const highHz = Math.exp(logMin + (logMax - logMin) * (b + 1) / bandCount);
|
|
266
|
-
const startBin = Math.max(0, Math.min(binCount - 1, Math.floor(lowHz / nyquist * binCount)));
|
|
267
|
-
const endBin = Math.max(startBin, Math.min(binCount - 1, Math.ceil(highHz / nyquist * binCount) - 1));
|
|
268
|
-
ranges.push({
|
|
269
|
-
startBin,
|
|
270
|
-
endBin
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
return ranges;
|
|
274
|
-
};
|
|
275
|
-
const applyFilterbank = (spectrum, bands, out) => {
|
|
276
|
-
for (let b = 0; b < bands.length; b++) {
|
|
277
|
-
const { startBin, weights } = bands[b];
|
|
278
|
-
let sum = 0;
|
|
279
|
-
for (let i = 0; i < weights.length; i++) sum += spectrum[startBin + i] * weights[i];
|
|
280
|
-
out[b] = sum;
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
const applyLogRanges = (spectrum, ranges, out) => {
|
|
284
|
-
for (let b = 0; b < ranges.length; b++) {
|
|
285
|
-
const { startBin, endBin } = ranges[b];
|
|
286
|
-
let sum = 0;
|
|
287
|
-
const count = endBin - startBin + 1;
|
|
288
|
-
for (let i = startBin; i <= endBin; i++) sum += spectrum[i];
|
|
289
|
-
out[b] = sum / count;
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
//#endregion
|
|
294
|
-
export { AudioAnalyser };
|
|
295
|
-
//# sourceMappingURL=AudioAnalyser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AudioAnalyser.js","names":[],"sources":["../../src/AudioAnalyser.ts"],"sourcesContent":["import { type AudioBus, getAudioContext, isAudioContextReady, onAudioContextReady, type Voice } from '@codexo/exojs';\n\nimport { AudioTap } from './AudioTap';\nimport { buildMelFilterbank, type MelBand } from './dsp/mel';\n\n/**\n * What to analyse: a bus or voice (the usual case), a `MediaStream` such as a\n * microphone, or `null` for none yet. A raw `AudioNode` is Web Audio interop\n * for graphs built outside the engine.\n */\nexport type AudioAnalyserSource = AudioBus | Voice | MediaStream | AudioNode | null;\n\n/** Construction options for {@link AudioAnalyser}. */\nexport interface AudioAnalyserOptions {\n /** FFT window size; must be a power of two between 32 and 32768. Default 2048. */\n fftSize?: number;\n /** Time-domain smoothing constant in 0..1 applied between successive analyses. Default 0.8. */\n smoothingTimeConstant?: number;\n /** Minimum dBFS rendered by the byte-domain spectrum getters. Default -100. */\n minDecibels?: number;\n /** Maximum dBFS rendered by the byte-domain spectrum getters. Default -30. */\n maxDecibels?: number;\n /**\n * Optional initial source. Equivalent to `analyser.source = value` after\n * construction; provided for ergonomic one-shot construction. The setter\n * remains usable for runtime source switches.\n */\n source?: AudioAnalyserSource;\n}\n\n/** Mapping options for {@link AudioAnalyser.getSpectrumMel} and {@link AudioAnalyser.getSpectrumLog}. */\nexport interface SpectrumMappingOptions {\n /** Number of output bands. Default 32. */\n bands?: number;\n /** Lower frequency bound in Hz. Default 20. */\n fMin?: number;\n /** Upper frequency bound in Hz. Default 20000 (clamped to nyquist at runtime). */\n fMax?: number;\n}\n\ntype RequiredAnalyserOptions = Required<AudioAnalyserOptions>;\n\n/**\n * Lightweight visualisation analyser backed by a Web Audio AnalyserNode.\n *\n * Accepts any of: AudioBus, Voice, MediaStream, AudioNode, or null. The tap is\n * a parallel branch - it does not affect the source's main routing. Tap a bus\n * for a whole submix, or an individual {@link Voice} (its `output` node) for a\n * single playing instance.\n */\nexport class AudioAnalyser {\n private _analyser: AnalyserNode | null = null;\n private readonly _options: RequiredAnalyserOptions;\n private readonly _tap = new AudioTap();\n private readonly _onAudioContextReady = (ctx: AudioContext): void => {\n onAudioContextReady.remove(this._onAudioContextReady);\n this._setupAnalyser(ctx);\n };\n\n // Pre-allocated buffers\n private _byteSpectrum: Uint8Array<ArrayBuffer>;\n private _floatSpectrum: Float32Array<ArrayBuffer>;\n private _byteWaveform: Uint8Array<ArrayBuffer>;\n private _floatWaveform: Float32Array<ArrayBuffer>;\n\n // Cached mel/log filterbanks. Key: `${bands}|${fMin}|${fMax}|${fftSize}`.\n // Filterbank construction is non-trivial; caching avoids per-frame allocation.\n private _melCache = new Map<string, MelBand[]>();\n private _logCache = new Map<string, LogBandRange[]>();\n\n /**\n * Create an `AudioAnalyser` with the given options. The underlying\n * `AnalyserNode` is created immediately if the `AudioContext` is already\n * running, or deferred until {@link onAudioContextReady} fires.\n */\n public constructor(options?: AudioAnalyserOptions) {\n this._options = {\n fftSize: options?.fftSize ?? 2048,\n smoothingTimeConstant: options?.smoothingTimeConstant ?? 0.8,\n minDecibels: options?.minDecibels ?? -100,\n maxDecibels: options?.maxDecibels ?? -30,\n source: options?.source ?? null,\n };\n\n const binCount = this._options.fftSize >> 1;\n this._byteSpectrum = new Uint8Array(binCount);\n this._floatSpectrum = new Float32Array(binCount);\n this._byteWaveform = new Uint8Array(binCount);\n this._floatWaveform = new Float32Array(binCount);\n\n if (isAudioContextReady()) {\n this._setupAnalyser(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\n // -----------------------------------------------------------------------\n\n /**\n * The currently tapped audio source, or `null` if none is set.\n * Assigning a new value disconnects the previous tap and connects the new\n * source as a parallel branch without affecting the source's main routing.\n */\n public get source(): AudioAnalyserSource {\n return this._tap.source;\n }\n\n public set source(value: AudioAnalyserSource) {\n this._tap.source = value;\n }\n\n // -----------------------------------------------------------------------\n // AnalyserNode property pass-throughs\n // -----------------------------------------------------------------------\n\n public get fftSize(): number {\n return this._options.fftSize;\n }\n\n /** Number of frequency bins available - half of `fftSize`. */\n public get frequencyBinCount(): number {\n return this._options.fftSize >> 1;\n }\n\n public get smoothingTimeConstant(): number {\n return this._analyser?.smoothingTimeConstant ?? this._options.smoothingTimeConstant;\n }\n\n public set smoothingTimeConstant(v: number) {\n this._options.smoothingTimeConstant = v;\n if (this._analyser) this._analyser.smoothingTimeConstant = v;\n }\n\n public get minDecibels(): number {\n return this._analyser?.minDecibels ?? this._options.minDecibels;\n }\n\n public set minDecibels(v: number) {\n this._options.minDecibels = v;\n if (this._analyser) this._analyser.minDecibels = v;\n }\n\n public get maxDecibels(): number {\n return this._analyser?.maxDecibels ?? this._options.maxDecibels;\n }\n\n public set maxDecibels(v: number) {\n this._options.maxDecibels = v;\n if (this._analyser) this._analyser.maxDecibels = v;\n }\n\n // -----------------------------------------------------------------------\n // Raw data\n // -----------------------------------------------------------------------\n\n /** Fill and return the byte frequency spectrum (0..255 per bin). */\n public getSpectrum(into?: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer> {\n const buf = into ?? this._byteSpectrum;\n if (this._analyser) {\n this._analyser.getByteFrequencyData(buf);\n } else {\n buf.fill(0);\n }\n return buf;\n }\n\n /** Fill and return the float frequency spectrum (dB per bin). */\n public getSpectrumFloat(into?: Float32Array<ArrayBuffer>): Float32Array<ArrayBuffer> {\n const buf = into ?? this._floatSpectrum;\n if (this._analyser) {\n this._analyser.getFloatFrequencyData(buf);\n } else {\n buf.fill(0);\n }\n return buf;\n }\n\n /** Fill and return the byte time-domain waveform (0..255 per sample). */\n public getWaveform(into?: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer> {\n const buf = into ?? this._byteWaveform;\n if (this._analyser) {\n this._analyser.getByteTimeDomainData(buf);\n } else {\n buf.fill(0);\n }\n return buf;\n }\n\n /** Fill and return the float time-domain waveform (-1..1 per sample). */\n public getWaveformFloat(into?: Float32Array<ArrayBuffer>): Float32Array<ArrayBuffer> {\n const buf = into ?? this._floatWaveform;\n if (this._analyser) {\n this._analyser.getFloatTimeDomainData(buf);\n } else {\n buf.fill(0);\n }\n return buf;\n }\n\n // -----------------------------------------------------------------------\n // Convenience helpers\n // -----------------------------------------------------------------------\n\n /**\n * Return the mean energy of frequency bins in the given Hz range, normalised 0..1.\n * Uses the byte spectrum (0..255), normalised by dividing by 255.\n */\n public getBandEnergy(fromHz: number, toHz: number): number {\n if (!this._analyser) return 0;\n const ctx = getAudioContext();\n const nyquist = ctx.sampleRate / 2;\n const binCount = this.frequencyBinCount;\n const fromBin = Math.max(0, Math.min(binCount - 1, Math.round((fromHz / nyquist) * binCount)));\n const toBin = Math.max(0, Math.min(binCount - 1, Math.round((toHz / nyquist) * binCount)));\n\n const lo = Math.min(fromBin, toBin);\n const hi = Math.max(fromBin, toBin);\n\n const spectrum = this.getSpectrum();\n let sum = 0;\n const count = hi - lo + 1;\n for (let i = lo; i <= hi; i++) {\n sum += spectrum[i]!;\n }\n return sum / (count * 255);\n }\n\n /** Return low (0-250 Hz), mid (250-2 kHz), and high (2 k-20 kHz) band energies (0..1 each). */\n public getLowMidHigh(): { low: number; mid: number; high: number } {\n return {\n low: this.getBandEnergy(0, 250),\n mid: this.getBandEnergy(250, 2000),\n high: this.getBandEnergy(2000, 20000),\n };\n }\n\n /** Return overall RMS energy across all bins, normalised 0..1. */\n public getRms(): number {\n if (!this._analyser) return 0;\n const ctx = getAudioContext();\n const nyquist = ctx.sampleRate / 2;\n return this.getBandEnergy(0, nyquist);\n }\n\n // -----------------------------------------------------------------------\n // Spectrum mapping (mel / log scaling)\n //\n // The raw FFT bins from AnalyserNode are linearly distributed across\n // 0..nyquist, which gives bass a few bins and treble hundreds. For\n // visualisations you typically want perceptually-weighted spacing.\n //\n // Both `getSpectrumMel` and `getSpectrumLog` operate on the byte-domain\n // spectrum (0..255) and produce byte output by default. The float\n // variants operate on dBFS values and produce float output.\n //\n // Filterbanks are cached on the analyser; they only rebuild when fftSize\n // or the (bands, fMin, fMax) parameters change.\n // -----------------------------------------------------------------------\n\n /**\n * Mel-scaled spectrum, byte domain (0..255). Output length = `bands`.\n * Each output bin is a triangular-weighted sum of the linear FFT bins\n * underneath it, mel-spaced from `fMin` to `fMax`.\n */\n public getSpectrumMel(into?: Uint8Array<ArrayBuffer>, options?: SpectrumMappingOptions): Uint8Array<ArrayBuffer> {\n const bandCount = options?.bands ?? 32;\n const out = into ?? new Uint8Array(bandCount);\n const filterbank = this._getMelFilterbank(bandCount, options?.fMin ?? 20, options?.fMax ?? 20000);\n\n if (!this._analyser || filterbank === null) {\n out.fill(0);\n return out;\n }\n\n this._analyser.getByteFrequencyData(this._byteSpectrum);\n applyFilterbank(this._byteSpectrum, filterbank, out);\n\n return out;\n }\n\n /** Mel-scaled spectrum, float domain (dBFS values). Output length = `bands`. */\n public getSpectrumMelFloat(into?: Float32Array<ArrayBuffer>, options?: SpectrumMappingOptions): Float32Array<ArrayBuffer> {\n const bandCount = options?.bands ?? 32;\n const out = into ?? new Float32Array(bandCount);\n const filterbank = this._getMelFilterbank(bandCount, options?.fMin ?? 20, options?.fMax ?? 20000);\n\n if (!this._analyser || filterbank === null) {\n out.fill(0);\n return out;\n }\n\n this._analyser.getFloatFrequencyData(this._floatSpectrum);\n applyFilterbank(this._floatSpectrum, filterbank, out);\n\n return out;\n }\n\n /**\n * Log-scaled spectrum, byte domain (0..255). Output length = `bands`.\n * Bins are spaced so each output covers an equal fraction of the\n * `log2(fMax / fMin)` octave range - useful when you want a\n * frequency-axis visualization where each octave gets the same width.\n */\n public getSpectrumLog(into?: Uint8Array<ArrayBuffer>, options?: SpectrumMappingOptions): Uint8Array<ArrayBuffer> {\n const bandCount = options?.bands ?? 32;\n const out = into ?? new Uint8Array(bandCount);\n const ranges = this._getLogRanges(bandCount, options?.fMin ?? 20, options?.fMax ?? 20000);\n\n if (!this._analyser || ranges === null) {\n out.fill(0);\n return out;\n }\n\n this._analyser.getByteFrequencyData(this._byteSpectrum);\n applyLogRanges(this._byteSpectrum, ranges, out);\n\n return out;\n }\n\n /** Log-scaled spectrum, float domain (dBFS values). Output length = `bands`. */\n public getSpectrumLogFloat(into?: Float32Array<ArrayBuffer>, options?: SpectrumMappingOptions): Float32Array<ArrayBuffer> {\n const bandCount = options?.bands ?? 32;\n const out = into ?? new Float32Array(bandCount);\n const ranges = this._getLogRanges(bandCount, options?.fMin ?? 20, options?.fMax ?? 20000);\n\n if (!this._analyser || ranges === null) {\n out.fill(0);\n return out;\n }\n\n this._analyser.getFloatFrequencyData(this._floatSpectrum);\n applyLogRanges(this._floatSpectrum, ranges, out);\n\n return out;\n }\n\n // -----------------------------------------------------------------------\n // Lifecycle\n // -----------------------------------------------------------------------\n\n /**\n * Disconnect the analyser tap, release the internal `AnalyserNode`, and\n * cancel any pending setup callbacks. Call when the analyser is no longer\n * needed to avoid memory leaks.\n */\n public destroy(): void {\n onAudioContextReady.remove(this._onAudioContextReady);\n\n this._tap.destroy();\n this._analyser?.disconnect();\n this._analyser = null;\n }\n\n // -----------------------------------------------------------------------\n // Private helpers\n // -----------------------------------------------------------------------\n\n private _getMelFilterbank(bands: number, fMin: number, fMax: number): MelBand[] | null {\n if (!this._analyser) return null;\n const ctx = getAudioContext();\n const fftSize = this._options.fftSize;\n const clampedFmax = Math.min(fMax, ctx.sampleRate / 2);\n const key = `${bands}|${fMin}|${clampedFmax}|${fftSize}`;\n\n let cached = this._melCache.get(key);\n if (cached === undefined) {\n cached = buildMelFilterbank(bands, fMin, clampedFmax, fftSize, ctx.sampleRate);\n this._melCache.set(key, cached);\n }\n return cached;\n }\n\n private _getLogRanges(bands: number, fMin: number, fMax: number): LogBandRange[] | null {\n if (!this._analyser) return null;\n const ctx = getAudioContext();\n const fftSize = this._options.fftSize;\n const clampedFmax = Math.min(fMax, ctx.sampleRate / 2);\n const key = `${bands}|${fMin}|${clampedFmax}|${fftSize}`;\n\n let cached = this._logCache.get(key);\n if (cached === undefined) {\n cached = buildLogRanges(bands, fMin, clampedFmax, fftSize, ctx.sampleRate);\n this._logCache.set(key, cached);\n }\n return cached;\n }\n\n private _setupAnalyser(audioContext: AudioContext): void {\n const node = audioContext.createAnalyser();\n node.fftSize = this._options.fftSize;\n node.minDecibels = this._options.minDecibels;\n node.maxDecibels = this._options.maxDecibels;\n node.smoothingTimeConstant = this._options.smoothingTimeConstant;\n this._analyser = node;\n this._tap.attach(node, audioContext);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Filterbank helpers - module-private, shared between byte and float variants.\n// ---------------------------------------------------------------------------\n\ninterface LogBandRange {\n /** Inclusive start FFT bin. */\n readonly startBin: number;\n /** Inclusive end FFT bin. */\n readonly endBin: number;\n}\n\nconst buildLogRanges = (bandCount: number, fMin: number, fMax: number, fftSize: number, sampleRate: number): LogBandRange[] => {\n const binCount = fftSize >> 1;\n const nyquist = sampleRate / 2;\n const logMin = Math.log(fMin);\n const logMax = Math.log(fMax);\n const ranges: LogBandRange[] = [];\n\n for (let b = 0; b < bandCount; b++) {\n const lowHz = Math.exp(logMin + ((logMax - logMin) * b) / bandCount);\n const highHz = Math.exp(logMin + ((logMax - logMin) * (b + 1)) / bandCount);\n const startBin = Math.max(0, Math.min(binCount - 1, Math.floor((lowHz / nyquist) * binCount)));\n const endBin = Math.max(startBin, Math.min(binCount - 1, Math.ceil((highHz / nyquist) * binCount) - 1));\n ranges.push({ startBin, endBin });\n }\n\n return ranges;\n};\n\nconst applyFilterbank = (spectrum: Uint8Array | Float32Array, bands: MelBand[], out: Uint8Array | Float32Array): void => {\n for (let b = 0; b < bands.length; b++) {\n const { startBin, weights } = bands[b]!;\n let sum = 0;\n for (let i = 0; i < weights.length; i++) {\n sum += spectrum[startBin + i]! * weights[i]!;\n }\n out[b] = sum;\n }\n};\n\nconst applyLogRanges = (spectrum: Uint8Array | Float32Array, ranges: LogBandRange[], out: Uint8Array | Float32Array): void => {\n for (let b = 0; b < ranges.length; b++) {\n const { startBin, endBin } = ranges[b]!;\n let sum = 0;\n const count = endBin - startBin + 1;\n for (let i = startBin; i <= endBin; i++) {\n sum += spectrum[i]!;\n }\n out[b] = sum / count;\n }\n};\n"],"mappings":";;;;;;;;;;;;;AAkDA,IAAa,gBAAb,MAA2B;CACzB,AAAQ,YAAiC;CACzC,AAAiB;CACjB,AAAiB,OAAO,IAAI,SAAS;CACrC,AAAiB,wBAAw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QAAQ,CAAC,CAAC;EAC7F,MAAM,SAAS,KAAK,IAAI,UAAU,KAAK,IAAI,WAAW,GAAG,KAAK,KAAM,SAAS,UAAW,QAAQ,IAAI,CAAC,CAAC;EACtG,OAAO,KAAK;GAAE;GAAU;EAAO,CAAC;CAClC;CAEA,OAAO;AACT;AAEA,MAAM,mBAAmB,UAAqC,OAAkB,QAAyC;CACvH,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,MAAM,EAAE,UAAU,YAAY,MAAM;EACpC,IAAI,MAAM;EACV,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAClC,OAAO,SAAS,WAAW,KAAM,QAAQ;EAE3C,IAAI,KAAK;CACX;AACF;AAEA,MAAM,kBAAkB,UAAqC,QAAwB,QAAyC;CAC5H,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;EACtC,MAAM,EAAE,UAAU,WAAW,OAAO;EACpC,IAAI,MAAM;EACV,MAAM,QAAQ,SAAS,WAAW;EAClC,KAAK,IAAI,IAAI,UAAU,KAAK,QAAQ,KAClC,OAAO,SAAS;EAElB,IAAI,KAAK,MAAM;CACjB;AACF"}
|
package/dist/esm/AudioTap.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { type AudioBus, type Voice } from '@codexo/exojs';
|
|
2
|
-
/** What an analysis tap can listen to. */
|
|
3
|
-
export type AudioTapSource = AudioBus | Voice | MediaStream | AudioNode | null;
|
|
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
|
-
export declare class AudioTap {
|
|
14
|
-
private _source;
|
|
15
|
-
private _target;
|
|
16
|
-
private _tapNode;
|
|
17
|
-
private _streamSource;
|
|
18
|
-
private _pendingSourceSetup;
|
|
19
|
-
private _cancelDeferredRetry;
|
|
20
|
-
get source(): AudioTapSource;
|
|
21
|
-
set source(value: AudioTapSource);
|
|
22
|
-
/** Sets the node the source feeds and connects a source assigned before it existed. */
|
|
23
|
-
attach(target: AudioNode, context: AudioContext): void;
|
|
24
|
-
/** Disconnects the tap, cancels pending setup and forgets source and target. */
|
|
25
|
-
destroy(): void;
|
|
26
|
-
private _connect;
|
|
27
|
-
private _resolve;
|
|
28
|
-
private _deferUntilBusSetup;
|
|
29
|
-
private _cancelDeferred;
|
|
30
|
-
private _disconnect;
|
|
31
|
-
private _cancelPendingSetup;
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=AudioTap.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AudioTap.d.ts","sourceRoot":"","sources":["../../src/AudioTap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAA6D,KAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AAErH,0CAA0C;AAC1C,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,KAAK,GAAG,WAAW,GAAG,SAAS,GAAG,IAAI,CAAC;AAE/E;;;;;;;;GAQG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,QAAQ,CAA0B;IAC1C,OAAO,CAAC,aAAa,CAA2C;IAChE,OAAO,CAAC,mBAAmB,CAAkD;IAI7E,OAAO,CAAC,oBAAoB,CAA6B;IAEzD,IAAW,MAAM,IAAI,cAAc,CAElC;IAED,IAAW,MAAM,CAAC,KAAK,EAAE,cAAc,EAwBtC;IAED,uFAAuF;IAChF,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAM5D;IAED,gFAAgF;IACzE,OAAO,IAAI,IAAI,CAMrB;IAED,OAAO,CAAC,QAAQ;IAehB,OAAO,CAAC,QAAQ;IAkChB,OAAO,CAAC,mBAAmB;IAyB3B,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,WAAW;IAgBnB,OAAO,CAAC,mBAAmB;CAM5B"}
|