Troubleshooting#
Turn on the native library's log first: UsbDac.setLogLevel(4) (debug), then adb logcat -s usbdac. Include that log in a bug report, together with the DAC's name and USB ids (DacDeviceInfo.vendorId, productId), session.capabilities, the StreamFormat (its clock and pacing in particular, see diagnostics) and stream.stats().
Error codes#
Most SDK failures are DacExceptions. An opt-in checked playback open may instead throw DacPlaybackOpenException; read its failure and retain its pendingCleanup as described in checked playback open. For a DacException, error.code is a DacErrorCode, error.detail the message without the code, and error.message is "<code>: <detail>".
| Code | Where from | Meaning and what to do |
|---|---|---|
BUSY |
UsbDac.open |
The attachment already has an owner. Close that session first; distinct attachments can have separate owners. |
PLATFORM_UNSUPPORTED |
native | Direct output needs Linux usbfs: Android or Linux. Not an Android problem; you are on another host |
CLAIM |
UsbDac.open |
The audio interfaces could not be taken from Android's USB audio driver, or are not the set the library expected. See Android keeps the DAC |
UNSUPPORTED |
UsbDac.open, negotiate, openStream, AndroidManagedOutput.open, AAudioExclusiveOutput.open |
At open: the device has no AudioControl interface together with a playback AudioStreaming interface. Later: no alternate setting carries the request (rate, depth, channels, DSD), or a managed request the platform cannot make. The message lists how many alternate settings the DAC offers; read session.capabilities.altSettings. With RatePolicy.EXACT a rate the DAC cannot run ends here |
IMPLICIT_FEEDBACK_UNSUPPORTED |
negotiate, openStream |
See asynchronous endpoints without feedback |
CLOCK_UNVERIFIED |
openStream |
The DAC did not confirm the sampling frequency it was told (or reported another), and DacConfig.requireVerifiedRate is on. The message gives the requested and reported rate. Some DACs have a broken readback: the applicable explicit compatibility policy can admit an acknowledged SET with unusable readback as unverified. A different reported rate is not proof and remains an error |
DEVICE_LOST |
any call | The DAC was unplugged or stopped answering. DacState.LOST and DacEvent.DeviceLost follow; close the session |
TRANSFER |
stream, events | An isochronous transfer or the stream machinery failed: a transfer that completed with an error the loss budget does not cover, loss beyond its bounds, or an explicit feedback deadline that expired. The stream goes to FAILED and stays open until closed. A cable, hub or port problem is the usual cause |
CONTROL |
volume, clock | A class control request failed (volume, mute, clock). A DAC without a volume control throws this for volume calls; session.volume is null for it |
INVALID_STATE |
many | The call is not valid now: a second stream, negotiate while a stream is open, write after drain() or after the stream closed or failed, any call on a closed session |
INVALID_ARGUMENT |
many | A value out of range or inconsistent: buffer depths, startupVolume ceiling outside -128..0 dB, busQueueMs outside 4..64, transfersInFlight outside 2..16, a DSD slot size other than 1, 2 or 4, a malformed request |
VOLUME_UNAVAILABLE |
openStream |
The DAC has no usable hardware volume control (none, or the start-up attenuation could not be verified) and DacConfig.requireHardwareVolume is on: a stream would play at the DAC's own level and nothing could bring it down. negotiate and capabilities still work. Show the user what the DAC offers, ask whether to allow fixed-level output, and open the session again with requireHardwareVolume = false. See start-up volume protection |
EXCLUSIVE_UNAVAILABLE |
AAudioExclusiveOutput.open |
AAudioConfig.requireExclusive is on and the platform granted only a shared AAudio stream. The message carries the grant's reason. Exclusive mode depends on the device and the route; open with requireExclusive = false to accept a shared stream, or fall back to AndroidManagedOutput |
PERMISSION_DENIED |
UsbDac.open |
The app has no USB permission for the device. See permission |
OPEN_FAILED |
UsbDac.open, AndroidManagedOutput.open |
Android refused to open the device or gave no file descriptor, or the AudioTrack could not be created |
CONFIGURATION_UNAVAILABLE, CONFIGURATION_SELECTION_FAILED, CONFIGURATION_RESTORE_FAILED |
UsbDac.open, openPlaybackForRequest, openCapture, openDuplex with a configurationId; close or pending hand-back |
The configuration ID is absent or advertised twice; Android rejected the selection or GET_CONFIGURATION did not confirm it; or the original configuration could not be confirmed again on hand-back (a configuration changed by someone else is not overwritten) |
RECONFIGURE_DRAIN_TIMEOUT |
reconfigure, reconfigureCandidates |
The current stream did not drain before the deadline. It is still open and draining and its token is still valid: wait longer, flush, or close it. Nothing was discarded |
RECONFIGURE_UNUSABLE |
reconfigure, reconfigureCandidates, later session calls |
Retirement, the retained USB owner or the rollback could not be proved. Do not play through the old stream; close the session before using the DAC again |
HOST_USB |
macOS host only | A host USB stack refused the device (the libusb open, an interface claim or the whole-device capture). The Android usbfs path does not raise it |
UNKNOWN |
any | A code this version of the SDK does not know, from a newer native library |
Asynchronous endpoints without feedback#
An asynchronous OUT endpoint runs on the DAC's own clock. The driver follows explicit rate reports or derives pacing from a compatible IN data endpoint on the same clock. If neither source is usable, the host and DAC can drift apart until playback under- or overruns. Read format.pacing for the selected source. For an implicit route, it identifies the capture interface, alternate setting and endpoint.
One case is admitted by default: a full-speed UAC 1.0 PCM alternate setting that declares no feedback pipe (bSynchAddress 0) streams at the nominal rate, host-paced (DacConfig.asyncFallbackPolicy = FULL_SPEED_UAC1, the default). It carries the blocker UNSYNCHRONIZED_ASYNC and emits a nominal_async compatibility event; set asyncFallbackPolicy = FORBID to refuse it. Every other asynchronous alternate without usable feedback is refused by negotiate or openStream with IMPLICIT_FEEDBACK_UNSUPPORTED, when it is the only way to carry the request. A DAC that also offers a synchronised alternate setting for the same format gets that one. A malformed endpoint (a feedback endpoint that cannot be resolved) is never streamed.
DacConfig(allowUnsynchronizedAsync = true) streams those other alternates anyway, at the nominal rate, host-paced. Expect the drift to end in clicks or dropouts after some time, and the stream is never bit-perfect (blocker UNSYNCHRONIZED_ASYNC). Use the managed output (AndroidManagedOutput) for such a DAC if it works there.
Feedback lock and dropouts#
If a direct stream has opened but loses feedback, record format.pacing,
stats().feedbackLocked, feedbackAgeMs and the usbdac log. Include the
DAC's USB IDs, the requested format, and whether the issue occurs at startup
or after playback begins.
- Explicit. A successful empty poll increments
feedbackEmptyand leaves the last valid report timestamp alone. A burst of rejected reports shows up infeedbackRejected. If the source goes stale, the driver emitsFeedbackStaleand holds the last valid rate during the recovery window. If valid timing fails to return by the deadline, it emitsStreamFailedwithTRANSFER. - Implicit.
format.pacingidentifies the IN interface, alternate setting and endpoint. IncludeimplicitFifoDepth,implicitWaitsandimplicitInvalidPacketsto distinguish a timing-source gap from a writer underrun. A transport failure can end the stream withTRANSFER.
In both modes, FEEDBACK_UNLOCKED can appear while the driver acquires or
reacquires timing. See all feedback counters.
Collect a feedback support report#
For an in-app capture toggle, a listener flow and export examples in Kotlin and Rust, see collect a USB playback support report. The sample app has Capture USB feedback for support and Copy feedback report controls. It keeps the latest report available after Stop or disconnect.
Wrong pitch, or no sound at one sample rate#
On a DAC with more than one clock (a Clock Selector choosing between an internal oscillator and another source, or Clock Multipliers in front of a source), the sampling frequency is programmed on one Clock Source. If it goes to the wrong one, the DAC plays at the wrong pitch, or is silent at one rate while others work. Look at clock.path and clock.resolution of the StreamFormat that negotiate returned:
clock.resolution == FALLBACK_FIRST_SOURCE: the library could not trace the stream's terminal to its clock (no terminal link, a malformed or looping entity, a selector that would not say which pin is active) and used the first Clock Source in descriptor order. On a multi-clock DAC that may be the wrong one. Theusbdaclog (UsbDac.setLogLevel(2)or more) has the reason on a warning line. Report it with the log, the DAC's USB ids and its descriptors (lsusb -vor the Android USB host dump).clock.resolution == RESOLVED: readclock.pathfrom the terminal down. EachSelectorhop shows the pin the DAC reported as active (selectedPinofpinCount). The library starts from that pin and keeps it when the clock behind it can run the requested rate. When it cannot, and the selector is writable, the library may select another input, so a path that differs from the front-panel setting can be the library's choice; it puts the original pin back when the session ends. If the source at the end is not the one that clocks the playback terminal on that DAC, the selector is on another input than you expect: a clock switch on the DAC, an external clock input, or the DAC's own default. Compare with the DAC's descriptors.clock.sourceIdandclock.controlInterfacesay where the sampling frequency was written and read back.CLOCK_UNVERIFIED(see the table above) is the DAC refusing to confirm it on that source.clock == null: the DAC describes no clock entities (UAC 1.0, whose rate is set on the endpoint). The clock topology is not the cause.
format.pacing answers the other half, how packets are paced: Unsynchronized on an asynchronous endpoint is the no-feedback case, the usual cause of clicks that appear after some time. See diagnostics for the fields.
Permission#
USB permission is per device and asked at run time.
UsbDac.requestPermission(context, device) { granted -> ... }shows the system dialog. The callback runs on the main thread, withtrueat once if the permission is already held.UsbDac.openwithout permission throwsPERMISSION_DENIED; it never shows a dialog itself.- If the activity declares the
USB_DEVICE_ATTACHEDintent filter with a device filter (see getting started) and the user chooses "always" in the dialog Android shows on attach, the permission is remembered for that device and app. - Permission is not kept across unplugging unless it was granted that way.
- A request needs a foreground app: Android may not show the dialog from the background.
Android keeps the DAC#
CLAIM at open usually means Android's USB audio driver still has the interface. The library claims the AudioControl interface and the playback AudioStreaming interfaces with claimInterface(interface, force = true), which detaches the kernel driver. If that fails:
- Unplug the DAC and plug it in again.
- Turn on Disable USB audio routing in Developer options, then plug it in again. It stops Android from routing audio to USB devices, which is what the force-claim fights.
- Check that no other app (or an earlier session of yours) holds the DAC.
- Read the
usbdaclog for the interface number that failed.
On release the library returns the streaming interfaces to alternate setting 0 and calls releaseInterface, which also asks Android to take its driver back. If the DAC does not come back as an Android audio output after close(), replug it.
Nothing plays#
Work down the list.
attachedDacsis empty. The device has no Audio Streaming interface with an isochronous OUT endpoint: it is not a USB audio playback device, the cable carries power only, or the adapter or hub is the problem. A capture-only device is not listed.- Open fails. Read the code above.
BUSY,PERMISSION_DENIEDandCLAIMare the usual ones. negotiatefails.UNSUPPORTED: pick a rate and depth fromcapabilities.IMPLICIT_FEEDBACK_UNSUPPORTED,CLOCK_UNVERIFIED: see above. Silence or a wrong pitch at one rate on a DAC with several clocks: look at the clock.- The stream opens and is silent. In this order:
- Is the DAC's volume at its minimum, or muted? Read
session.volume?.state.UsbDac.openlowers the volume to at most -40 dB (DacConfig.startupVolume), so a DAC that was at full scale is quiet until the slider goes up;session.volume?.startupsays what it had and what it was lowered to. Ifsession.volumeisnullthe DAC has no usable hardware volume, andopenStreamfails withVOLUME_UNAVAILABLEunlessrequireHardwareVolumeis off. - Is the writer running?stats().framesWrittenmust rise. A writer that writes less thanstartThresholdMsof audio leaves the stream inBUFFERING, and it never starts. Write at leaststartThresholdMs(100 ms), or calldrain()for a short clip. - Is the streamPAUSED,DRAINEDorFAILED?stream.statesays. Afterdrain()writes fail untilflush(). - Doeswritereturn 0 forever?writableBytesis 0 while the ring is full (the DAC is not taking audio) or afterdrain(). Checkstats().transferQueueDepthandcompletedTransfers. - Noise or static. The bytes are in the wrong layout. Match
StreamFormat.subslotBytesandvalidBits: 24-bit in a 4-byte slot is the sample shifted left by 8; samples are little-endian and interleaved. For native DSD, normalize the source first. DSF field 1 stores bits least-significant first, so reverse each source byte. Field 8 stores bits most-significant first and needs no reversal. Deblock and interleave the DSF channels. DSDIFF stores audio bytes interleaved and most-significant bit first. See Sony DSF v1.01, Annotation 4 and Philips DSDIFF v1.5, §3.3. Standard UAC3 DSD uses fixed little-endian 64-bit channel words without bit reversal. Legacy DAC-specific settings such asdsdBigEndian/DsdBigEndian,DsdBitReverseanddsdSubslotdescribe the device transport and are separate from source normalization. For DoP, write the DSD bits as the layout says and leave the marker byte alone. - Clicks and dropouts.
DacEvent.Underrunmeans the writer did not keep the ring filled: raisebufferTargetMs, make sure the writer thread is not starved (do not render on the main thread, avoid long garbage collections in it), and write whenwritableBytessays there is room. If the ring is full and the stream still underruns, the output thread itself is late: raisebusQueueMs(16 ms by default) a few milliseconds at a time. The packets in flight never exceed 255, so a very deep queue at a short service interval is capped. With the default geometry (andadaptiveQueueon, except on implicit-feedback routes) the queue already grows by two transfers after a loss, to at most 30 ms at a 125 µs service interval and 32 ms at the longer ones; any non-defaultbusQueueMs,transfersInFlightortransferPeriodUsfixes the depth you set and turns that growth off.DacEvent.LostFramesandstats().urbTimeoutsmean the USB transport lost audio: cable, hub or port.DacEvent.FeedbackStalemeans the feedback source stopped providing usable timing. Use the feedback diagnostics above to identify the source and collect the counters. A click or a short re-lock of a DoP or native DSD DAC at a seek or a track change is the gap a flush makes when it cancels the transfers on the bus: setDacConfig(cancelInFlightOnFlush = false)and the queue plays out instead (up tobusQueueMsof the old audio is then heard after the seek). - The flag says not bit-perfect.
stream.bitPerfect.valuecarries the blocker and a sentence. See bit-perfect output. - The volume keys do nothing.
session.volumeisnull(the DAC has no volume control), ordispatchKeyEventdoes not callDacVolumeKeys.handle, or the screen is off and noDacVolumeProvideris attached to aMediaSession. - After unplugging.
DacEvent.DeviceLostandDacState.LOST. Close the session, wait for the nextDacHotplugEvent.Attached, and open again.
Conversion#
ConversionPlan.between, PcmConverter.create and ConvertingOutput fail with typed codes:
UNSUPPORTEDfor DSD: check rate and channel limits,allowConversion, and, for explicit DoP input,allowDopPcmConversion. DoP unpacking validates markers. Direct bitstream and PCM fallback have different guarantees.UNSUPPORTEDwith "only mono to stereo is supported": no downmix, no upmix, no channel remapping.UNSUPPORTEDwith "needs a filter of ... taps in ... phases": a rate ratio that does not reduce to small integers (44100 to 47993 Hz) would need a filter larger than the converter builds. Rates between 8000 and 768000 Hz in the 44.1 and 48 kHz families are all fine.INVALID_ARGUMENT: a rate or channel count out of range, a negativeditherSeed, aheadroomDboutside -60 to 0, a heap buffer given toPcmConverter.convert(use direct buffers).INVALID_STATE:convertafterfinishwithoutreset(), or any call afterclose().- A rejected padded PCM
ConvertingOutput.writeleaves the source buffer position unchanged. Correct the sample bytes and padding layout before retrying. - Clipping:
PcmConverter.clippedSamplescounts post-dither integer-quantizer saturations, including rounding or dither clamps even without resampling. A resampled signal can exceed its input's peak; setConversionOptions.headroomDb(-3.5covers a full-scale square wave). - A
ConvertingOutputwhosewritetakes fewer bytes than you offered is full: the target is not taking audio, and the converted audio waits in the wrapper. Write whenwritableBytessays there is room.
AAudio exclusive output#
AAudioExclusiveOutput.open says why it could not open; the usual ones:
UNSUPPORTEDwith "need Android 12 (API 31)": packed 24-bit and 32-bit integer samples are not in AAudio before Android 12. Use 16-bit, 32-bit float (AAudioConfig(floatSamples = true)) or another output.UNSUPPORTEDwith "did not open the stream as requested": the platform opened the stream at another rate, channel count or format than the one you write. The message says which. The output never converts, so it refuses; the route may only run one rate (readAudioDeviceInfo.sampleRatesof the device).UNSUPPORTEDwith "AAudio is not available":libaaudio.socould not be opened.BUSY: another app holds the device exclusively.EXCLUSIVE_UNAVAILABLE: see the table above.DEVICE_LOSTfromwrite,AAudioEvent.Disconnectedandstate == FAILED: the route went away. Close the output and open another.- Clicks:
AAudioEvent.Underrun(the ring ran dry: raisebufferTargetMs, check the writer thread) againstAAudioEvent.Xrun(the device-side buffer ran dry: raisedeviceBufferBursts, or check thatperformanceModeisLOW_LATENCY). - Silence: the writer must write at least
startThresholdMsof audio before playback starts, as for a direct stream; checkstateandwritableBytes.
The usbdac log (UsbDac.setLogLevel) also covers this output.
Automatic output#
OutputSelector.select and open say why the output they chose is not a better one in decision.alternativesRejected (see automatic output); read it first. Then:
- The direct output is never chosen. Look for its rejection.
POLICY:allowDirectUsbis off.PERMISSION_MISSING: ask withUsbDac.requestPermission(the decision'sneedsUsbPermissionnames the DAC) and select again.ROUTE_UNSUITABLE: audio is routed to Bluetooth or a cast device.IMPLICIT_FEEDBACK,NO_HARDWARE_VOLUME,BUSYandFAILEDcarry theDacErrorCodeinerror: the same codes as above. - The exclusive AAudio output is never chosen.
EXCLUSIVE_NOT_GRANTEDmeans the platform granted only a shared stream on that route;NOT_AS_REQUESTEDmeans the hardware runs another rate or format;PLATFORM_TOO_OLDmeans 24-bit or 32-bit integer samples on a release before Android 12. Whether a device grants exclusive mode is the platform's decision, not the library's. INVALID_STATEfromselectoropen. An output this selector opened is still open. Close it first: the DAC and an exclusive stream can only be held once.UNSUPPORTEDlisting every output. No output can carry the request, typically DSD with no DAC, or 24-bit PCM on a release before Android 12. Read the list.- A forced output fails. With
OutputPolicy.forcethe typed error of that output is thrown and nothing else is tried; it is the same code the rejection would have had. selecttakes a long time or the DAC glitches. With a DAC attached it opens a session and negotiates, which programs the clock, and gives the DAC back afterwards. Do not call it while another app is playing to the DAC, and call it off the main thread.- The decision lists the wrong route before Android 13. Android cannot say where media goes before release 13, so the library guesses from the connected outputs. Select again after the route settles, or force an output.
Build and packaging#
UnsatisfiedLinkErrorforusbdac: the AAR has no library for the device's ABI. The AAR carries arm64-v8a, armeabi-v7a, x86_64 and x86; checkabiFiltersin your app and that you did not build the AAR with-Pusbdac.abisrestricted.UnsatisfiedLinkErrorfor adev.usbdac.internal.NativeorAAudioNativemethod, or a crash on the first event, with R8 enabled: the library ships consumer rules that keepNative,AAudioNativeandNativeListener. If your build replaces or ignores consumer rules, keep them.- A heap
ByteBufferpassed towriteworks but is copied on every call; use a direct buffer in a real player.