[HowTo] BruteFIR Digital-Room-Correction and Convolver

BruteFIR is a convolver-application to manipulate audio-streams for e.g. equalizing, Digital-Room-Correction, active crossover of passive speakers, etc.

OSMC is limited to the ALSA sound API. This explains how to insert BruteFIR into the ALSA audio-chain on OSMC:

OSMC/KODI -> ALSA plug-in "plug" -> ALSA loopback-device "BruteFIR" -> BruteFIR -> ALSA soundcard

Insert into /etc/asound.conf:

# OSMC/KODI cannot connect an audio-stream directly to BruteFIR via a PIPE
# and BruteFIR uses a fixed number of channels, format and sampling-rate.
# The sampling-rate/format-conversion in OSMC/KODI is a CPU-hog
# which renders it unusable on low-power machines like the Raspberry PI 2B.
# So we need to connect the output of OSMC/KODI via the ALSA loopback-device to
# the input of BruteFIR and the ALSA plug-in "plug" for sampling-rate/format-conversion.
# OSMC/KODI -> ALSA plug-in "plug" -> ALSA loopback-device "BruteFIR" -> BruteFIR -> ALSA soundcard
# Run the following commands as root to load the ALSA loopback-device on boot automatically:
#	echo 'snd-aloop'								> /etc/modules-load.d/brutefir-alsa-loopback.conf
#	echo 'options snd-aloop id=BruteFIR enable=1 pcm_substreams=1 pcm_notify=1'	> /etc/modprobe.d/brutefir-alsa-loopback.conf
# Corresponding BruteFIR input configuration:
# input 0,1,2,3,4,5,6,7 {
#     device:	"alsa" { device: "hw:BruteFIR,1"; ignore_xrun: true; };
#     sample:	"S32_LE";
#     channels:	8;
# };

# Create an ALSA default audio-device for the ALSA loopback-device.
pcm.!default {

    # Use the ALSA plug-in "plug" for rate-/format-conversion.
    type plug

    # Forward the audio stream of OSMC/KODI to the ALSA loopback-device
    slave {
	pcm {

	    # Direct hardware access
	    type	hw

	    # Loopback card name
	    # Has to match "id" in the options of the snd-aloop module
	    card	"BruteFIR"

	    # Loopback device ID
	    device	0

	    # Number of audio channels
	    # Has to match the number of channels in OSMC/KODI (e.g. 7.1 -> 8)
	    # and "channels" in the BruteFIR input configuration
	    channels	8

	    # Format of audio stream
	    # Has to match the format defined in the "sample"-tag
	    # of the BruteFIR input configuration
	    format	"S32_LE"

	    # Sampling-rate of audio stream
	    # Has to match the sampling-rate defined in the global "sampling_rate"-tag
	    # of the global BruteFIR configuration
	    rate	96000

# Create an ALSA default control-device for the ALSA loopback-device.
ctl.!default {

	# Direct hardware access
        type	hw

	# Loopback card name
	# Has to match "id" in the options of the snd-aloop module
        card	"BruteFIR"

Add an output-configuration for your soundcard to the BruteFIR-configuration like:

output 0,1,2,3,4,5,6,7,8,9 {
    device:     "alsa" { device: "hw:FCA610,0"; ignore_xrun: true; };
    sample:    "S32_LE";
    channels:  10;

Create filters in the BruteFIR-configuration connecting the input- and output-channels:

##### Line/headphone A (Downmix 7.1 -> 2.0 Stereo)
filter "Front-/Rear-/Center-/LFE-/Side-Left"   { from_inputs: 0,2,4/0.5,5/0.5,6;  to_outputs: 0;  coeff: -1; };
filter "Front-/Rear-/Center-/LFE-/Side-Right"  { from_inputs: 1,3,4/0.5,5/0.5,7;  to_outputs: 1;  coeff: -1; };

##### Line surround (Downmix 7.1 -> 5.0)
filter "Line Front-/LFE-Left"                  { from_inputs: 0/0.5,5/0.25;       to_outputs: 2;  coeff: -1; };
filter "Line Front-/LFE-Right"                 { from_inputs: 1/0.5,5/0.25;       to_outputs: 3;  coeff: -1; };
filter "Line Rear-/Side-Left"                  { from_inputs: 2/0.5,6/0.5;        to_outputs: 4;  coeff: -1; };
filter "Line Rear-/Side-Right"                 { from_inputs: 3/0.5,7/0.5;        to_outputs: 5;  coeff: -1; };
filter "Line Center"                           { from_inputs: 4/0.5;              to_outputs: 6;  coeff: -1; };

Start BruteFIR as root-user, e.g.

sudo /usr/bin/brutefir -nodefault /home/osmc/.brutefir_config

Hi. Many thanks for sharing this. Will this work on the rpi images as well? I cant figure out if the default audio is sent via alsa on the raspberry. I’m trying to learn more how the sound is processed in kodi/osmc and at the same time minimize cpu demand. In my case I’m trying to output it to a USB soundcard.

Also would something like ecasound require less resources for simple corrections? My use case is active cross over and some eq/room correction when I’m listening to music.

If “rpi images” means Raspbian, etc., yes. The first models RPi A(+) or B(+) are to slow for BruteFIR. OSMC only uses the ALSA device drivers for audio output. Other distros may use Pulseaudio on top of ALSA in which case you have to disable your USB-soundcard in Pulseaudio and select the ALSA-loopback-device instead.

  1. Find the name of your sound-card with “cat /proc/asound/card[0-9]/id”. The names of your sound-card are consistent even after reboot or (un-)plugging external sound-cards while the card numbers can change.

  2. Find the hardware capabilities of your USB-devices: “cat /proc/asound/card[0-9]/stream[0-9]”

  3. Create the BruteFIR output configuration using the name and capabilities (format, sampling-rate, channels) of your sound-card. BruteFIR now is directly on top of the hardware device driver of the sound-card without any interference from other sound applications.

I’ve never tested ECASound.

P.S.: I have clicking noise with multi-channel USB devices. I don’t know if this is the buggy Broadcom-SOC (problem solved according to the RPi-developers) or an incompatibility between RPi2 and the SD-card.

Thanks for this great article!

I use brutefir a lot on the PI but so far only for 2 channel Stereo setups and this works great. As far as I understood this approach would only work for multichannel soundcards with analog outputs as it requires AC3 decoding -> convolution and output.
Do you know if the PI2 has enough pefromance for Full HD mkv playback + 6 channel DRC convolution?

I also had the crackeling problem with multichannel USB devices, but tested the last time over a year ago…

I got the answer for my 1st question. The limitation is to output encoded AC3 output again. For that the A52 Alsa plugin would need to work, which seems to be not the case:

so it seems the limitation for the PI in above approach is the absence of any multi channel audio device and that AC3 output only works in pass through.

Above described approach works perfect with my PC.

As BruteFIR was never stable for me (buffer underruns) I switched to an HDMI-AVR with Audyssey MultXT.

You need an I²S-Hat with S/PDIF-output (electrical or TOSLink) and the A52 ALSA-plug-in to output AC3 if your amplifier has an S/PDIF-input. If your amplifier has a multi-channel-input or you have multiple amplifiers the Audio Injector Octo looks promising.