Skip to main content

CpalOutput

Struct CpalOutput 

Source
pub struct CpalOutput { /* private fields */ }
Available on crate feature cpal-output only.
Expand description

Audio output device impl using cpal.

Implementations§

Source§

impl CpalOutput

Source

pub fn open() -> Result<Self, Error>

Open an audio output device using the default configuration.

Source

pub fn open_with_config(config: CpalOutputConfig) -> Result<Self, Error>

Open an audio output device using the given configuration.

Use CpalOutput::available_drivers, CpalOutput::available_devices and CpalOutput::supported_sample_rates to enumerate available options dynamically.

Source

pub fn available_drivers() -> Vec<CpalOutputDeviceDriver>

Returns all audio drivers available on this platform.

Always includes CpalOutputDeviceDriver::Default, followed by any named drivers that are currently available (e.g. ASIO, WASAPI on Windows; ALSA, JACK on Linux).

Source

pub fn available_devices( driver: CpalOutputDeviceDriver, ) -> Result<Vec<(DeviceId, String)>, Error>

Returns (id, name)s of all output devices available for the given driver.

Source

pub fn supported_sample_rates( driver: CpalOutputDeviceDriver, device_id: Option<CpalDeviceId>, ) -> Result<Vec<u32>, Error>

Returns unique sample rates supported by an output device, sorted ascending.

Pass device_name = None to query the driver’s default device.

Trait Implementations§

Source§

impl OutputDevice for CpalOutput

Source§

fn channel_count(&self) -> usize

Returns the output buffer channel count (e.g., 1 for mono, 2 for stereo).
Source§

fn sample_rate(&self) -> u32

Returns the output sample rate in Hz.
Source§

fn sample_position(&self) -> u64

Returns the current playhead position in samples (not frames). Tracks the total number of samples output since device creation.
Source§

fn volume(&self) -> f32

Returns the current output volume (typically 0.0 to 1.0).
Source§

fn set_volume(&mut self, volume: f32)

Sets the output volume.
Source§

fn is_suspended(&self) -> bool

Returns true if audio output is suspended by the system. Only relevant for web audio backends; always returns false for desktop backends.
Source§

fn is_running(&self) -> bool

Returns true if audio is currently playing (not paused).
Source§

fn pause(&mut self)

Pauses playback while keeping the output source active.
Source§

fn resume(&mut self)

Resumes playback from a paused state.
Source§

fn play(&mut self, source: Box<dyn Source>)

Starts playback of a new audio source.
Source§

fn stop(&mut self)

Stops playback and replaces the source with silence.
Source§

fn close(&mut self)

Releases the audio device and cleans up resources.

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<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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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