Forcing Audacity to use the default ALSA device (dmix) for output

I’m using an USB sound card that has dmix disabled by default, so I’ve manually created a dmix device in asound.conf, made my USB sound card its slave and set the dmix sevice as the default output device. With this setup all of my other programs output to the dmix device, but Audacity always attempts to reserve the physical device for itself. This messes up the audio for the whole system and results in loud and nasty distortion which is probably not good for the speakers or the amp. Selecting the dmix device as output in Audacity releases the physical device and fixes the system audio, but I have to do this even if my dmix device is already selected when Audacity starts.

Is there any way to block Audacity from attempting to use the sound card directly? I’d even be happy with completely hiding the device systemwide so that it’s only visible to the dmix device that uses it, if that’s possible. I’m using plain ALSA, PulseAudio is not an option.

Which version of Audacity?
Which Linux distribution?

With Audacity 2.2.2 on Xubuntu, if I set the playback device to dmix in the device toolbar and then restart Audacity, dmix is still selected as the playback device. Is that not happening for you?

Audacity 2.2.2, 64-bit Gentoo.

It’s still selected in the toolbar for me as well, but I have to reselect it (switch to any other device and then back to dmix) for Audacity to actually start using it.

Or maybe Audacity is using it but also reserves the physical device at startup for no reason?

Audacity scans the sound system when the application launches (so that it can populate the Device Toolbar with a list of available devices), but it does not reserve any devices. Audacity connects to devices dynamically (on demand, when Play or Record or monitoring are started).

People usually say that when they have flaky ALSA drivers or other sound system problems that they are unable to resolve. Why is PulseAudio not an option for your computer?

I’ve just tested playing a file with:

aplay -D"plug:'dmix:RATE=44100'" "./test.wav"

and playing Audacity 2.2.2 via dmix at the same time, and it works fine here, so I don’t think it is anything intrinsically wrong with Audacity.

The problem is not dmix not working (like I said it does work), but the fact that every time I start Audacity it’s attempting to use the sound card directly even when it’s not selected. I don’t know if it happens when scanning for the devices, but since no other program I use does this I don’t see how it’s not a problem with Audacity.

Is it possible to configure Audacity not to automatically scan for new devices at startup?

No. Audacity needs to scan the sound system so that it can populate the options in the Device Toolbar.
It may help you to debug the problem by forcing Audacity to rescan. That option is near the bottom of the Transport menu.

Rescanning does cause the same distortion I get at startup. I’ll try playing around with my ALSA config, maybe there’s something in the way I’ve set up dmix I could change.

Strangely enough, disabling OSS emulation support in the kernel seems to have solved the problem.