bmc0/dsp

32-bit applications won't play sound - ALSA

cut1less opened this issue · 6 comments

On Arch Linux. I'm using ALSA alone (no Pulse, JACK, etc.). Things seemingly work on most applications, including big ones like Chromium, mpd, mpv, vlc, and some others. But other applications just refuse to play sound through this plugin. However, from what I've lazily tested, they'll all work with vanilla ALSA and/or ALSA with dmix.

Relevant errors:

ALSA lib pcm_ladspa.c:1502:(snd_pcm_ladspa_add_plugin) Unable to load plugin 'ladspa_dsp' ID 0, filename '/usr/lib/ladspa/ladspa_dsp.so'

This is with the "filename" part specified in the ladspa module. Without it (as recommended in the wiki and other places), it's something like

ALSA lib pcm_ladspa.c:1509:(snd_pcm_ladspa_add_plugin) Unable to find or load plugin 'ladspa_dsp' ID 0, path '/usr/lib/ladspa'

My /etc/asound.conf contents or at least the relevant parts are:

pcm.dsper {
	type plug
	slave {
		format FLOAT
		rate unchanged
		channels unchanged
		pcm {
			type ladspa
			path "/usr/lib/ladspa"
			plugins [{
				label ladspa_dsp
                                filename "/usr/lib/ladspa/ladspa_dsp.so"
			}]
			slave.pcm {
				type plug
				slave.pcm "dmix"
			}
		}
	}
}

pcm.!default {
	type plug
	slave.pcm "dsper"
}

I've tried some combinations of using "type plug" or "type copy" when possible (no difference); I've tried specifically defining the "dmix"' slave (no difference; seemingly not the issue); "plugins" vs. "playback_plugins" also hasn't made a difference. It feels like maybe I'm defining the ladspa_dsp plugin improperly somehow, but I don't know.

As to the affected programs, it's a random-ish sample. GoldSrc games don't have sound; the Source games that I've tried haven't worked except for Portal 2. Braid, Hollow Knight, and Undertale don't have sound. Notably, Hollow Knight and Portal 1 have an odd pitch that plays some time after starting the games; the other games are just silent. I thought it may be a Steam runtime issue or something, but using the native runtime or not using Steam at all (in the case of Undertale) hasn't mattered; Wine/Proton also hasn't seemed to matter.

Well, at the very least, I know the cause. These were all 32bit applications that wanted a 32bit version of ladspa_dsp.so. I'm trying to hack together a version of that, but I feel like I'm in over my head.

bmc0 commented

You should be able to do a 32-bit build as of commit 9787a5a (fixes an issue with library detection in the configure script) with this command:

$ CFLAGS+=" -m32" CXXFLAGS+=" -m32" LDFLAGS+=" -m32" PKG_CONFIG_LIBDIR="/usr/lib32" make

I've not looked into how to configure ALSA for this, but I can try to figure it out if you aren't able to.

bmc0 commented

I haven't tested this, but I think it'll work if you just put the 32-bit ladspa_dsp.so in /usr/lib/ladspa with a different filename (like ladspa_dsp_32.so). You'll also need to remove the filename ... line in your ALSA configuration. 32-bit applications will fail to open the 64-bit object and vice-versa, but that should be fine since it's looking for the plugin label instead of a specific filename.

Thanks for the response!

What you've written has mostly worked -- most of my 32bit applications/games now have sound without issue. Counter-Strike Condition Zero is an odd one that doesn't, though: it plays the menu music, but all in-game sounds are gone. (Switching the plug directly to dmix makes it work, albeit without my filters)

The Steam logs show the error as:

ladspa_dsp: eq: error: f0 out of range
ladspa_dsp: error: failed to initialize effect: eq
ALSA lib pcm_ladspa.c:643:(snd_pcm_ladspa_allocate_instances) Unable to create instance of LADSPA plugin 'ladspa_dsp'

All of my filters' center frequencies are within 20Hz-20KHz, and there are otherwise no issues in 64bit programs.

Another problematic program is Hollow Knight, but even without dsp in the mix, it doesn't interact with ALSA well and is being a bit buggy. It's spitting out:

ALSA lib pcm_ladspa.c:1509:(snd_pcm_ladspa_add_plugin) Unable to find or load plugin 'ladspa_dsp' ID 0, path '/usr/lib/ladspa'

bmc0 commented

f0 out of range means that the center frequency of the filter is greater than or equal to half the sample rate (or <= 0), so the in-game sounds must have a low sample rate. There are two possible solutions:

  1. Force a specific sample rate in the ALSA configuration by changing the rate unchanged line to rate 44100 (or whatever sample rate you prefer).
  2. Put an exclamation mark before any filter with a center frequency above 11kHz or so (I'm assuming the sample rate isn't lower than 22.05kHz). Example: ! eq 12k 1.0 -3. This will cause the filter to be discarded if it can't initialize, but will have no effect otherwise.

Not sure about Hollow Knight. Maybe it's running in a chroot jail or some kind of sandbox.

Thanks once again. Yeah, changing the rate to 48000 fixed CSCZ's sound for me.

Hollow Knight's issues are now solved. The Linux version was just being buggy in general, so I moved to the Wine/Proton version. That version didn't have any LADSPA/equalization issues but did have its own sound issues (buzzing). I somehow fixed that by lowering the blur quality (a visual setting). The Unity engine that the game uses is just weird, I think.

So yeah, that fixes everything on my machine. I'll close this issue.