ex_audio.rs

Process audio. Decode and transform audio using the Rust-backed API.

ExSDK source-ownedRustAudio

Source

Example

1use anyhow::Context;
2use oa::{Engine, Filesystem, Path, audio};
3
4fn main() -> anyhow::Result<()> {
5 let engine = Engine::new().context("create OA engine")?;
6
7 let audio_path = Path::asset_rel("audio/oaNarration.wav");
8
9 let output = Path::var_rel("example/audio/oaNarrationRoom.wav");
10 Filesystem::create_directories(&output.parent().unwrap())?;
11
12 let source = audio::decode_file(&engine, &audio_path)
13 .with_context(|| format!("decode {}", audio_path.display()))?;
14 let mono = audio::to_mono(&source)?;
15 let normalized = audio::normalize(
16 &mono,
17 audio::NormalizeAudioConfig {
18 target_db: -3.0,
19 ..Default::default()
20 },
21 )?;
22 let faded = audio::fade(&normalized, 2400, 2400)?;
23 let reverberated = audio::reverb(&faded, 1.5, 0.4)?;
24 audio::save_wav_f32(&output, &reverberated)?;
25
26 assert!(reverberated.channels() == 1);
27 assert!(output.is_file());
28
29 println!(
30 "Saved reverberated audio (1.5 s tail): {}",
31 output.display()
32 );
33 Ok(())
34}
35