# REW EQ filters and SoX FIR



## robertopisa (Jan 12, 2013)

After obtaining the following EQ filters with REW


```
Filter  1: ON  PK       Fc    41.5 Hz  Gain  -5.8 dB  Q 12.22
Filter  2: ON  PK       Fc    47.2 Hz  Gain   1.3 dB  Q  7.63
Filter  3: ON  PK       Fc    57.0 Hz  Gain  -5.7 dB  Q 10.31
Filter  4: ON  PK       Fc    63.9 Hz  Gain  -3.1 dB  Q 14.09
Filter  5: ON  PK       Fc     102 Hz  Gain   1.4 dB  Q  6.62
Filter  6: ON  PK       Fc     118 Hz  Gain  -6.2 dB  Q  9.44
Filter  7: ON  PK       Fc     133 Hz  Gain  -6.3 dB  Q 15.40
```
I would like to use them in SoX (simply because my NAS can run it). Any help/suggestion please?

Idea #1: use Sox's *equalizer* option
Idea #2: use Sox's *fir* option for its FFT convolution FIR coefficients

From SoX's manual

_equalizer frequency[k] width[q|o|h|k] gain_

Apply a two-pole peaking equalisation (EQ) filter. With this filter, the signal-level at and around a selected frequency can be increased or decreased, whilst (unlike band-pass and band-reject filters) that at all other frequencies is unchanged.
frequency gives the filter’s central frequency in Hz, width, the band-width, and gain the required gain or attenuation in dB. Beware of Clipping when using a positive gain.
In order to produce complex equalisation curves, this effect can be given several times, each with a different central frequency.


_fir [coefs-file|coefs]_

