pub struct AudioEngine { /* private fields */ }Expand description
Audio-thread synthesis, also used by offline rendering.
Construction and play allocate. render neither allocates nor locks. Output
time starts at zero; the host must pace its machine clock against playback.
Late commands take effect at the current output position and are counted.
The configured fixed latency absorbs jitter but does not synchronize clocks.
Implementations§
Source§impl AudioEngine
impl AudioEngine
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
Output rate in frames per second.
Sourcepub fn stats(&self) -> EngineStats
pub fn stats(&self) -> EngineStats
Current synthesis counters.
Sourcepub fn midi_dropped_messages(&self) -> u64
pub fn midi_dropped_messages(&self) -> u64
Dropped messages reported by a bounded MIDI synthesis backend.
Sourcepub fn start_capture(&mut self, capacity: usize) -> Result<MusicCapture>
pub fn start_capture(&mut self, capacity: usize) -> Result<MusicCapture>
Capture applied OPL writes from manual I/O, sequencers and live events. Create outside rendering; stop is acknowledged at the next frame start. The bounded writer stays owned by the engine after capture ends.
Sourcepub fn music_controller(&mut self, capacity: usize) -> Result<MusicController>
pub fn music_controller(&mut self, capacity: usize) -> Result<MusicController>
Construct a unique runtime music sender before moving this engine to a stream. Allocates two bounded queues. Retired resources are reclaimed by the sender.
Sourcepub fn play_speaker(
&mut self,
music: impl Into<PreparedMusic>,
options: PlayOptions,
) -> Result<SpeakerHandle>
pub fn play_speaker( &mut self, music: impl Into<PreparedMusic>, options: PlayOptions, ) -> Result<SpeakerHandle>
Independently sequence a speaker melody or PWM stream alongside FM/MIDI music.
Construction/replacement allocates only on the caller’s thread.
The melody starts at the engine’s current output time, like play.
Sourcepub fn play_speaker_at(
&mut self,
music: impl Into<PreparedMusic>,
options: PlayOptions,
at: Tick,
) -> Result<SpeakerHandle>
pub fn play_speaker_at( &mut self, music: impl Into<PreparedMusic>, options: PlayOptions, at: Tick, ) -> Result<SpeakerHandle>
Start a speaker melody at a future absolute output timestamp, such as
machine time on a host that renders behind it. Allocates like play_speaker.
Sourcepub fn speaker_controller(&mut self, capacity: usize) -> Result<MusicController>
pub fn speaker_controller(&mut self, capacity: usize) -> Result<MusicController>
Construct a bounded runtime sender dedicated to speaker melodies/PWM.
Sourcepub fn play(
&mut self,
sequence: impl Into<PreparedMusic>,
options: PlayOptions,
) -> Result<MusicHandle>
pub fn play( &mut self, sequence: impl Into<PreparedMusic>, options: PlayOptions, ) -> Result<MusicHandle>
Install music before handing the engine to an audio stream.
This method allocates the control handle and may drop an earlier sequence. The sequence starts at the engine’s current output time. OPL3 can play an OPL2 sequence; dual OPL2 and OPL3 arrangements require matching hardware. Retain the returned handle while playing: its last drop stops the music.
Sourcepub fn play_at(
&mut self,
sequence: impl Into<PreparedMusic>,
options: PlayOptions,
at: Tick,
) -> Result<MusicHandle>
pub fn play_at( &mut self, sequence: impl Into<PreparedMusic>, options: PlayOptions, at: Tick, ) -> Result<MusicHandle>
Install music at a future absolute output timestamp. Allocates like play.
Sourcepub fn play_soundtrack(
&mut self,
soundtrack: Arc<Soundtrack>,
preferred: MusicDevice,
options: PlayOptions,
) -> Result<MusicHandle>
pub fn play_soundtrack( &mut self, soundtrack: Arc<Soundtrack>, preferred: MusicDevice, options: PlayOptions, ) -> Result<MusicHandle>
Start a soundtrack and prepare a switchable handle before streaming.
Sourcepub fn render(&mut self, out: &mut [Frame])
pub fn render(&mut self, out: &mut [Frame])
Overwrite a buffer with the next stereo frames, without allocating.
Each sample interval is split at port commands, music events and native OPL boundaries. Speaker pulses, held DSP DAC values and native FM frames are integrated over those intervals, including commands inside a single output sample. Commands at the sample’s end belong to the following sample.
Trait Implementations§
Source§impl StereoStream for AudioEngine
Available on crate feature toolkit only.
impl StereoStream for AudioEngine
toolkit only.