AGCCoreV2Fract32
Discussion
The AGCCoreV2Fract32 module is a slowly varying dynamics computer based on the RMS level of the signal. The module is used inconjunction with the MultiplierV2 module to create automatic gain controls. The module outputs a linear gain which can be applied to another signal using the MultiplierV2 module.
The first part of the module's processing function computes the RMS signal level over all input samples. The RMS value is then smoothed by a filter with the specified smoothingTime. The smoothed value is converted to dB and this input level feeds the control logic. The control logic computes an output gain so that when multiplied by the input signal the output signal has an RMS level of .targetLevel. .targetLevel is similar to the threshold in a limiter and .ratio has a similar meaning. If the input signal is .ratio dB loader than .targetLevel then the output will actually be 1 db above .targetLevel. Basically, .ratio specifies how hard the AGC will work to achieve the .targetLevel.
The variables .maxGain and .maxAttenuation control the maximum boost and cut that the AGC will allow. Both .maxGain and .maxAttenuation are positive numbers. For example, if maxGain = 10 and maxAttenuation = 20 then the AGCCore will boost by up to +10 dB and cut by up to -20 dB.
When the input level falls below .activationThreshold then the AGC freezes and holds its output gain. If .enableRecovery is checked then when the input signal falls below .activationThreshold then the AGCCore's gain will slew back to 0 dB. The rate of slewing is specified by recoveryRate which has units of dB/sec.
The output gain format of AGCCoreV2Fract32 is Q8.24. The signal should be shifted to left by 7 bits after the AGC gain is applied
Module Pack
Advanced
ClassID
classID = 1441
Type Definition
typedef struct _ModuleAGCCoreV2Fract32
{
ModuleInstanceDescriptor instance; // Common Audio Weaver module instance structure
FLOAT32 targetLevel; // Target audio level
FLOAT32 maxAttenuation; // Maximum attenuation of the AGC
FLOAT32 maxGain; // Maximum gain of the AGC
FLOAT32 ratio; // Slope of the output attenuation when the signal is above threshold
FLOAT32 activationThreshold; // Activation threshold of the AGC. The AGC stops updating its gain when the instantaneous input level is below this value
FLOAT32 smoothingTime; // Response time of the AGC. This controls the RMS smoothing interval and the time constant of the smoothly updating gain
INT32 enableRecovery; // Boolean which enables the AGC's gain recovery. If enabled, the AGC slows returns 0 dB gain when the input is below the activation threshold
FLOAT32 recoveryRate; // Rate at which the gain is adjusted when the input is below the activation threshold
FLOAT32 currentGain; // Instantaneous gain of the smoothing operation.
fract32 smoothingCoeffBlockFract32; // Block-by-block smoothing coefficient for the RMS measurement. Set via smoothingTime.
FLOAT32 oneOverSlope; // Used by the processing function to compute the amount of cut/boost. Equal to 1-1/ratio.
FLOAT32 smoothingCoeffSample; // Sample-by-sample smoothing coefficient for the output gain adjustment. Set via smoothingTime.
FLOAT32 smoothingCoeffBlock; // Block-by-block smoothing coefficient for the RMS measurement. Set via smoothingTime.
FLOAT32 recoveryRateUp; // Recovery rate coefficient when increasing the gain (it is always >= 1)
FLOAT32 recoveryRateDown; // Recovery rate coefficient when decreasing the gain (it is always <= 1)
FLOAT32 targetGain; // Target gain of the smoothing operation.
FLOAT32 energy; // Smoothed energy measurement.
FLOAT32 oneOverNumSamples; // 1 divided by the number of samples in the input pin. Used internally by the algorithm in order to save a divide operation.
fract32 targetLevelFract32; // Target audio level
fract32 maxGainFract32; // Maximum gain of the AGC
fract32 maxAttenuationFract32; // Maximum attenuation of the AGC
fract32 activationThresholdFract32; // Activation threshold of the AGC. The AGC stops updating its gain when the instantaneous input level is below this value
fract32 recoveryRateUpFract32; // Recovery rate coefficient when increasing the gain (it is always >= 1)
fract32 recoveryRateDownFract32; // Recovery rate coefficient when decreasing the gain (it is always <= 1)
fract32 currentGainFract32; // Instantaneous gain of the smoothing operation.
fract32 smoothingCoeffSampleFract32; // Sample-by-sample smoothing coefficient for the output gain adjustment. Set via smoothingTime.
fract32 targetGainFract32; // Target gain of the smoothing operation.
fract32 energyFract32; // Smoothed energy measurement.
fract32 oneOverNumSamplesFract32; // 1 divided by the number of samples in the input pin. Used internally by the algorithm in order to save a divide operation.
fract32 oneOverSlopeFract32; // Used by the processing function to compute the amount of cut/boost. Equal to 1-1/ratio.
} ModuleAGCCoreV2Fract32Class;
Variables
Properties
| Name | Type | Usage | isHidden | Default Value | Range | Units |
|---|---|---|---|---|---|---|
| targetLevel | float | parameter | 0 | -20 | -50:0.1:50 | dB |
| maxAttenuation | float | parameter | 0 | 100 | 0:100 | dB |
| maxGain | float | parameter | 0 | 12 | 0:40 | dB |
| ratio | float | parameter | 0 | 10 | 1:100 | dB/dB |
| activationThreshold | float | parameter | 0 | -50 | -100:-20 | dB |
| smoothingTime | float | parameter | 0 | 100 | 1:250 | msec |
| enableRecovery | int | parameter | 0 | 1 | 0:1 | |
| recoveryRate | float | parameter | 0 | 2.4 | 1:20 | dB/sec |
| currentGain | float | state | 0 | 0 | -12:12 | |
| smoothingCoeffBlockFract32 | fract32 | derived | 0 | 0 | Unrestricted | |
| oneOverSlope | float | derived | 1 | 0.9 | Unrestricted | |
| smoothingCoeffSample | float | derived | 1 | 0.0002083 | Unrestricted | |
| smoothingCoeffBlock | float | derived | 1 | 0.006644 | Unrestricted | |
| recoveryRateUp | float | derived | 1 | 1 | Unrestricted | |
| recoveryRateDown | float | derived | 1 | 0.9998 | Unrestricted | |
| targetGain | float | state | 1 | 1 | Unrestricted | |
| energy | float | state | 1 | 0 | Unrestricted | |
| oneOverNumSamples | float | derived | 1 | 0.03125 | Unrestricted | |
| targetLevelFract32 | fract32 | derived | 1 | -0.15625 | Unrestricted | |
| maxGainFract32 | fract32 | derived | 1 | 0.09375 | Unrestricted | |
| maxAttenuationFract32 | fract32 | derived | 1 | 0.78125 | Unrestricted | |
| activationThresholdFract32 | fract32 | derived | 1 | -0.39062 | Unrestricted | |
| recoveryRateUpFract32 | fract32 | derived | 1 | 0 | Unrestricted | |
| recoveryRateDownFract32 | fract32 | derived | 1 | 0 | Unrestricted | |
| currentGainFract32 | fract32 | state | 1 | 0 | Unrestricted | |
| smoothingCoeffSampleFract32 | fract32 | derived | 1 | 0 | Unrestricted | |
| targetGainFract32 | fract32 | state | 1 | 0 | Unrestricted | |
| energyFract32 | fract32 | state | 1 | 0 | Unrestricted | |
| oneOverNumSamplesFract32 | fract32 | derived | 1 | 0.03125 | Unrestricted | |
| oneOverSlopeFract32 | fract32 | derived | 1 | 0 | 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 |
Matlab Usage
File Name: agc_core_v2_fract32_module.m
M=agc_core_v2_fract32_module(NAME)
Audio Weaver modules which calculates the instantaneous gain needed
by an automatic gain control AGC module. This module is used in
conjunction with the agc_multiplier_module. The input format for this
module is 1.31 and output format is 8.24.
NAME - name of the module.
Copyright (c) 2026 DSP Concepts, Inc.