Use SoX’s FFT convolution engine with given FIR filter coefficients. If a single argument is given then this is treated as the name of a file containing the filter coefficients (white-space separated; may contain ‘#’ comments). If the given filename is ‘−’, or if no argument is given, then the coefficients are read from the ‘standard input’ (stdin); otherwise, coefficients may be given on the command line. Examples:
sox infile outfile fir 0.0195 −0.082 0.234 0.891 −0.145 0.043 
sox infile outfile fir coefs.txt
with coefs.txt containing
# HP filter
# freq=10000
1.2311233052619888e−01
−4.4777096106211783e−01
5.1031563346705155e−01
−6.6502926320995331e−02
...


Thanks
-R


----------



## AudiocRaver (Jun 6, 2012)

If I understand correctly, you would like to use SoX as a real-time online continuously-streaming sound processor. It does not do that. It is more like an on-demand offline batch sound file processor, with a command line interface (there may be gui variants). From a command line, you type in the SoX command, a series of file names, and the processes to be applied, something like...

sox recital.au −b 16 recital.wav channels 1 rate 16k fade 3 norm

and it gives you new files with the changes applied. It may sound archaic, but it is incredibly powerful and useful, great for file format conversions, great if you have 100 files that need a 3 dB gain reduction factor applied, stuff like that.

Does that answer your question?


----------



## robertopisa (Jan 12, 2013)

Thanks for the reply. Actually not 

I am legally hacking my Synology NAS + Logitech Media Server on it, as I use them also as a DLNA music sever. Due to the limited computing power of the Synology processor, it supports sox but not, say, brutefir. When my DLNA client (player) asks for a music file, it receives a WAV file that is the outcome of sox launched on the fly. I would say that this scheme is not batch processing: it allows me to use sox as an internal pipelined filter (for example I invert polarity using sox -v -1.0) when a file is streamed outside the NAS, withuot the need of batch conversion. 

But my question is not whether sox is batch or not. What it would be nice to know is if launching

Idea #1: 


```
sox input.flac output.wav equalizer 41.5 12.22q -5.8 equalizer 47.2 7.63q 1.3 equalizer 57.0 10.31q -5.7 equalizer 63.9 14.09q -3.1 equalizer 102 6.62q 1.4 equalizer 118 9.44q -6.2 equalizer 133 15.40q -6.3
```
is better or worse than using Sox's FFT

Idea #2:

```
sox input.flac output.wav fir coeffs
```
where the coeffs are the convolution coefficients of SoX's FFT. In the latter case, how can I get these coefficients from REW's EQ filters.

Thank you
-R




AudiocRaver said:


> If I understand correctly, you would like to use SoX as a real-time online continuously-streaming sound processor. It does not do that. It is more like an on-demand offline batch sound file processor, with a command line interface (there may be gui variants). From a command line, you type in the SoX command, a series of file names, and the processes to be applied, something like...
> 
> sox recital.au −b 16 recital.wav channels 1 rate 16k fade 3 norm
> 
> ...


----------



## AudiocRaver (Jun 6, 2012)

Ah, I see what you are doing. An offline process, performed very quickly at just the right moment, becomes "almost real time." Gotcha. Very nice.

You can get the convolution coefficients from REW via FILE > EXPORT > FILTERS IMPULSE RESPONSE AS WAV

As you know, the filters are all minimum phase.

I am a bit of a convolution fan, but in answer to your question, it would seem like applying the filters, as in your first example, would be the "purer" approach, simpler calculations involved. But SoX performs all 32-bit calculations, if I am remembering correctly, so it shouldn't matter much.

Here would be an interesting experiment:
Generate a set of filters and the filter impulse in REW
Use SoX to process sound file A with the filters => A1
Use SoX to process sound file A with the convolution/impulse => A2
Use Sox to calculate the difference, (A1 - A2 => X), or (A1 + (A2 X -1) => X)
Run X through a spectrum analyzer, see what is left, hopefully nothing.

If X is nothing, it doesn't matter which process you use - I would still probably vote for the simpler approach, filter calculations. If X is not nothing..... Well, then you have more questions to get answered. Welcome to Science Lab Earth.:huh:


----------



## robertopisa (Jan 12, 2013)

Thanks, this is a great suggestion, I will try to implement it 
_R


----------



## Wayne A. Pflughaupt (Apr 13, 2006)

robertopisa said:


> After obtaining the following EQ filters with REW
> 
> 
> ```
> ...


Most likely Filter 6 is the only one of any legitimate value. The rest either don’t have enough change in gain to make an audible difference, or are too narrow. Typically low frequency filters that boost or cut only a couple dB or less don’t make an audible change (Filters 2 & 5). Filters tighter than 1/6-octave (Q 8.7) are notch filters and probably should be avoided as well. If you haven’t already, you might want to give my “Minimal EQ” article a read – you can access it from the link in my signature.

Regards, 
Wayne


----------



## AudiocRaver (Jun 6, 2012)

Agree with Wayne P. it might be worth taking a second look at the filter values before implementing. I would want to see the REW before & after plots before making a call on specific values. Do read his article, it is a good one.

My approach (pretty consistent with Wayne P.'s) is 1) set the target line for minimum needed correction and none below the LF rolloff point, AND little or no individual boosting 2) see what REW comes up with, 3) tweak by hand, remove those not needed or not doing much, see where one hand-created filter might replace 2 or more that REW generated, allow only broad boosts, never narrow (bad bad) etc. I am not totally against a narrow cut filter if I have verified by different mic positions that what it is correcting exists through the listening area.


----------



## robertopisa (Jan 12, 2013)

Dear AudiocRaver and Wayne,

I'm reading and implementing your suggestions to produce filters by hands. Actually, the idea I'm working is to compute the modal resonances of the room with REW, and use modal filters: they are essentially PK filters where T60 for some modal resonances are given, and they are then transformed into Q values.

I was surprised that my Synology NAS can run sox with these filters, so music can exit my NAS already filtered. Hope that this idea can be spread, since it does not force to change your favorite player.

Thanks
-Roberto


----------



## AudiocRaver (Jun 6, 2012)

robertopisa said:


> Dear AudiocRaver and Wayne,
> 
> I'm reading and implementing your suggestions to produce filters by hands. Actually, the idea I'm working is to compute the modal resonances of the room with REW, and use modal filters: they are essentially PK filters where T60 for some modal resonances are given, and they are then transformed into Q values.
> 
> ...


Great work.

I love your NAS file processing idea. Just curious, once a track gets processed/filtered, is it saved for future access, other than in cache, or does it get processed at each accessing? Not that it affect anything, just curious.


----------



## robertopisa (Jan 12, 2013)

Really sorry to have missed your reply. 

Here it is how to transform you LMS (Logitech Media Server) installed on Synology as a simple DSP unit. This processing is performed on the fly each time, and it seems to me that there is no caching. Fortunately, when I feed the resulting file to my DLNA player I cannot witness any drop even with 24/94 hi-rez audio files.

The mods are quite simple but you need to have access to CLI (Common Line Interface), which is well documented on the Synology Web site. I am quite confident that these mods can be made also on other kinds of NAS that can install LMS, since the mods are on the LMS rather than the hosting NAS firmware.

1. Reach the LMS installed directory, which is /volume1/@appstore/SqueezeCenter/ in Synology.

2. Modify convert.conf as follows (it is a diff with the original file), where I change the behavior only for flac files (I store everything in this format) and use a "fake" *ssox* program instead of sox:


```
< 	#[flac] -dcs --force-raw-format --endian=little --sign=signed $START$ $END$ -- $FILE$
< 	# fake ssox instead of sox
< 	[ssox] -q -t flac $FILE$ -t wav - 
< 	
---
> 	[flac] -dcs --force-raw-format --endian=little --sign=signed $START$ $END$ -- $FILE$
```
3. At this point, reach the Bin directory in /volume1/@appstore/SqueezeCenter/Bin and create the executable file ssox 


```
touch ssox; chmod +x ssox
```

4. Write inside the ssox file the actual sox command, note that I can also *invert* the polarity of the audio files using the option "-v -1.0" as an example, and each *equalizer* option has the format "frequency q-value decibel" for its argument:


```
#!/bin/ash
/volume1/@appstore/SqueezeCenter/Bin/sox -v -1.0 $* equalizer 57.0 10.05q -4.0 equalizer 72.0 12.15q -3.0 equalizer 121 14.58 -3.0 equalizer 135 15.31q -4.0
```
The cute thing is that your DLNA player sees the incoming file as an innocent WAV file while instead it is an already DSPed FLAC file. This also keeps the processing overload of the DLNA player at a minimum since the WAV is faster to play (no decompression needed on the DLNA player side).

-R




AudiocRaver said:


> Great work.
> 
> I love your NAS file processing idea. Just curious, once a track gets processed/filtered, is it saved for future access, other than in cache, or does it get processed at each accessing? Not that it affect anything, just curious.


----------



## AudiocRaver (Jun 6, 2012)

Very nice. It always tickles the funny bone to see such an innovative, elegant solution. I count about 10 lines of code.:T SoX is a nice tool, isn't it?

Thanks for the detail.


----------



## robertopisa (Jan 12, 2013)

sox is very nice indeed.
The fact the Synology supports it (actually Logitch Media Server) makes it easy to correct room modes on any devise that uses LMS
-R 



AudiocRaver said:


> Very nice. It always tickles the funny bone to see such an innovative, elegant solution. I count about 10 lines of code.:T SoX is a nice tool, isn't it?
> 
> Thanks for the detail.


----------



## isabido (Apr 15, 2012)

The first excuse my bad English. 

You would know as to send a separate EQ for each channel?

This is my script line for run Airplay protocol with EQ.


> shairport -o pipe /dev/stdout | sox -t raw -e si -c 2 -b16 -r 44100 - -t alsa default equalizer 81 2q 2.1 equalizer 120 8.37q -16.6 equalizer 198 2q -4.2 equalizer 152 5.38q 4 equalizer 58.7 9.6q -7


Thanks in advanced!


----------



## jiiteepee (Oct 20, 2013)

Wayne A. Pflughaupt said:


> robertopisa said:
> 
> 
> > After obtaining the following EQ filters with REW
> ...


Hmm... :


----------



## palindrom (Jul 12, 2014)

This is how to convert the REW Filter TXT Export to SOX equalizer:



robertopisa said:


> After obtaining the following EQ filters with REW
> 
> 
> ```
> ...




```
equalizer	41.5	12.22q	-5.8
equalizer	47.2	7.63q		1.3
equalizer	57.0	10.31q	-5.7
equalizer	63.9	14.09q	-3.1
equalizer	102	6.62q		1.4
equalizer	118	9.44q		-6.2
equalizer	133	15.40q	-6.3
```
to call it via batch the CMD line should look like:

```
sox.exe -V0 -q [I]{FileName}[/I] -r 44100 --type FLAC --compression 8 --bits 16 --no-dither equalizer	41.5	12.22q	-5.8 equalizer	47.2	7.63q		1.3 equalizer	57.0	10.31q	-5.7 equalizer	 3.9	14.09q	-3.1 equalizer	102	6.62q		1.4 equalizer	118	9.44q		-6.2 equalizer	133	15.40q	-6.3
```


----------



## palindrom (Jul 12, 2014)

robertopisa said:


> sox is very nice indeed.
> The fact the Synology supports it (actually Logitch Media Server) makes it easy to correct room modes on any devise that uses LMS
> -R


You can use SOX to down-mix multi channel sources on the fly to Dolby Surround Pro Logic for your Logitech Media Server (LMS) too. This (and DRC) will improve the sound of your Squeeze Box Touch or Squeeze Box Radio dramatically.


----------

