use crate::sample::Sample; use std::sync::Arc; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum LoopMode { Off, On, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(i32)] pub enum AudioOpStatus { Ok = 0, VoiceInvalid = 1, SampleNotFound = 2, ArgRangeInvalid = 3, AssetNotFound = 4, NoEffect = 5, BankInvalid = 6, CommandLimit = 7, } /// High-level commands are staged with the ordinary frame/lifecycle batch. #[derive(Debug, Clone, Copy)] pub enum AudioControl { GroupVolume { group: usize, gain: u8 }, MusicStop { group: usize }, MusicPause { group: usize, paused: bool }, MusicVolume { group: usize, gain: u8 }, MusicFade { group: usize, gain: u8, frames: u32, smooth: bool }, Crossfade { source: usize, target: usize, frames: u32, smooth: bool }, BusVolume { bus: usize, gain: u8 }, Effect { group: usize, cutoff_hz: u32, delay_frames: u32, feedback: f32, wet: f32, dry: f32 }, SfxSend { voice: usize, gain: u8 }, } pub trait AudioBridge { #[allow(clippy::too_many_arguments)] fn play( &mut self, bank_id: u8, sample_id: u16, voice_id: usize, volume: u8, pan: u8, pitch: f64, priority: u8, loop_mode: LoopMode, ) -> AudioOpStatus; #[allow(clippy::too_many_arguments)] fn play_sample( &mut self, sample: Arc, voice_id: usize, volume: u8, pan: u8, pitch: f64, priority: u8, loop_mode: LoopMode, ) -> AudioOpStatus; fn music_play(&mut self, group: usize, bank: usize, looping: bool) -> AudioOpStatus; fn control(&mut self, control: AudioControl) -> AudioOpStatus; fn stop(&mut self, voice_id: usize) -> AudioOpStatus; fn set_volume(&mut self, voice_id: usize, volume: u8) -> AudioOpStatus; fn set_pan(&mut self, voice_id: usize, pan: u8) -> AudioOpStatus; fn set_pitch(&mut self, voice_id: usize, pitch: f64) -> AudioOpStatus; /// Pending publication must be consumed before starting another guest frame. fn ready(&self) -> bool; fn begin_frame(&mut self); fn finish_frame(&mut self); fn abort_frame(&mut self); /// Lifecycle has independent bounded staging/publication, even with a pending frame. fn lifecycle_ready(&self) -> bool; fn begin_lifecycle(&mut self); /// Success publishes the interrupted frame prefix before callback commands, /// without replenishing frame quota. Failure cancels both unpublished parts. fn finish_lifecycle(&mut self, success: bool); fn set_session(&mut self, session: Option); fn reset(&mut self); fn set_paused(&mut self, paused: bool); }