System Wide DSP Guide

Michael Barbour edited this page Nov 20, 2016 · 13 revisions
Clone this wiki locally

This is a guide to using dsp as a LADSPA plugin to do system-wide audio processing on Linux.

Installing Packages

First, make sure you have git, the base development tools, and ladspa_dsp's required dependencies installed. For Debian and derivatives, you'll need build-essential, pkg-config, git, and ladspa-sdk. For Arch Linux, you need the base-devel metapackage, git, and ladspa.

If you want to build all the optional effects and codecs have a look at the Optional Dependencies. If your OS splits development packages (like Debian does), make sure you install the -dev (or equivalent) packages.

Getting the Code

Clone the dsp repository:

$ git clone https://github.com/bmc0/dsp.git
$ cd dsp

Building

If you only want the bare-bones LADSPA plugin, run configure manually to disable the convolver effects and the CLI frontend:

$ ./configure --disable-dsp --disable-fftw3 --disable-zita-convolver

If you want the CLI frontend and all the optional effects (assuming you have their dependencies installed), you can either run ./configure manually with no options or just let make run it for you.

Now build and install:

$ make
$ sudo make install

Creating the Configuration File

The default search paths for the configuration file are as follows:

  • $XDG_CONFIG_HOME/ladspa_dsp/config
  • $HOME/.config/ladspa_dsp/config (if $XDG_CONFIG_HOME is not set)
  • /etc/ladspa_dsp/config

The README has a short description of the config format. If you want to apply the same effects to every channel, you only need to specify the effects chain:

effects_chain=gain -3.0 lowshelf 90 0.9s +3.0

This will apply a simple bass boost. See the README for more information about each effect.

If you want individual control over each channel, you need to set the number of input and output channels. Here is an example configuration for a 6-channel soundcard that implements an LR2 crossover at 1.8kHz plus an LR4 crossover at 80Hz to a mono LFE channel:

input_channels=2
output_channels=6
# Output mapping: [Tweeter_left, Tweeter_right, Woofer_left, Woofer_right, LFE, No_connection]
effects_chain=remix 0 1 0 1 0,1 . :0,1 mult -1 highpass 1.8k 0.5 :2,3 lowpass 1.8k 0.5 highpass 80 0.7071 highpass 80 0.7071 :4 mult 0.5 lowpass 80 0.7071 lowpass 80 0.7071 :

Generating the Effects Chain from a Room EQ Wizard Filter Settings File

The script scripts/rew_to_dsp.sh can generate an effects chain from a Room EQ Wizard filter settings file. It currently supports the following filter types: PK, LP, HP, LPQ, HPQ, NO, LS, HS, and AP. The Equalizer APO style Preamp: line is also supported.

Let's use the Micca MB42x correction file from http://noaudiophile.com as an example:

Filter Settings file

Dated: October 14th, 2013 03:23:23 AM

Notes: NoAudiophile.com Micca MB42x Correction

Preamp: -3.7 dB


Filter 1: ON  PK    Fc   13058 Hz  Gain  -3.7 dB  Q  1.0
Filter 2: ON  PK    Fc   12260 Hz  Gain  2.3 dB  Q  1.0
Filter 3: ON  PK    Fc   10880 Hz  Gain  -2.3 dB  Q  3.0
Filter 4: ON  PK    Fc   16500 Hz  Gain  -2.1 dB  Q  3.0
Filter 5: ON  PK    Fc   6580 Hz  Gain  -2.5 dB  Q  6.38
Filter 6: ON  PK    Fc   8210 Hz  Gain  -5.0 dB  Q  2.4
Filter 7: ON  PK    Fc   8144 Hz  Gain  5.0 dB  Q  6.0
Filter 8: ON  PK    Fc   5895 Hz  Gain  5.2 dB  Q  5.0
Filter 9: ON  PK    Fc   2990 Hz  Gain  2.0 dB  Q  1.0
Filter 10: ON  PK   Fc   2750 Hz  Gain  -4.2 dB  Q  2.0
Filter 11: ON  PK   Fc   1836 Hz  Gain   3.0 dB  Q  5.7
Filter 12: ON  PK   Fc   1700 Hz  Gain  -1.6 dB  Q  4.0
Filter 13: ON  PK   Fc   1304 Hz  Gain  -2.5 dB  Q  4.19
Filter 14: ON  PK   Fc   1281 Hz  Gain  -3.1 dB  Q  2.0

To generate the effects chain, run:

