#![allow(clippy::precedence)] use { bevy::prelude::*, bevy_fundsp::prelude::*, bevy_oddio::{Audio, AudioPlugin, AudioSource}, }; fn main() { App::new() .add_plugins(DefaultPlugins) .add_plugins(AudioPlugin::new()) .add_plugins(DspPlugin::default()) .add_dsp_source(sine_wave, SourceType::Static { duration: 0.5 }) .add_dsp_source(triangle_wave, SourceType::Static { duration: 0.5 }) .add_systems(Update, interactive_audio) .run(); } fn sine_wave() -> impl AudioUnit32 { // Note is A4 sine_hz(440.0) >> split::() * 0.2 } fn triangle_wave() -> impl AudioUnit32 { // Note is G4 triangle_hz(392.0) >> split::() * 0.2 } fn interactive_audio( input: Res>, mut assets: ResMut>>, dsp_manager: Res, mut audio: ResMut>>, ) { if input.just_pressed(KeyCode::S) { audio.play_dsp(assets.as_mut(), &dsp_manager.get_graph(sine_wave).unwrap()); } if input.just_pressed(KeyCode::T) { audio.play_dsp( assets.as_mut(), &dsp_manager.get_graph(triangle_wave).unwrap(), ); } }