pub struct SpatialAudioSystem {
pub listener_pos: Vec2,
pub arena_half_width: f32,
pub distance_model: DistanceModel,
pub reverb: SpatialReverb,
pub room_type: RoomType,
/* private fields */
}Expand description
Manages spatial audio: positioned sounds, distance attenuation, and reverb.
Fields§
§listener_pos: Vec2Listener position (usually camera/player center).
arena_half_width: f32Arena half-width for pan calculation.
distance_model: DistanceModelDistance model.
reverb: SpatialReverbRoom reverb.
room_type: RoomTypeCurrent room type.
Implementations§
Source§impl SpatialAudioSystem
impl SpatialAudioSystem
pub fn new() -> Self
Sourcepub fn set_listener(&mut self, pos: Vec2)
pub fn set_listener(&mut self, pos: Vec2)
Set the listener position (usually the camera center or player position).
Sourcepub fn play(
&mut self,
name: &str,
origin: SoundOrigin,
volume: f32,
lifetime: f32,
) -> u32
pub fn play( &mut self, name: &str, origin: SoundOrigin, volume: f32, lifetime: f32, ) -> u32
Spawn a positioned sound and return its ID.
Sourcepub fn update_travel(&mut self, id: u32, from: Vec2, to: Vec2, progress: f32)
pub fn update_travel(&mut self, id: u32, from: Vec2, to: Vec2, progress: f32)
Update a traveling sound’s progress.
Sourcepub fn spatialize(
&mut self,
sample: f32,
origin: SoundOrigin,
volume: f32,
) -> (f32, f32)
pub fn spatialize( &mut self, sample: f32, origin: SoundOrigin, volume: f32, ) -> (f32, f32)
Compute the spatial mix for a mono sample at a given origin. Returns (left_sample, right_sample) with pan, attenuation, and reverb.
Sourcepub fn compute_pan_gain(&self, source_pos: Vec2) -> (StereoPan, f32)
pub fn compute_pan_gain(&self, source_pos: Vec2) -> (StereoPan, f32)
Compute pan and gain for a world position (for external use).
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of active sounds.
Auto Trait Implementations§
impl Freeze for SpatialAudioSystem
impl RefUnwindSafe for SpatialAudioSystem
impl Send for SpatialAudioSystem
impl Sync for SpatialAudioSystem
impl Unpin for SpatialAudioSystem
impl UnsafeUnpin for SpatialAudioSystem
impl UnwindSafe for SpatialAudioSystem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.