Audio Limiter

Hello ! I am completely new to electronics/arduino, but I have some programming knowledge. I have an audio "limiter" project in my mind. The program would be this simple :

  • Takes an analog audio input (from a jack plug)
  • Check if it is below a certain threshold (determinated by a knob) ->> If yes, then output the exact same input to the headphone ->> If no, then output the threshold value to the headphone

So basically I want to cut everything that goes over a certain threshold (I am aware it will create clipping).

Here are my questions: - Which module is needed to read the two analog inputs of a jack (as it is stereo) and output to another jack ? (I read that the arduino can't output analog) - Will this create latency ? Does adding programmable leds/switch contribute to adding audio latency ? - Is an arduino strong enough to run this, as it should run the program 44 100 times per second (a good bitrate) ? If yes, then what arduino model should I get ?

That was a lot of questions, any help would be greatly appreciated! Thank you :D

None of the arduinos are powerful enough to handle 44kHz 16 bit audio. However there are I2C modules („digital potentiometers“) which can be controlled by an arduino. You can use the analog input of an arduino to measure the level of the signal. No extra module needed. You simply „split“ the signal, no electronic parts needed. One branch goes to the analog input. The other branch goes to input of the digital pot. The arduino then sets the volume of the digital pot module See here for some digital pot chips / modules. https://forum.arduino.cc/index.php?topic=391969.msg2698953#msg2698953

Thomas

No, normal Arduinos cannot do this. Their ADC is not fast enough for high sample rates, the bit depth is way too low for audio applications, and most Arduinos do not have an analog output.

A Teensy 3.x should be able to do what you want. It has I2S interfaces with DMA, and a much more capable ARM processor. You'll need an I2S DAC and an I2S ADC.

Teensy Audio System Design Tool

All conversions will create latency. The questions you should be asking are "how much", and "how much can I afford". Going from analog to digital audio and back again will introduce some discretization noise, but it should be inaudible.

Note that this can be easily done using only analog components. Compressors and limiters have been analog devices for a long time, before digital took over, and many audio engineers still prefer the analog versions today.

Pieter

Okay, I will check out the I2S/I2C modules. Thank you for answering :slight_smile:

I believe that what you are looking for is a a COMPANDER - input compressor, output expander.

if you listen to the radio, it is highly companded. the volume from words to music to commercials, soft whispers or shouting, are all companded to the same volume.

This is why you never change the station and get blasted with loud noises.

Okay, I will check out the I2S/I2C modules.

IMO, you are better-off using hydrocontrol’s suggestion of a digital pot. A digital pot is controlled digitally, but the signal path is analog. (There are I2C digital pots.) Since the signal-path is analog there is no latency. The Arduino should be fast-enough since it won’t have to digitize and process the audio. (It’s not fast-enough to accurately sample/read 20kHz, but if you’re clipping at 20kHz you’ve got bigger problems.) :wink:

The problem with doing it digitally that the (analog) signal has to be limited before the signal clips the ADC. Once the ADC is clipped, it’s too late.

  • Will this create latency ? Does adding programmable leds/switch contribute to adding audio latency ?

No, not necessarily. Hopefully you can write to the LEDs in-between samples… You might have to live with one or two samples of latency, but that’s just a few microseconds and not noticeable. The latency in a computer is related to multi-tasking… The operating system is always multitasking even when you’re running only one application. So when you’re recording the audio data goes-into a buffer (a holding tank) at a smooth-constant rate. Whenever the operating system gets-around to it, it reads the buffer in a quick burst and writes the data to the hard drive. So the buffer is a delay. If the buffer is too small or if some process “hogs” the system for a few miliseconds too long, you get buffer-overflow and a glitch. When you play-back, the data is written to the playback buffer in a quick-burst and it flows-out at a smooth-constant rate. If the buffer is too small or if it doesn’t get re-filled in time, you get buffer underflow and a glitch.

However… If you can live with latency there is a big advantage to some delay in a limiter… The limiter can effectively “look ahead” and limit only where needed instead of kicking-in when you get close to clipping. (But, you still can’t clip the ADC.)

I believe that what you are looking for is a COMPANDER - input compressor, output expander.

if you listen to the radio, it is highly companded. the volume from words to music to commercials, soft whispers or shouting, are all companded to the same volume

No... Radio (and [u]Loudness War CDs/MPs)[/u] is compressed, but never re-expanded. It's actually impossible to un-do this kind of compression because we don't know the parameters and there is usually compression the individual tracks before mixing. It's also impossible to reverse limiting because it's impossible to know the original amplitude and wave shape .

There are "de-clippers" and "peak unlimiters" that try to undo limiting or clipping, but they can only guess the original amplitude and wave shape.

Compression/expansion was used in DBX noise reduction and with analog telephone. The idea is to crank-up the signal when it's weak (compression during recording or transmission) for a good signal-to-noise ratio. When played-back (or received) it's turned back down (expanded) so the signal is correct but the noise (analog tape hiss, etc.) is reduced.

Dynamic compression reduces dynamic range (or "dynamic contrast") by making loud parts quieter and/or making quiet sounds louder. Compression is used a LOT in audio production. In practice, it's normally used to "push down" the louder parts, then "make-up gain" is applied to make "everything loud".

Limiting is a special kind of compression, and it's also often used with make-up gain.

Dynamic expansion increases dynamic range by making the loud parts louder, or the quiet parts quieter. Expansion is almost never used, except for a noise gate which is downward expansion (quiet sounds made quieter or killed completely).

...Don't confuse dynamic compression with file compression... MP3 makes a smaller file. It doesn't change the dynamics of the sound.