Compressor#

Compressor stages allow for control of the dynamic range of the signal, such as reducing the level of loud sounds.

class audio_dsp.stages.compressor.CompressorRMS(**kwargs)

A compressor based on the RMS envelope of the input signal.

When the RMS envelope of the signal exceeds the threshold, the signal amplitude is reduced by the compression ratio.

The threshold sets the value above which compression occurs. The ratio sets how much the signal is compressed. A ratio of 1 results in no compression, while a ratio of infinity results in the same behaviour as a limiter. The attack time sets how fast the compressor starts compressing. The release time sets how long the signal takes to ramp up to its original level after the envelope is below the threshold.

Attributes:
dsp_blockaudio_dsp.dsp.drc.drc.compressor_rms

The DSB block class; see RMS Compressor for implementation details.

make_compressor_rms(ratio, threshold_db, attack_t, release_t, Q_sig=27)

Update compressor configuration based on new parameters.

Parameters:
ratiofloat

Compression gain ratio applied when the signal is above the threshold.

threshold_dbfloat

Threshold in decibels above which compression occurs.

attack_tfloat

Attack time of the compressor in seconds.

release_tfloat

Release time of the compressor in seconds.

CompressorRMS Control#

The following runtime command ids are available for the CompressorRMS Stage. For details on reading and writing these commands, see the Run-Time Control User Guide.

Control parameter

Payload length

CMD_COMPRESSOR_RMS_ATTACK_ALPHA

sizeof(int32_t)

The attack alpha in Q0.31 format. To convert an attack time in seconds to an int32_t control value, use the function calc_alpha(fs, attack_time) in control/helpers.h.


CMD_COMPRESSOR_RMS_RELEASE_ALPHA

sizeof(int32_t)

The release alpha in Q0.31 format. To convert a release time in seconds to an int32_t control value, use the function calc_alpha(fs, release_time) in control/helpers.h.


CMD_COMPRESSOR_RMS_ENVELOPE

sizeof(int32_t)

The current RMS² envelope of the signal in Q_SIG format. To read the int32_t control value, use the function qxx_to_db_pow(envelope, Q_SIG) in control/helpers.h. This command is read only. When sending a write control command, it will be ignored.


CMD_COMPRESSOR_RMS_THRESHOLD

sizeof(int32_t)

The threshold in Q_SIG format above which compression will occur. To convert a threshold in dB to the int32_t control value, use the function calculate_rms_threshold(x) in control/helpers.h.


CMD_COMPRESSOR_RMS_GAIN

sizeof(int32_t)

The current gain applied by the compressor in Q0.31 format. To read the int32_t control value, use the function qxx_to_db(envelope, 31) in control/helpers.h This command is read only. When sending a write control command, it will be ignored.


CMD_COMPRESSOR_RMS_SLOPE

sizeof(float)

The compression slope of the compressor. This is calculated as (1 - 1 / ratio) / 2.0. To convert a ratio to a slope, use the function rms_compressor_slope_from_ratio(ratio) in control/helpers.h.