20#include "definitions_cxx.hpp"
21#include "dsp/filter/ladder_components.h"
22#include "dsp/stereo_sample.h"
26class [[gnu::hot]] RMSFeedbackCompressor {
28 RMSFeedbackCompressor();
31 constexpr void setup(q31_t a, q31_t r, q31_t t, q31_t rat, q31_t fc, q31_t blend,
float baseGain) {
58 void render(std::span<StereoSample> buffer, q31_t volAdjustL, q31_t volAdjustR, q31_t finalVolume);
63 void renderVolNeutral(std::span<StereoSample> buffer, q31_t finalVolume);
67 [[nodiscard]]
float runEnvelope(
float current,
float desired,
float numSamples)
const;
70 [[nodiscard]]
inline constexpr q31_t
getAttack()
const {
return attackKnobPos; }
73 [[nodiscard]]
inline constexpr float getAttackMS()
const {
return attackMS; }
80 attackMS = 0.5 + (std::exp(2 *
float(attack) / ONE_Q31f) - 1) * 10;
81 a_ = (-1000.0f / kSampleRate) / attackMS;
82 attackKnobPos = attack;
87 [[nodiscard]]
inline constexpr q31_t
getRelease()
const {
return releaseKnobPos; }
90 [[nodiscard]]
inline constexpr float getReleaseMS()
const {
return releaseMS; }
97 releaseMS = 50 + (std::exp(2 *
float(release) / ONE_Q31f) - 1) * 50;
98 r_ = (-1000.0f / kSampleRate) / releaseMS;
99 releaseKnobPos = release;
104 [[nodiscard]]
inline constexpr q31_t
getThreshold()
const {
return thresholdKnobPos; }
109 thresholdKnobPos = t;
110 threshold = 1 - 0.8f * (float(thresholdKnobPos) / ONE_Q31f);
114 [[nodiscard]]
inline constexpr q31_t
getRatio()
const {
return ratioKnobPos; }
124 fraction = 0.5f + (float(ratioKnobPos) / ONE_Q31f) / 2;
139 sideChainKnobPos = f;
142 fc_hz = (std::exp(1.5 *
float(f) / ONE_Q31f) - 1) * 30;
143 float fc = fc_hz / float(kSampleRate);
144 float wc = fc / (1 + fc);
145 hpfA_ = wc * ONE_Q31;
158 dry = ONE_Q31 - blend;
170 void updateER(
float numSamples, q31_t finalVolume);
173 float calcRMS(std::span<StereoSample> buffer);
180 float a_ = (-1000.0f / kSampleRate);
182 float r_ = (-1000.0f / kSampleRate);
211 bool onLastTime =
false;
227 q31_t thresholdKnobPos = 0;
228 q31_t ratioKnobPos = 0;
229 q31_t attackKnobPos = 0;
230 q31_t releaseKnobPos = 0;
231 q31_t sideChainKnobPos = 0;
constexpr void setBaseGain(float baseGain)
Definition rms_feedback.h:167
constexpr void setThreshold(q31_t t)
Definition rms_feedback.h:108
constexpr q31_t getRatio() const
Get the current ratio as a full-scale (0 to 2^31) number.
Definition rms_feedback.h:114
constexpr void setup(q31_t a, q31_t r, q31_t t, q31_t rat, q31_t fc, q31_t blend, float baseGain)
takes in all values as knob positions in the range 0-ONE_Q31
Definition rms_feedback.h:31
uint8_t gainReduction
Amount of gain reduction applied during the last render pass, in 6.2 fixed point decibels.
Definition rms_feedback.h:176
constexpr int32_t setAttack(q31_t attack)
Definition rms_feedback.h:78
constexpr float getAttackMS() const
Get the current attack time constant in MS for a 3db change.
Definition rms_feedback.h:73
constexpr q31_t getAttack() const
Get the current attack time constant in terms of the full knob range (0 to 2^31)
Definition rms_feedback.h:70
float a_
Attack time constant, in inverse samples.
Definition rms_feedback.h:180
constexpr q31_t getRelease() const
Get the current release time constant in terms of the full knob range (0 to 2^31)
Definition rms_feedback.h:87
void reset()
Reset the state of the compressor so no gain reduction is applied at the start of the next render win...
Definition rms_feedback.h:42
constexpr q31_t getBlend()
returns blend in q31
Definition rms_feedback.h:150
uint32_t lastSaturationTanHWorkingValue[2]
tanh working values for output saturation
Definition rms_feedback.h:210
q31_t currentVolumeR
Current right channel volume as a 5.26 signed fixed-point number.
Definition rms_feedback.h:204
constexpr float getReleaseMS() const
Get the current release time constant in MS for a 3db change.
Definition rms_feedback.h:90
float threshdb
Threshold, in decibels.
Definition rms_feedback.h:193
constexpr int32_t setSidechain(q31_t f)
Definition rms_feedback.h:138
float state
State for the internal envelope follower.
Definition rms_feedback.h:200
float rms
Log-RMS value of the last render.
Definition rms_feedback.h:206
q31_t hpfA_
A parameter for the internal HPF.
Definition rms_feedback.h:197
constexpr q31_t getThreshold() const
Get the current theshold as a full-scale (0 to 2^31) number.
Definition rms_feedback.h:104
float er
Definition rms_feedback.h:191
constexpr float getSidechainForDisplay() const
Get the current sidechain cutoff frequency in hertz.
Definition rms_feedback.h:133
constexpr int32_t getBlendForDisplay()
returns blend as an integer percentage
Definition rms_feedback.h:152
constexpr int32_t setRatio(q31_t rat)
Definition rms_feedback.h:122
constexpr int32_t setRelease(q31_t release)
Definition rms_feedback.h:95
float r_
Release time constant, in inverse samples.
Definition rms_feedback.h:182
constexpr int32_t setBlend(q31_t blend)
Definition rms_feedback.h:156
q31_t getSidechain()
Get the current sidechain cutoff frequency as a full-scale (0 to 2^31) integer.
Definition rms_feedback.h:130
float fraction
Definition rms_feedback.h:186
float threshold
The raw threshold value.
Definition rms_feedback.h:195
q31_t currentVolumeL
Current left channel volume as a 5.26 signed fixed-point number.
Definition rms_feedback.h:202
float mean
Mean value of the last render.
Definition rms_feedback.h:208
float baseGain_
Definition rms_feedback.h:224
constexpr float getRatioForDisplay() const
Get the current ratio as a float.
Definition rms_feedback.h:117
Definition ladder_components.h:23