Skip to content

fix: route audio to a USB DAC connected at power-on on tg5040 - #866

Open
cjwhitedev wants to merge 1 commit into
LoveRetro:mainfrom
cjwhitedev:fix/usb-dac-at-boot
Open

cjwhitedev wants to merge 1 commit into
LoveRetro:mainfrom
cjwhitedev:fix/usb-dac-at-boot

Conversation

@cjwhitedev

Copy link
Copy Markdown

Fixes #865

What

In the tg5040 MinUI.pak/launch.sh, before audiomon starts: if ALSA card 0 is a USB audio device, unbind and rebind that USB device.

Why

A USB DAC that is already connected at power-on registers before the internal codec and takes card 0, pushing audiocodec to card 1. audiomon finds the DAC and writes .asoundrc for card 0, but playback still goes to the speaker. After a physical replug the codec is card 0 and the DAC card 1, the layout the rest of the audio path expects (see AUDIO_SINK_USBDAC's "assumes being exposed as card 1"), and audio reaches the DAC.

Rebinding the device in software gives the same card order as a replug. The USB device is found from /sys/class/sound/card0/device, so it doesn't depend on which port or DAC is used. Nothing happens when no USB audio device holds card 0, and the extra 1 s delay only applies in that case.

Testing

On a TrimUI Brick (NextUI 6.15.0 with this launch.sh), DAC: TTGK KM-HIFI-384KHZ:

  • DAC connected at power-on, then Rockbox launched: audio from the DAC (previously the speaker);
  • no DAC at power-on: speaker audio as before;
  • DAC plugged in after boot: audio from the DAC as before.

Not tested on the Smart Pro, which uses the same script. tg5050 isn't changed.

AI disclosure

This change was written with the help of an AI coding assistant (GitHub Copilot). I directed the work, reviewed the changes, and tested them on my own TrimUI Brick as described above.

A USB DAC that is already plugged in when the device boots registers before
the internal audiocodec and takes ALSA card 0, pushing the codec to card 1.
audiomon still writes .asoundrc for the DAC, but playback goes to the speaker
until the DAC is unplugged and plugged back in, which leaves the codec on card 0
and the DAC on card 1.

At boot, if card 0 is a USB audio device, unbind and rebind that USB device
before audiomon starts, giving the same card order as a hotplug.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

USB DAC connected at power-on plays through the speaker on TrimUI Brick

1 participant