I would like to (automatically) tune output of an audio source (i.e input) using a program which I will be writing. Do you know any source codes for PID-controller or for adaptive controller? Mostly I'd be interested in software libraries I can include to my program. Would you prefer PID or adaptive model?
If you don't know whether you need a simple PID loop or an adaptive loop you're probably not ready to start downloading code and randomly applying it.
What are you tuning? For any controller to work there has to be a defined input/output relationship that you can affect to control it, and that you can sense to use for feedback. If this I/O relationship is reasonably straightforward and does not change then you don't need adaptive control; if this I/O relationship is reasonably linear then a fairly simple loop will do -- you may not even need a full PID loop.
If you already know that you have something that's fit for PID control you can see my article at
I wouldn't recommend that you try applying an adaptive control solution unless you really understand it thoroughly. In fact, I would recommend that you investigate every alternative that you can to adaptive control
-- it's a powerful method, but it's not a magic bullet that you can casually apply and have everything turn out right.
I am trying to control audio source. So the input would be audio stream, and output would be, again, audio stream, which is tuned to make constant audio power level. At this point, it seems that PID- control is proper choice for the task, but since the task is to control audio stream on a computer, I need an PID-algorithm to do this. The article was good and it gave me good insight of what my program should do and how it should be done.
If you want to keep the volume flat, look up volume compressors. They have been around for a long time. (You will need to become familiar with attack and release times ans be able to set them properly.)
If that's not what you want, and PID is really appropriate, then I don't understand what you ask for.
You do not need a PID algorithm to do this. A standard PID loop is not frequency-sensitive.
If you're just trying to feed an audio source into a computer, what you need is called an Automatic Gain Control (AGC). A compressor (on it's own) won't do the job properly because it doesn't expand the quiet bits.
Tri-band AGC's (as used by radio & tv stations worldwide) are available off-the-shelf from several professional audio suppliers including
The compressor built into the microphone amplifier for the Mercury space capsule had a 2 dB output change for a 60 dB input change*. The headphone amplifier had only a 40 dB dynamic range, AGC in the receiver taking care of the rest.
Whenever gain to makes softer bits louder, noise is made louder as well. How could it be otherwise?
The spec was 3 dB. We accomplished it with diodes, resistors, and capacitors. Distortion never reached 1% THD even at the highest input levels.
Hi, Jerry. Using a compressor and turning up the volume increases the background noise level continuously - start, end and at all times during transmission.
An AGC will not increase background noise level during loud bits (it will probably decrease it) and will only increase noise level during quiet bits (volume increase) and then not much at all ifg properly set up, then once the input level falls below a set threshold, it will turn off the output all together.
How so? When the compressor cuts the gain back, everything through the amplifier is reduced. We probably mean different things. As I see it, a compressor is an amplifier with AGC. Here's what we did:
Microphone (5 ohm, 5 millivolts shouting). Matching transformer for 500 ohm load. (50 millivolts at output.) Current-controlled attenuator at the input to the first base, followed by 80 dB of gain to the transformer-coupled output. An extra winding on the output primary went below ground before the collector hit the rail, pulling current through the attenuator. 5 microvolts was enough to provide -3 dB audio to modulate the transmitters. 5 millivolts gave only 2 dB more. I managed to make the amplifier stable on a circuit board 1.4 x 6 inches using all discrete components (including both transformers). Whew!
We suggested a squelch, but NASA said no because it would have been a frill that could go wrong. With everything doubly redundant, there were two noise-canceling throat (contact) microphones, each with its own AGCed amplifier chain. Background noise wasn't an issue. When the astronaut wasn't talking, it didn't matter what he wasn't saying.
I did it for my Master's thesis. Afterward, a friend of my thesis adviser mentioned that an integrating AGC doesn't sound good in an AM system because it just amplifies noise, but that it isn't a bad way to go in a digital system.
History as I remember it: AGC in receivers (mostly AM receivers) was done at IF by varying the bias on so-called "variable-mu" or "remote cutoff" tubes. The distortion products created by the bias-dependent transfer characteristic were primarily at harmonics of the IF and filtered out by the selective coupling between stages. AGC is used in receivers to keep the carrier level at the detector constant, not the demodulated volume. Better receivers had an AGC threshold, below which no gain reduction was applied. That was called "delayed AGC".
Relatively distortion-free voltage-controlled gain is harder to get at audio. Devices that did that were called compressors to distinguish them from the 6SK7-style variable-mu approach. At least one early compressor for broadcast studios modulated the signal to a low RF, varied the RF gain, and restored the signal to audio with a synchronous detector. In my lexicon at least, "volume compression" and "audio AGC" are different names for the same collection of techniques.
Naturally, perfect audio AGC acting instantaneously would remove all of the signal. To avoid that, some sort of low-pass filtering is always used. Separately adjustable attack and release times are common, as well as gain suppression when the signal becomes too small to be useful.
Please expand my picture by telling me how an integrator fits into it.
The "compressor" part of a "modern professional audio compressor" (likes of Aphex, Beringer, and numerous others out there) only reduces gain by a set amount (say 3db) above a set threshold (say 0dB) _leaving the rest of the the audio stream untouched_.
In this way, the peaks are gently limited and the overall "volume" (as you hear it) can be increased without risk of distortion by clipping. There is no AGC involved (not in a true "compressor" anyway).
It is common to find such things as a "Tri-band AGC/Compressor/Expander/Limiter" used for radio & TV broadcast that splits the incoming audio stream into high, mid and low frequencies, adjust the level of each to what you want, squashes the peaks, lifts the low spots, blocks any spikes and pops and then recombines it all for transmission... and from the sound of it would have been ideal for the Space Program. :-)
Maybe so. I wish car ratios had a way to reduce the dynamic range of a received signal. When soft passages of, say, Schubert are loud enough to be heard despite road noise, crescendos get to be unpleasantly loud.