Microcontroller Compressor

Started by sammyadam, April 17, 2023, 11:00:45 AM

Previous topic - Next topic

sammyadam

I was thinking about wether it would be worthwhile using a microcontroller to control a compressor. A search here showed up some discussion about the FMR Audio RNC.

I guess you'd full wave rectify and filter the signal and send it to the micro ADC. Then control a VCA depending upon the level getting to the dac. Attack, release and threshold could be done in software, and you should be able to get rid of any ripple by checking if the signal gets lower, then waiting for a while to check if it's gotten higer again, and only reducing the gain the signal continues to get lower.

I think the hardest part of the software would be calculating the attack time. Say we just use 8 bits of A/D. If the input gets to the level set by the threshold - at shortest attck time it should immediately reduce the level. If the attack time is longer you could have the attack time value stored in a register and use this to control a timer. Every time the timer finishes a cycle you go down 1 bit on the VCA control DAC until you get to the desired level.

I know there's a lot more to sort out on this, to work out the ratio, release etc. Suggestions are welcomed.

marcelomd

Hi!
The Darkglass Super Simmetry works like that. Microcontroller controlling an analog compressor.
I have no idea what the algorithm looks like though.
I bet there are open source compressor algorithms out there you can use as a starting point.

Ben N

Cool idea. Once you're doing microcontroller control of a VCA, you could do pretty much any dynamics function through the same bones: tremolo, ADSR, gate, whatever, and even make the loops in the code switch selectable, with multifunction controls. I know writing all that is far from trivial, and I wouldn't even know where to start, but it's doable is all I'm saying.
  • SUPPORTER

FSFX


ElectricDruid

I've done some basic experiments in this direction.

I did an envelope follower on a PIC. I wondered about the approach you proposed, doing the FWR outside the chip on the analog side, but rather than use "all" that extra circuitry, I decided I'd give it a try without, and just fed the audio direct to the chip. The ADC input had two 100K resistors to provide a midpoint bias, and the audio was coupled in with a 100n cap - dead simple. I sampled the audio at 9-bit resolution. If the most-signifcant bit was clear, I flipped the bits, and if it was set, I didn't. That's the absolute-most-naive digital fullwave rectification you can do, and it gave  me an 8-bit signal from my 9-bit input. That extra bit slightly improves the dynamic range you can measure from 50dB to 56dB, but it's still pretty lousy. Don't know how good analog env followers are, though.

Then I did some IIR filtering on it. You can't get too choosy about the coefficients on a chip with no multiply. The best way is to use things that are binary-friendly so the "multiply" can be done with bitshifts. I managed to get a reasonable range of options, and I think it'd cover most real-world uses. A lot of analog envelope followers only use a single RC for the filtering, so I tried to go one better and added a second IIR, so two-pole filtering. That worked and defnitely gives a smoother output with less ripple, as you'd expect. The frankly-lame quality of the filtering on most analog envelope followers is something I've not really understood. It's not like we don't know how to do 4-pole analog filters, so has no-one ever tried it for an envelope follower?

The end result was pretty good. You could line up the input audio waveform and the output envelope waveform on the oscilloscope and see how close it was. Of course, any "live" envelope follower is going to lag slightly behind the signal (that need not be the case if you're doing analysis on a recorded signal so you can look ahead) but it followed pretty tightly and certainly compared well to any analog envelope follower I've ever seen.

I haven't done anything with the design thus far. I was originally thinking of an autowah (envelope-followed filter) effect, but a compressor is another obvious application.

So, yeah, it can definitely be done, it's definitely worth doing, and I think you should go for it!  :icon_cool: