SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Member Functions | Public Attributes | List of all members
AudioCompressorSnd::CompressorState Struct Reference

Public Member Functions

void sf_advancecomp (int rate, float pregain, float threshold, float knee, float ratio, float attack, float release, float predelay, float releasezone1, float releasezone2, float releasezone3, float releasezone4, float postgain, float wet)
 

Public Attributes

float metergain
 
float meterrelease
 
float threshold
 
float knee
 
float linearpregain
 
float linearthreshold
 
float slope
 
float attacksamplesinv
 
float satreleasesamplesinv
 
float wet
 
float dry
 
float k
 
float kneedboffset
 
float linearthresholdknee
 
float mastergain
 
float a
 
float b
 
float c
 
float d
 
float detectoravg
 
float compgain
 
float maxcompdiffdb
 
int delaybufsize
 
int delaywritepos
 
int delayreadpos
 
float delaybuf [AUDIOCOMPRESSORSND_SF_COMPRESSOR_MAXDELAY]
 

Detailed Description

Definition at line 169 of file audiocompressorsnd.h.

Member Function Documentation

◆ sf_advancecomp()

void AudioCompressorSnd::CompressorState::sf_advancecomp ( int  rate,
float  pregain,
float  threshold,
float  knee,
float  ratio,
float  attack,
float  release,
float  predelay,
float  releasezone1,
float  releasezone2,
float  releasezone3,
float  releasezone4,
float  postgain,
float  wet 
)

Definition at line 76 of file audiocompressorsnd.cpp.

References AUDIOCOMPRESSORSND_SF_COMPRESSOR_MAXDELAY, AudioCompressorSnd::compcurve(), AudioCompressorSnd::db2lin(), i, AudioCompressorSnd::kneecurve(), AudioCompressorSnd::kneeslope(), and AudioCompressorSnd::lin2db().

Referenced by AudioCompressorSnd::initState().

87 {
88  // setup the predelay buffer
89  int delaybufsize = rate * predelay;
90 
91  if (delaybufsize < 1)
92  {
93  delaybufsize = 1;
94  }
95  else if (delaybufsize > AUDIOCOMPRESSORSND_SF_COMPRESSOR_MAXDELAY)
96  {
98  std::fill(delaybuf, delaybuf+delaybufsize, 0.0f);
99  }
100 
101  // useful values
102  float linearpregain = db2lin(pregain);
104  float slope = 1.0f / ratio;
105  float attacksamples = rate * attack;
106  float attacksamplesinv = 1.0f / attacksamples;
107  float releasesamples = rate * release;
108  float satrelease = 0.0025f; // seconds
109  float satreleasesamplesinv = 1.0f / ((float)rate * satrelease);
110  float dry = 1.0f - wet;
111 
112  // metering values (not used in core algorithm, but used to output a meter if desired)
113  float metergain = 1.0f; // gets overwritten immediately because gain will always be negative
114  float meterfalloff = 0.325f; // seconds
115  float meterrelease = 1.0f - expf(-1.0f / ((float)rate * meterfalloff));
116 
117  // calculate knee curve parameters
118  float k = 5.0f; // initial guess
119  float kneedboffset = 0.0f;
120  float linearthresholdknee = 0.0f;
121 
122  if (knee > 0.0f) // if a knee exists, search for a good k value
123  {
124  float xknee = db2lin(threshold + knee);
125  float mink = 0.1f;
126  float maxk = 10000.0f;
127 
128  // search by comparing the knee slope at the current k guess, to the ideal slope
129  for (int i = 0; i < 15; i++)
130  {
131  if (kneeslope(xknee, k, linearthreshold) < slope) {
132  maxk = k;
133  } else {
134  mink = k;
135  }
136 
137  k = sqrtf(mink * maxk);
138  }
139 
140  kneedboffset = lin2db(kneecurve(xknee, k, linearthreshold));
141  linearthresholdknee = db2lin(threshold + knee);
142  }
143 
144  // calculate a master gain based on what sounds good
145  float fulllevel = compcurve(1.0f, k, slope, linearthreshold, linearthresholdknee, threshold, knee, kneedboffset);
146  float mastergain = db2lin(postgain) * powf(1.0f / fulllevel, 0.6f);
147 
148  // calculate the adaptive release curve parameters
149  // solve a,b,c,d in `y = a*x^3 + b*x^2 + c*x + d`
150  // interescting points (0, y1), (1, y2), (2, y3), (3, y4)
151  float y1 = releasesamples * releasezone1;
152  float y2 = releasesamples * releasezone2;
153  float y3 = releasesamples * releasezone3;
154  float y4 = releasesamples * releasezone4;
155  float a = (-y1 + 3.0f * y2 - 3.0f * y3 + y4) / 6.0f;
156  float b = y1 - 2.5f * y2 + 2.0f * y3 - 0.5f * y4;
157  float c = (-11.0f * y1 + 18.0f * y2 - 9.0f * y3 + 2.0f * y4) / 6.0f;
158  float d = y1;
159 
160  // save everything
161  this->metergain = 1.0f; // large value overwritten immediately since it's always < 0
162  this->meterrelease = meterrelease;
163  this->threshold = threshold;
164  this->knee = knee;
165  this->wet = wet;
166  this->linearpregain = linearpregain;
167  this->linearthreshold = linearthreshold;
168  this->slope = slope;
169  this->attacksamplesinv = attacksamplesinv;
170  this->satreleasesamplesinv = satreleasesamplesinv;
171  this->dry = dry;
172  this->k = k;
173  this->kneedboffset = kneedboffset;
174  this->linearthresholdknee = linearthresholdknee;
175  this->mastergain = mastergain;
176  this->a = a;
177  this->b = b;
178  this->c = c;
179  this->d = d;
180  this->detectoravg = 0.0f;
181  this->compgain = 1.0f;
182  this->maxcompdiffdb = -1.0f;
183  this->delaybufsize = delaybufsize;
184  this->delaywritepos = 0;
185  this->delayreadpos = delaybufsize > 1 ? 1 : 0;
186 }
#define AUDIOCOMPRESSORSND_SF_COMPRESSOR_MAXDELAY
static float kneecurve(float x, float k, float linearthreshold)
static float compcurve(float x, float k, float slope, float linearthreshold, float linearthresholdknee, float threshold, float knee, float kneedboffset)
int32_t i
Definition: decimators.h:244
static float lin2db(float lin)
float delaybuf[AUDIOCOMPRESSORSND_SF_COMPRESSOR_MAXDELAY]
static float kneeslope(float x, float k, float linearthreshold)
static float db2lin(float db)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ a

