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.
- 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.
- 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
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. - Volume
Control - Handle to the DAC’s hardware volume control.
- Volume
Range - The DAC’s volume range in decibels.
- Volume
State - The DAC’s volume as read back from the device.
Enums§
- AltFormat
- What an alternate setting carries.
- 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
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. - 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
Trace Event - An observation from the selected USB feedback path.
- Hand
Back - What happens to the DAC’s hardware volume when the
Dacis closed. - 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.
- 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.
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.