## Math behind dynamic compression - help me to understand

DSP, Plug-in and Host development discussion.
fikiz
KVRer
2 posts since 9 Jan, 2014
Hi all.

I'm trying to build my own digital dynamic compressor using my pc and usb audio card. I read a lot of code and documentation but there's something that i still don't get.

My target is very simple: a compressor with thresold and compression ratio as parameters. No attack and release. Just for the sake of my understanding of how things work - I'd like to have an easy-but-working compressor rather than a good compressor (fine details will come later).

What I need to know is how to calculate the multiplication factor (excuse my bad jargon) I have to apply to my samples when the compression kicks in.

I'm receiving samples from my audio input, and I apply the RMS formula to the last n samples, where n is my RMS window. I convert the rms value to db:
rms_db = 20 * log10(rms)

if rms_db is higher than my defined thresold (also expressed in db, between -Inf and 0) the compression starts and it will stop when the input rms_db goes below the thresold.
Let's say in a given moment rms_db = -3, thresold_db = -3.5, and the compression ratio is 3:1. What's the math to find the gain to multiply the input sample to get the corresponding output?

Also... am I reasoning right? Or this completely wrong?

stratum
KVRAF
2115 posts since 29 May, 2012