Microcontroller Based Audio Volume Level Compressor

In an effort listen to his music on shuffle without the need to touch the volume knob [Mike] build his own automatic volume leveling hardware. He knows what you’re thinking right now: there’s software to do that for you. But building the feature in hardware is a great stepping off point for a project.

He started the prototype using LabVIEW along with a Mobile Studio development board and a Bus Pirate. This project will be a mix of digital and analog components and it’s a bit easier starting off the exploration with these tools rather than jumping right into the AVR code.

The circuit will sample the incoming audio, modify it accordingly, and output the result. The output side is where the Bus Pirate really shines. He’s using some MCP42010 digital potentiometer chips to make the necessary changes to the levels. They communicate via SPI and it’s nice to have the Bus Pirate’s terminal to issue commands without the need to reflash a microcontroller.

[Mike] made a video showing an audio waveform with and without the hardware leveling. Sound quality is still great, and each clip is played at a reasonably comfortable listening level. We’ve embedded that demonstration after the break.


18 thoughts on “Microcontroller Based Audio Volume Level Compressor

  1. +1 for BusPirate!

    I spent a couple of hours this weekend writing a set of functions to drive a Noritake SPI VFD from an Arduino board, and I would have gone mad without my BusPirate.

    This was my first taste of SPI, and I saved huge amounts of time by using the BusPirate to get my head around the finer points of the bus operation and command use, rather than uploading a new sketch to my board each time I wanted to change a register map or time delay, etc.

    When you factor in the fact it can also function as a SPI bus sniffer, and also talks I^2C, 1-Wire and more, I can’t really say enough good things about this little box!

  2. Haven’t read this yet, but I need this so bad! Why isn’t this built into tv’s so I can watch movies without waking my family up at 3 am or so low that I can’t hear the speech!

    1. Some TVs have exactly that, and call it something like “night mode”.

      I’m thinking this is something that’s more in the realm of analog circuitry. There are plenty of simple compressor schematics floating around the internet that do the job just fine, and don’t need to bring a microcontroller in to the equation.

    2. Many (most? all?) DVD players can do this: Amplitude compression is a feature of Dolby Digital for exactly this reason.

      So if “watching movies at 3AM” means “playing a DVD,” chances are that your needs are just a read of the fine manual away.

  3. Two thoughts:
    1) If it’s sampling as it plays with a short timebase that could get very annoying on music where contrasts in volume are required.
    2) On TV, to stop the damn stupid increase in volume used for adverts, this is a great little project inspiration.

  4. I made something like this ages ago using a PGA2310 and ATmega8. Connection via USB to the PC, LED 7 seg display and a rotary controller for manual level setting. I made a little WinAMP plugin to automatically set the volume with ReplayGain data in file tags.

    It was pretty good for listening to random tracks. The only thing was that the sound quality was less than I would have liked because it was made up on breadboard, so I had planned to do an updated version on PCB. Got as far as setting up a nice colour LCD I got off eBay but after doing some measurements I think LED is best. In particular static LED displays (not multiplexed) because they don’t create any switching noise. Even the noise from the LCD refresh scanning was measurable. It will need a completely isolated power supply for the audio side anyway but no need to bring more noise in when ‘595s can eliminate the problem.

  5. verry nice.
    i’m planning something similar, an auto ducker. for microphonr talkover.
    its basicly the same idea but thr microphone controls the volumeof the music. so that when you speak the music fades out and when you stop speaking it fades back in.

    how many steps do those digital pots have?

    1. Why do that, when plugging the microphone’s audio into the sidechain input of almost any random, already-put-together compressor will do it for you? Used compressors can be had really, really cheap.

      (That said, I hate the way ducking sounds, and wish for the technique to have never been developed to begin with.)

  6. I admit I haven’t read the post completely.

    But to keep the volume level nearly constant it is possible to use simple AGC like in radios. Sound is rectified and filtered, and then this control voltage is used to reduce base current of transistor. In this way more sound output -> more negative base current -> less output. It is self-regulating. With single transistor you could get up to 100:1 dynamic range I think.


Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.