AGCLimiterCoreV2Fract32
Overview
Soft knee gain computer for use in peak limiters
Discussion
The agc_limiter_core_v2_fract32_module computes a time varying gain which is used to restrict the peak value of a signal. The module is designed to take its input from the max_abs_fract32_module. The module computes a time varying gain on a sample-by-sample basis, and this gain is later applied by the agc_multiplier_fract32_module. The output gain signal is in 8.24 format. The agc_multiplier_fract32_module expects the gain to be in 1.31 format. Thus, the multiplier must be configured to shift by 7 bits. The combination of max_abs_fract32_module, agc_limiter_core_v2_fract32_module, and agc_multiplier_fract32_module modules is referred to as a "limiter" and is contained in the script limiter_module.m.
![](../../__attachments/3170796366/image-20240108-160950.png?inst-v=326272e9-cc04-48f3-a51a-5d633eb0a230)
It is also possible to incorporate delay into the limiter effectively allowing it to "look ahead" and anticipate transients. See the limiter_module.m script for details.
![](../../__attachments/3170796366/image-20240108-161015.png?inst-v=326272e9-cc04-48f3-a51a-5d633eb0a230)
One way to understand the operation of the limiter is to consider the input / output curve shown in the figure below. The X-axis represents the level of the input signal, in dB. For simplicity, assume that the input signal is a sine wave. The Y-axis represents the level of the output sine wave. In the figure, the limitThreshold is set to -30 dB. Signals below limitThreshold are unaffected. Signals above limitThreshold are compressed by the parameter ratio. In the figure, ratio is set to 3 dB/dB, and thus the output signal gets 1 dB louder for every 3 dB increase in the input signal. In typical limiter applications, ratio is set to 100 preventing the signal from getting much louder than threshold.
![](../../__attachments/3170796366/image-20240108-161029.png?inst-v=326272e9-cc04-48f3-a51a-5d633eb0a230)
The AGCLimiterCoreV2Fract32 module computes the gain needed to realize the input / output curve shown above. The gain curve is shown below. Below limitThreshold, the gain equals 0 dB and thus the level of the signal is unaffected. After limitThreshold, attenuation is applied.
![](../../__attachments/3170796366/image-20240108-161049.png?inst-v=326272e9-cc04-48f3-a51a-5d633eb0a230)
The outputGain parameter allows you to specify additional gain through the limiter. This gain is just incorporated into the output signal.
The limiter includes a soft knee which causes the attenuation to kick in gradually. The knee is a quadratic function extending from limitThreshold – kneeDepth to limitThreshold + kneeDepth. Due to manner in which the knee is implemented, kneeDepth must always be > 0. The figure below illustrates the input / output level characteristic with:
limitThreshold = -10
ratio = 100
kneeDepth = 10
![](../../__attachments/3170796366/image-20240108-161109.png?inst-v=326272e9-cc04-48f3-a51a-5d633eb0a230)
Type Definition
typedef struct _ModuleAGCLimiterCoreV2Fract32
{
ModuleInstanceDescriptor instance; // Common Audio Weaver module instance structure
INT32 numChan; // Number of channels.
FLOAT32* threshold; // Amplitude level at which the AGC Limiter Core reduces its output gain value
FLOAT32* gain; // Value used to scale the output of the AGC Limiter Core (make up gain)
FLOAT32* kneeDepth; // Knee depth controls the sharpness of the transition between no limiting and limiting
FLOAT32* ratio; // Slope of the output attenuation when the signal is above threshold - derived from the standard compression ratio parameter by the formula slope = 1.0 - (1.0/ratio)
FLOAT32* attackTime; // Envelope detector attack time constant
FLOAT32* decayTime; // Envelope detector decay time constant
fract32* slope; // Internal derived variable which holds the slope of the compression curve
FLOAT32* sharpnessFactor; // Internal derived variable which is used to implement the soft knee
fract32* attackCoeff; // Internal derived variable which implements the attackTime
fract32* decayCoeff; // Internal derived variable which implements the decayTime
fract32* thresholdFract32; // threshold - in 8.24 "base2 dB"
fract32* gainFract32; // gain - in 8.24 "base2 dB"
fract32* kneeDepthFract32; // Knee depth - in 8.24 "base2 dB"
fract32* sharpnessFactorFract32; // Internal derived variable which is used to implement the soft knee
fract32* envState; // Holds the instantaneous state of the envelope detector
fract32* currentGain; // Instantaneous gain computed by the block
} ModuleAGCLimiterCoreV2Fract32Class;
Variables
Properties
Name | Type | Usage | isHidden | Default value | Range | Units |
numChan | int | const | 1 | 1 | Unrestricted | |
threshold | float* | parameter | 0 | [1 x 1] | -60:0 | dB |
gain | float* | parameter | 0 | [1 x 1] | 0:40 | dB |
kneeDepth | float* | parameter | 0 | [1 x 1] | 0.1:60 | dB |
ratio | float* | parameter | 0 | [1 x 1] | 1:100 | |
attackTime | float* | parameter | 0 | [1 x 1] | 1:2000 | msec |
decayTime | float* | parameter | 0 | [1 x 1] | 1:2000 | msec |
slope | fract32* | derived | 1 | [1 x 1] | Unrestricted | dB/dB |
sharpnessFactor | float* | derived | 1 | [1 x 1] | Unrestricted | |
attackCoeff | fract32* | derived | 1 | [1 x 1] | Unrestricted | |
decayCoeff | fract32* | derived | 1 | [1 x 1] | Unrestricted | |
thresholdFract32 | fract32* | derived | 0 | [1 x 1] | Unrestricted | |
gainFract32 | fract32* | derived | 0 | [1 x 1] | Unrestricted | |
kneeDepthFract32 | fract32* | derived | 0 | [1 x 1] | Unrestricted | |
sharpnessFactorFract32 | fract32* | derived | 1 | [1 x 1] | Unrestricted | |
envState | fract32* | state | 1 | [1 x 1] | Unrestricted | |
currentGain | fract32* | state | 0 | [1 x 1] | Unrestricted |
Pins
Input Pins
Name: in
Description: audio input
Data type: fract32
Channel range: Unrestricted
Block size range: Unrestricted
Sample rate range: Unrestricted
Complex support: Real
Output Pins
Name: out
Description: audio output
Data type: fract32
Scratch Pins
Channel count: 1
Block size: 32
Sample rate: 48000
Channel count: 1
Block size: 32
Sample rate: 48000
MATLAB Usage
File Name: agc_limiter_core_v2_fract32_module.m
M=agc_limiter_core_v2_fract32_module(NAME)
Creates a limiter gain computer with soft knee for use in Audio
Weaver. It is used in conjunction with the AGCMultiplier to
implement full limiter.
Arguments:
NAME - name of the module.