• WANTED: Happy members who like to discuss audio and other topics related to our interest. Desire to learn and share knowledge of science required as is 20 years of participation in forums (not all true). There are daily reviews of audio hardware and expert members to help answer your questions. Click here to have your audio equipment measured for free!

Room correction - Linux

OP
Lilith

Lilith

Active Member
Joined
Mar 28, 2021
Messages
267
Likes
78
What I didn't understand is if there's any advantage of using the inverse impulse response compared to using the filters directly. Is the IR accounting for the phase and the EQ correction not?
 

dasdoing

Major Contributor
Joined
May 20, 2020
Messages
3,851
Likes
2,353
Location
Salvador-Bahia-Brasil
I don't like the DRC-desginer. Align 2 gives more control for tweeking. afair DRC-designer doesn't even let you switch of the psychoacoustic target computation which is default in the code and isn't realy working imo
 

Daverz

Major Contributor
Joined
Mar 17, 2019
Messages
1,215
Likes
1,355
I don't like the DRC-desginer. Align 2 gives more control for tweeking. afair DRC-designer doesn't even let you switch of the psychoacoustic target computation which is default in the code and isn't realy working imo

Yeah, DRC Designer is for an older version of drc-fir, before he made the psychoacoustic target the default.

The psychoacoustic target works well with my Buchardt S400s, though it makes a corrected response that looks like it would be too bright. It does not seem to be based on the Toole/Olive research.
 
Last edited:

Daverz

Major Contributor
Joined
Mar 17, 2019
Messages
1,215
Likes
1,355
What I didn't understand is if there's any advantage of using the inverse impulse response compared to using the filters directly. Is the IR accounting for the phase and the EQ correction not?

Well, you could try it, though I think it would sound horrible. The inverse impulse response would be trying to undo every deviation in the high frequencies.
 

digitalfrost

Major Contributor
Forum Donor
Joined
Jul 22, 2018
Messages
1,428
Likes
2,743
Location
Palatinate, Germany
Yeah, DRC Designer is for an older version of drc-fir, before he made the psychoacoustic target the default.
You can just edit the config file?

I honestly didn't know/never bothered with that settings but now that I tested it I prefer the psychoacoustic target setting, and my config files from DRC designer have this enabled.
 

Daverz

Major Contributor
Joined
Mar 17, 2019
Messages
1,215
Likes
1,355
Here's the bash script I use to run drc-fir:

Bash:
#!/bin/bash

IMPULSE_FILE="$1"
FILTER_NAME="$2"
CONFIG="$3"
DRC_DIR="/usr/share/drc"
DRC="/usr/bin/drc"
MIC_CORRECTION="$HOME/drc/mic/7032857-mod.txt"
TARGET_DIR="$DRC_DIR/target"
CONFIG_DIR="$DRC_DIR/config"
NFILTERS=8
TARGET_TYPE="pa"
TEMP_DIR="$(mktemp -d tmp.XXXX)"
trap "rm -rf $TEMP_DIR" EXIT

RATE=44100
FILTER_DIR="$FILTER_NAME"
mkdir -p "$FILTER_DIR"
MAX_GAIN=2
RATE_STRING="$((RATE/1000)).$((RATE%1000/100))"
CONFIG_FILE="$CONFIG_DIR/$RATE_STRING kHz/$CONFIG-$RATE_STRING.drc"
TARGET_FILE="$TARGET_DIR/$RATE_STRING kHz/$TARGET_TYPE-$RATE_STRING.txt"

for i in 0 1; do
  sox "$IMPULSE_FILE" -t f32 "$TEMP_DIR/impulse.pcm" remix $((i+1)) rate -v -L -s $RATE
  $DRC --BCInFile="$TEMP_DIR/impulse.pcm" \
    --PSOutFile="$TEMP_DIR/filter_$i.pcm" \
    --PSPointsFile="$TARGET_FILE" \
    --MCFilterType=M \
    --MCPointsFile="$MIC_CORRECTION" \
    --PLMaxGain="$MAX_GAIN" \
    --TCOutFile="$TEMP_DIR/predicted_$i.pcm" \
    "$CONFIG_FILE" | tee "$TEMP_DIR/output_$i.txt"
done

