4

I live in a duplex, and my neighbor can hear my music if it has any bass in it at all. As a solution, I want to configure ALSA to apply a high-pass filter to audio which goes out through my speakers (but not my headphones). How do I accomplish this?

3

Here's the relevant section from my ~/.asoundrc. I have my speakers connected to a USB audio device which appears as hw:3 to ALSA. In my personal setup, there is already a device hw3mix, as described here, which mixes multiple client streams onto the hw:3. Other options are possible, as shown in the commented lines:

pcm.hw3highpass {
    type ladspa
    slave.pcm "plug:hw3mix";
    # you can choose a different hardware device (no mixing) like this:
#    slave.pcm "plughw:0,0";
    # and you can even specify basic mixing in the same line:
#    slave.pcm "plug:dmix:0"

    # but note that the following doesn't work, we need 'plug' to
    # convert to/from floating point
#    slave.pcm "hw3mix";

    path "/usr/lib/ladspa";
    plugins [{
        label hpf
        input {
            controls [ 1000 ]
        }
    }]
    hint {
        show on
        description "Highpass filter for hw:3"
    } 
}

pcm.!default plug:hw3highpass

The high pass filter is a LADSPA plugin (label hpf). Other plugins are available which might be useful in my living situation, for example to add a compressor.

The plug plugin, which I invoke twice, is a somewhat magical plugin that does automatic format conversion. It is needed to interface with LADSPA, which wants floating point. You can see the filter chain and observe the fact that floating point conversion is being done, by executing the command aplay -v some.wav. Without a plug: prefix on the hw3mix slave definition you get an obscure error message "ALSA lib pcm_params.c:2162:(snd1_pcm_hw_refine_slave) Slave PCM not usable". Without plug: in the default alias on the last line, you get another obscure error message "aplay: set_params:1292: Access type not available". Yay Linux!

I'm asking and answering my own question because the ALSA documentation was incomprehensible, and other solutions I found on the net were unnecessarily complicated - either using a numeric id instead of label for the LADSPA plugins section; or defining two extra named devices to do manual floating<->integer conversion, instead of using the plug: prefix as shown here; or not mentioning the possibility of aliasing directly to a plug:... device as I do on the last line. I was surprised to find how simple the configuration is, and how useful and powerful ALSA/LADSPA can be once one understands the basics.

I found the Volker Schatz tutorial "A close look at ALSA" indispensible to figuring out some of this stuff. Apparently ALSA has evolved a bit since his tutorial was written, since for instance he says he never got Dmix to work, and he says that aliases to devices with arguments are not allowed (my pcm.default is such an alias).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.