Skip to content

Commit f154755

Browse files
committed
Update readme
1 parent d2108f9 commit f154755

File tree

1 file changed

+59
-4
lines changed

1 file changed

+59
-4
lines changed

Readme.md

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,60 @@
1-
== Very low part count audio compressor based on Arduino ==
1+
# Very low part count audio compressor based on Arduino
22

3-
Hardware description to follow, but the basic idea is very simple:
4-
- Connect pin A0 to audio in, biased to 2.5V
5-
- Connect pin D3 to the gate of two 2n7000 N-Fets, back to back, switchin the signal on an off at a high rate
3+
This project aims to provide a simple to build audio-compressor based on an arduino / genuino.
4+
5+
## A small bit of theory
6+
7+
If you came here, you probably know, what an audio-compressor is used for: Reducing the dynamic range of an audio
8+
signal, often so the more subtle sounds are not affected, but the louders sounds are brought down to levels compatible
9+
with your hardware, ears, and/or neighbors.
10+
11+
Achieving a useful compression without undesirable side-effects depends on careful tuning of some parameters, though:
12+
- Attack: Onset response time, i.e. how soon the compressor starts toning down. Should be fast, but not _too_ fast. You want to cut out loudness, not crispiness.
13+
- Release: Offset response time. Usually several times longer than attack, in oder to avoid oscillation.
14+
- Threshold: Signals below a certain level should not be compressed.
15+
- Ratio: Proportion by which to tune down signals exceeding the threshold, e.g. 2, in order to cut excess in half.
16+
17+
Sounds like a perfect job for a microcontroller, right?
18+
19+
Beyond the logic and timing, however, there are two main technical difficulties: First, we need to sense the signal level to work on. Ok, not terribly difficult,
20+
but does require some tricks to achieve with an acceptable sampling rate on a microcontroller. Second, we need to modify (or output) the signal, accordingly. Typical
21+
approaches involve voltage controlled amplifiers (VCAs), J-FETs, or some other technique to transform a voltage signal into a variable resistance. Well-established,
22+
but not quite trivial, if you read up on it. Instead of these, I decided to capitalize on the main advantage of a microprocessor: Doing simple things _fast_. In this
23+
case this means switch the audio signal on and off at a rate much higher than audible sounds, in order to achieve a variable resistance very easily.
24+
25+
## A first basic version
26+
27+
The following circuit is far from ideal in many ways, but don't worry, it's easy to improve on (even without changing the microcontroller code, for the most part).
28+
But we'll start simple (and quite possibly, this may already be enough for your prupose):
29+
30+
![Basic mono schematic](https://github.com/tfry-git/compressor-arduino/raw/master/doc/basic_mono_circuit.png)
31+
32+
Let's start with the bottom half of the circuit: Here, the audio signal is decoupled via a largish capacitor, and biased to a level of roughly 2.5V, created by theory
33+
voltage divder formed from the two 1k resistors. The whole point is to convert the signal to a level suitable for sampling by the arduino. Contrary to the schematic, an
34+
electrolyte cap is perfectly fine, here, with the negative side connected to ground. It should be rather large in order to allow for low frequencies to pass. However, the exact
35+
value does not matter. Similarly, the resistor values do not matter too much at all.
36+
37+
The biased signal is now fed into the Arduino (pin A0), where it will be sampled at roughly 77kHz. The sampling accuracy is not terribly good, and so one of the requirements of this basic circuit is
38+
having a suitably large input signal (line level/headphone level is more than enough). But not a whole lot of accuracy is needed, either: The only point of this part of the circuit is to allow
39+
the Arduino to detect the current signal level, and - remember - low signal levels are not of interest in the first place.
40+
41+
The more interesting part of the circuit is the upper half. Two N-FETs are connected back to back (D of the first connected to S of the second and vice versa), which are both controlled
42+
synchronously from Arduino pin D3. These two FETs simply function as a _simple_ analog switch. The good news is that you are pretty likely to have those N-FETs in your part-collection already:
43+
A pair of 2N7000 or any other common small signal N-FET will do ok. Importantly, the FET should be _far_ inside the on-region at 4-5 Volts. Also, preferrably, the forward-voltage drop of the
44+
body diode should be as large as possible. A somewhat better choice than 2N7000 would be IRLML2502, and an even better choice will be to use a dedicated analog switch (in this particular schematic
45+
you'd want one supporting negative voltage swings!), but again, the 2N7000 will perform ok-ish, so try that, first.
46+
47+
What the switch is doing is simply turning on and off the audio signal at a rate and duty cycle controlled by Arduino digital pin 3 (PWM). The code uses a ~66kHz frequency with duty cycle adjusted
48+
between 100% and ~5%. The 66kHz switching will not be audible (your speakers will not even be able to represent such frequencies), but if you are concerned about high frequency artifact, you could
49+
easily add a simple low-pass filter.
50+
51+
That's all folks, nothing else needed. At least if all you need is switching a line level / headphone level mono signal. Need more? Read on / hang on for more sophisticated circuits built around
52+
the same idea.
53+
54+
## Adding status indicators and parameter control
55+
56+
- Acutally already implemented in the sketch. Try reading the comments, there.
57+
58+
## More to come
59+
60+
... but writing this up is more work than it may seem. If you find this useful, consider donating a bread crumb or two via Paypal: thomas.friedrichsmeier@gmx.de

0 commit comments

Comments
 (0)