-
Our goal was to a make a dynamic range compressor where the user had control over the four basic compressor settings--threshold, ratio, attack, and release--first as a function in MATLAB and then as a real-time processing unit that could be used in a Digital Audio Workstation.
-
We succeeded in making a compressor in MATLAB that allows the user to identify any audio file in the MATLAB workspace and specify threshold, ratio, attack, and release settings. The effective attack and release times were the two hardest items to implement, but all settings work as desired.
-
We built a real-time processing unit with a graphical user interface that we were able to use in a Digital Audio Workstation, but the processing unit yielded quite a bit of noise. It did not perform up to our goal. Here is a picture of the graphical user interface:
Goals
Methods
After working our way through several different methods of level detection and gain reduction, our final model of the compressor – which by far is most accurate – works as follows:
-
A custom envelope detector traces the peak level of the incoming signal by matching any rising signal that is higher than its current level, with a "fall-off" constant between 0 and 1 that allows the value to decrease at a constant rate until it reaches the next peak. As you raise the constant towards 1, less noise is apparent in the detector, but it also "hugs" the signal much less closely and results in a much slower response time. The results are to the right, with the original signal in blue and the envelope detector signal in green (with a fall-off constant equal to 0.997, which appeared to be a happy medium achieved by experimentation).
-
We then constructed a second "laggy" envelope detector that traced the first envelope detector, but took the attack and release times (as set by the user) into account. It therefore takes the attack time to rise to a new signal level and the release time to fall back to a lower one. The results are to the right, with the original audio in blue, the first envelope detector in green, and the "laggy" envelope detector in red (with an attack time of 500ms and a release time of 700ms).
-
From there, we created a formula that calculates (on a sample by sample basis) how far over the threshold, in dB, the "laggy" envelope detector is. Another fomula then applies gain reduction by multiplying this difference by the user-set ratio and subtracting that from the original audio signal. On the right is an example of the compressor in action on a sample of sung vocals. The settings used were: Threshold of -21dB, Ratio of 5:1, Attack time of 5ms, Release time of 700ms. The original audio with the 2 envelope detectors is the first image, the compressed signal – with automatic normalizing – is the second, and the gain reduction (the difference between the two) is the third.
Original Audio with Envelope Detector
Original Audio with Envelope Detector and "Laggy" Envelope Detector
Original Audio with Envelope Detectors, Compressed Audio, and Gain Reduction
Image courtesy of Peter Leonard, Khari Cousins, and Dylan Sundberg.
All images taken from graphs of the PKD Compressor and courtesy of Peter Leonard, Khari Cousins, and Dylan Sundberg.