@newgameplusinc/odyssey-audio-video-sdk-dev 1.0.257 → 1.0.259
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 +45 -1
- package/dist/audio/AudioNodeFactory.d.ts +130 -0
- package/dist/audio/AudioNodeFactory.js +158 -0
- package/dist/audio/AudioPipeline.d.ts +89 -0
- package/dist/audio/AudioPipeline.js +138 -0
- package/dist/{MLNoiseSuppressor.d.ts → audio/MLNoiseSuppressor.d.ts} +7 -7
- package/dist/{MLNoiseSuppressor.js → audio/MLNoiseSuppressor.js} +13 -41
- package/dist/audio/index.d.ts +6 -0
- package/dist/audio/index.js +22 -0
- package/dist/channels/huddle/HuddleChannel.d.ts +87 -0
- package/dist/channels/huddle/HuddleChannel.js +152 -0
- package/dist/channels/huddle/HuddleTypes.d.ts +85 -0
- package/dist/channels/huddle/HuddleTypes.js +25 -0
- package/dist/channels/huddle/index.d.ts +5 -0
- package/dist/channels/huddle/index.js +21 -0
- package/dist/channels/index.d.ts +5 -0
- package/dist/channels/index.js +21 -0
- package/dist/channels/spatial/SpatialAudioChannel.d.ts +144 -0
- package/dist/channels/spatial/SpatialAudioChannel.js +455 -0
- package/dist/channels/spatial/SpatialAudioTypes.d.ts +85 -0
- package/dist/channels/spatial/SpatialAudioTypes.js +42 -0
- package/dist/channels/spatial/index.d.ts +5 -0
- package/dist/channels/spatial/index.js +21 -0
- package/dist/{EventManager.d.ts → core/EventManager.d.ts} +4 -2
- package/dist/{EventManager.js → core/EventManager.js} +5 -3
- package/dist/{MediasoupManager.d.ts → core/MediasoupManager.d.ts} +10 -4
- package/dist/{MediasoupManager.js → core/MediasoupManager.js} +31 -42
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +21 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +30 -4
- package/dist/sdk/index.d.ts +36 -0
- package/dist/sdk/index.js +121 -0
- package/dist/types/events.d.ts +154 -0
- package/dist/{types.js → types/events.js} +3 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.js +23 -0
- package/dist/types/participant.d.ts +65 -0
- package/dist/types/participant.js +5 -0
- package/dist/types/position.d.ts +47 -0
- package/dist/types/position.js +9 -0
- package/dist/types/room.d.ts +82 -0
- package/dist/types/room.js +5 -0
- package/dist/utils/audio/clarity-score.d.ts +33 -0
- package/dist/utils/audio/clarity-score.js +81 -0
- package/dist/utils/audio/index.d.ts +5 -0
- package/dist/utils/audio/index.js +21 -0
- package/dist/utils/audio/voice-filter.d.ts +30 -0
- package/dist/utils/audio/voice-filter.js +70 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +23 -0
- package/dist/utils/position/coordinates.d.ts +37 -0
- package/dist/utils/position/coordinates.js +61 -0
- package/dist/utils/position/index.d.ts +6 -0
- package/dist/utils/position/index.js +22 -0
- package/dist/utils/position/normalize.d.ts +37 -0
- package/dist/utils/position/normalize.js +78 -0
- package/dist/utils/position/snap.d.ts +51 -0
- package/dist/utils/position/snap.js +81 -0
- package/dist/utils/smoothing/gain-smoothing.d.ts +45 -0
- package/dist/utils/smoothing/gain-smoothing.js +77 -0
- package/dist/utils/smoothing/index.d.ts +5 -0
- package/dist/utils/smoothing/index.js +21 -0
- package/dist/utils/smoothing/pan-smoothing.d.ts +43 -0
- package/dist/utils/smoothing/pan-smoothing.js +85 -0
- package/dist/utils/spatial/angle-calc.d.ts +24 -0
- package/dist/utils/spatial/angle-calc.js +69 -0
- package/dist/utils/spatial/distance-calc.d.ts +33 -0
- package/dist/utils/spatial/distance-calc.js +48 -0
- package/dist/utils/spatial/gain-calc.d.ts +37 -0
- package/dist/utils/spatial/gain-calc.js +52 -0
- package/dist/utils/spatial/head-position.d.ts +32 -0
- package/dist/utils/spatial/head-position.js +76 -0
- package/dist/utils/spatial/index.d.ts +9 -0
- package/dist/utils/spatial/index.js +25 -0
- package/dist/utils/spatial/listener-calc.d.ts +28 -0
- package/dist/utils/spatial/listener-calc.js +74 -0
- package/dist/utils/spatial/pan-calc.d.ts +48 -0
- package/dist/utils/spatial/pan-calc.js +80 -0
- package/package.json +1 -1
- package/dist/SpatialAudioManager.d.ts +0 -272
- package/dist/SpatialAudioManager.js +0 -1537
- package/dist/types.d.ts +0 -73
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import { EventManager } from "./EventManager";
|
|
2
|
-
import { Position } from "./types";
|
|
3
|
-
type SpatialAudioDistanceConfig = {
|
|
4
|
-
refDistance?: number;
|
|
5
|
-
maxDistance?: number;
|
|
6
|
-
rolloffFactor?: number;
|
|
7
|
-
unit?: "auto" | "meters" | "centimeters";
|
|
8
|
-
};
|
|
9
|
-
type DenoiserOptions = {
|
|
10
|
-
enabled?: boolean;
|
|
11
|
-
threshold?: number;
|
|
12
|
-
noiseFloor?: number;
|
|
13
|
-
release?: number;
|
|
14
|
-
attack?: number;
|
|
15
|
-
holdMs?: number;
|
|
16
|
-
maxReduction?: number;
|
|
17
|
-
hissCut?: number;
|
|
18
|
-
expansionRatio?: number;
|
|
19
|
-
learnRate?: number;
|
|
20
|
-
voiceBoost?: number;
|
|
21
|
-
voiceSensitivity?: number;
|
|
22
|
-
voiceEnhancement?: boolean;
|
|
23
|
-
silenceFloor?: number;
|
|
24
|
-
silenceHoldMs?: number;
|
|
25
|
-
silenceReleaseMs?: number;
|
|
26
|
-
speechBoost?: number;
|
|
27
|
-
highBandGate?: number;
|
|
28
|
-
highBandAttack?: number;
|
|
29
|
-
highBandRelease?: number;
|
|
30
|
-
};
|
|
31
|
-
export type SpatialAudioOptions = {
|
|
32
|
-
distance?: SpatialAudioDistanceConfig;
|
|
33
|
-
denoiser?: DenoiserOptions;
|
|
34
|
-
};
|
|
35
|
-
export declare class SpatialAudioManager extends EventManager {
|
|
36
|
-
private static readonly BUILD_STAMP;
|
|
37
|
-
private audioContext;
|
|
38
|
-
private participantNodes;
|
|
39
|
-
private masterGainNode;
|
|
40
|
-
private monitoringIntervals;
|
|
41
|
-
private compressor;
|
|
42
|
-
private options;
|
|
43
|
-
private denoiseWorkletReady;
|
|
44
|
-
private denoiseWorkletUrl?;
|
|
45
|
-
private listenerPosition;
|
|
46
|
-
private listenerInitialized;
|
|
47
|
-
private listenerDirection;
|
|
48
|
-
private listenerRight;
|
|
49
|
-
private lastLogTime?;
|
|
50
|
-
private localParticipantId;
|
|
51
|
-
private isMasterMuted;
|
|
52
|
-
private smoothedPanValues;
|
|
53
|
-
private lastPanValue;
|
|
54
|
-
private lastSpatialUpdateTime;
|
|
55
|
-
private _spatialDebugTimes;
|
|
56
|
-
private panSmoothingFactor;
|
|
57
|
-
private panChangeThreshold;
|
|
58
|
-
private panCenterDeadZone;
|
|
59
|
-
private cachedSpeakerPositions;
|
|
60
|
-
private cachedListenerPosition;
|
|
61
|
-
private positionSnapThreshold;
|
|
62
|
-
private cachedGainValues;
|
|
63
|
-
private gainChangeThreshold;
|
|
64
|
-
private _listenerDebugLogTime?;
|
|
65
|
-
private mlSuppressor;
|
|
66
|
-
private mlModelReady;
|
|
67
|
-
constructor(options?: SpatialAudioOptions);
|
|
68
|
-
getAudioContext(): AudioContext;
|
|
69
|
-
/**
|
|
70
|
-
* Initialize ML-based noise suppression (TensorFlow.js)
|
|
71
|
-
* Falls back to AudioWorklet denoiser if ML initialization fails
|
|
72
|
-
*/
|
|
73
|
-
initializeMLNoiseSuppression(modelUrl: string): Promise<void>;
|
|
74
|
-
/**
|
|
75
|
-
* Get current noise suppression mode
|
|
76
|
-
*/
|
|
77
|
-
getNoiseSuppressionMode(): 'ml' | 'audioworklet' | 'none';
|
|
78
|
-
/**
|
|
79
|
-
* True if the TFJS model assets were loaded and the model is ready.
|
|
80
|
-
* This does NOT mean it is currently processing the live WebAudio stream.
|
|
81
|
-
*/
|
|
82
|
-
isMLModelLoaded(): boolean;
|
|
83
|
-
/**
|
|
84
|
-
* Setup spatial audio for a participant
|
|
85
|
-
*
|
|
86
|
-
* CRITICAL: Each participant gets their OWN audio processing chain:
|
|
87
|
-
* Stream -> Source -> Panner -> Analyser -> Gain -> Compressor -> Output
|
|
88
|
-
*
|
|
89
|
-
* This ensures:
|
|
90
|
-
* - Each voice is positioned independently in 3D space
|
|
91
|
-
* - No server-side mixing required
|
|
92
|
-
* - Scalable to unlimited participants (browser handles the mixing)
|
|
93
|
-
*
|
|
94
|
-
* @param participantId Unique ID for this participant
|
|
95
|
-
* @param track Audio track from MediaSoup consumer
|
|
96
|
-
* @param bypassSpatialization For testing - bypasses 3D positioning
|
|
97
|
-
*/
|
|
98
|
-
setupSpatialAudioForParticipant(participantId: string, track: MediaStreamTrack, bypassSpatialization?: boolean): Promise<void>;
|
|
99
|
-
private startMonitoring;
|
|
100
|
-
/**
|
|
101
|
-
* Toggle spatialization for a participant (for huddle/spatial switching)
|
|
102
|
-
* @param participantId The participant to update
|
|
103
|
-
* @param enableSpatialization True for spatial audio, false for non-spatial (huddle)
|
|
104
|
-
*/
|
|
105
|
-
setParticipantSpatialization(participantId: string, enableSpatialization: boolean): void;
|
|
106
|
-
/**
|
|
107
|
-
* Update spatial audio position and orientation for a participant
|
|
108
|
-
*
|
|
109
|
-
* This is called every time we receive position/direction updates from the server.
|
|
110
|
-
*
|
|
111
|
-
* Position: Where the participant is in 3D space (their location)
|
|
112
|
-
* Direction: Which way they're facing (their forward vector)
|
|
113
|
-
*
|
|
114
|
-
* Example:
|
|
115
|
-
* - Position: (x: -200, y: 0, z: 100) = 2m to your left
|
|
116
|
-
* - Direction: (x: 0, y: 1, z: 0) = facing forward (away from you)
|
|
117
|
-
* - Result: Sound comes from your left, oriented as if speaking away
|
|
118
|
-
*
|
|
119
|
-
* The Web Audio API's PannerNode uses HRTF to create realistic 3D audio
|
|
120
|
-
* based on these parameters plus the listener's position/orientation.
|
|
121
|
-
*
|
|
122
|
-
* @param participantId Who to update
|
|
123
|
-
* @param position Where they are (from socket data)
|
|
124
|
-
* @param direction Which way they're facing (from socket data)
|
|
125
|
-
*/
|
|
126
|
-
updateSpatialAudio(participantId: string, position: Position, direction?: {
|
|
127
|
-
x: number;
|
|
128
|
-
y: number;
|
|
129
|
-
z: number;
|
|
130
|
-
}, _spatialMeta?: {
|
|
131
|
-
pan?: number;
|
|
132
|
-
dxLocal?: number;
|
|
133
|
-
}): void;
|
|
134
|
-
/**
|
|
135
|
-
* Mute or unmute a participant's audio
|
|
136
|
-
* Used for channel-based audio routing (huddle vs spatial)
|
|
137
|
-
* @param participantId The participant to mute/unmute
|
|
138
|
-
* @param muted True to mute, false to unmute
|
|
139
|
-
*/
|
|
140
|
-
setParticipantMuted(participantId: string, muted: boolean): void;
|
|
141
|
-
/**
|
|
142
|
-
* Master mute/unmute for ALL audio output
|
|
143
|
-
* Use this to prevent audio from playing until user explicitly joins the space.
|
|
144
|
-
* @param muted True to mute all audio, false to unmute
|
|
145
|
-
*/
|
|
146
|
-
setMasterMuted(muted: boolean): void;
|
|
147
|
-
/**
|
|
148
|
-
* Get current master mute state
|
|
149
|
-
* @returns True if master mute is enabled
|
|
150
|
-
*/
|
|
151
|
-
getMasterMuted(): boolean;
|
|
152
|
-
/**
|
|
153
|
-
* Update listener position and orientation
|
|
154
|
-
* The \"listener\" is YOU - where your ears/head are positioned
|
|
155
|
-
*
|
|
156
|
-
* @param position Your HEAD position (camera position), not body position!
|
|
157
|
-
* @param orientation Which way your head is facing (forward and up vectors)
|
|
158
|
-
*/
|
|
159
|
-
setListenerPosition(position: Position, orientation: {
|
|
160
|
-
forwardX: number;
|
|
161
|
-
forwardY: number;
|
|
162
|
-
forwardZ: number;
|
|
163
|
-
upX: number;
|
|
164
|
-
upY: number;
|
|
165
|
-
upZ: number;
|
|
166
|
-
}): void;
|
|
167
|
-
/**
|
|
168
|
-
* POSITION-ONLY MODE: Set listener HEAD position (no direction needed)
|
|
169
|
-
* IMPORTANT: Uses CAMERA position (head) as listener, not body position!
|
|
170
|
-
*
|
|
171
|
-
* @param listenerPos Player body position (for reference, not used as listener)
|
|
172
|
-
* @param cameraPos Camera/HEAD position - THIS is the actual listener position for audio
|
|
173
|
-
* @param lookAtPos Look-at position (where camera is pointing) - stored but not used for panning
|
|
174
|
-
* @param rot Rotation data (pitch, yaw, roll) - stored but not used for panning
|
|
175
|
-
*/
|
|
176
|
-
setListenerFromLSD(listenerPos: Position, cameraPos: Position, lookAtPos: Position, rot?: {
|
|
177
|
-
x: number;
|
|
178
|
-
y: number;
|
|
179
|
-
z: number;
|
|
180
|
-
}, localParticipantId?: string): void;
|
|
181
|
-
private applyListenerTransform;
|
|
182
|
-
removeParticipant(participantId: string): void;
|
|
183
|
-
resumeAudioContext(): Promise<void>;
|
|
184
|
-
getAudioContextState(): AudioContextState;
|
|
185
|
-
private getDistanceConfig;
|
|
186
|
-
private applySpatialBoostIfNeeded;
|
|
187
|
-
private getDistanceBetween;
|
|
188
|
-
private calculateDistanceGain;
|
|
189
|
-
private normalizePositionUnits;
|
|
190
|
-
/**
|
|
191
|
-
* Snap position to grid to prevent jitter from micro-movements
|
|
192
|
-
* If the position hasn't changed significantly, return the cached position
|
|
193
|
-
* This prevents gain/pan fluctuation when users are "stationary"
|
|
194
|
-
*
|
|
195
|
-
* @param position New incoming position
|
|
196
|
-
* @param participantId Participant ID for caching (use 'listener' for listener)
|
|
197
|
-
* @returns Snapped position (either new or cached)
|
|
198
|
-
*/
|
|
199
|
-
private snapPosition;
|
|
200
|
-
private getVectorFromListener;
|
|
201
|
-
private applyDirectionalSuppression;
|
|
202
|
-
/**
|
|
203
|
-
* Dynamically adjust highpass filter based on voice characteristics
|
|
204
|
-
* Analyzes audio spectrum and sets filter between 85-300Hz
|
|
205
|
-
*/
|
|
206
|
-
private adjustVoiceAdaptiveFilter;
|
|
207
|
-
private calculateClarityScore;
|
|
208
|
-
private calculateProximityWeight;
|
|
209
|
-
private calculateDirectionFocus;
|
|
210
|
-
private normalizeVector;
|
|
211
|
-
private clamp;
|
|
212
|
-
private isDenoiserEnabled;
|
|
213
|
-
/**
|
|
214
|
-
* Compute estimated head/mouth position from body position
|
|
215
|
-
* Body position is typically at feet/base - add head height offset
|
|
216
|
-
* Average human head height: 1.6m (adjustable based on avatar)
|
|
217
|
-
*/
|
|
218
|
-
private computeHeadPosition;
|
|
219
|
-
private calculatePanning;
|
|
220
|
-
private panningFromPanValue;
|
|
221
|
-
/**
|
|
222
|
-
* SMOOTH PAN VALUE to prevent random left/right jumping
|
|
223
|
-
* Uses exponential moving average (EMA) to smooth out jittery position data
|
|
224
|
-
* With SNAP behavior for large direction changes (e.g., turning around)
|
|
225
|
-
* With DEAD-ZONE around center to prevent face-to-face oscillation
|
|
226
|
-
* @param participantId The participant to smooth pan for
|
|
227
|
-
* @param newPanValue The new calculated pan value (-1 to +1)
|
|
228
|
-
* @returns Smoothed pan value
|
|
229
|
-
*/
|
|
230
|
-
private smoothPanValue;
|
|
231
|
-
private computeAzimuthFromPositions;
|
|
232
|
-
/**
|
|
233
|
-
* OLD METHOD - Kept for reference but not used in position-only mode
|
|
234
|
-
* Calculate angle between listener and sound source in degrees (0-360)
|
|
235
|
-
* 0° = front, 90° = right, 180° = back, 270° = left
|
|
236
|
-
*/
|
|
237
|
-
private calculateAngle;
|
|
238
|
-
/**
|
|
239
|
-
* Calculate gain based on distance using logarithmic scale
|
|
240
|
-
* Distance range: 0.5m to 15m
|
|
241
|
-
* Gain range: 100% to 20% (reduced minimum for audibility at distance)
|
|
242
|
-
* Uses smoother curve for more consistent audio across distances
|
|
243
|
-
*
|
|
244
|
-
* TUNED FOR CONSISTENT VOICE CLARITY:
|
|
245
|
-
* - Near range (0-3m): Full volume for clear conversation
|
|
246
|
-
* - Medium range (3-8m): Gradual falloff, still easily audible
|
|
247
|
-
* - Far range (8-15m): Soft but still present
|
|
248
|
-
*/
|
|
249
|
-
/**
|
|
250
|
-
* Calculate gain based on distance - AGGRESSIVE FALLOFF
|
|
251
|
-
*
|
|
252
|
-
* Uses inverse-square law (realistic sound propagation) with floor:
|
|
253
|
-
* Gain = 1 / (1 + k * distance²)
|
|
254
|
-
*
|
|
255
|
-
* Distance → Gain mapping:
|
|
256
|
-
* - 0-1m → 100% (full volume, very close)
|
|
257
|
-
* - 2m → ~80%
|
|
258
|
-
* - 3m → ~55%
|
|
259
|
-
* - 5m → ~30%
|
|
260
|
-
* - 8m → ~15%
|
|
261
|
-
* - 10m+ → 5% (minimum, barely audible)
|
|
262
|
-
*/
|
|
263
|
-
private calculateLogarithmicGain;
|
|
264
|
-
/**
|
|
265
|
-
* Apply stereo panning to participant audio using StereoPannerNode
|
|
266
|
-
* This provides STABLE left-right panning without jitter
|
|
267
|
-
*/
|
|
268
|
-
private applyStereoPanning;
|
|
269
|
-
private ensureDenoiseWorklet;
|
|
270
|
-
private resolveOptions;
|
|
271
|
-
}
|
|
272
|
-
export {};
|