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
impl PlaybackHandle
Sourcepub fn producer_mut(&mut self) -> &mut Producer<f32>
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).
pub fn channels(&self) -> usize
pub fn sample_rate(&self) -> u32
pub fn flush_flag(&self) -> Arc<AtomicBool>
pub fn device_error_flag(&self) -> Arc<AtomicBool>
pub fn underrun_counter(&self) -> Arc<AtomicU64>
Sourcepub fn is_live(&self) -> bool
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).
Sourcepub fn split(self) -> (StreamKeeper, FeederBundle)
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.