jcjr PeakLimit 2

Copyright (C) 2016 and later James Chandler Jr

Web: http://www.errnum.co

Contact: errnum@gmail.com

License: GPL - http://www.gnu.org/licenses/gpl.html

Version: 1.0

Contents

Download and Installation

Overview

Controls

Metering

Signal Flow

Practical Applications

Overview

PeakLimit 2 is a Reaper jsfx lookahead peak limiter intended to apply transparent peak limiting.

Some of my old songs needed Peak-to-Average Ratio reduced by about 4 dB. It seemed reasonable to try about 2 dB of transparent slow compression followed by 2 dB of transparent peak limiting.

After writing the RMS Compressor and Limiter plugins good enough to finish my old songs, I added more features though the focus remains on gentle low-distortion sculpting.

Controls

Ceiling (dB)

Range: -6 dB to -0.1 dB adjustable in tenth-dB increments.

Ceiling is the "brick wall" loudest peak level allowed at the limiter output.

A ceiling value of -0.3 dB was popular in early years of digital peak limiting such as CD audio mastering. Nowadays ceiling values in the ballpark of -1.0 dB seem more fashionable.

A practical reason for the more-conservative -1 dB ceiling-- Some data-compressed formats such as MP3 can distort when peaks are allowed to go "all the way to the top". Which can be caused by "intersample peaks" louder than 0.0 dB during playback, largely due to mathematical issues how digital audio and lossy data compression works. There can be cases where all the discrete digital samples in the audio file are less than 0 DB-- But when converted into analog so that you can hear the music, some of the continuous analog peaks "in-between the discrete digital samples" can exceed 0 dB and cause analog clipping. A ceiling of -1 dB offers more safety headroom so that distorted intersample peaks are less likely to occur.

There are also new social pressures. "Loudness Wars" initiatives because over-loud music offends some listeners. Government initiatives setting new lower limits on broadcast audio loudness. To avoid annoying customers, many music streaming services have begun to automatically "turn down the level" of over-loud songs. Perhaps there is now less motivation for misguided artists to release ugly louder-than-snot music.

In-depth explanation is beyond the scope of this little manual. Unsurprisingly there are numerous opinions. If you wish to know more then you can begin by googling "loudness wars".

Threshold (dB)

Range: -24 dB to -0.1 dB adjustable in tenth-dB increments.

Threshold is the peak input level above which hard limiting occurs. Makeup gain is automatically calculated such that an input level just kissing Threshold dB gets enough gain to reach an output level of Ceiling dB.

For example, if Ceiling = -1.0 dB and Threshold = -6 dB-- The input signal gets a default +5 dB of makeup gain. Input peaks reaching the -6.0 dB input Threshold with +5 dB gain, would have an output level of -1.0 dB which is the output Ceiling value. Peaks louder than the -6 dB input Threshold get hard limited.

With -1 dB Ceiling and -6 dB Threshold-- The entire input gets +5 dB louder at the output. Exceopt that gain is temporarily reduced for input peaks louder than -6 dB. That temporary gain reduction is the hard limiting. For example if the input has a short peak of -5 dB (1 dB higher than the Threshold) then the makeup gain is temporarily reduced from +5 dB down to +4 dB in order to limit the output level to its -1 dB Ceiling. [ -5 dB input peak + 4 dB of gain ] = -1 dB peak output.

DAW Float-format computer digital audio can exceed 0 dB inside the computer without distortion, so long as levels are turned back down below 0 dB before saving to non-float file formats or playing thru analog outputs. So with a -6 dB Threshold and -1 dB Ceiling, there could be a loud input peak for example +12 dB (or any other real hot level). In which case the limiter would temporarily turn down the gain to -13 dB so that the peak output would never exceed the -1 dB Ceiling. [+12 dB input peak - 13 dB of gain ] = -1 dB peak output, the output Ceiling setting.

Simple Control Summary

Limiters typically work best when used conservatively applying small rare gain changes. But basically, first decide on your desired peak output ceiling. Then the output gets louder as you drag the Threshold slider toward the left. Lowering the Threshold raises the gain and also causes more frequent and deeper peak limiting. It seems obvious that when you raise audio gain, then there will be more peaks which would be louder than the Ceiling unless they get limited.

