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 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 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)?;

v0.1 supports one open Dac per process.

Modules§

convert
Opt-in conversion helpers.
descriptors

Structs§

AltSetting
One isochronous OUT alternate setting of an AudioStreaming interface.
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.
QuirkOverride
Extra quirks for one VID/PID, added to the built-in table.
RateRange
A continuous or discrete range of sampling frequencies.
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.
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.
VolumeControl
Handle to the DAC’s hardware volume control.
VolumeRange
The DAC’s volume range in decibels.
VolumeState
The DAC’s volume as read back from the device.

Enums§

AltFormat
What an alternate setting carries.
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.
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.
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.
FeedbackTraceEvent
An observation from the selected USB feedback path.
HandBack
What happens to the DAC’s hardware volume when the Dac is closed.
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.
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.

Constants§

DEFAULT_VOLUME_STEPS
Default number of steps for VolumeControl::step.

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.