Skip to main content

AudioEngine

Struct AudioEngine 

Source
pub struct AudioEngine {
    pub out_rate: u32,
    /* private fields */
}
Expand description

The live audio engine. Create once at startup; keep alive for the program duration. All methods take &self — mutation is routed through an interior Arc<Mutex<>>.

Fields§

§out_rate: u32

Device sample rate (informational).

Implementations§

Source§

impl AudioEngine

Source

pub fn new() -> Result<Self, Box<dyn Error>>

Initialise cpal, open the default output device, start the audio thread. Returns Err if no audio device is available (e.g. headless CI).

Source

pub fn set_tone(&self, idx: usize, params: ToneParams)

Insert or update the tone at slot idx. At most 64 slots; grows as needed.

Source

pub fn blip(&self, freq: f32, amp: f32, dur: f32, wave: Wave)

Fire a one-shot interface sound (fast attack, exponential decay). dur is in seconds; up to 32 blips overlap before the oldest is dropped.

Source

pub fn sfx( &self, x: f32, y: f32, z: f32, w: f32, freq: f32, amp: f32, dur: f32, wave: Wave, )

Fire a positional (2D/3D/4D) one-shot sound effect at a world point.

Source

pub fn add_sample(&self, mono: Vec<f32>, src_rate: u32) -> usize

Register a mono sample buffer (decoded elsewhere), returning its id.

Source

pub fn play_sample( &self, id: usize, x: f32, y: f32, z: f32, w: f32, vol: f32, looping: bool, ) -> u32

Play a loaded sample at a world position (looping or one-shot). Returns a voice id.

Source

pub fn stop_sample(&self, voice: u32)

Stop a sample voice by id.

Source

pub fn fx_delay(&self, time_s: f32, feedback: f32, mix: f32)

Source

pub fn fx_reverb(&self, mix: f32)

Source

pub fn fx_lowpass(&self, cutoff01: f32)

Master low-pass cutoff ∈ (0,1]; 1.0 ≈ open, lower = muffled/underwater.

Source

pub fn clear_tone(&self, idx: usize)

Silence and remove the tone at idx.

Source

pub fn set_listener(&self, cry: f32, sry: f32, crx: f32, srx: f32)

Update the listener orientation to match the Ling set_camera values.

Source

pub fn set_listener_pos(&self, x: f32, y: f32, z: f32)

Update the listener (camera) world position so positional sounds pan and attenuate relative to where the camera actually is.

Source

pub fn load_bgm(&self, path: &str, vol: f32)

Load a WAV file and start looping it as background music. Silently ignores missing files so scenes still run in silent environments.

Source

pub fn set_bgm_volume(&self, vol: f32)

Adjust BGM playback volume without reloading.

Source

pub fn set_master_volume(&self, vol: f32)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.