38 #define SAMPLE_FORMAT float
53 #define FEXP10 ff_exp10f
54 #define EPSILON (1.f / (1 << 23))
57 #define SAMPLE_FORMAT double
72 #define FEXP10 ff_exp10
73 #define EPSILON (1.0 / (1LL << 53))
77 #define LIN2LOG(x) (20.0 * FLOG10(x))
78 #define LOG2LIN(x) (FEXP10(x / 20.0))
80 #define fn3(a,b) a##_##b
81 #define fn2(a,b) fn3(a,b)
82 #define fn(a) fn2(a, SAMPLE_FORMAT)
87 const ftype v3 = v0 -
b[1];
88 const ftype v1 =
a[0] *
b[0] +
a[1] * v3;
89 const ftype v2 =
b[1] +
a[1] *
b[0] +
a[2] * v3;
91 b[0] =
TWO * v1 -
b[0];
92 b[1] =
TWO * v2 -
b[1];
94 return m[0] * v0 + m[1] * v1 + m[2] * v2;
100 const ftype sample_rate =
ctx->inputs[0]->sample_rate;
101 const ftype dfrequency =
FMIN(
s->dfrequency, sample_rate * 0.5);
103 const ftype dqfactor =
s->dqfactor;
104 const int dftype =
s->dftype;
109 s->threshold_log =
LIN2LOG(
s->threshold);
110 s->dattack_coef =
get_coef(
s->dattack, sample_rate);
111 s->drelease_coef =
get_coef(
s->drelease, sample_rate);
112 s->gattack_coef =
s->dattack_coef * 0.25;
113 s->grelease_coef =
s->drelease_coef * 0.25;
119 da[0] =
ONE / (
ONE + dg * (dg + k));
130 da[0] =
ONE / (
ONE + dg * (dg + k));
141 da[0] =
ONE / (
ONE + dg * (dg + k));
152 da[0] =
ONE / (
ONE + dg * (dg + k));
165 #define PEAKS(empty_value,op,sample, psample)\
166 if (!empty && psample == ss[front]) { \
167 ss[front] = empty_value; \
168 if (back != front) { \
173 empty = front == back; \
176 if (!empty && sample op ss[front]) { \
178 ss[front] = empty_value; \
179 if (back == front) { \
189 while (!empty && sample op ss[back]) { \
190 ss[back] = empty_value; \
191 if (back == front) { \
208 const int nb_samples)
211 ftype *qq = cc->queue;
212 int front = cc->front;
214 int empty, n,
pos = cc->position;
219 if (cc->size >= nb_samples) {
226 if (
pos >= nb_samples)
230 if (cc->size < nb_samples)
234 empty = (front == back) && (
ss[front] ==
ZERO);
246 s =
FEXP2(
fn(cc->log_sum) / cc->size) / (
fn(cc->sum) / cc->size);
248 return ss[cc->front];
259 const ftype makeup =
s->makeup;
260 const ftype ratio =
s->ratio;
262 const ftype tfrequency =
FMIN(
s->tfrequency, sample_rate * 0.5);
263 const int mode =
s->mode;
265 const ftype grelease =
s->grelease_coef;
266 const ftype gattack =
s->gattack_coef;
267 const ftype drelease =
s->drelease_coef;
268 const ftype dattack =
s->dattack_coef;
269 const ftype tqfactor =
s->tqfactor;
270 const ftype itqfactor =
ONE / tqfactor;
274 const int is_disabled =
ctx->is_disabled;
275 const int detection =
s->detection;
276 const int tftype =
s->tftype;
280 if (detection ==
DET_ON) {
281 for (
int ch = start; ch < end; ch++) {
284 ftype *tstate =
fn(cc->tstate);
287 if (cc->detection != detection) {
288 cc->detection = detection;
294 new_threshold =
FMAX(new_threshold, detect);
297 fn(cc->new_threshold_log) =
FMAX(
fn(cc->new_threshold_log),
LIN2LOG(new_threshold));
300 for (
int ch = start; ch < end; ch++) {
303 ftype *tstate =
fn(cc->tstate);
316 fn(cc->threshold_log) =
s->threshold_log;
318 cc->detection = detection;
321 for (
int ch = start; ch < end; ch++) {
323 fn(cc->threshold_log) =
s->threshold_log;
326 }
else if (detection ==
DET_OFF) {
327 for (
int ch = start; ch < end; ch++) {
330 fn(cc->threshold_log) =
fn(cc->new_threshold_log);
332 fn(cc->threshold_log) =
s->threshold_log;
337 for (
int ch = start; ch < end; ch++) {
341 const ftype threshold_log =
fn(cc->threshold_log);
342 ftype *fa =
fn(cc->fa), *fm =
fn(cc->fm);
343 ftype *fstate =
fn(cc->fstate);
344 ftype *dstate =
fn(cc->dstate);
346 ftype lin_gain =
fn(cc->lin_gain);
349 for (
int n = 0; n <
out->nb_samples; n++) {
350 ftype new_detect, new_lin_gain =
ONE;
355 new_detect =
FABS(listen);
356 f = (new_detect > detect) * dattack + (new_detect <= detect) * drelease;
357 detect =
f * new_detect + (
ONE -
f) * detect;
366 if (ld < threshold_log) {
368 new_lin_gain =
LOG2LIN(new_log_gain);
374 if (ld > threshold_log) {
376 new_lin_gain =
LOG2LIN(new_log_gain);
381 f = (new_lin_gain > lin_gain) * gattack + (new_lin_gain <= lin_gain) * grelease;
382 new_lin_gain =
f * new_lin_gain + (
ONE -
f) * lin_gain;
384 if (lin_gain != new_lin_gain || !
init) {
386 lin_gain = new_lin_gain;
390 k = itqfactor / lin_gain;
392 fa[0] =
ONE / (
ONE + fg * (fg + k));
397 fm[1] = k * (lin_gain * lin_gain -
ONE);
402 g = fg /
SQRT(lin_gain);
409 fm[1] = k * (lin_gain -
ONE);
410 fm[2] = lin_gain * lin_gain -
ONE;
414 g = fg *
SQRT(lin_gain);
420 fm[0] = lin_gain * lin_gain;
421 fm[1] = k * (
ONE - lin_gain) * lin_gain;
422 fm[2] =
ONE - lin_gain * lin_gain;
429 dst[n] = is_disabled ?
src[n] : v;
432 fn(cc->detect) = detect;
433 fn(cc->lin_gain) = lin_gain;