Skip to main content

Dac

Struct Dac 

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

An open USB DAC.

v0.1 supports one open Dac per process; a second Dac::open returns Error::Busy until the first is closed or dropped. The host keeps its UsbDeviceConnection open until then.

Implementations§

Source§

impl Dac

Source

pub fn await_usb_retirement(timeout: Duration) -> bool

Wait until USB activity has retired before releasing the host’s claimed interfaces and FD.

After Dac::close returns a transfer timeout, retain all host ownership and call this until it returns true. This does not require a live Dac handle.

Source

pub fn feedback_preflight(fd: RawFd, info: &DeviceInfo) -> Result<(u8, Vec<u8>)>

Identify optional capture interfaces after the host claims the base audio interfaces. Returns the active configuration ID and source interface numbers without starting audio.

Source

pub fn open(fd: RawFd, info: DeviceInfo, config: DacConfig) -> Result<Dac>

Opens the DAC behind fd.

fd is the usbfs file descriptor of the device (on Android UsbDeviceConnection.getFileDescriptor()); the library duplicates it, so the host keeps ownership of its own. info.claimed_interfaces must be the AudioControl and playback AudioStreaming interfaces plus any optional capture sources identified by Dac::feedback_preflight.

Opening scans the descriptors, finds the hardware volume control, records the DAC’s current level and, with the default StartupVolume::Attenuate, lowers every channel to at most -40 dB and verifies it, so that no stream can start at the DAC’s own (often full-scale) level. It does not touch the clock or start any audio. VolumeControl::startup says what it did.

Source

pub fn info(&self) -> &DeviceInfo

The identity the host gave at open.

Source

pub fn feedback_trace(&self) -> Option<FeedbackTrace>

Export the last stream’s opt-in support capture, even after the stream has closed. A new successfully opened stream replaces it.

Source

pub fn capabilities(&self) -> Result<Capabilities>

What the DAC offers, from the descriptors scanned at open.

Source

pub fn negotiate(&self, request: &StreamRequest) -> Result<StreamFormat>

Settles the wire format for request.

This programs the DAC’s sampling frequency and reads it back (it is the step that can fail with Error::ClockUnverified later), so it takes 100 ms or more. It fails with Error::InvalidState while a stream is open. Nothing is resampled: with RatePolicy::Exact a rate the DAC cannot run is Error::Unsupported; with NearestSupported the returned format carries the rate the DAC will run.

Source

pub fn open_stream( &self, format: &StreamFormat, listener: Arc<dyn DacListener>, ) -> Result<DacStream>

Opens the output stream for a negotiated format and starts the output thread. The stream plays as soon as the ring holds the start threshold (DacConfig::start_threshold_ms) of audio. Only one stream can be open at a time.

Fails with Error::VolumeUnavailable when the stream’s own route has no usable hardware volume control and DacConfig::require_hardware_volume is on; nothing is programmed and no output thread starts.

listener receives the stream’s events; see DacListener.

Source

pub fn volume(&self) -> Option<VolumeControl>

The hardware volume control, if the DAC has a writable one.

Source

pub fn set_listener(&self, listener: Option<Arc<dyn DacListener>>)

Sets the listener for events about the device itself (volume changes, device loss) while no stream is open. While a stream is open its listener gets those events too.

Source

pub fn close(self) -> Result<()>

Closes the DAC: stops the stream if one is open, hands the volume back as DacConfig::hand_back says, and releases the session so another Dac::open can succeed. The host may then release its interfaces and close its connection after success. If closing times out, keep all host claims and the connection until Dac::await_usb_retirement returns true. Dropping the Dac initiates the same cleanup, but cannot report a timeout; hosts must still wait for retirement before releasing claims.

Source

pub fn close_with(self, volume: CloseVolume) -> Result<()>

Like close, but the host says what becomes of the level the DAC had before the library first changed it, instead of DacConfig::hand_back deciding at open: write it back (another driver gets the DAC), keep the record (the host holds on to the DAC or takes it straight back) or forget it (the DAC was unplugged).

A DAC the library saw disappear is always forgotten: nothing can be written to it and a later attachment must start fresh.

Source

pub fn set_dsd_overrides( &self, big_endian: Option<bool>, subslot: Option<u8>, ) -> Result<()>

Changes the native DSD overrides of the open DAC (DacConfig::dsd_big_endian and DacConfig::dsd_subslot), for a host whose user can change them while the DAC stays open. None goes back to the device quirk.

They are read when a format is negotiated and when a stream is opened: a stream that is already open keeps what it started with, and capabilities reflects a new subslot size after the next negotiate. subslot must be 1, 2 or 4.

Trait Implementations§

Source§

impl Debug for Dac

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Dac

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§

§

impl !RefUnwindSafe for Dac

§

impl !UnwindSafe for Dac

§

impl Forget for Dac

§

impl Freeze for Dac

§

impl Move for Dac

§

impl Send for Dac

§

impl Sync for Dac

§

impl Unpin for Dac

§

impl UnsafeUnpin for Dac

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