Skip to main content

AudioEngine

Struct AudioEngine 

Source
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

Source

pub fn sample_rate(&self) -> u32

Output rate in frames per second.

Source

pub fn now(&self) -> Tick

Current output time, rounded down to a crystal tick.

Source

pub fn stats(&self) -> EngineStats

Current synthesis counters.

Source

pub fn midi_dropped_messages(&self) -> u64

Dropped messages reported by a bounded MIDI synthesis backend.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn speaker_controller(&mut self, capacity: usize) -> Result<MusicController>

Construct a bounded runtime sender dedicated to speaker melodies/PWM.

Source

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.

Source

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.

Source

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.

Source

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.
Source§

fn fill(&mut self, out: &mut [[f32; 2]])

Overwrite out with the next frames, each channel in -1.0..=1.0.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.