@aura3d/audio 1.4.0 → 1.4.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/package.json +34 -3
- package/src/AdaptiveMusicFixtures.ts +0 -132
- package/src/AudioBus.ts +0 -47
- package/src/AudioClip.ts +0 -26
- package/src/AudioContextManager.ts +0 -74
- package/src/AudioEffect.ts +0 -7
- package/src/AudioEffectsAnalysisFixtures.ts +0 -311
- package/src/AudioFileManager.ts +0 -252
- package/src/AudioListener.ts +0 -17
- package/src/AudioMixer.ts +0 -123
- package/src/AudioSource.ts +0 -75
- package/src/AudioSystem.ts +0 -34
- package/src/AudioTimelineTrack.ts +0 -516
- package/src/AudioWaveform.ts +0 -226
- package/src/SceneAudioBridge.ts +0 -49
- package/src/SpatialAudio.ts +0 -36
- package/src/SpatialAudioFixtures.ts +0 -137
- package/src/effects/Filter.ts +0 -39
- package/src/effects/Reverb.ts +0 -30
- package/src/index.ts +0 -74
- package/tests/audio.test.ts +0 -353
- package/tsconfig.json +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aura3d/audio",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -11,6 +11,37 @@
|
|
|
11
11
|
"main": "./dist/index.js",
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@aura3d/scene": "1.4.
|
|
15
|
-
}
|
|
14
|
+
"@aura3d/scene": "1.4.1"
|
|
15
|
+
},
|
|
16
|
+
"description": "Browser audio lifecycle, clips, sources, buses, mixing, listener transforms, spatial attenuation, effects, and scene audio bridges for Aura3D.",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"aura3d",
|
|
19
|
+
"3d",
|
|
20
|
+
"browser-3d",
|
|
21
|
+
"web-3d",
|
|
22
|
+
"typescript",
|
|
23
|
+
"audio",
|
|
24
|
+
"web-audio",
|
|
25
|
+
"spatial-audio",
|
|
26
|
+
"audio-engine",
|
|
27
|
+
"3d-audio",
|
|
28
|
+
"sound-effects"
|
|
29
|
+
],
|
|
30
|
+
"homepage": "https://aura3d.auraone.ai",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/auraoneai/aura3d.git",
|
|
34
|
+
"directory": "packages/audio"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/auraoneai/aura3d/issues"
|
|
38
|
+
},
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"README.md",
|
|
45
|
+
"dist"
|
|
46
|
+
]
|
|
16
47
|
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
export type AdaptiveMusicFixtureState = "calm" | "tension" | "action" | "victory" | "defeat";
|
|
2
|
-
|
|
3
|
-
export type AdaptiveMusicCrossfadeCurve = "linear" | "equal-power" | "s-curve";
|
|
4
|
-
|
|
5
|
-
export interface AdaptiveMusicFixtureOptions {
|
|
6
|
-
readonly state?: AdaptiveMusicFixtureState;
|
|
7
|
-
readonly intensity?: number;
|
|
8
|
-
readonly curve?: AdaptiveMusicCrossfadeCurve;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface AdaptiveMusicLayerMix {
|
|
12
|
-
readonly id: string;
|
|
13
|
-
readonly role: "bed" | "pulse" | "lead" | "stinger";
|
|
14
|
-
readonly threshold: number;
|
|
15
|
-
readonly baseVolume: number;
|
|
16
|
-
readonly targetVolume: number;
|
|
17
|
-
readonly enabled: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface AdaptiveMusicFixture {
|
|
21
|
-
readonly source: "origin-master-adaptive-music-adapted";
|
|
22
|
-
readonly state: AdaptiveMusicFixtureState;
|
|
23
|
-
readonly intensity: number;
|
|
24
|
-
readonly curve: AdaptiveMusicCrossfadeCurve;
|
|
25
|
-
readonly transitionSeconds: number;
|
|
26
|
-
readonly loopBars: number;
|
|
27
|
-
readonly tempoBpm: number;
|
|
28
|
-
readonly layers: readonly AdaptiveMusicLayerMix[];
|
|
29
|
-
readonly activeLayerCount: number;
|
|
30
|
-
readonly peakLayerVolume: number;
|
|
31
|
-
readonly crossfade: {
|
|
32
|
-
readonly outGain: readonly number[];
|
|
33
|
-
readonly inGain: readonly number[];
|
|
34
|
-
readonly equalPowerNormalized: boolean;
|
|
35
|
-
};
|
|
36
|
-
readonly hash: string;
|
|
37
|
-
readonly claimBoundary: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const STATE_INTENSITY: Record<AdaptiveMusicFixtureState, number> = {
|
|
41
|
-
calm: 0.05,
|
|
42
|
-
tension: 0.42,
|
|
43
|
-
action: 0.82,
|
|
44
|
-
victory: 0.58,
|
|
45
|
-
defeat: 0.22
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const LAYERS: readonly Omit<AdaptiveMusicLayerMix, "targetVolume" | "enabled">[] = [
|
|
49
|
-
{ id: "ambient-bed", role: "bed", threshold: 0, baseVolume: 0.46 },
|
|
50
|
-
{ id: "rhythm-pulse", role: "pulse", threshold: 0.32, baseVolume: 0.7 },
|
|
51
|
-
{ id: "lead-motif", role: "lead", threshold: 0.62, baseVolume: 0.58 },
|
|
52
|
-
{ id: "result-stinger", role: "stinger", threshold: 0.52, baseVolume: 0.84 }
|
|
53
|
-
];
|
|
54
|
-
|
|
55
|
-
export function sampleAdaptiveMusicFixture(options: AdaptiveMusicFixtureOptions = {}): AdaptiveMusicFixture {
|
|
56
|
-
const state = options.state ?? "tension";
|
|
57
|
-
const intensity = clamp01(options.intensity ?? STATE_INTENSITY[state]);
|
|
58
|
-
const curve = options.curve ?? "equal-power";
|
|
59
|
-
const layers = LAYERS.map((layer) => {
|
|
60
|
-
const enabled = layer.role === "stinger" ? state === "victory" || state === "defeat" : intensity >= layer.threshold;
|
|
61
|
-
const ramp = layer.threshold >= 1 ? 0 : clamp01((intensity - layer.threshold) / Math.max(0.08, 1 - layer.threshold));
|
|
62
|
-
const stateBoost = layer.role === "stinger" && state === "victory" ? 1 : layer.role === "stinger" && state === "defeat" ? 0.62 : 1;
|
|
63
|
-
return {
|
|
64
|
-
...layer,
|
|
65
|
-
enabled,
|
|
66
|
-
targetVolume: enabled ? round(layer.baseVolume * Math.max(layer.role === "bed" ? 0.45 : 0.18, ramp) * stateBoost) : 0
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
const crossfade = crossfadeSamples(curve, 6);
|
|
70
|
-
const hash = stableHash([
|
|
71
|
-
state,
|
|
72
|
-
intensity.toFixed(4),
|
|
73
|
-
curve,
|
|
74
|
-
...layers.map((layer) => `${layer.id}:${layer.targetVolume.toFixed(4)}:${layer.enabled ? 1 : 0}`)
|
|
75
|
-
].join("|"));
|
|
76
|
-
return {
|
|
77
|
-
source: "origin-master-adaptive-music-adapted",
|
|
78
|
-
state,
|
|
79
|
-
intensity: round(intensity),
|
|
80
|
-
curve,
|
|
81
|
-
transitionSeconds: state === "victory" || state === "defeat" ? 0.65 : 1.4,
|
|
82
|
-
loopBars: 8,
|
|
83
|
-
tempoBpm: state === "action" ? 138 : state === "victory" ? 124 : 112,
|
|
84
|
-
layers,
|
|
85
|
-
activeLayerCount: layers.filter((layer) => layer.enabled && layer.targetVolume > 0).length,
|
|
86
|
-
peakLayerVolume: round(Math.max(...layers.map((layer) => layer.targetVolume))),
|
|
87
|
-
crossfade,
|
|
88
|
-
hash,
|
|
89
|
-
claimBoundary: "Adaptive music fixture adapts old layer/crossfade state for deterministic runtime evidence; it does not play authored stems or prove Unity/Unreal audio middleware parity."
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function crossfadeSamples(curve: AdaptiveMusicCrossfadeCurve, steps: number): AdaptiveMusicFixture["crossfade"] {
|
|
94
|
-
const outGain: number[] = [];
|
|
95
|
-
const inGain: number[] = [];
|
|
96
|
-
for (let index = 0; index <= steps; index += 1) {
|
|
97
|
-
const t = index / steps;
|
|
98
|
-
if (curve === "equal-power") {
|
|
99
|
-
outGain.push(round(Math.cos(t * Math.PI * 0.5)));
|
|
100
|
-
inGain.push(round(Math.sin(t * Math.PI * 0.5)));
|
|
101
|
-
} else if (curve === "s-curve") {
|
|
102
|
-
const s = (Math.sin((t - 0.5) * Math.PI) + 1) / 2;
|
|
103
|
-
outGain.push(round(1 - s));
|
|
104
|
-
inGain.push(round(s));
|
|
105
|
-
} else {
|
|
106
|
-
outGain.push(round(1 - t));
|
|
107
|
-
inGain.push(round(t));
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
outGain,
|
|
112
|
-
inGain,
|
|
113
|
-
equalPowerNormalized: curve === "equal-power" && outGain.every((out, index) => Math.abs(out * out + (inGain[index] ?? 0) * (inGain[index] ?? 0) - 1) < 0.002)
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function stableHash(value: string): string {
|
|
118
|
-
let hash = 0x811c9dc5;
|
|
119
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
120
|
-
hash ^= value.charCodeAt(index);
|
|
121
|
-
hash = Math.imul(hash, 0x01000193);
|
|
122
|
-
}
|
|
123
|
-
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function clamp01(value: number): number {
|
|
127
|
-
return Number.isFinite(value) ? Math.max(0, Math.min(1, value)) : 0;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function round(value: number): number {
|
|
131
|
-
return Number(value.toFixed(4));
|
|
132
|
-
}
|
package/src/AudioBus.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { AudioContextLike } from "./AudioContextManager";
|
|
2
|
-
|
|
3
|
-
export class AudioBus {
|
|
4
|
-
readonly input: GainNode;
|
|
5
|
-
readonly output: GainNode;
|
|
6
|
-
private muted = false;
|
|
7
|
-
private storedVolume = 1;
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
10
|
-
readonly name: string,
|
|
11
|
-
context: AudioContextLike,
|
|
12
|
-
destination?: AudioNode
|
|
13
|
-
) {
|
|
14
|
-
this.input = context.createGain();
|
|
15
|
-
this.output = context.createGain();
|
|
16
|
-
this.input.connect(this.output);
|
|
17
|
-
this.output.connect(destination ?? context.destination);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
get volume(): number {
|
|
21
|
-
return this.storedVolume;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get isMuted(): boolean {
|
|
25
|
-
return this.muted;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
setVolume(value: number): void {
|
|
29
|
-
if (!Number.isFinite(value) || value < 0) {
|
|
30
|
-
throw new Error("Audio bus volume must be a non-negative finite number");
|
|
31
|
-
}
|
|
32
|
-
this.storedVolume = value;
|
|
33
|
-
if (!this.muted) {
|
|
34
|
-
this.output.gain.value = value;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
mute(value = true): void {
|
|
39
|
-
this.muted = value;
|
|
40
|
-
this.output.gain.value = value ? 0 : this.storedVolume;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
dispose(): void {
|
|
44
|
-
this.input.disconnect();
|
|
45
|
-
this.output.disconnect();
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/AudioClip.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export interface AudioClipOptions {
|
|
2
|
-
readonly name?: string;
|
|
3
|
-
readonly buffer: AudioBuffer;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export class AudioClip {
|
|
7
|
-
readonly name?: string;
|
|
8
|
-
readonly buffer: AudioBuffer;
|
|
9
|
-
|
|
10
|
-
constructor(options: AudioClipOptions) {
|
|
11
|
-
this.name = options.name;
|
|
12
|
-
this.buffer = options.buffer;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
get duration(): number {
|
|
16
|
-
return this.buffer.duration;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get channels(): number {
|
|
20
|
-
return this.buffer.numberOfChannels;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
get sampleRate(): number {
|
|
24
|
-
return this.buffer.sampleRate;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
export type AudioContextState = "locked" | "running" | "suspended" | "closed";
|
|
2
|
-
|
|
3
|
-
export interface AudioContextLike {
|
|
4
|
-
readonly state: AudioContextState | string;
|
|
5
|
-
readonly destination: AudioNode;
|
|
6
|
-
currentTime: number;
|
|
7
|
-
resume(): Promise<void>;
|
|
8
|
-
suspend(): Promise<void>;
|
|
9
|
-
close(): Promise<void>;
|
|
10
|
-
createGain(): GainNode;
|
|
11
|
-
createBufferSource(): AudioBufferSourceNode;
|
|
12
|
-
createPanner(): PannerNode;
|
|
13
|
-
createBiquadFilter(): BiquadFilterNode;
|
|
14
|
-
createConvolver(): ConvolverNode;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface AudioContextManagerOptions {
|
|
18
|
-
readonly context?: AudioContextLike;
|
|
19
|
-
readonly createContext?: () => AudioContextLike;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class AudioContextManager {
|
|
23
|
-
private contextRef?: AudioContextLike;
|
|
24
|
-
private unlocked = false;
|
|
25
|
-
|
|
26
|
-
constructor(private readonly options: AudioContextManagerOptions = {}) {
|
|
27
|
-
this.contextRef = options.context;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get context(): AudioContextLike {
|
|
31
|
-
if (!this.contextRef) {
|
|
32
|
-
const createContext = this.options.createContext ?? (() => new AudioContext() as unknown as AudioContextLike);
|
|
33
|
-
this.contextRef = createContext();
|
|
34
|
-
}
|
|
35
|
-
return this.contextRef;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get state(): AudioContextState {
|
|
39
|
-
if (!this.contextRef) {
|
|
40
|
-
return "locked";
|
|
41
|
-
}
|
|
42
|
-
if (this.contextRef.state === "running") {
|
|
43
|
-
return "running";
|
|
44
|
-
}
|
|
45
|
-
if (this.contextRef.state === "closed") {
|
|
46
|
-
return "closed";
|
|
47
|
-
}
|
|
48
|
-
return this.unlocked ? "suspended" : "locked";
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async unlock(): Promise<void> {
|
|
52
|
-
if (this.state === "closed") {
|
|
53
|
-
throw new Error("Cannot unlock a closed audio context");
|
|
54
|
-
}
|
|
55
|
-
await this.context.resume();
|
|
56
|
-
this.unlocked = true;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async suspend(): Promise<void> {
|
|
60
|
-
if (this.state !== "closed") {
|
|
61
|
-
await this.context.suspend();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async resume(): Promise<void> {
|
|
66
|
-
await this.unlock();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async dispose(): Promise<void> {
|
|
70
|
-
if (this.contextRef && this.contextRef.state !== "closed") {
|
|
71
|
-
await this.contextRef.close();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
package/src/AudioEffect.ts
DELETED
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
export type AudioCompressorPreset = "gentle" | "moderate" | "aggressive" | "limiter" | "vocal" | "drums" | "master";
|
|
2
|
-
export type AudioDelayPreset = "slapback" | "short_echo" | "medium_echo" | "long_echo" | "ping_pong" | "tape_echo";
|
|
3
|
-
export type AudioChorusPreset = "subtle" | "classic" | "deep" | "wide" | "ensemble" | "vibrato";
|
|
4
|
-
export type AudioDistortionCurve = "sigmoid" | "asymmetric" | "hardclip" | "softclip" | "fuzz" | "saturation";
|
|
5
|
-
|
|
6
|
-
export interface AudioEffectsAnalysisFixtureOptions {
|
|
7
|
-
readonly preset?: AudioCompressorPreset;
|
|
8
|
-
readonly inputPeakDb?: number;
|
|
9
|
-
readonly intensity?: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface AudioEqBandFixture {
|
|
13
|
-
readonly name: string;
|
|
14
|
-
readonly type: "lowshelf" | "peaking" | "highshelf";
|
|
15
|
-
readonly frequencyHz: number;
|
|
16
|
-
readonly q: number;
|
|
17
|
-
readonly gainDb: number;
|
|
18
|
-
readonly enabled: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface AudioSpectrumBandFixture {
|
|
22
|
-
readonly name: string;
|
|
23
|
-
readonly minHz: number;
|
|
24
|
-
readonly maxHz: number;
|
|
25
|
-
readonly magnitude: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface AudioEffectsAnalysisFixture {
|
|
29
|
-
readonly source: "origin-master-audio-effects-analysis-adapted";
|
|
30
|
-
readonly effectChain: readonly ["parametric-eq", "dynamic-compressor", "delay", "chorus", "distortion", "filter", "spectrum-analyzer"];
|
|
31
|
-
readonly compressor: {
|
|
32
|
-
readonly preset: AudioCompressorPreset;
|
|
33
|
-
readonly thresholdDb: number;
|
|
34
|
-
readonly kneeDb: number;
|
|
35
|
-
readonly ratio: number;
|
|
36
|
-
readonly attackSeconds: number;
|
|
37
|
-
readonly releaseSeconds: number;
|
|
38
|
-
readonly inputPeakDb: number;
|
|
39
|
-
readonly outputPeakDb: number;
|
|
40
|
-
readonly gainReductionDb: number;
|
|
41
|
-
readonly makeupGainDb: number;
|
|
42
|
-
readonly limiterTriggered: boolean;
|
|
43
|
-
};
|
|
44
|
-
readonly eq: {
|
|
45
|
-
readonly bands: readonly AudioEqBandFixture[];
|
|
46
|
-
readonly activeBandCount: number;
|
|
47
|
-
readonly lowShelfGainDb: number;
|
|
48
|
-
readonly presenceGainDb: number;
|
|
49
|
-
readonly outputGain: number;
|
|
50
|
-
};
|
|
51
|
-
readonly delay: {
|
|
52
|
-
readonly source: "origin-master-delay-effect-adapted";
|
|
53
|
-
readonly preset: AudioDelayPreset;
|
|
54
|
-
readonly delayTimeSeconds: number;
|
|
55
|
-
readonly feedback: number;
|
|
56
|
-
readonly wetDryMix: number;
|
|
57
|
-
readonly filterFrequencyHz: number;
|
|
58
|
-
readonly pingPong: boolean;
|
|
59
|
-
readonly repeatsAboveNoiseFloor: number;
|
|
60
|
-
};
|
|
61
|
-
readonly chorus: {
|
|
62
|
-
readonly source: "origin-master-chorus-effect-adapted";
|
|
63
|
-
readonly preset: AudioChorusPreset;
|
|
64
|
-
readonly rateHz: number;
|
|
65
|
-
readonly depthSeconds: number;
|
|
66
|
-
readonly feedback: number;
|
|
67
|
-
readonly wetDryMix: number;
|
|
68
|
-
readonly delaySeconds: number;
|
|
69
|
-
readonly voices: number;
|
|
70
|
-
readonly stereoWidth: number;
|
|
71
|
-
};
|
|
72
|
-
readonly distortion: {
|
|
73
|
-
readonly source: "origin-master-distortion-effect-adapted";
|
|
74
|
-
readonly curve: AudioDistortionCurve;
|
|
75
|
-
readonly amount: number;
|
|
76
|
-
readonly preGain: number;
|
|
77
|
-
readonly postGain: number;
|
|
78
|
-
readonly wetDryMix: number;
|
|
79
|
-
readonly harmonicBoost: number;
|
|
80
|
-
readonly outputCeiling: number;
|
|
81
|
-
};
|
|
82
|
-
readonly filter: {
|
|
83
|
-
readonly source: "origin-master-filter-effect-adapted";
|
|
84
|
-
readonly type: "lowpass" | "highpass" | "bandpass";
|
|
85
|
-
readonly frequencyHz: number;
|
|
86
|
-
readonly q: number;
|
|
87
|
-
readonly resonanceDb: number;
|
|
88
|
-
readonly enabled: boolean;
|
|
89
|
-
};
|
|
90
|
-
readonly spectrum: {
|
|
91
|
-
readonly bands: readonly AudioSpectrumBandFixture[];
|
|
92
|
-
readonly barCount: number;
|
|
93
|
-
readonly bars: readonly number[];
|
|
94
|
-
readonly peakFrequencyHz: number;
|
|
95
|
-
readonly peakMagnitude: number;
|
|
96
|
-
readonly logarithmicScale: boolean;
|
|
97
|
-
};
|
|
98
|
-
readonly hash: string;
|
|
99
|
-
readonly claimBoundary: string;
|
|
100
|
-
readonly blockedClaims: readonly string[];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const COMPRESSOR_PRESETS: Record<AudioCompressorPreset, {
|
|
104
|
-
readonly thresholdDb: number;
|
|
105
|
-
readonly kneeDb: number;
|
|
106
|
-
readonly ratio: number;
|
|
107
|
-
readonly attackSeconds: number;
|
|
108
|
-
readonly releaseSeconds: number;
|
|
109
|
-
}> = {
|
|
110
|
-
gentle: { thresholdDb: -30, kneeDb: 20, ratio: 2, attackSeconds: 0.01, releaseSeconds: 0.3 },
|
|
111
|
-
moderate: { thresholdDb: -24, kneeDb: 30, ratio: 4, attackSeconds: 0.005, releaseSeconds: 0.25 },
|
|
112
|
-
aggressive: { thresholdDb: -18, kneeDb: 10, ratio: 8, attackSeconds: 0.001, releaseSeconds: 0.1 },
|
|
113
|
-
limiter: { thresholdDb: -6, kneeDb: 0, ratio: 20, attackSeconds: 0.001, releaseSeconds: 0.05 },
|
|
114
|
-
vocal: { thresholdDb: -20, kneeDb: 15, ratio: 3, attackSeconds: 0.005, releaseSeconds: 0.2 },
|
|
115
|
-
drums: { thresholdDb: -18, kneeDb: 5, ratio: 6, attackSeconds: 0.001, releaseSeconds: 0.08 },
|
|
116
|
-
master: { thresholdDb: -14, kneeDb: 8, ratio: 3, attackSeconds: 0.004, releaseSeconds: 0.16 }
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const SPECTRUM_BANDS: readonly Omit<AudioSpectrumBandFixture, "magnitude">[] = [
|
|
120
|
-
{ name: "Sub Bass", minHz: 20, maxHz: 60 },
|
|
121
|
-
{ name: "Bass", minHz: 60, maxHz: 250 },
|
|
122
|
-
{ name: "Low Mid", minHz: 250, maxHz: 500 },
|
|
123
|
-
{ name: "Mid", minHz: 500, maxHz: 2_000 },
|
|
124
|
-
{ name: "High Mid", minHz: 2_000, maxHz: 4_000 },
|
|
125
|
-
{ name: "Presence", minHz: 4_000, maxHz: 6_000 },
|
|
126
|
-
{ name: "Brilliance", minHz: 6_000, maxHz: 20_000 }
|
|
127
|
-
];
|
|
128
|
-
|
|
129
|
-
export function sampleAudioEffectsAnalysisFixture(options: AudioEffectsAnalysisFixtureOptions = {}): AudioEffectsAnalysisFixture {
|
|
130
|
-
const preset = options.preset ?? "master";
|
|
131
|
-
const compressorPreset = COMPRESSOR_PRESETS[preset];
|
|
132
|
-
const intensity = clamp01(options.intensity ?? 0.72);
|
|
133
|
-
const inputPeakDb = clamp(options.inputPeakDb ?? -3.5, -60, 6);
|
|
134
|
-
const overThresholdDb = Math.max(0, inputPeakDb - compressorPreset.thresholdDb);
|
|
135
|
-
const compressedOverage = overThresholdDb / compressorPreset.ratio;
|
|
136
|
-
const gainReductionDb = round(Math.max(0, overThresholdDb - compressedOverage));
|
|
137
|
-
const makeupGainDb = round(Math.min(6, gainReductionDb * 0.38));
|
|
138
|
-
const outputPeakDb = round(inputPeakDb - gainReductionDb + makeupGainDb);
|
|
139
|
-
const eqBands = eqBandsForIntensity(intensity);
|
|
140
|
-
const spectrumBands = SPECTRUM_BANDS.map((band, index) => ({
|
|
141
|
-
...band,
|
|
142
|
-
magnitude: round(clamp01((Math.sin(index * 1.37 + intensity * 2.1) + 1) * 0.29 + intensity * (index === 1 || index === 5 ? 0.28 : 0.16)))
|
|
143
|
-
}));
|
|
144
|
-
const bars = spectrumBars(spectrumBands, 16);
|
|
145
|
-
const peak = spectrumBands.reduce((best, band) => band.magnitude > best.magnitude ? band : best, spectrumBands[0]!);
|
|
146
|
-
const fixture = {
|
|
147
|
-
source: "origin-master-audio-effects-analysis-adapted" as const,
|
|
148
|
-
effectChain: ["parametric-eq", "dynamic-compressor", "delay", "chorus", "distortion", "filter", "spectrum-analyzer"] as const,
|
|
149
|
-
compressor: {
|
|
150
|
-
preset,
|
|
151
|
-
...compressorPreset,
|
|
152
|
-
inputPeakDb: round(inputPeakDb),
|
|
153
|
-
outputPeakDb,
|
|
154
|
-
gainReductionDb,
|
|
155
|
-
makeupGainDb,
|
|
156
|
-
limiterTriggered: outputPeakDb >= -0.5 || preset === "limiter"
|
|
157
|
-
},
|
|
158
|
-
eq: {
|
|
159
|
-
bands: eqBands,
|
|
160
|
-
activeBandCount: eqBands.filter((band) => band.enabled).length,
|
|
161
|
-
lowShelfGainDb: eqBands[0]?.gainDb ?? 0,
|
|
162
|
-
presenceGainDb: eqBands.find((band) => band.name === "presence-lift")?.gainDb ?? 0,
|
|
163
|
-
outputGain: round(1 - Math.max(0, outputPeakDb) * 0.05)
|
|
164
|
-
},
|
|
165
|
-
delay: delayFixture(intensity),
|
|
166
|
-
chorus: chorusFixture(intensity),
|
|
167
|
-
distortion: distortionFixture(intensity, inputPeakDb),
|
|
168
|
-
filter: filterFixture(intensity),
|
|
169
|
-
spectrum: {
|
|
170
|
-
bands: spectrumBands,
|
|
171
|
-
barCount: bars.length,
|
|
172
|
-
bars,
|
|
173
|
-
peakFrequencyHz: Math.round((peak.minHz + peak.maxHz) / 2),
|
|
174
|
-
peakMagnitude: peak.magnitude,
|
|
175
|
-
logarithmicScale: true
|
|
176
|
-
},
|
|
177
|
-
hash: "",
|
|
178
|
-
claimBoundary: "Audio effects fixture adapts old compressor, EQ, delay, chorus, distortion, filter, and spectrum-analysis concepts for deterministic telemetry; it does not instantiate a production WebAudio mastering graph or prove audio middleware parity.",
|
|
179
|
-
blockedClaims: [
|
|
180
|
-
"production WebAudio effects graph parity",
|
|
181
|
-
"production delay/chorus/distortion/filter node graph parity",
|
|
182
|
-
"real-time FFT browser analyzer certification",
|
|
183
|
-
"audio middleware mastering parity",
|
|
184
|
-
"Unity Audio Mixer parity",
|
|
185
|
-
"Unreal Audio Mixer parity"
|
|
186
|
-
] as const
|
|
187
|
-
};
|
|
188
|
-
return {
|
|
189
|
-
...fixture,
|
|
190
|
-
hash: stableHash([
|
|
191
|
-
fixture.compressor.preset,
|
|
192
|
-
fixture.compressor.outputPeakDb,
|
|
193
|
-
fixture.compressor.gainReductionDb,
|
|
194
|
-
fixture.delay.preset,
|
|
195
|
-
fixture.delay.repeatsAboveNoiseFloor,
|
|
196
|
-
fixture.chorus.voices,
|
|
197
|
-
fixture.chorus.stereoWidth,
|
|
198
|
-
fixture.distortion.curve,
|
|
199
|
-
fixture.distortion.harmonicBoost,
|
|
200
|
-
fixture.filter.frequencyHz,
|
|
201
|
-
fixture.eq.bands.map((band) => `${band.frequencyHz}:${band.gainDb}`).join(","),
|
|
202
|
-
fixture.spectrum.peakFrequencyHz,
|
|
203
|
-
fixture.spectrum.peakMagnitude
|
|
204
|
-
].join("|"))
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function delayFixture(intensity: number): AudioEffectsAnalysisFixture["delay"] {
|
|
209
|
-
const preset: AudioDelayPreset = intensity > 0.7 ? "tape_echo" : intensity > 0.52 ? "medium_echo" : "short_echo";
|
|
210
|
-
const delayTimeSeconds = preset === "tape_echo" ? 0.42 : preset === "medium_echo" ? 0.5 : 0.25;
|
|
211
|
-
const feedback = round(preset === "tape_echo" ? 0.58 : 0.22 + intensity * 0.35);
|
|
212
|
-
const wetDryMix = round(0.24 + intensity * 0.34);
|
|
213
|
-
return {
|
|
214
|
-
source: "origin-master-delay-effect-adapted",
|
|
215
|
-
preset,
|
|
216
|
-
delayTimeSeconds,
|
|
217
|
-
feedback,
|
|
218
|
-
wetDryMix,
|
|
219
|
-
filterFrequencyHz: Math.round(7_500 - intensity * 4_600),
|
|
220
|
-
pingPong: preset === "tape_echo" || intensity > 0.82,
|
|
221
|
-
repeatsAboveNoiseFloor: Math.max(1, Math.min(8, Math.ceil(Math.log(0.04) / Math.log(Math.max(0.05, feedback)))))
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function chorusFixture(intensity: number): AudioEffectsAnalysisFixture["chorus"] {
|
|
226
|
-
const preset: AudioChorusPreset = intensity > 0.72 ? "ensemble" : intensity > 0.5 ? "classic" : "subtle";
|
|
227
|
-
const voices = preset === "ensemble" ? 4 : preset === "classic" ? 2 : 1;
|
|
228
|
-
return {
|
|
229
|
-
source: "origin-master-chorus-effect-adapted",
|
|
230
|
-
preset,
|
|
231
|
-
rateHz: round(0.85 + intensity * 2.2),
|
|
232
|
-
depthSeconds: round(0.0012 + intensity * 0.006),
|
|
233
|
-
feedback: round(0.08 + intensity * 0.26),
|
|
234
|
-
wetDryMix: round(0.18 + intensity * 0.42),
|
|
235
|
-
delaySeconds: round(0.012 + intensity * 0.018),
|
|
236
|
-
voices,
|
|
237
|
-
stereoWidth: round(Math.min(1, 0.36 + voices * 0.13 + intensity * 0.22))
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function distortionFixture(intensity: number, inputPeakDb: number): AudioEffectsAnalysisFixture["distortion"] {
|
|
242
|
-
const curve: AudioDistortionCurve = intensity > 0.76 ? "saturation" : intensity > 0.58 ? "softclip" : "sigmoid";
|
|
243
|
-
const amount = round(18 + intensity * 62);
|
|
244
|
-
const preGain = round(1 + intensity * 2.4);
|
|
245
|
-
const postGain = round(Math.max(0.42, 1 - intensity * 0.36));
|
|
246
|
-
const harmonicBoost = round(Math.max(0, amount / 100 * preGain * Math.max(0.25, (inputPeakDb + 24) / 24)));
|
|
247
|
-
return {
|
|
248
|
-
source: "origin-master-distortion-effect-adapted",
|
|
249
|
-
curve,
|
|
250
|
-
amount,
|
|
251
|
-
preGain,
|
|
252
|
-
postGain,
|
|
253
|
-
wetDryMix: round(0.2 + intensity * 0.55),
|
|
254
|
-
harmonicBoost,
|
|
255
|
-
outputCeiling: round(Math.min(0.98, postGain + harmonicBoost * 0.08))
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function filterFixture(intensity: number): AudioEffectsAnalysisFixture["filter"] {
|
|
260
|
-
const type = intensity > 0.62 ? "lowpass" : "bandpass";
|
|
261
|
-
const frequencyHz = Math.round(type === "lowpass" ? 6_800 - intensity * 2_400 : 1_200 + intensity * 2_200);
|
|
262
|
-
const q = round(0.7 + intensity * 1.6);
|
|
263
|
-
return {
|
|
264
|
-
source: "origin-master-filter-effect-adapted",
|
|
265
|
-
type,
|
|
266
|
-
frequencyHz,
|
|
267
|
-
q,
|
|
268
|
-
resonanceDb: round(q * 2.6),
|
|
269
|
-
enabled: true
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function eqBandsForIntensity(intensity: number): readonly AudioEqBandFixture[] {
|
|
274
|
-
return [
|
|
275
|
-
{ name: "low-body", type: "lowshelf", frequencyHz: 120, q: 0.7, gainDb: round(2.4 * intensity), enabled: true },
|
|
276
|
-
{ name: "mud-cut", type: "peaking", frequencyHz: 360, q: 1.1, gainDb: round(-1.8 * intensity), enabled: true },
|
|
277
|
-
{ name: "presence-lift", type: "peaking", frequencyHz: 3_200, q: 0.9, gainDb: round(2.2 * intensity), enabled: true },
|
|
278
|
-
{ name: "air", type: "highshelf", frequencyHz: 8_500, q: 0.8, gainDb: round(1.6 * intensity), enabled: true }
|
|
279
|
-
];
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function spectrumBars(bands: readonly AudioSpectrumBandFixture[], count: number): readonly number[] {
|
|
283
|
-
const bars: number[] = [];
|
|
284
|
-
for (let index = 0; index < count; index += 1) {
|
|
285
|
-
const band = bands[Math.min(bands.length - 1, Math.floor(index / count * bands.length))]!;
|
|
286
|
-
const shimmer = 0.85 + 0.15 * Math.sin(index * 0.9);
|
|
287
|
-
bars.push(round(clamp01(band.magnitude * shimmer)));
|
|
288
|
-
}
|
|
289
|
-
return bars;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function clamp01(value: number): number {
|
|
293
|
-
return clamp(value, 0, 1);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
function clamp(value: number, min: number, max: number): number {
|
|
297
|
-
return Math.max(min, Math.min(max, Number.isFinite(value) ? value : min));
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
function round(value: number): number {
|
|
301
|
-
return Number(value.toFixed(4));
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
function stableHash(value: string): string {
|
|
305
|
-
let hash = 0x811c9dc5;
|
|
306
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
307
|
-
hash ^= value.charCodeAt(index);
|
|
308
|
-
hash = Math.imul(hash, 0x01000193);
|
|
309
|
-
}
|
|
310
|
-
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
311
|
-
}
|