Skip to main content

PlaybackHandle

Struct PlaybackHandle 

Source
pub struct PlaybackHandle { /* private fields */ }
Expand description

Owns a real-time audio playback resource.

cpal::Stream is held privately — there is no public accessor and no way to destructure it out. Drop the entire PlaybackHandle to stop playback. The borrow checker prevents the bug class where a caller drops the stream while holding the producer.

PlaybackHandle is !Send because cpal::Stream is !Send. For the stream-on-init-thread, producer-on-feeder-thread pattern. Call PlaybackHandle::split to obtain a !Send StreamKeeper that stays on the init thread and a Send FeederBundle that moves into the audio feeder thread.

For the co-located pattern (where stream and producer live in the same thread, e.g. forge-app-winamp), hold the whole handle in scope and use PlaybackHandle::producer_mut to push samples.

Implementations§

Source§

impl PlaybackHandle

Source

pub fn producer_mut(&mut self) -> &mut Producer<f32>

Push samples to the audio device. Use only inside the thread that owns this handle (typically the audio feeder thread or, for the co-located pattern, the player thread).

Source

pub fn channels(&self) -> usize

Source

pub fn sample_rate(&self) -> u32

Source

pub fn flush_flag(&self) -> Arc<AtomicBool>

Source

pub fn device_error_flag(&self) -> Arc<AtomicBool>

Source

pub fn underrun_counter(&self) -> Arc<AtomicU64>

Source

pub fn is_live(&self) -> bool

Returns true when a real cpal output device is open. Returns false under DAW_NO_AUDIO=1 (the hard-gate test mode).

Source

pub fn split(self) -> (StreamKeeper, FeederBundle)

Split the handle into a !Send StreamKeeper (must stay on the init thread or be intentionally leaked) and a Send FeederBundle (move into the audio feeder thread).

Use this only when stream and producer cannot be co-located. The co-located pattern is preferred — it keeps audio device lifetime trivially correct without any !Send dance.

Trait Implementations§

Source§

impl Drop for PlaybackHandle

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.