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: u32Device sample rate (informational).
Implementations§
Source§impl AudioEngine
impl AudioEngine
Sourcepub fn new() -> Result<Self, Box<dyn Error>>
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).
Sourcepub fn set_tone(&self, idx: usize, params: ToneParams)
pub fn set_tone(&self, idx: usize, params: ToneParams)
Insert or update the tone at slot idx. At most 64 slots; grows as needed.
Sourcepub fn blip(&self, freq: f32, amp: f32, dur: f32, wave: Wave)
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.
Sourcepub fn sfx(
&self,
x: f32,
y: f32,
z: f32,
w: f32,
freq: f32,
amp: f32,
dur: f32,
wave: Wave,
)
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.
Sourcepub fn add_sample(&self, mono: Vec<f32>, src_rate: u32) -> usize
pub fn add_sample(&self, mono: Vec<f32>, src_rate: u32) -> usize
Register a mono sample buffer (decoded elsewhere), returning its id.
Sourcepub fn play_sample(
&self,
id: usize,
x: f32,
y: f32,
z: f32,
w: f32,
vol: f32,
looping: bool,
) -> u32
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.
Sourcepub fn stop_sample(&self, voice: u32)
pub fn stop_sample(&self, voice: u32)
Stop a sample voice by id.
pub fn fx_delay(&self, time_s: f32, feedback: f32, mix: f32)
pub fn fx_reverb(&self, mix: f32)
Sourcepub fn fx_lowpass(&self, cutoff01: f32)
pub fn fx_lowpass(&self, cutoff01: f32)
Master low-pass cutoff ∈ (0,1]; 1.0 ≈ open, lower = muffled/underwater.
Sourcepub fn clear_tone(&self, idx: usize)
pub fn clear_tone(&self, idx: usize)
Silence and remove the tone at idx.
Sourcepub fn set_listener(&self, cry: f32, sry: f32, crx: f32, srx: f32)
pub fn set_listener(&self, cry: f32, sry: f32, crx: f32, srx: f32)
Update the listener orientation to match the Ling set_camera values.
Sourcepub fn set_listener_pos(&self, x: f32, y: f32, z: f32)
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.
Sourcepub fn load_bgm(&self, path: &str, vol: f32)
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.
Sourcepub fn set_bgm_volume(&self, vol: f32)
pub fn set_bgm_volume(&self, vol: f32)
Adjust BGM playback volume without reloading.