echo
cat "$TEMP_DIR"/output_[01].txt | grep 'Filtered signal RMS level'

sox -M -t f32 -r $RATE -c 1 "$TEMP_DIR/filter_0.pcm" \
       -t f32 -r $RATE -c 1 "$TEMP_DIR/filter_1.pcm" \
       "$FILTER_DIR/$FILTER_NAME-$CONFIG.wav"
      
sox -M -t f32 -r $RATE -c 1 "$TEMP_DIR/predicted_0.pcm" \
       -t f32 -r $RATE -c 1 "$TEMP_DIR/predicted_1.pcm" \
       "$FILTER_DIR/$FILTER_NAME-$CONFIG-predicted-response.wav"

The arguments it takes are the impulse response as a stereo wav file (I use REW to measure it), the name your filter will have, and the name of the drc-fir "preset" (one of: erb, minimal, soft, normal, strong, extreme, insane). It outputs the filter and a the predicted response as stereo wav files to to a directory with your filter name in the current working directory.

Note that I use just one sample rate in my setup, so if you may need resample the filter with sox for your own setup.
 

dasdoing

Major Contributor
Joined
May 20, 2020
Messages
3,851
Likes
2,353
Location
Salvador-Bahia-Brasil
complete inversion would only work for exact position the mic is meassuring. even if you could keep you ear at same place 100% of the time, the other ear allready would have artifacts from the same speaker. the cancelation is off moving a few cm. also this would produce a ton of pre-delay.

The psychoacoustic target works well with my Buchardt S400s

I prefer the psychoacoustic target setting

I am using my curent filter for quite some time now.
I must confess that the target sounded good for me, too. but when I created my last filters I was focussing on direct sound (*), and it wont produce a flat direct sound.

speaking of direct sound:
It does not seem to be based on the Toole/Olive research

DRC uses frequency dependent windowing http://drc-fir.sourceforge.net/doc/drc.html#sec32
Toole/Olive's target is a heavy generalization of a FR in a long (e.g. the REW standard 500ms) window.

(*) atm I am actualy not sure anymore that this is the best method, I might look into the psy target again
 

Daverz

Major Contributor
Joined
Mar 17, 2019
Messages
1,215
Likes
1,355
DRC uses frequency dependent windowing http://drc-fir.sourceforge.net/doc/drc.html#sec32
Toole/Olive's target is a heavy generalization of a FR in a long (e.g. the REW standard 500ms) window.

(*) atm I am actualy not sure anymore that this is the best method, I might look into the psy target again

What I meant was that the DRC-FIR psychoacoustic target has only a modest tilt compared to the "ideal" one you usually see. But perhaps that's only the case in my room.
 

dasdoing

Major Contributor
Joined
May 20, 2020
Messages
3,851
Likes
2,353
Location
Salvador-Bahia-Brasil
What I meant was that the DRC-FIR psychoacoustic target has only a modest tilt compared to the "ideal" one you usually see. But perhaps that's only the case in my room.

yes, if the Harman tilt is realy neutral in the Harman room...it wont be in another room, or even in the same room with a bigger or smaller stereo triangle. it's easy to understand that if you think about an "aechoic living room"; the neutral target there would be flat.
there isn't realy a true method to create a neutral target out there. If Denis's psy target is it, this would be a first
 

jlo

Member
Joined
Aug 3, 2018
Messages
98
Likes
172
I don't like the DRC-desginer. Align 2 gives more control for tweeking.
I commited Align2 a long long time ago. Now I'm working on the website loudspeakers.audio (in beta version at the moment, so all free) which is a much more advanced way to measure and calculate correction (have a look at FAQ).
loudspeakers.audio has a very unique feature : calculation of the target curve is based on your room and speakers by using some measured values. Another nice feature, I think so ;), is that it is the only DRC correction based on MMM measurements coupled (linear phase) or not (min phase) to a smoothed phase measurement.
The calculated target is also available as a text file so you could use it directly with DRC-FIR.
 

dasdoing