For example if you move the Threshold slider all the way to -24 dB then with a -1 dB Ceiling, there would be +23 dB of makeup gain. That is a lot of gain. If the input audio is fairly loud, then that much default makeup gain could cause the majority of the music to be over-threshold, and the limiter would be applying gain reduction to limit the output the majority of the time.

Metering


Meters are auto-sized to fit the plugin window. A small-sized plugin window shows a small meter. A big-sized plugin window shows a big meter. If you want a bigger meter then drag the plugin window bigger.

Input / Output Meters

Peak: Instant peak hold, decaying about 1 dB per 100 ms.

Fast RMS: Instant RMS level with fast decay. This part of the meter is fast enough to flicker on-screen. Punchy audio with many transients would strongly flicker. Smooth audio with fewer transients would show minimal flicker.

VU RMS: VU meter ballistics-- Both the VU Attack and Release require about 300 ms to reach 99 percent of the RMS audio level.

Slow RMS: A slow indicator showing a 10 second average of the Audio Level.

Max Peak: This remembers the Maximum Peak encountered since the last PeakLimit reset.

Max VU: This remembers the Maximum VU encountered since the last PeakLimit reset.

Gain Meter

Gain: Draws a red bar downward (toward meter left) from the level of the current calculated makeup gain. The current makeup gain also happens to be the Max gain. When used conservatively, slight limiting of rare peaks, gain reduction can duck and recover so fast that a "normal speed" display would miss out on drawing some gain changes while other gain changes draw then erase too quickly for the eye to notice.

Therefore the gain meter release is "slowed down" so that a single brief peaklimit event could light the meter for a half second or more. The actual PeakLimit gain which is applied to the audio happens fast. Only the meter display is "time stretched" to make the meter easier to read.

This is a difficult GUI design decision. On one hand it is silly to draw gain changes so fast that the eye can't see them. On the other hand a time stretched meter display could be deceptive, leading the user to conclude that more limiting is happening than is actually the case. Keep in mind that if you are limiting conservatively with very small occasional peaklimit events, the time-stretched meter might imply more limiting activity than is actually taking place.

Max Gain: This remembers the Maximum Gain encountered since the last PeakLimit reset. Which is the same as the current default makeup gain. When used conservatively, some short peaklimit gain ducking might be only a tenth of a dB or less, peaks just barely peeking over-threshold. Small gain changes too small to clearly see on the meter even if the meter gain indicator is "slowed down" as described above. Gain changes so small as to draw only a single tiny column of red on the meter. Even gain change so small that not even one column of pixels get colored red.

Therefore the Max Gain indicator also acts as a peaklimit activity light to help see "very small" gain change events. The Max Gain indicator draws in red when not limiting. The Max Gain indicator flashes bright yellow when peaklimit events occur. The indicator flash time is time-stretched in order to aid visibility. A single tiny short peaklimit event might flash the indicator for a half second or more.

So there is similar risk as with the "time stretched" gain meter-- Remember that the flashes are stretched-- That in some cases the flashes might imply frequent limiting when actually there is very little limiting activity. Perhaps rare brief gain changes occuring only the once per second which would be necessary to keep the "time stretched" limit indicator always turned on.

Min Gain: This remembers the Minimum Gain encountered since the last PeakLimit reset.

Auto-Release Meter

The Auto-Release meter shows the current auto-release time constant at any time during playback.

Rare individual peaks can be transparently limited with very quick gain-ducking. Short individual peaks are cleanly ducked with only about 2 ms attack lookahead gain change before a peak and about 4 ms release after the peak. Longer-duration or lower-frequency individual peaks have longer attack and release times. Ridiculous loud low-frequency peaks could have up to 24 ms attack time lookahead gain change before a peak and 50+ ms release time after the peak.

The above fast-ducking is quite transparent on occasional peaks. However if you push into heavy limiting with frequent gain-ducking, and long strings of gain-ducking events on very loud sustained notes, especially bass notes-- The normal short attack and release no longer prevents distortion. Fast attack and release can transparently limit rare peaks but frequent peaks need longer release times. The heavier you limit, the longer a release time is required to avoid audible distortion.

Therefore jcjr PeakLimit 2 has an adaptive auto-release feature. The auto-release envelope is inactive when over-threshold peaks are rare. As over-threshold peaks become more frequent (caused by heavier limiting) the auto-release time increases. Very heavy limiting could drive the auto-release time up to its maximum of 1000 ms extra release time (in addition to the normal shorter release times always applied to any rare individual peaks).

