Creating a DRC Room Correction Filter for your Squeezebox

This article explains how to create a room correction filter using a Slim Devices Squeezebox using Denis Sbragion's DRC tools.

This process is particularly handy for users of the BrutefirDRC plugin. It may also be useful for users of the Inguz room correction plugin as an alternative to its built-in filter recording process.

Overview

The process involves playing a sweep through your Squeezebox and simultaneously recording it on your PC using a microphone. Two sweeps are recorded, one for the left channel and one for right. Each sweep lasts less than a minute.

Equipment

  1. You will need a measurement microphone to record the room response.
  2. A PC sound card. Ideally one which can record at 44.1kHz without resampling, and must be able to record from line-in and microphone simultaneously.
  3. A microphone cable.
  4. A cable to connect one channel of your Squeezebox RCA analog out to the sound card line in.
  5. Some string.
  6. Software for editing .wav files. Audacity is good.
  7. Software to record from the sound card.
  8. DRC.
  9. sox.

The Recording Process

First you need to create the sweep.wav file using DRC's glsweep program. This command creates a sweep at 44.1kHz, at 50% full amplitude, from 5Hz to 22kHz. The sweep lasts 45 seconds. Then use sox to convert the sweep.pcm file to a .wav, and copy it to a directory which can be found from 'Browse Music Folder' on your Squeezebox

glsweep 44100 0.5 5 22000 45 2 0.05 0.005 sweep.pcm inverse.pcm
sox -t raw -r 44100 -c 1 -fl sweep.pcm -t wav -c 2 -sw sweep.wav

If there is significant background noise then you may benefit from a longer sweep - perhaps 90 seconds.

The Measurement Channel

Connect the microphone to the left channel of your sound card's Mic input. The left input channel will be used to record the room response.

Position the microphone at your normal listening position, ensuring it is approximately the same distance from both speakers. I find it easiest to use String.

The Reference Channel

For your first sweep you will be measuring the room response for your left speaker, with the right speaker silent. To do that you will need to disconnect the right channel RCA output from your squeezebox and replace it with a connection to the right channel of your sound card's Line In.

To summarize, for the sweep for the left speaker:

SB RCA Left --> Amplifier Left --> Speaker Left --> Sound Waves --> Microphone --> Mic In Left

SB RCA Right --> Line In Right

After the left sweep is complete you need to switch the RCA connections for the right speaker sweep. That gives you:

SB RCA Left --> Line In Right

SB RCA Right --> Amplifier Right --> Speaker Right --> Sound Waves --> Microphone --> Mic In Left

Performing the Measurement

First, turn the SB volume right down. Play the sweep file (using 'Browse Music Folder') and gradually increase the volume to a normal listening level. Be careful with volume: Playing the sweep.wav at high volume will damage your speakers.

When the levels are right remind the family to be quiet, lock the dog out of the room, start recording, and play the sweep.wav.

Audacity can be used to record the sweep. Alternatively I prefer the ALSA command line:

arecord -D hw:2,0 -c 2 -f cd left.wav

When the sweep is complete trim the recording using audacity leaving a few seconds of silence before and after the sweep, then save it to left.wav. It should look like this. Here you can see the left channel (The uneven top trace) contains the room response recorded by the microphone. The right channel contains the reference signal recorded directly from the Squeezebox.

left.wav sweep in audacity

Now is a good time to check levels. The traces should not be much smaller than shown above, and neither should they be close to clipping.

When you have a good sweep in left.wav, switch the RCA connections and record a right.wav without moving the microphone or adjusting levels.

When you are complete it is a good idea to delete sweep.wav right away. Before it turns up in a random mix.

Further Automation

It is probably best to record your first few sweeps as described above. But once you have done it a few times the process quickly becomes tedious, particularly if the computer and squeezebox are not in the same room.

It is possible to automatically start the squeezebox playing the sweep while getting alsa to record for exactly the right duration using:

echo -e "00:00:00:00:00:00 playlist play /path/to/my/sweep.wav\nexit\n" | nc localhost 9090;arecord -D hw:2,0 -c 2 -f cd -d 60 right.wav