Major Contributor
Joined
May 20, 2020
Messages
3,851
Likes
2,353
Location
Salvador-Bahia-Brasil
I commited Align2 a long long time ago. Now I'm working on the website loudspeakers.audio (in beta version at the moment, so all free) which is a much more advanced way to measure and calculate correction (have a look at FAQ).
loudspeakers.audio has a very unique feature : calculation of the target curve is based on your room and speakers by using some measured values. Another nice feature, I think so ;), is that it is the only DRC correction based on MMM measurements coupled (linear phase) or not (min phase) to a smoothed phase measurement.
The calculated target is also available as a text file so you could use it directly with DRC-FIR.

wow, I thought you have abandoned the projects.....no, you were reinventing the whole thing lol
will denfently give it a try.
this is allready VERY promissing: https://www.loudspeakers.audio/en/faqs/correction-at-mid-and-high-frequencies/
 
OP
Lilith

Lilith

Active Member
Joined
Mar 28, 2021
Messages
267
Likes
78
Got it running today and it's basically working.

@Daverz : I didn't understood your whole script and I made a simpler version which I will refine later based on yours. I wondered what the "remix" command is doing.

This is how I did it and I hope it's correct:

First I exported the IR files of both channels (left and right speaker) from the REW sweeps (Options: 32 bit Floats; Export measured IR, normalize sample to peak value). The sweeps were taken at 48 kHz sampling rate. This is important for the filters that also has to be generated based on 48 kHz.

Opening the file for the left channel with audacity looks like this and it seems to be nomalized to -1:

H9UmlHz.png


These two files must be converted to pcm files with sox so that they can be used as input data for DRC:

Code:
sox rew_ir_left.wav -t f32 -r 48000 -c 1  rew_ir_48_left.pcm                                                                                                                                                                                           
sox rew_ir_right.wav -t f32 -r 48000 -c 1 rew_ir_48_right.pcm

Now the filters can be generated with DRC:

Code:
drc --BCInFile=/home/marco/DRC_room_correction/rew_ir_48_left.pcm --PSOutFile=/home/marco/DRC_room_correction/filter_48_left.pcm --PSPointsFile="/usr/share/drc/target/48.0 kHz/pa-48.0.txt" --MCFilterType=N --PLMaxGain=1.2 --MSNormType=E --MSNormFactor=1 "/usr/share/drc/config/48.0 kHz/erb-48.0.drc"
drc --BCInFile=/home/marco/DRC_room_correction/rew_ir_48_right.pcm --PSOutFile=/home/marco/DRC_room_correction/filter_48_right.pcm --PSPointsFile="/usr/share/drc/target/48.0 kHz/pa-48.0.txt" --MCFilterType=N --PLMaxGain=1.2 --MSNormType=E --MSNormFactor=1 "/usr/share/drc/config/48.0 kHz/erb-48.0.drc"

To work as input for a convolver the resulting pcm files have to be converted to wav again:

Code:
sox -t f32 -r 48000 -c 1 filter_48_left.pcm filter_48_left.wav
sox -t f32 -r 48000 -c 1 filter_48_right.pcm filter_48_right.wav

As convolver I used jconvolver that can be started from the terminal and appears in jack.
It can be started with
Code:
jconvolver jc.config

where jc.config is a config file that looks like:

Code:
# This file is for use at 48 kHz.
#
#
# Verzeichnis wo die Filter files sind:
#
#/cd /home/
#
#                        in  out   partition    maxsize
# ---------------------------------------------------------------
/convolver/new    2    2        1024        65536
#
#               in out  gain  delay  offset  length  chan      file
# --------------------------------------------------------------------------
/impulse/read    1   1    1      0      0       0    1     filter_48_left.wav
/impulse/read    2   2    1      0      0       0    1     filter_48_right.wav

Here I'm not sure what's the correct setting for partition and maxsize and if this does have any effect at all. Does anybody know?
Is there any better convolver than jconvolver?

I then use Carla to route the audio from my DAW or from the Pulse2Jack sink through jconvolver:
0RGUDmy.png

The left channel (=left speaker) is corrected by the left inverse IR and the right speaker signal by the right IR file.

The correction works very good, except of one thing for which I didn't find a solution yet. For all settings I have tested the sound is amplified by the filter which lead to clipping. For instance with a filter generated by:

Code:
--BCInFile=/home/marco/DRC_room_correction/rew_ir_48_left.pcm --PSOutFile=/home/marco/DRC_room_correction/filter_48_left.pcm --PSPointsFile="/usr/share/drc/target/48.0 kHz/pa-48.0.txt" --MCFilterType=N --PLMaxGain=1.2 "/usr/share/drc/config/48.0 kHz/erb-48.0.drc"