The user can use the tool to his own personal taste. When writing the tool I imagined auto-release as a "distortion prevention failsafe" rather than a feature active the majority of the time during processing. I imagined if conservatively limiting a song so that occasional peaks get attenuated a dB or two without needing auto-release, but if the song happens to have a couple of outrageously hot little sections which would distort without auto-release-- The song would go cooking thru playback limiting occasional brief mild overs without triggering auto-release, but maybe a couple or three times in the song auto-release might temporarily be driven up to 20 or even 50 ms in response to brutally loud short segments. Drummer got real excited or the vocalist sang one phrase louder than we could ever imagine.

PeakLimit 2 will continue to peaklimit even if driven up to steady 100 ms, or 500 ms, or even 1000 ms auto-release levels. If you like the sound or behavior when limiting hard enough to drive up the auto-release time, then by all means use the tool so that it pleases you. Just a caution that once auto-release gets steadily "pretty long" thruout a song, the song won't continue to get any "louder" beyond a certain point. At high auto-release levels the song will remain generally clean-sounding and about the same perceived loudness, and the song will just pump a little more.

When limiting hard enough to drive up a steady large auto-release level, it will continue to limit peaks but will tend to behave more like an old-fashioned auto-level effect, rather than a fast peak limiter effect. But if you need an auto-level effect then maybe you will like the result of hard-driving jcjr Peaklimit 2.

Signal Flow


Audio Path

The audio path is simple. Computed gain is applied to the delayed Input to create the delayed peaklimited Output signal.

Control Path

Peaklimiting always has independent processing for left vs right channels. When used conservatively, peak-ducking gain changes should not occur often enough, with sufficient duration, for transient gain change on the left channel to spoil the stereo image of the right channel or vice-versa. Because peaks can be rather uncorrelated between channels in a stereo mix, stereo linking seems counter-productive, needlessly peaklimiting the right channel because the left channel momentarily got too loud, or vice-versa.

However the auto-release envelope is mono, derived from both left and right Input channels. If heavy limiting drives auto-release to fairly long release times, mis-matched release times on left vs right channel could conceivably cause a "wandering stereo image" or some other odd-sounding result. Even if loud peaks in the left channel might happen to be primarily responsible for driving-up the auto-release time, the right channel gets the same auto-release amount, and vice-versa.

Intersample Peak Detector: Attempts to estimate the "true interpolated peak" levels, which can be bigger than the discrete sample values in the audio.

Synthetic Lookahead Peak Envelope: I call it a synthetic peak envelope because PeakLimit 2 "draws in" lookahead control shapes in simple geometric patterns, in response to detected over-threshold peaks. The synthetic envelope is similar to a simple DAW volume automation envelope or a synthesizer ASR envelope. Such a simple envelope naturally contains "not very much" high frequency content. In contrast, most dynamics processors generate control envelopes by rectifying the audio in some way and then lowpass filtering high frequencies from the rectified audio "as good possible".

All dynamic processors are nonlinear processors. Multiplying the control envelope against the audio in order to ride gain, unavoidably causes intermodulation and also risks aliasing. Every frequency in the audio gets multiplied against every frequency in the control envelope, forming sum and difference frequencies in the output. If the audio might happen to contain 100 Hz and the control envelope might happen to contain 76 Hz, then the output will contain at least a little bit of 176 Hz and 24 Hz added along with the 100 Hz in the original audio.

This control intermodulation is unavoidable, so the best we can do is to arrange an algorithm to have "not noticeable" small amounts of added distortion. A strategy to minimize audible distortion is to use smooth control envelopes with as few high harmonics possible which can still achieve what the plugin wants to do. A fast envelope will have more high harmonics than a slow envelope, but peaklimiting generally demands "fairly fast" envelopes, so we can't cure it by using slow smooth envelopes as seen in jcjr RMSComp.

A fast peaklimiting envelope is hard to derive by directly rectifying/filtering audio to make a control envelope sufficiently smooth and lacking in high frequencies. The "synthetic envelope" divorces the envelope from the nature of the audio (to a degree) so that the synthetic peak envelope does not inherit numerous different high frequencies which might be in the source audio. The synthetic envelope yielding (IMO) a smoother fast envelope having minimal high-frequency content.