Replace 00:00:00:00:00:00 with your player's MAC address. The -d 60 switch sets it recording for 60 seconds - a little longer than the sweep duration.

Processing

Impulse Response

The room's impulse response needs to be calculated from left.wav, right.wav, and the inverse.pcm file which was generated at the same time as your sweep.wav. Here we use sox to extract the pcm data from the two wav files, then DRC's lsconv program:

sox left.wav -t raw -c 1 -fl recorded-l.pcm mixer -l
sox left.wav -t raw -c 1 -fl reference-l.pcm mixer -r
sox right.wav -t raw -c 1 -fl recorded-r.pcm mixer -l
sox right.wav -t raw -c 1 -fl reference-r.pcm mixer -r

lsconv sweep.pcm inverse.pcm impulse-l.pcm reference-l.pcm 0.1 0.8
lsconv sweep.pcm inverse.pcm impulse-r.pcm reference-r.pcm 0.1 0.8

Filter Generation

If you are not familiar with DRC and do not already have a preferred DRC configuration:

  1. Copy /usr/local/share/drc/config/soft.drc into the same directory as your measurement files. (other .drc files are available, but soft.drc is a good starting point.)

  2. Copy a microphone calibration file from /usr/local/share/drc/mic which matches your microphone, and change the MCPointsFile line in soft.drc to refer to this file name. If your microphone is not mentioned then use a flatmic.txt file containing:

    0.0 0 0
    22050.0 0 0
    
  3. Copy a target frequency response file from /usr/local/share/drc/target and change the PSPointsFile line in soft.drc to refer to this file name. bk-3-spline.txt may be a good starting point.

The DRC manual contains more information on its configuration which is beyond the scope of this document.

DRC needs to be run twice, once for each channel:

drc --BCInFile=impulse-l.pcm --PSOutFile=filter-l.pcm --TCOutFile=test-l.pcm soft.drc
drc --BCInFile=impulse-r.pcm --PSOutFile=filter-r.pcm --TCOutFile=test-r.pcm soft.drc

Finally, the files filter-l.pcm and filter-r.pcm can be used in a BruteFIR filter.

Filter Review

It is sometimes interesting to review the frequency response of a filter (filter-l.pcm), of the room's uncorrected response (impulse-l.pcm), or of the theoretical corrected response (test-l.pcm) using Room EQ Wizard.

The floating point .pcm files loved by DRC must first be converted to integer .wav files for use in REW. The -v switch adjusts amplitude - you may need to adjust this (check in audacity). The impulse files need 45 seconds of silence trimmed from the start. This also may need to be changed to match your sweep duration.:

sox -t raw -r 44100 -v 20 -c 1 -fl impulse-l.pcm -t wav -c 1 -sw int/impulse-l.wav trim 45
sox -t raw -r 44100 -v 20 -c 1 -fl impulse-r.pcm -t wav -c 1 -sw int/impulse-r.wav trim 45
sox -t raw -r 44100 -c 1 -fl filter-l.pcm -t wav -c 1 -sw int/filter-l.wav
sox -t raw -r 44100 -c 1 -fl filter-r.pcm -t wav -c 1 -sw int/filter-r.wav
sox -t raw -r 44100 -v 0.8 -c 1 -fl test-r.pcm -t wav -c 1 -sw int/test-r.wav
sox -t raw -r 44100 -v 0.8 -c 1 -fl test-l.pcm -t wav -c 1 -sw int/test-l.wav

Inguz

The procedure described in this article may also be of advantage to users of the Inguz DRC plugin, instead of the InguzTools package. Key advantages of this approach include:

  1. You can adjust the sweep duration. A longer sweep may help if your listening environment has background noise.
  2. You can adjust the sweep start and end frequency to include (or exclude!) the subsonic range.
  3. Inguz attempts to correct for inter-channel delay, however the process described above adjust each channel independantly and leaves inter-channel delay untouched. Whether each approach is an advantage depends on whether you see inter-channel delay as something worth correcting, or an artifact of your microphone positioning.
  4. The DRC tools are much faster (2 minutes vs 15 minutes on my AMD Athlon(tm) XP 2400+) and use less memory than InguzTools. (InguzTools needs 2G!)
  5. All open source