the volume after jconvolver is ~0.6 dB louder while with --PLMaxGain=4 its much worse and it's almost 5 dB louder. I played with the normalization setting (MSNormType and MSNormFactor), but the resulting filters (when opening the wav files) look identical and the signal though the filter is amplified.

Another thing I wonder how DRC is taking care if one is using an 8 inch or e.g. 5 inch woofer. How can I prevent that DRC is boosting low frequencies which my speaker can't reproduce?

Under the line that's really great and on par with Sonarworks.
 
Last edited:

Daverz

Major Contributor
Joined
Mar 17, 2019
Messages
1,215
Likes
1,355
Got it running today and it's basically working.

@Daverz : I didn't understood your whole script and I made a simpler version which I will refine later based on yours. I wondered what the "remix" command is doing.

Since I saved both left and right impulse responses as a single stereo file, remix here just picks out left and right channels.

Here I'm not sure what's the correct setting for partition and maxsize and if this does have any effect at all. Does anybody know?
Is there any better convolver than jconvolver?

You could try CamillaDSP:

https://github.com/HEnquist/camilladsp
 

Daverz

Major Contributor
Joined
Mar 17, 2019
Messages
1,215
Likes
1,355
For all settings I have tested the sound is amplified by the filter which lead to clipping.

Yes, depending on the drc-fir normalization, you have to attenuate before filtering. E.g. for the 'E' normalization and PLMaxGain=2, you want to attenuate by 6 dB, for PLMaxGain=4 by 12 dB.

"The default configuration files all use the E normalization with a normalization factor set to 1, leaving the task of scaling the filter gain to avoid clipping to the convolver. With the default configuration files you should set the convolver gain to something below −6 dB, which is the default maximum gain allowed by the peak limiting procedure."

Another thing I wonder how DRC is taking care if one is using an 8 inch or e.g. 5 inch woofer. How can I prevent that DRC is boosting low frequencies which my speaker can't reproduce?

Good question. Usually the peak limiting keeps it from trying to amplify too much. But you might want to modify the pa-48k.txt target so it starts rolling off at a higher frequency.
 
OP
Lilith

Lilith

Active Member
Joined
Mar 28, 2021
Messages
267
Likes
78
Yes, depending on the drc-fir normalization, you have to attenuate before filtering. E.g. for the 'E' normalization and PLMaxGain=2, you want to attenuate by 6 dB, for PLMaxGain=4 by 12 dB.

"The default configuration files all use the E normalization with a normalization factor set to 1, leaving the task of scaling the filter gain to avoid clipping to the convolver. With the default configuration files you should set the convolver gain to something below −6 dB, which is the default maximum gain allowed by the peak limiting procedure."



Good question. Usually the peak limiting keeps it from trying to amplify too much. But you might want to modify the pa-48k.txt target so it starts rolling off at a higher frequency.

The strange thing is that the parameter MSNormFactor does not have any influence on the amplitude of the resulting WAV file. I assumed that the amplitude should be lower with MSNormFactor=0.5 compared to MSNormFactor=1 but the files look identical (first was with MSNormFactor=1 second MSNormFactor=0.5) :

4vK5has.png


When I change the amplitude by hand in Audacity the volume after the filter is indeed lower.

As a workaround I set the gain in jconvolver to 0.6 and I get no clipping now and maybe 2dB less volume which is fine. Anyway I will understand more and look again into tomorrow.
 

Daverz

Major Contributor
Joined
Mar 17, 2019
Messages
1,215
Likes
1,355
Yes, depending on the drc-fir normalization, you have to attenuate before filtering.

I probably should have written that you have to attenuate before convolving. The convolver should have a gain or attenuation setting.
 
OP
Lilith

Lilith

Active Member
Joined
Mar 28, 2021
Messages
267
Likes
78
My fault (I test it tomorrow):

Of course the parameter is PSNormFactor and not MSNormFactor.
 
OP
Lilith

Lilith

Active Member
Joined
Mar 28, 2021
Messages
267
Likes
78
Now it worked:

8I8o3m6.png


Awesome!
 
Top Bottom