Fourth Order Lowpass Smoother: The synthetic envelope is further smoothed with a 24 dB per octave lowpass filter which is -12 dB at 800 Hz, -24 dB at 1.6 kHz, -48 dB at 3.2 kHz, -72 dB at 6.4 kHz, -96 dB at 12.8 kHz-- Further attenuating whatever high harmonics may be in the synthetic envelope. In time-domain, the lowpass filter makes the synthetic envelope a smooth curve. The filtered lookahead before a peak is a smooth rising sigmoid (S-shape) and the release after a peak is a smooth falling sigmoid.

Auto-Release Smoother: The lowpass-smoothed synthetic envelope is further smoothed by the instant-attack, variable-release final auto-release smoother. However unless the plugin is PeakLimiting hard enough to light up the Auto-Release meter, the additional release is miniscule, a minimum of about 1 ms additional release smoothing. On the other hand if the Auto-Release meter might happen to show 100 ms time constant, then it would apply a final stage of instant-attack, 100 ms release smoothing.

[Geek Alert] The term Time Constant means the time it takes to release to about 37 percent of the original value. If the Time Constant might happen to be 100 ms and it is doing a clean release from a value of 1.0 down to 0.0: Then after 100 ms the release value would be 0.37. After two time constants (200 ms) the release would be [ 37 percent of 0.37 ] = 0.137. After three time constants (300 ms) the release would be [ 37 percent of 0.137 ] = 0.0507. Etcetera. Music usually changes so much over time that there are few opportunities to view a "scientific specimen of a long clean release" as described. I just wanted to point out that an attack or release expressed in Time Constants could take up to 5 time constants to "completely release" or "completely attack". If it says 100 ms time constant then don't assume that the envelope is all done releasing after only 100 ms.

[Geek Alert] On the other hand PeakLimit 2's synthetic peak envelopes are constant time attack and release, not time constants. A 2 ms synthetic envelope attack means it really does take 2 ms from start to finish. Or a 10 ms release really takes 10 ms to complete from start to finish. On the synthetic peak envelope I try to speak about "attack/release time" versus the auto-release "time constant" which has a well-defined meaning in electronics and physics.

Lookahead Auto-Release Envelope: Determines the Auto-Release time constant based on the input samples. This is a 40 ms Attack and 200 ms Release (time constants) envelope which can vary within values of 0 to 1. The envelope attacks toward 1 on every over-threshold input sample and it releases toward 0 on every under-threshold input sample.

Therefore the Auto-Release Envelope maintains a short-term average of the percentage of over-threshold peaks. During a time span of a few hundred ms, if the Auto-Release has a value of 0.1 then it means that the input is over-threshold about ten percent of the time. An Auto-Release Envelope value of 0.5 means that the input is over-threshold about 50 percent of the time. If the Auto-Release Envelope has a value approaching 1.0 then it means that the input is over-threshold almost all of the time.

Because its attack time is faster than release time, the auto-release envelope "over-estimates" the over-threshold percentage. In actuality, less than 10 percent of over-threshold samples would be needed to short-term drive the auto-release envelope up to a value of 0.1. But that's OK because the auto-release code is "seat of the pants" tuned-- It does not require exact percentages in order to work properly.

In order to get "exact percentages" I believe that the attack and release times would need to be identical, which is not desirable here. We want to respond "fairly fast" to sudden increases in the incidence of over-threshold samples, and we want to "relax vigilance" slower than that, so that if we get "surprised" by the first sudden increase of over-threshold density, the auto-release envelope will wait a little bit before recovering just in case a second or third sudden over-threshold density burst might quickly follow-on behind a first sudden burst. The longer release lets the auto-release envelope stay "ready" for strings of hot peaks for awhile before lowering its vigilance.

Given a max auto-release time constant of 1000 ms, we can multiply the Auto-Release Envelope value times 1000 ms to determine the current auto-release time constant. Auto-Release Envelope value of 0.1 would be a 100 ms auto-release time constant. Auto-Release Envelope value of 0.5 would be a 500 ms auto-release time constant.

