Expand description
Bit-perfect direct USB DAC output for Android and Linux.
usbdac-core drives a USB Audio Class 1.0, 2.0 or 3.0 DAC through usbfs, without the
platform audio stack: PCM at the DAC’s native depth, DSD over PCM (DoP) and
native DSD, feedback-paced isochronous transfers, loss accounting, and the
DAC’s own hardware volume. Asynchronous streams can follow explicit rate
reports or frame counts from a compatible UAC2 or UAC3 input stream. Use
StreamFormat::pacing for the selected mechanism and
DacStream::stats for live lock and feedback counters.
The library never resamples, dithers or scales samples unless the host
explicitly enables software gain, and it reports honestly whether the audio
on the wire is bit-perfect (DacStream::is_bit_perfect). (The opt-in
convert module, which the stream never calls, is for a host that wants
to convert before writing.)
use std::sync::Arc;
use usbdac_core::{Dac, DacConfig, DacEvent, DeviceInfo, StreamRequest};
// `fd` comes from UsbDeviceConnection.getFileDescriptor(); the host has
// claimed the audio interfaces and lists them here.
let info = DeviceInfo::new(0x2fc6, 0xf09a, "Some DAC").with_claimed_interfaces(vec![0u8, 1]);
let dac = Dac::open(fd, info, DacConfig::default())?;
let format = dac.negotiate(&StreamRequest::pcm(44_100, 2, 16))?;
let stream = dac.open_stream(&format, Arc::new(|event: DacEvent| log::info!("{event:?}")))?;
let silence = vec![0u8; stream.writable_bytes()];
stream.write(&silence)?;Distinct USB attachments have independent Dac owners and retirement tokens.
Re-exports§
pub use capture::CaptureFormat;pub use capture::CaptureRequest;pub use capture::CaptureState;pub use capture::CaptureStats;pub use capture::ChannelMap;pub use capture::ChannelPosition;pub use capture::DacCaptureStream;pub use fake::PlaybackDevice;pub use fake::PlaybackStream;pub use hotplug::HotplugEvent;pub use hotplug::HotplugHub;pub use hotplug::HotplugSubscription;pub use hotplug::LinuxHotplugMonitor;pub use hotplug::UsbAttachment;pub use hotplug::UsbPermission;
Modules§
- capture
- PCM capture data contracts and bounded buffering.
- convert
- Opt-in conversion helpers.
- descriptors
- dsd_pcm
- Explicit lossy native DSD to PCM conversion.
Streaming native DSD to PCM. Input is chronological channel-interleaved
bytes with the oldest bit in bit 7, as accepted by
DacStream::write. This converter is always lossy; DoP carrier words are not accepted. - fake
- Deterministic application tests without USB, permissions, threads or a DAC.
- hotplug
- Discovery is independent of opening a DAC and never grants USB permission.
- pioneer
- Explicit Pioneer DJM routing choices, independent of the USB backend.
- playback
- Explicit source-domain playback resolution and streaming. Existing strict negotiation and direct stream APIs remain unchanged.
- routing
- Pure USB Audio 1/2/3 routing inventory and control transactions.
- scarlett
- Focusrite routing protocol primitives independently implemented from Linux
v7.0
mixer_scarlett2.cprotocol evidence. New exact-model firmware-minimum profiles additionally require live complete protocol and geometry proof.
Structs§
- AltSetting
- One playback configuration on an isochronous OUT alternate. A UAC2 or UAC3 OUT alternate can appear with several implicit-feedback IN alternates. Each entry’s rates apply to the input named by its pacing.
- Async
Volume Control - A bounded FIFO worker. Submission fails with
Error::Busywhen 32 requests are waiting. Accepted operations use the same verified hardware writes, rollback and event delivery asVolumeControl. Close waits for an executing control transfer; queued operations then fail as closed. - Capabilities
- Summary of what the DAC can do.
- Clock
Choice - How the clock the library programs the sample rate on was reached, for diagnosing a DAC with more than one clock. Read-only: nothing here changes what the library does.
- Clock
Hop - One entity on the path from a streaming terminal to its Clock Source.
- Dac
- An open USB DAC.
- DacConfig
- Every tunable of a session.
DacConfig::default()is what the library was tuned with. - DacStream
- An open output stream. Dropping it closes it.
- Device
Info - Identity of the USB device and the interfaces the host has claimed.
- Explicit
Feedback Diagnostics - Feedback endpoint geometry and observations for one stream. Status counts are indexed by libusb transfer status (0 completed, 1 error, 2 timed out, 3 cancelled, 4 stall, 5 no device, 6 overflow). Index 7 is unknown or unreported. An interrupt transfer has no separate packet status.
- Explicit
Feedback Packet - The most recent packet observed for one feedback outcome.
- Feedback
Trace - A shareable support capture for the most recent stream of a DAC session.
- Feedback
Trace Entry - A record in the trace, timed from stream creation using a monotonic clock.
- Quirk
Override - Extra quirks for one VID/PID, added to the built-in table.
- Rate
Range - A continuous or discrete range of sampling frequencies.
- Shipped
Support - Authoritative shipped API boundaries used by the generated SDK status page. Update together with implementation when enabling another transport tier.
- Source
Quirk Entry - Pinned factual identity match. No bcdDevice bounds were specified by these
source rows;
Nonemeans all revisions, never a guessed revision range. - Startup
Volume Report - What
Dac::opendid with the DAC’s level before any stream could start (seeStartupVolume). - Stream
Format - What will go on the wire, as chosen by
Dac::negotiate. - Stream
Reconfiguration - A replacement stream on the same physical handle, paused with zero-based counters. A failed requested format can still return a successfully restored old-format stream.
- Stream
Request - A format the host would like.
- Stream
Stats - Counters of a stream. Frames are in the unit
StreamFormat::counter_rate_hzgives the rate of. - Underrun
Edge - Relaxed atomic snapshots taken at the observed worker edge, after preparing the transfer.
elapsed_usshares the exact origin of the enclosing feedback trace. Sample counts are interleaved ring samples; frame counters use the stream’s native counter rate. - UsbRetirement
- A particular DAC owner’s USB retirement, independent of other devices.
- Volume
Control - Handle to the DAC’s hardware volume control.
- Volume
Operation - An accepted volume request:
.await,try_resultorwaitretrieves its result exactly once. Dropping this handle leaves the accepted operation queued, preserving write ordering. - Volume
Range - The DAC’s volume range in decibels.
- Volume
State - The DAC’s volume as read back from the device.
Enums§
- Alsa
Quirk Flag - AltFormat
- What an alternate setting carries.
- Async
Fallback Policy - Policy for asynchronous endpoints without a proven feedback source.
- BitPerfect
Blocker - What stands in the way of
DacStream::is_bit_perfect, most significant first.NonefromDacStream::bit_perfect_blockermeans nothing does. - Clock
HopKind - What a
ClockHopis. - Clock
Readback Policy - Policy for unusable frequency readback after an acknowledged rate write.
- Clock
Resolution - How
ClockChoice::source_idwas found. - Close
Volume - What
Dac::close_withdoes with the level the DAC had before the library first changed it, decided at close rather than at open. - Compatibility
Fallback Tier - Compatibility tier actually admitted by a successfully started stream. This never changes the stream’s bit-perfect blockers.
- DacEvent
- Something that happened to the DAC or a stream.
- Encoding
- How the audio is carried.
- Endpoint
Usage - The usage bits of an isochronous endpoint’s
bmAttributes. - Error
- Everything the public API can fail with.
- Explicit
Feedback Outcome - What happened to a packet while it was examined for explicit feedback.
- Feedback
Smoothing - How validated explicit feedback reports change packet timing.
- Feedback
Trace Event - An observation from the selected USB feedback path.
- Hand
Back - What happens to the DAC’s hardware volume when the
Dacis closed. - Host
UsbFailure Kind - Host-side USB admission failure; it does not by itself identify a DAC fault.
- Link
Speed - Bus speed the device is connected at.
- Pacing
- What keeps the host’s packets and the DAC’s clock in step on an endpoint: the transport’s pacing, named for diagnostics. It only labels what the transport does for the endpoint; it never selects a mode.
- Quirk
- One behaviour switch for a device. Only switches the transport actually honours are listed.
- Quirk
Policy - Origin of a factual device rule, independent of local hardware evidence.
- Rate
Policy - What to do when the DAC cannot run the requested rate.
- Startup
Volume - What
Dac::opendoes with the DAC’s hardware volume before any stream can start. - Stream
State - Where a stream is in its life.
- Sync
Kind - Synchronisation type of an isochronous data endpoint.
- UacVersion
- USB Audio Class version of the device’s interfaces.
- Underrun
Edge Kind - A worker-observed transition into or out of an underrun episode.
- UsbQueue
Profile - Starting points for USB bus queue tuning. Queue times are approximate and depend on the endpoint’s service interval. The software ring is independent.
Constants§
- DEFAULT_
VOLUME_ STEPS - Default number of steps for
VolumeControl::step. - SHIPPED_
SUPPORT - SOURCE_
QUIRKS
Traits§
- DacListener
- Receives
DacEvents. Must not block: it runs on the library’s event thread, and a blocked listener delays every later event.