Need help setting up an ALSA software ducker / sidechaining compressor
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Need help setting up an ALSA software ducker / sidechaining compressor
Hi guys, a bit of an advanced ALSA config question, hopefully someone can help me, I'll post what I have so far.
I'm trying to setup some software DSP, in particular, I want music to duck (lower its volume) when I speak into the microphone. This is for a streaming setup. To do this, there seem to be multiple ways, however, I'd like to do it with .asoundrc. Alternatives are using pulseaudio or jack or pipewire, but I'd rather do this using .asoundrc.
To achieve ducking, or sidechaining compression, I can use a LADSPA plugin, with the ladspa block in .asoundrc. I've already identified the plugin I want to use, at least for now, called sc3. It is part of swh plugins.
I'd also like to use two compressors, but getting one to work will be fine. The second one is for the Text To Speech feature, I want that to also be able to duck the music, but I want to be able to have my speech duck the TTS if need be, so it doesn't talk over me. So it's kind of a cascaded setup.
Below is a schematic of how I'd like this to work. I've used the bus metaphor to illustrate it. Basically I want to be able to control which streams go to the sidechain input of each of the two compressors.
Explanation: on the left you have a 5 line bus, the rightmost one are a stereo pair. MIC 1 and MIC 2 are just the left and right channels of the Mic In port on the motherboard. MUSIC is going to be the default pcm device, where most audio will be played from the PC: music, videos etc. TTS is going to be a secondary pcm device, where the TTS will be played. The big rectangles are sidechaining compressors, with input, output and sidechain (SC) input. PAN and VOL are just panning and volume, I think in alsa it's called softvol.
I'm currently getting the following error. I think I'm just not understanding bindings:
Code:
aplay -D sc3 poopy.wav
ALSA lib pcm_ladspa.c:1362:(snd_pcm_ladspa_parse_bindings) Unable to find an audio port (left_in) for channel 0
aplay: main:830: audio open error: Invalid argument
For starter, I'm not sure how to configure the inputs and the outputs of the ladspa block.
The diagram explains how I'd implement this with analog audio, but it seems I need to somehow restructure it so it works with the master/slave audio used in .asoundrc. However, I don't understand, for example, how I can get the 3 inputs that the compressor plugin needs. It has 3 inputs and 2 outputs: left in, right in, sidechain in, left out, right out. If I'm understanding correctly, the first master is the music pcm, and the last slaves are the hardware mic and hardware out. But somehow I can't figure out how to route from the music pcm, and join it with the sidechain, into a 3 channel stream, and then feed that into the compressor node.
This should be possible, but it won't be flexible, and your distro's alsa setup might interfere with things.
Good luck getting help with that - ALSA is a book with seven seals (and I only replied because you already took yourself out of zero reply status anyhow).
My recommendation: try for sure, but don't drive yourself mad trying. Switch to JACK which is designed for these kinds of things.
Thanks, just trying to figure out how master/slave works in regard to input/output, with the ladspa plugin. I'll take another look at its source code. The only flexibility I need is to be able to mute and pan, and I've provisioned for that with the VOL blocks in my schematic, I'm assuming they're going to show up as volume controls in alsa mixer, and that I can control those from the command line.
I'm getting ready to reach a conclusion here. Because opening a pcm device is unidirectional, i.e. you can only open a pcm for capture or for playback, it is the nature of the client/slave chains to be unidirectional when instantiated. In effect, the asound config file is similar to a class in C++, and opening a pcm definition with aplay or arecord, or any ALSA client program, is similar to instantiating that class, either for capture or for playback. This, in turn, has the effect that you can't use a mic in a playback chain, which is what I need. I need the mic to be connected to the sidechain input of the LADSPA sc3 plugin, but I need the rest of the inputs and outputs of the plugin to be used in playback mode. So this might make it seem impossible to achieve what I want, but there is one more possibility, and that is, using dmix and dsnoop with the same ipc key, and opening TWO pcm definitions, one in playback and one in capture mode. This might work, but I haven't managed to get it to work. At this point I'm going against the grain, and I might just give up. I'll wait for the author of the ladspa plugin to respond and I'll report back here.
Next, I'm looking at 4 avenues: using jack, using pipewire, using pulseaudio, and possibly writing my own alsa plugin. The pulseaudio route seems to make most sense, because it's stable and I'm already using it, being forced so by Firefox and OBS. Writing my own plugin might or might not work, as it might be the case that alsa itself cannot effectively allow this setup. For jack, I don't like having to run jackd at startup, and for pipewire, it seems promising but it's too new to rely on, or at least it seems that way.
I've used pipewire and a custom config file to setup most of what I wanted, they've been helpful on the IRC channel, just figuring out a few things, and dealing with occasional choppy audio, but this ended up being my choice.
I had to upgrade to debian testing so I could get wireplumber as the session manager.
I used a lv2 plugin instead of ladspa, I just couldn't get the ladspa one (sc3) to work.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.