$ ./scripts/rew_to_dsp.sh ~/Micca_MB42x.txt
gain -3.7 eq 13058 1.0 -3.7 eq 12260 1.0 2.3 eq 10880 3.0 -2.3 eq 16500 3.0 -2.1 eq 6580 6.38 -2.5 eq 8210 2.4 -5.0 eq 8144 6.0 5.0 eq 5895 5.0 5.2 eq 2990 1.0 2.0 eq 2750 2.0 -4.2 eq 1836 5.7 3.0 eq 1700 4.0 -1.6 eq 1304 4.19 -2.5 eq 1281 2.0 -3.1

Now you can copy and paste the output into the configuration file:

effects_chain=gain -3.7 eq 13058 1.0 -3.7 eq 12260 1.0 2.3 eq 10880 3.0 -2.3 eq 16500 3.0 -2.1 eq 6580 6.38 -2.5 eq 8210 2.4 -5.0 eq 8144 6.0 5.0 eq 5895 5.0 5.2 eq 2990 1.0 2.0 eq 2750 2.0 -4.2 eq 1836 5.7 3.0 eq 1700 4.0 -1.6 eq 1304 4.19 -2.5 eq 1281 2.0 -3.1

Configuring PulseAudio

Run this command to make PulseAudio load the LADSPA plugin:

$ pacmd load-module module-ladspa-sink sink_name=dsp master=<sinkname> plugin=ladspa_dsp label=ladspa_dsp

Replace <sinkname> with the preferred output device (example: alsa_output.pci-0000_00_1b.0.analog-stereo). You can find the device name with pacmd list-sinks. Now you can make the dsp sink the default. See this Ask Ubuntu post for more information about changing the default sink.

To make PulseAudio load the plugin every time and set dsp as the default sink, put this in ~/.config/pulse/default.pa:

.include /etc/pulse/default.pa

load-module module-ladspa-sink sink_name=dsp master=<sinkname> plugin=ladspa_dsp label=ladspa_dsp
set-default-sink dsp

Again, replace <sinkname> with the preferred output device. If your ladspa_dsp configuration requires control over each channel, you need to set the number of (output) channels:

load-module module-ladspa-sink sink_name=dsp master=<sinkname> plugin=ladspa_dsp label=ladspa_dsp channels=<channels>

You'll also probably want to disable remixing in ~/.config/pulse/daemon.conf if you're controlling each channel to stop pulseaudio from doing anything fancy:

enable-remixing=no

Starting with version 7.0, pulseaudio enables LFE remixing by default (in other words, it inserts a crossover). The above disables this behavior as well.

Configuring ALSA

If you don't use PulseAudio (I don't), you can configure ALSA to load the LADSPA plugin. Put this in ~/.asoundrc:

pcm.dsp {
    type plug
    slave {
        format FLOAT
        rate unchanged
        channels unchanged
        pcm {
            type ladspa
            path "/usr/lib/ladspa"
            playback_plugins [{
                label "ladspa_dsp"
            }]
            slave.pcm {
                type plug
                slave {
                    pcm "<hw_device>"
                    rate unchanged
                    channels unchanged
                }
            }
        }
    }
}

Replace <hw_device> with the preferred output device. To set the dsp pcm as the default device, add this:

pcm.!default {
    type copy
    slave.pcm "dsp"
}

If your ladspa_dsp configuration requires control over each channel, you need to set the number of (output) channels:

pcm.dsp {
    type plug
    slave {
        format FLOAT
        rate unchanged
        pcm {
            type ladspa
            channels <channels>
            path "/usr/lib/ladspa"
            playback_plugins [{
                label "ladspa_dsp"
            }]
            slave.pcm {
                type plug
                slave {
                    pcm "<hw_device>"
                    rate unchanged
                    channels unchanged
                }
            }
        }
    }
}

Notes

  • Currently, the configuration file is not reloaded when it is changed. In order to reload the configuration file, the plugin must be reinitialized. If you're using PulseAudio, you can accomplish this by either unloading and reloading the LADSPA module, or by restarting the server (pulseaudio -k). With ALSA, the pcm must be reset.
  • When the input to a biquad filter is non-silence followed by silence, denormal values may be produced (http://en.wikipedia.org/wiki/Denormal). On many systems, this causes a large increase in the CPU time required run the filter. You can usually avoid this problem by using noise effect to add extremely low-level (totally inaudible) noise to the signal at the beginning of the effects chain (noise -200, for example).