Skip to main content

Crate usbdac_core

Crate usbdac_core 

Source
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.c protocol 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.
AsyncVolumeControl
A bounded FIFO worker. Submission fails with Error::Busy when 32 requests are waiting. Accepted operations use the same verified hardware writes, rollback and event delivery as VolumeControl. Close waits for an executing control transfer; queued operations then fail as closed.
Capabilities
Summary of what the DAC can do.
ClockChoice
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.
ClockHop
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.
DeviceInfo
Identity of the USB device and the interfaces the host has claimed.
ExplicitFeedbackDiagnostics
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.
ExplicitFeedbackPacket
The most recent packet observed for one feedback outcome.
FeedbackTrace
A shareable support capture for the most recent stream of a DAC session.
FeedbackTraceEntry
A record in the trace, timed from stream creation using a monotonic clock.
IsoSubmitIncident
Evidence of an isochronous OUT submit failure or its one retry. The slot and generation pair joins both attempts within the same stream.
QuirkOverride
Extra quirks for one VID/PID, added to the built-in table.
RateRange
A continuous or discrete range of sampling frequencies.
ShippedSupport
Authoritative shipped API boundaries used by the generated SDK status page. Update together with implementation when enabling another transport tier.
SourceQuirkEntry
Pinned factual identity match. No bcdDevice bounds were specified by these source rows; None means all revisions, never a guessed revision range.
StartupVolumeReport
What Dac::open did with the DAC’s level before any stream could start (see StartupVolume).
StreamFormat
What will go on the wire, as chosen by Dac::negotiate.
StreamReconfiguration
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.
StreamRequest
A format the host would like.
StreamStats
Counters of a stream. Frames are in the unit StreamFormat::counter_rate_hz gives the rate of.
UnderrunEdge
Relaxed atomic snapshots taken at the observed worker edge, after preparing the transfer. elapsed_us shares 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.
VolumeControl
Handle to the DAC’s hardware volume control.
VolumeOperation
An accepted volume request: .await, try_result or wait retrieves its result exactly once. Dropping this handle leaves the accepted operation queued, preserving write ordering.
VolumeRange
The DAC’s volume range in decibels.
VolumeState
The DAC’s volume as read back from the device.

Enums§

AlsaQuirkFlag
AltFormat
What an alternate setting carries.
AsyncFallbackPolicy
Policy for asynchronous endpoints without a proven feedback source.
BitPerfectBlocker
What stands in the way of DacStream::is_bit_perfect, most significant first. None from DacStream::bit_perfect_blocker means nothing does.
ClockHopKind
What a ClockHop is.
ClockReadbackPolicy
Policy for unusable frequency readback after an acknowledged rate write.
ClockResolution
How ClockChoice::source_id was found.
CloseVolume
What Dac::close_with does with the level the DAC had before the library first changed it, decided at close rather than at open.
CompatibilityFallbackTier
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.
EndpointUsage
The usage bits of an isochronous endpoint’s bmAttributes.
Error
Everything the public API can fail with.
ExplicitFeedbackOutcome
What happened to a packet while it was examined for explicit feedback.
FeedbackSmoothing
How validated explicit feedback reports change packet timing.
FeedbackTraceEvent
An observation from the selected USB feedback path.
HandBack
What happens to the DAC’s hardware volume when the Dac is closed.
HostUsbFailureKind
Host-side USB admission failure; it does not by itself identify a DAC fault.
LinkSpeed
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.
QuirkPolicy
Origin of a factual device rule, independent of local hardware evidence.
RatePolicy
What to do when the DAC cannot run the requested rate.
StartupVolume
What Dac::open does with the DAC’s hardware volume before any stream can start.
StreamState
Where a stream is in its life.
SyncKind
Synchronisation type of an isochronous data endpoint.
UacVersion
USB Audio Class version of the device’s interfaces.
UnderrunEdgeKind
A worker-observed transition into or out of an underrun episode.
UsbQueueProfile
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.

Type Aliases§

Result
Result with the crate Error.