@newgameplusinc/odyssey-audio-video-sdk-dev 1.0.14 → 1.0.15

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.
@@ -114,10 +114,6 @@ export declare class SpatialAudioManager extends EventManager {
114
114
  private applyHardwareNoiseConstraints;
115
115
  private startOutboundMonitor;
116
116
  private cleanupOutboundProcessor;
117
- private toWebAudioPosition;
118
- private toWebAudioDirection;
119
- private convertListenerOrientation;
120
- private normalizeVector;
121
117
  private ensureDenoiseWorklet;
122
118
  private resolveOptions;
123
119
  }
@@ -429,8 +429,7 @@ class SpatialAudioManager extends EventManager_1.EventManager {
429
429
  if (nodes?.panner) {
430
430
  const distanceConfig = this.getDistanceConfig();
431
431
  const normalizedPosition = this.normalizePositionUnits(position);
432
- const webAudioPosition = this.toWebAudioPosition(normalizedPosition);
433
- const targetPosition = this.applySpatialBoostIfNeeded(webAudioPosition);
432
+ const targetPosition = this.applySpatialBoostIfNeeded(normalizedPosition);
434
433
  // Update position (where the sound is coming from)
435
434
  nodes.panner.positionX.setValueAtTime(targetPosition.x, this.audioContext.currentTime);
436
435
  nodes.panner.positionY.setValueAtTime(targetPosition.y, this.audioContext.currentTime);
@@ -438,10 +437,18 @@ class SpatialAudioManager extends EventManager_1.EventManager {
438
437
  // Update orientation (where the participant is facing)
439
438
  // This makes the audio source directional based on participant's direction
440
439
  if (direction) {
441
- const convertedDirection = this.toWebAudioDirection(direction);
442
- nodes.panner.orientationX.setValueAtTime(convertedDirection.x, this.audioContext.currentTime);
443
- nodes.panner.orientationY.setValueAtTime(convertedDirection.y, this.audioContext.currentTime);
444
- nodes.panner.orientationZ.setValueAtTime(convertedDirection.z, this.audioContext.currentTime);
440
+ // Normalize direction vector
441
+ const length = Math.sqrt(direction.x * direction.x +
442
+ direction.y * direction.y +
443
+ direction.z * direction.z);
444
+ if (length > 0.001) {
445
+ const normX = direction.x / length;
446
+ const normY = direction.y / length;
447
+ const normZ = direction.z / length;
448
+ nodes.panner.orientationX.setValueAtTime(normX, this.audioContext.currentTime);
449
+ nodes.panner.orientationY.setValueAtTime(normY, this.audioContext.currentTime);
450
+ nodes.panner.orientationZ.setValueAtTime(normZ, this.audioContext.currentTime);
451
+ }
445
452
  }
446
453
  const listenerPos = this.listenerPosition;
447
454
  const distance = this.getDistanceBetween(listenerPos, targetPosition);
@@ -521,23 +528,32 @@ class SpatialAudioManager extends EventManager_1.EventManager {
521
528
  if (!listener) {
522
529
  return;
523
530
  }
524
- const convertedPosition = this.toWebAudioPosition(normalizedPosition);
525
- const convertedOrientation = this.convertListenerOrientation(orientation);
526
- this.listenerPosition = { ...convertedPosition };
531
+ this.listenerPosition = { ...normalizedPosition };
527
532
  this.listenerInitialized = true;
528
- this.listenerDirection = convertedOrientation;
533
+ this.listenerDirection = {
534
+ forward: {
535
+ x: orientation.forwardX,
536
+ y: orientation.forwardY,
537
+ z: orientation.forwardZ,
538
+ },
539
+ up: {
540
+ x: orientation.upX,
541
+ y: orientation.upY,
542
+ z: orientation.upZ,
543
+ },
544
+ };
529
545
  if (listener.positionX) {
530
- listener.positionX.setValueAtTime(convertedPosition.x, this.audioContext.currentTime);
531
- listener.positionY.setValueAtTime(convertedPosition.y, this.audioContext.currentTime);
532
- listener.positionZ.setValueAtTime(convertedPosition.z, this.audioContext.currentTime);
546
+ listener.positionX.setValueAtTime(normalizedPosition.x, this.audioContext.currentTime);
547
+ listener.positionY.setValueAtTime(normalizedPosition.y, this.audioContext.currentTime);
548
+ listener.positionZ.setValueAtTime(normalizedPosition.z, this.audioContext.currentTime);
533
549
  }
534
550
  if (listener.forwardX) {
535
- listener.forwardX.setValueAtTime(convertedOrientation.forward.x, this.audioContext.currentTime);
536
- listener.forwardY.setValueAtTime(convertedOrientation.forward.y, this.audioContext.currentTime);
537
- listener.forwardZ.setValueAtTime(convertedOrientation.forward.z, this.audioContext.currentTime);
538
- listener.upX.setValueAtTime(convertedOrientation.up.x, this.audioContext.currentTime);
539
- listener.upY.setValueAtTime(convertedOrientation.up.y, this.audioContext.currentTime);
540
- listener.upZ.setValueAtTime(convertedOrientation.up.z, this.audioContext.currentTime);
551
+ listener.forwardX.setValueAtTime(orientation.forwardX, this.audioContext.currentTime);
552
+ listener.forwardY.setValueAtTime(orientation.forwardY, this.audioContext.currentTime);
553
+ listener.forwardZ.setValueAtTime(orientation.forwardZ, this.audioContext.currentTime);
554
+ listener.upX.setValueAtTime(orientation.upX, this.audioContext.currentTime);
555
+ listener.upY.setValueAtTime(orientation.upY, this.audioContext.currentTime);
556
+ listener.upZ.setValueAtTime(orientation.upZ, this.audioContext.currentTime);
541
557
  }
542
558
  if (Math.random() < 0.01) {
543
559
  console.log(`🎧 [Spatial Audio] Listener updated:`, {
@@ -733,49 +749,6 @@ class SpatialAudioManager extends EventManager_1.EventManager {
733
749
  processor.context.close();
734
750
  this.outgoingProcessors.delete(processorId);
735
751
  }
736
- toWebAudioPosition(position) {
737
- return {
738
- x: position.y,
739
- y: position.z,
740
- z: -position.x,
741
- };
742
- }
743
- toWebAudioDirection(vector) {
744
- return this.normalizeVector(this.toWebAudioPosition(vector));
745
- }
746
- convertListenerOrientation(orientation) {
747
- const forward = this.toWebAudioDirection({
748
- x: orientation.forwardX,
749
- y: orientation.forwardY,
750
- z: orientation.forwardZ,
751
- });
752
- const upRaw = this.toWebAudioDirection({
753
- x: orientation.upX,
754
- y: orientation.upY,
755
- z: orientation.upZ,
756
- });
757
- const dot = forward.x * upRaw.x + forward.y * upRaw.y + forward.z * upRaw.z;
758
- const upOrtho = {
759
- x: upRaw.x - dot * forward.x,
760
- y: upRaw.y - dot * forward.y,
761
- z: upRaw.z - dot * forward.z,
762
- };
763
- return {
764
- forward,
765
- up: this.normalizeVector(upOrtho, { x: 0, y: 1, z: 0 }),
766
- };
767
- }
768
- normalizeVector(vector, fallback = { x: 0, y: 0, z: -1 }) {
769
- const length = Math.hypot(vector.x, vector.y, vector.z);
770
- if (length < 1e-5) {
771
- return { ...fallback };
772
- }
773
- return {
774
- x: vector.x / length,
775
- y: vector.y / length,
776
- z: vector.z / length,
777
- };
778
- }
779
752
  async ensureDenoiseWorklet(targetContext = this.audioContext) {
780
753
  if (!this.isDenoiserEnabled()) {
781
754
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newgameplusinc/odyssey-audio-video-sdk-dev",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Odyssey Spatial Audio & Video SDK using MediaSoup for real-time communication",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",