float AudioCompressorSnd::CompressorState::a

Definition at line 192 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ attacksamplesinv

float AudioCompressorSnd::CompressorState::attacksamplesinv

Definition at line 184 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ b

float AudioCompressorSnd::CompressorState::b

Definition at line 193 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ c

float AudioCompressorSnd::CompressorState::c

Definition at line 194 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ compgain

float AudioCompressorSnd::CompressorState::compgain

Definition at line 197 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ d

float AudioCompressorSnd::CompressorState::d

Definition at line 195 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ delaybuf

float AudioCompressorSnd::CompressorState::delaybuf[AUDIOCOMPRESSORSND_SF_COMPRESSOR_MAXDELAY]

Definition at line 202 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ delaybufsize

int AudioCompressorSnd::CompressorState::delaybufsize

Definition at line 199 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ delayreadpos

int AudioCompressorSnd::CompressorState::delayreadpos

Definition at line 201 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ delaywritepos

int AudioCompressorSnd::CompressorState::delaywritepos

Definition at line 200 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ detectoravg

float AudioCompressorSnd::CompressorState::detectoravg

Definition at line 196 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ dry

float AudioCompressorSnd::CompressorState::dry

Definition at line 187 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ k

float AudioCompressorSnd::CompressorState::k

Definition at line 188 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ knee

float AudioCompressorSnd::CompressorState::knee

Definition at line 180 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ kneedboffset

float AudioCompressorSnd::CompressorState::kneedboffset

Definition at line 189 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ linearpregain

float AudioCompressorSnd::CompressorState::linearpregain

Definition at line 181 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ linearthreshold

float AudioCompressorSnd::CompressorState::linearthreshold

Definition at line 182 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ linearthresholdknee

float AudioCompressorSnd::CompressorState::linearthresholdknee

Definition at line 190 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ mastergain

float AudioCompressorSnd::CompressorState::mastergain

Definition at line 191 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ maxcompdiffdb

float AudioCompressorSnd::CompressorState::maxcompdiffdb

Definition at line 198 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ metergain

float AudioCompressorSnd::CompressorState::metergain

Definition at line 174 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ meterrelease

float AudioCompressorSnd::CompressorState::meterrelease

Definition at line 178 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ satreleasesamplesinv

float AudioCompressorSnd::CompressorState::satreleasesamplesinv

Definition at line 185 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ slope

float AudioCompressorSnd::CompressorState::slope

Definition at line 183 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ threshold

float AudioCompressorSnd::CompressorState::threshold

Definition at line 179 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().

◆ wet

float AudioCompressorSnd::CompressorState::wet

Definition at line 186 of file audiocompressorsnd.h.

Referenced by AudioCompressorSnd::sf_compressor_process().


The documentation for this struct was generated from the following files: