Skip to content

[Feature] Spatial/3D audio #116

Open

Description

@vmarcella

Overview

Add positional audio support where sounds have a position in 3D space and are
panned/attenuated based on listener position and orientation.

Current State

Requires audio mixer implementation. No spatial audio exists.

Scope

  • Set sound position in 3D space
  • Set listener position and orientation
  • Distance-based volume attenuation
  • Stereo panning based on direction
  • Configurable attenuation model

Non-Goals:

  • HRTF (head-related transfer function) - complex, deferred
  • Doppler effect (separate issue)
  • Occlusion/obstruction (separate issue)
  • Reverb zones (separate issue)

Proposed API

pub struct AudioListener {
  position: [f32; 3],
  forward: [f32; 3],
  up: [f32; 3],
}

pub struct SpatialSound {
  position: [f32; 3],
  min_distance: f32,
  max_distance: f32,
  // ...
}

impl SpatialSound {
  pub fn set_position(&mut self, position: [f32; 3]);
  pub fn set_min_distance(&mut self, distance: f32);
  pub fn set_max_distance(&mut self, distance: f32);
}

impl AudioContext {
  pub fn set_listener(&mut self, listener: AudioListener);
  pub fn play_spatial(&mut self, buffer: &SoundBuffer) -> SpatialSound;
}

Acceptance Criteria

  • Sounds pan left/right based on listener orientation
  • Sounds attenuate with distance
  • Sounds beyond max_distance are silent
  • Sounds within min_distance play at full volume
  • Example with moving sound source

Affected Crates

lambda-rs, lambda-rs-platform

Notes

  • Linear or inverse-square attenuation models
  • Integrate with camera position for listener updates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    audioAll things related to audioenhancementNew feature or requestlambda-rsIssues pertaining to the core frameworklambda-rs-platformIssues pertaining to the dependency & platform wrappers

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions