oxframe_core/sound.rs
1//! A sound effect scheduled while a scene runs.
2//!
3//! The scene records *when* the clip starts. Decoding and mixing happen
4//! later, so this module stays free of audio codecs and works in the browser.
5
6use crate::runtime;
7
8/// One sound effect placed on the scene timeline.
9#[derive(Debug, Clone, PartialEq)]
10pub struct SoundClip {
11 /// Audio file, relative to the project root.
12 pub file: String,
13 /// Start, in seconds from the beginning of the scene.
14 pub at: f64,
15 /// Linear gain. `1.0` is unity.
16 pub volume: f32,
17 /// Fade in at the start of the clip, in seconds.
18 pub fade_in: f64,
19 /// Fade out at the end of the clip, in seconds.
20 pub fade_out: f64,
21 /// Seconds skipped from the start of the file.
22 pub trim_start: f64,
23 /// End point in the file, in seconds. `None` plays through to the end.
24 pub trim_end: Option<f64>,
25 /// Ducks the music while this clip is audible.
26 pub priority: bool,
27}
28
29/// Records `clip` on the running scene. Called by `sound()`.
30pub fn record_sound(clip: SoundClip) {
31 runtime::with(|rt| rt.sounds.borrow_mut().push(clip));
32}