Struct Device

Source
pub struct Device(/* private fields */);

Implementations§

Source§

impl Device

Source

pub fn new( context: Option<Context>, config: &DeviceConfig, ) -> Result<Device, Error>

Source

pub fn set_data_callback<F>(&mut self, callback: F)
where F: FnMut(&RawDevice, &mut FramesMut<'_>, &Frames<'_>) + Send + 'static,

Override the data callback of the device with a different one. This callback has less restrictions than the callback of the config because it does not have to be cloneable.

§Panics
  • This will panic if it is called after the device has been started.
  • This will also panic if there is more than one reference to the same device (if this has been cloned).
Source

pub fn set_stop_callback<F>(&mut self, callback: F)
where F: FnMut(&RawDevice) + Send + 'static,

Override the stop callback of the device with a different one. This callback has less restrictions than the callback of the config because it does not have to be cloneable.

§Panics
  • This will panic if it is called after the device has been started.
  • This will also panic if there is more than one reference to the same device (if this has
Source

pub fn start(&self) -> Result<(), Error>

Starts the device. For playback devices this begins playback. For capture devices this begins recording. Use stop to stop this device.

WARNING This should not be called from a callback.

Source

pub fn stop(&self) -> Result<(), Error>

Stops this device. For playback devices this stops playback. For capture devices this stops recording. Use start to start this device again.

WARNING This should not be called from a callback.

Methods from Deref<Target = RawDevice>§

Source

pub fn owned_context(&self) -> Option<&'static RawContext>

This will return the context owned by this device. A context that was passed into this device via new is not owned by this device and if you need a reference to that use context instead.

Source

pub fn context(&self) -> &RawContext

This will return a pointer to the context being used by this device.

Source

pub unsafe fn raw_start(&self) -> Result<(), Error>

Starts the device. For playback devices this begins playback. For capture devices this begins recording. Use stop to stop this device.

§Safety

This should not be called from a callback.

Source

pub unsafe fn raw_stop(&self) -> Result<(), Error>

Stops this device. For playback devices this stops playback. For capture devices this stops recording. Use start to start this device again.

§Safety

This should not be called from a callback.

Source

pub fn is_started(&self) -> bool

Returns true if this device has started.

Source

pub fn set_master_volume(&self, volume: f32) -> Result<(), Error>

Sets the master volume factor for the device.

The volume factor must be between 0 (silence) and 1 (full volume). Use set_master_gain_db() to use decibel notation, where 0 is full volume and values less than 0 decreases the volume.

§Callback Safety

Safe. If you set the volume in the data callback, that data written to the output buffer will have the new volume applied.

Source

pub fn get_master_volume(&self) -> Result<f32, Error>

Retrieves the master volume factor for the device.

Source

pub fn set_master_gain_db(&self, gain_db: f32) -> Result<(), Error>

Sets the master volume for the device as gain in decibels.

A gain of 0 is full volume, whereas a gain of < 0 will decrease the volume.

The volume factor must be between 0 (silence) and 1 (full volume). Use set_master_gain_db() to use decibel notation, where 0 is full volume and values less than 0 decreases the volume.

§Callback Safety

Safe. If you set the volume in the data callback, that data written to the output buffer will have the new volume applied.

Source

pub fn get_master_gain_db(&self) -> Result<f32, Error>

Retrieves the master gain in decibels.

Source

pub fn sample_rate(&self) -> u32

Source

pub fn resampling(&self) -> ResampleAlgorithm

Source

pub fn capture(&self) -> &DeviceCapture

Source

pub fn playback(&self) -> &DevicePlayback

Trait Implementations§

Source§

impl Clone for Device

Source§

fn clone(&self) -> Device

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Deref for Device

Source§

type Target = RawDevice

The resulting type after dereferencing.
Source§

fn deref(&self) -> &RawDevice

Dereferences the value.

Auto Trait Implementations§

§

impl Freeze for Device

§

impl RefUnwindSafe for Device

§

impl Send for Device

§

impl Sync for Device

§

impl Unpin for Device

§

impl UnwindSafe for Device

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.