<?sphp $this->text('pagetitle') ?>
 
Home of the Squeezebox™ & Transporter® network music players.

Brutefir Filter

From SqueezeboxWiki

Revision as of 08:22, 23 June 2010 by Soulkeeper (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Using brutefir to filter audio on Linux

This page contains a description on how brutefir can be used to filter audio before it is sent to the Squeezebox. I don't claim to be an expert on brutefir in any way, I can't make it do anything useful yet. But this is the first step towards Digital Room Correction on Linux.

This page was inspired by the work of HPyle: http://www.duffroomcorrection.com/wiki/User:Hpyle

Invitation to perl wizzen

The Windows-only InguzEQ plugin will make a good template for making this all wrap up nicely together. Its author would prefer a single cross-platform version than a huge fork. The perl module is available under the MIT license, here:

http://inguzaudio.com/EQ/download.php

See the Plugin section for the BrutefirDRC Plugin it does DRC under Linux using brutefir. It was not possible to extend the existing project without having more work than starting from scratch and using the InguzEQ stuff as guide. Brutefir is to different to configure, to put everything in one big plugin.

Warning

The description below (probably) only works with 44.1 kHz samples, i.e. anything that was ripped from CDs. If you have material with other sampling frequencies, I don't know what will happen. Always test with your amplifier at low volume.

Install brutefir

Hopefully, your distribution already has a package for brutefir:

aptitude install brutefir

Create .brutefir_defaults

Run brutefir without any arguments. This will create a file in your home-directory called .brutefir_defaults. Copy this file to /home/slimserver/.

Create a brutefir filter

This is the hard part. For now, put the following in /home/slimserver/.brutefir_simple. This will delay the right channel relative to the left channel, which destroys your listening experience, but at least you can hear that brutefir does something...

# Adapted from http://www.duffroomcorrection.com/wiki/Simple_Brutefir_Config
## DEFAULT GENERAL SETTINGS ##

float_bits: 32;             # internal floating point precision
sampling_rate: 44100;       # sampling rate in Hz of audio interfaces
filter_length: 8192,8;       # length of filters
overflow_warnings: true;    # echo warnings to stderr if overflow occurs
show_progress: false;        # echo filtering progress to stderr
max_dither_table_size: 0;   # maximum size in bytes of precalculated dither
allow_poll_mode: false;     # allow use of input poll mode
modules_path: ".";          # extra path where to find BruteFIR modules
monitor_rate: false;        # monitor sample rate
powersave: true;           # pause filtering when input is zero
lock_memory: true;          # try to lock memory if realtime prio is set

## INPUT DEFAULTS ##

input  "l_in","r_in" {
      device: "file" {path: "/dev/stdin";};  # module and parameters to get audio
      sample: "S16_LE";   # sample format
      channels: 2/0,1;    # number of open channels / which to use
      delay: 0,0;         # delay in samples for each channel
      maxdelay: -1;       # max delay for variable delays
      mute: false,false;  # mute active on startup for each channel
};

## OUTPUT DEFAULTS ##

output "l_out","r_out" {
      device: "file" {path: "/dev/stdout";};  # module and parameters to put audio
      sample: "S16_LE";   # sample format
      channels: 2/0,1;    # number of open channels / which to use
      delay: 0,0;         # delay in samples for each channel
      maxdelay: -1;       # max delay for variable delays
      mute: false,false;  # mute active on startup for each channel
      dither: false;      # apply dither
};

## FILTER DEFAULTS ##

filter "l_filter" {
      from_inputs: "l_in"/8.0;
      to_outputs: "l_out"/0.0;
      process: 0;        # process index to run in (-1 means auto)
      coeff: -1;          # -1 means "copy"
      delay: 0;           # predelay, in blocks
      crossfade: false;   # crossfade when coefficient is changed
};

filter "r_filter" {
      from_inputs: "r_in"/8.0;
      to_outputs: "r_out"/0.0;
      process: 0;        # process index to run in (-1 means auto)
      coeff: -1;
      delay: 7;           # predelay, in blocks
      crossfade: false;   # crossfade when coefficient is changed
};

Edit convert.conf

convert.conf can be found in the server/-directory of your slimserver-installation.

Add the following lines:

mp3 wav * *
	[lame] --mp3input --decode -t --silent $FILE$ - - |HOME=/home/slimserver brutefir -quiet /home/slimserver/.brutefir_simple

Beyond experimentation, a better approach will be to add a new file "slimserver-convert.conf", with overrides specific to the processing we want. This is the approach taken by the inguz plugin.

Restart slimserver

Activate brutefir-filter

Open the web-interface and go to Home->Server Settings->File Types.

Uncheck the line where it says "MP3 MP3 builtin". Check the line with "MP3 WAV lame".

Play and enjoy (?)

It will not be very enjoyable. But you now know that brutefir works and you can start dreaming of proper Room Correction.

Working Brutefir example providing 24 bits dithered output

Inguz room correction provides dithered 24 bits output in order to keep rounding errors due to correction to a minimum and also to keep good dynamics. It is possible to do the same with brutefir.

Slimserver configuration

Create /etc/slimserver/custom-convert.conf and add entries for each format that you would like to be "room corrected".

A flac entry would look like this:

flc flc * *
	[flac] -dcs --force-raw-format --endian=little --sign=signed --skip=$START$ --until=$END$ -- $FILE$ | /usr/bin/brutefir /etc/slimserver/brutefir.cfg 2> /etc/slimserver/brutefir.log |[flac] -cs -0 --totally-silent --endian=little --sign=signed --channels=2 --bps=24 --sample-rate=$RATE$ -

This would convert a 16 bits flac file to 16 bits pcm (wav), then pipe it to brutefir for room correction, brutefir uses 64 bits accuracy and finally outputs 24 bits pcm which is being piped to the flac encoder again in order to generate 24 bits flac file for processing by the Squeezebox hardware.

A mp3 entry would look like this:

mp3 flc * *
	[lame] --mp3input --decode -t --silent $FILE$ - - |/usr/bin/brutefir /etc/slimserver/brutefir.cfg 2>/etc/slimserver/brutefir.log | [flac] -cs -0 --totally-silent --endian=little --sign=signed --channels=2 --bps=24 --sample-rate=$RATE$ -

Repeat this for every format you would like to have room correction enabled for and then restart slimserver.

Don't forget to edit "file types" in the slimserver server settings! In this example you should enable flac to flac and mp3 to flac.

Brutefir config

Create the brutefir configuation file /etc/slimserver/brutefir.cfg

## DEFAULT GENERAL SETTINGS ##

float_bits: 64;             # internal floating point precision
sampling_rate: 44100;       # sampling rate in Hz of audio interfaces
filter_length: 8192,8;       # length of filters
overflow_warnings: true;    # echo warnings to stderr if overflow occurs
show_progress: false;        # echo filtering progress to stderr
max_dither_table_size: 0;   # maximum size in bytes of precalculated dither
allow_poll_mode: false;     # allow use of input poll mode
modules_path: ".";          # extra path where to find BruteFIR modules
monitor_rate: false;        # monitor sample rate
powersave: true;           # pause filtering when input is zero
lock_memory: true;          # try to lock memory if realtime prio is set

convolver_config: "/etc/slimserver/.brutefir_convolver"; # location of convolver config file
logic: "cli" { port: 3000; };

## Filter definition ##

coeff "drc_l" {
       filename: "/etc/slimserver/left.pcm";
       format: "FLOAT_LE";     # file format
       attenuation: 0.0;   # attenuation in dB
       blocks: -1;         # how long in blocks
       skip: 0;            # how many bytes to skip
       shared_mem: false;  # allocate in shared memory
};

coeff "drc_r" {
       filename: "/etc/slimserver/right.pcm";
       format: "FLOAT_LE";     # file format
       attenuation: 0.0;   # attenuation in dB
       blocks: -1;         # how long in blocks
       skip: 0;            # how many bytes to skip
       shared_mem: false;  # allocate in shared memory
};

## INPUT DEFAULTS ##

input  "l_in","r_in" {
       device: "file" {path: "/dev/stdin";};
       sample: "S16_LE";   # sample format
       channels: 2/0,1;    # number of open channels / which to use
       delay: 0,0;         # delay in samples for each channel
       maxdelay: -1;       # max delay for variable delays
       mute: false,false;  # mute active on startup for each channel
};

## OUTPUT DEFAULTS ##

output "l_out","r_out" {
       device: "file" {path: "/dev/stdout";};
       sample: "S24_LE";   # sample format
       channels: 2/0,1;    # number of open channels / which to use
       delay: 0,0;         # delay in samples for each channel
       maxdelay: -1;       # max delay for variable delays
       mute: false,false;  # mute active on startup for each channel
       dither: true;      # apply dither
};

## FILTER DEFAULTS ##

filter "l_filter" {
       from_inputs: "l_in"/8.0;
       to_outputs: "l_out"/0.0;
       process: 0;        # process index to run in (-1 means auto)
       coeff: "drc_l";
       delay: 0;           # predelay, in blocks
       crossfade: false;   # crossfade when coefficient is changed
};

filter "r_filter" {
       from_inputs: "r_in"/8.0;
       to_outputs: "r_out"/0.0;
       process: 0;        # process index to run in (-1 means auto)
       coeff: "drc_r";
       delay: 0;           # predelay, in blocks
       crossfade: false;   # crossfade when coefficient is changed
};

Please note that in this example my DRC generated FIR filters are called left.pcm and right.pcm, are 64k samples long and that they do reside in /etc/slimserver as well. Brutefir output is set to 24 bits (S24_LE) output for processing by the flac encoder.

Brutefir (in this configuration) uses about 6% cpu on my 32 bits 1,8 GHz AMD machine. There is of course also the (small) overhead of the extra flac encoder process.

Check /etc/slimserver/brutefir.log to make sure no clipping occurs. Be aware that this logfile is overwritten each time a new song is played.