Skip to main content

CpalSink

Struct CpalSink 

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

Plays through the default output device of a cpal host: ALSA on Linux (which a PipeWire or PulseAudio server serves through its ALSA plugin), AAudio on Android, and the native host elsewhere.

The stream is built as f32, or as i16 when the device offers nothing else; the render function always sees f32. The i16 path keeps a scratch buffer that grows to the largest block seen, so it allocates on the first callbacks only.

A request the device cannot do exactly is SinkError::UnsupportedConfig with the device’s default attached, never a silent change of rate.

Implementations§

Source§

impl CpalSink

Source

pub fn new() -> Self

The platform’s default host.

Source

pub fn with_host(host: Host) -> Self

Trait Implementations§

Source§

impl AudioSink for CpalSink

Source§

fn default_config(&self) -> Result<SinkConfig, SinkError>

The format the device prefers, to ask for when a request is SinkError::UnsupportedConfig.
Source§

fn start( &mut self, config: SinkConfig, render: RenderFn, ) -> Result<SinkHandle, SinkError>

Starts the stream. render is called on the audio thread with a buffer to fill. The stream stops when the handle is dropped. A sink that cannot run the exact config returns SinkError::UnsupportedConfig instead of running at another rate, so the render function never has to guess its format.
Source§

impl Default for CpalSink

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Forget for CpalSink

§

impl Freeze for CpalSink
where *const ArcInner<AlsaContext> is !null: Freeze, PhantomData<ArcInner<AlsaContext>>: Freeze, *const ArcInner<Atomic<bool>> is !null: Freeze, PhantomData<ArcInner<Atomic<bool>>>: Freeze,

§

impl Move for CpalSink

§

impl RefUnwindSafe for CpalSink

§

impl Send for CpalSink
where Arc<AlsaContext>: Send, Arc<Atomic<bool>>: Send,

§

impl Sync for CpalSink
where Arc<AlsaContext>: Sync, Arc<Atomic<bool>>: Sync,

§

impl Unpin for CpalSink
where Arc<AlsaContext>: Unpin, Arc<Atomic<bool>>: Unpin,

§

impl UnsafeUnpin for CpalSink
where *const ArcInner<AlsaContext> is !null: UnsafeUnpin, PhantomData<ArcInner<AlsaContext>>: UnsafeUnpin, *const ArcInner<Atomic<bool>> is !null: UnsafeUnpin, PhantomData<ArcInner<Atomic<bool>>>: UnsafeUnpin,

§

impl UnwindSafe for CpalSink
where Arc<AlsaContext>: UnwindSafe, Arc<Atomic<bool>>: UnwindSafe,

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