Oddio uses a hierarchical model for audio playback. A SpatialScene acts as a specialized Mixer that spatializes the signals played within it.
Workflow:
- Initialize: Create a scene and a handle using
SpatialScene::new(). - Prepare Audio: Wrap static audio data in
Frames and convert it into a FramesSignal. - Play: Use
scene_handle.play(frames, options) to start playback. This returns a handle to the specific instance of that sound. - Control: Use the returned handle to update the sound's position or velocity in real-time using
handle.set_motion(position, velocity, fade).
Example:
let (mut scene_handle, mut scene) = oddio::SpatialScene::new();
// In game logic:
let position = [0.0, 0.0, 0.0].into();
let velocity = [0.0, 0.0, 0.0].into();
let frames = oddio::FramesSignal::from(oddio::Frames::from_slice(sample_rate, &frames));
let mut handle = scene_handle.play(frames, oddio::SpatialOptions {
position,
velocity,
..Default::default()
});
// When position/velocity changes:
handle.set_motion(position, velocity, false);
let (mut scene_handle, mut scene) = oddio::SpatialScene::new();
// In audio callback:
# let data = &mut [][..];
# let output_sample_rate = 44100;
let out_frames = oddio::frame_stereo(data);
oddio::run(&mut scene, output_sample_rate, out_frames);
// In game logic:
# let frames = [];
# let sample_rate = 44100;
# let position = [0.0, 0.0, 0.0].into();
# let velocity = [0.0, 0.0, 0.0].into();
let frames = oddio::FramesSignal::from(oddio::Frames::from_slice(sample_rate, &frames));
let mut handle = scene_handle
.play(frames, oddio::SpatialOptions { position, velocity, ..Default::default() });
// When position/velocity changes:
handle.set_motion(position, velocity, false);