Units used in WDRC Compressor

The WDRC, or “Wide Dynamic Range Compressor”, is a compression algorithm that is part of our Tympan_Library. The version in our library is based directly on a C implementation written by Boys Town National Research Hospital for running on a desktop computer using pre-recorded audio. This is relevant because, if you’re trying to figure out how to use it, you might be confused by the units used in its settings.

First, for the basics of any compressor, you can browse this blog post of mine.

Second, to get a feel for the multiple kneepoints used in the WDRC, you might enjoy this live web-based graphing WDRC calculator! It makes pretty output like this:

So, once you’ve gotten a sense of the input-output characteristics of a generic compressor, and then of our specific WDRC implementation, you are ready to look at code. See next post.

Chip

The most basic place to get started with the Tympan WDRC is to use the simplest WDRC example, which is under the Arduino IDE File menu, under “Examples” under “Tympan_Library\03-Intermediate\WDRC_SingleBand”, or on GitHub here.

Looking at this code, I see that it is so simple that it doesn’t change any of the WDRC parameters. Perhaps that makes it too simple of an example?!? Sorry!

Still, it can be used to confirm that it compiles and runs.

The first place where we can really see the WDRC parameters is in the example “05-FullSystems\WDRC_8BandFIR”. In this example sketch, look at the file “GHA_Constants.h” (GHA stands for "General Hearing Aid).

In this file, you see two groups of settings: the “dsl” settings and the “gha” settings. Given that this example calls itself “8BandFIR”, this example breaks up the audio into 8 parallel frequency bands and applies a compressor to each. Then, at the end, it rejoins the 8 bands into a single “broadband” channel and applies one final compressor. Let’s focus on that last “gha” broadband compressor because will expose everything that we want to see about the WDRC compressor settings:

BTNRH_WDRC::CHA_WDRC gha = {5.f, // attack time (ms)
  300.f,    // release time (ms)
  24000.f,  // sampling rate (Hz)...ignored.  Set globally in the main program.
  115.f,    // maxdB.  calibration.  dB SPL for signal at 0dBFS.  Needs to be tailored to mic, spkrs, and mic gain.
  1.0,      // compression ratio for lowest-SPL region (ie, the expansion region) (should be < 1.0.  set to 1.0 for linear)
  0.0,      // kneepoint of end of expansion region (set very low to defeat the expansion)
  0.f,      // compression-start gain....set to zero for pure limitter
  115.f,    // compression-start kneepoint...set to some high value to make it not relevant
  1.f,      // compression ratio...set to 1.0 to make linear (to defeat)
  98.0      // output limiting threshold...hardwired to compression ratio of 10.0
};

By looking at the comments, you get an overall idea of what each setting does. It has the attack and release times, the sample rate (totally ignored), followed by the WDRC kneepoints and compression ratios. This is the good stuff.

For the kneepoints and compression ratios, you can learn everything that you need to know using that graphing calculator that I linked earlier. For me, playing with that calculator was way more helpful than words.

The odd setting here, the only one currently unexplained, is the setting named “maxdB” (shown at a value of 115). What is this??? Next post…

Chip

OK, what is “maxdB”?? In case you can’t see it, this should be read as “max dB”. But what does that mean?

This value is simply a scale factor to tell the Tympan how to interpret the SPL values that you use to specify the two kneepoints and one “output limiting threshold” that follow.

Remember, the Tympan is a digital processing device that knows nothing about “Sound Pressure Level” until you educate it. This line is its education.

Within the Tympan’s processing, the audio samples are held as floating point values spanning -1.0 to +1.0. This is the raw audio waveform. Quiet audio would have values (ie, closer to zero). Loud audio would get closer to this -1.0/+1.0 full scale range. For anyone familiar with Matlab, this is exactly how Matlab holds its audio data. There are no units here. It’s simply -1.0 to +1.0. It can mean anything.

When you set “maxdB”, you are telling the device how to interpret your kneepoint and output limiter SPL values that follow. If you tell it that you want the output limiter to be 98.0 dB SPL (per the example above), what does that mean relative to our +/-1.0 sense of full scale?? Well, since your maxdB value is 115.0 dB SPL, the Tympan sets the WDRC limiter at 98.0 - 115.0 = -17.0 dB relative to +/-1.0 full scale. Or, more specifically, it engages the output limiter at sqrt(10^( (-17.0)/10 ))= +/-0.14.

In reality, the calculation is a little more complicated than this (because of how the level estimation actually happens), but the central idea is the same: the “maxdB” is used to interpret your kneepoints and your output limiter settings. It’s just a tool to help you scale the numbers so that, in the real world, you can easily adjust your kneepoints and output limiter to have them end up where you want them.

Yes, this leads to questions of calibration. Calibration is a deep subject.

Chip

Here’s the simplest way to calibrate your system. It ignores a lot of troublesome problems that you will have to deal with in a real device. But, conceptually, it can get you started.

First, what you are calibrating is your Tympan plus your specific microphone plus your specific earphone plus your specific hardware and software gain settings in the Tympan firmware. If you change any of those elements, your calibration changes too!

Next, you do the calibration measurements.

  • Choose an example firmware to put on the Tympan. Turn off all of the compression (make it fully linear) and set all the gains to known values.
  • Play a known steady sound (a tone or narrow band noise) toward your Tympan’s mic. Target something loud but reasonable…maybe 80 dB SPL.
  • With a sound level meter, actually measure the loudness of the sound (in SPL) at the location of the Tympan’s mic.
  • Using an artificial ear plus sound level meter, record the output from the earphone that you have connected to the Tympan
  • Change gain levels within the Tympan firmware until the SPL in the artificial ear matches the SPL hitting the Tympan’s microphone. Change whichever gain you’d like, just know what the new value is so that you continue to use the new value in the future.
  • At these settings, command the Tympan to record the in-coming sound to a WAV file on the Tympan’s SD card.

Finally, you do the calibration calculations.

  • Open the WAV file on your PC
  • Analyze the WAV file to measure the average signal level relative to the full-scale of the WAV file, which is the same as full scale within the Tympan. (for example, -27 dB relative to full scale)
  • Compare this to the SPL actually measured coming out of the earphone. (for example, 80 dB SPL)
  • maxdB is the measured SPL minus the amplitude in the WAV file. So, in this example, maxdB = 80 dB - (-27 dB) = 107 dB

There are so many complications that you’ll discover and there are so many other philosophies about how this should be done, but this will get you started. You’re trying to relate the internal digital units (which are relative to “full scale”) to the real world units of SPL.

Chip