How can I apply a LADSPA plugin to a PulseAudio stream?

Solution 1:

Adding a LADSPA plugin to pulseaudio is done with module-ladspa-sink.

We install this module as an output sink where we can define the processing module and are able to send the processed signal to this newly created sink.

Load the LADSPA module:

This module can be loaded at runtime with:

pacmd load-module module-ladspa-sink sink_name=<yourname> master=<sinkname> plugin=<plugin> label=<label> control=<option1>,<option2>,[...]

The name of the master sink can be read with the following command:

 pacmd list-sinks

Give a name for the processed sink as it will appear in the output list in sink_name. All further options depend on the plugin we use (see example below).

To apply the LADSPA processor we choose the output sink from "Sound Settings..." and can now listen to the processed stream. Control options can not be altered at runtime.

Unload the LADSPA module:

We will have to unload the module and load it again for different options. To find the module index for unloading we may issue:

 pacmd list-modules

To unload a module we either restart the sound server with pulseaudio -k or we unload the module with it's index number #:

pacmd unload-module <#>

See also the reference wiki from pulseaudio.

Load LADSPA module at startup:

After having found the appropriate options we may want to run it per default. This can be done by including it to the /etc/pulse/default.pa configuration file to be loaded by the daemon on startup:

.ifexists module-ladspa-sink.so
.nofail
load-module module-ladspa-sink <options>
.fail
.endif

Example:

This is an example of one special case to give you an idea on how to do it. In this example we want to apply a pitch shift to our sound output using the TAP-plugin tap_pitch (tap-plugins Install tap-plugins). For this plugin the additional options needed for loading to Pulse Audio are the following:

plugin=tap_pitch # as from /usr/lib/ladspa/ without .so
label=tap_pitch  # defines which label of a plugin to use

To find the appropriate control options we browse to the plugin documentation (here TAP plugin pitch shifter). There we find a nice table of four relevant controls we have to apply in the control= command:

control=<semitone>,<rate>,<dry>,<wet>

Leaving an option empty will use the default in this case.

Thus the following command will apply a pitch shift of one octave downward from my master sink alsa_output.pci-0000_00_14.2.analog-stereo (replace with your sink) to the output sink ladspa_out with a semitone shift of -12, that is a rate shift of -50%, and with a dry (unprocessed) mixer level of -90dB, and a wet (processed) level of 0dB.

pacmd load-module module-ladspa-sink sink_name=ladspa_out master=alsa_output.pci-0000_00_14.2.analog-stereo plugin=tap_pitch label=tap_pitch control=-12,-50,-90,0

For some plugins the documentation may be not be complete, or appropriate setting will need quite some experimenting until they are right.