The ear is not sensitive to some kinds of short-duration distortions. Therefore occasional short peaks do not last long enough to over-ride the 40 ms Auto-Release Envelope Attack value, so the auto-release time constant would stay low for short occasional gain-ducking. As peaks get bigger and/or more frequent in a sustained burst, long enough duration that the ear would begin to hear systematic intermodulation distortion, the Auto-Release Envelope finally gets driven up in value, raising the auto-release time constant, lengthening the limiter's release times, and therefore reducing perceived distortion from longer-term or very loud over-threshold peaking. That is how it uses short release when peak-ducking is minimal and/or infrequent then smoothly transitions to longer release when peak-ducking long duration or heavy-gain-reduction, when otherwise with a shorter release time constant the ear would clearly hear intermodulation distortion.

Practical Applications

I like to use a metering plugin downstream of the PeakLimiter to better verify the operation and settings. I have been using TBProAudio's dpMeter plugin which seems quite good and is downloadable here: https://www.tb-software.com/TBProAudio/dpmeter.html

Metering methods have been standardized by such as EBU R128 specs. Many meters nowadays might give VERY SIMILAR results but so far as I can find out, different meter's results can still POSSIBLY show minor variation. Perhaps one meter would measure a tenth of a dB higher or lower than some other meter. However the "good meters" are similar enough that we ought to be able to rely on any one of them so long as we don't sweat the small stuff, that occasional tenth of a dB or whatever. Disclaimer: The above paragraph could be somehow all wrong but it is just what I was able to find out so far.

In my use of jcjr PeakLimit 2 along with dpMeter, I have to slightly adjust the PeakLimit ceiling to get my target True Peak measurement in dpMeter. I do not know why this is so but the required adjustments are small and am not worried about it. I did some unproductive debugging but after a certain point it wasn't worth the effort just to fix that last tenth-dB disagreement between my PeakLimiter and dpMeter. Any discrepancy is probably somehow more my fault than dpMeter's fault.

In my hobby mastering efforts I have always targeted a whole song max true peak of -1 dBFS (dB Full Scale). Somewhat depending on the song dynamics and the amount of limiting, if I set a PeakLimit ceiling of -1.0 then dpMeter is likely to measure a max true peak of -0.9 or -0.8 dB. To get my desired max true peak of -1.0 as measured in dpMeter, I have usually had to set the PeakLimit Ceiling to -1.1 or -1.2 dB. In a rare couple of songs I had to set the PeakLimit Ceiling to -1.3 dB in order to measure max true peak of -1.0 dB in dpMeter. It is a puzzling slight discrepancy but easily solved with the minor ceiling adjustment.

Here is an interesting article about Peak To Loudness Ratio: http://productionadvice.co.uk/plr/

Download and Installation

Download PeakLimit 2 here-- jcjrPeakLimit2.zip

If you do not know how to install jsfx plugins into Reaper then here is an excellent instructional video-- How To Install JS Plugins Video

  1. First unzip jcjrPeakLimit2.zip yielding the un-compressed folder jcjrPeakLimit2.

  2. Open the jcjrPeakLimit2 folder to find a jcjr folder inside.

  3. Contents of the jcjrPeakLimit2/jcjr folder--

    a) jcjr_PeakLimit_2 : The jsfx effects code.

    b) PeakLimit_Meter_BG.png : Image needed for PeakLimit meters.

    c) PeakLimit_Meter_FG.png : Image needed for PeakLimit meters.

    d) PeakLimit_Meter_PK.png : Image needed for PeakLimit meters.

    e) PeakLimit_Meter_SLO.png : Image needed for PeakLimit meters.

    f) jcjrPeakLimit2/jcjr/jcjrPeakLimit2Manual folder : Contains jcjrPeakLimit2Manual.html plus graphics files required by the manual.

  4. If you do not already have a folder titled jcjr in your Reaper effects folder, then copy the jcjrPeakLimit2/jcjr folder into your Reaper effects folder.

  5. Otherwise, if your Reaper effects folder already contains a jcjr folder, then copy the ENTIRE CONTENTS of your new-downloaded jcjrPeakLimit2/jcjr folder into your already-present REAPER/Effects/jcjr folder. This will add the new PeakLimit 2 files to any plugins already installed in the REAPER/Effects/jcjr folder. For example if you have installed both jcjr RMSComp and jcjr PeakLimit 2, then the Reaper effects folder would contain one jcjr folder. That single jcjr folder would contain both plugins' code, both plugins' required meter image files, and two folders for the manuals, one folder for the RMSComp manual and another folder for the PeakLimit 2 manual.


Back to Muddling With DSP

Back to Main Page