17 , wA_{std::exp(-std::log(real_t(9)) / (sample_rate *
attack_time))}
18 , wR_{std::exp(-std::log(real_t(9)) / (sample_rate *
release_time))} {
19 DSPLIB_ASSERT(
threshold >= -50 &&
threshold <= 0,
"`threshold` must be in range [-50:0] db");
36 const int n =
x.size();
38 for (
int i = 0;
i <
n; ++
i) {
39 const auto gc = _compute_gain(
x[
i]);
41 gs_ = (wA_ * gs_) + (1 - wA_) *
gc;
43 gs_ = (wR_ * gs_) + (1 - wR_) * gc;
45 const auto glin = db2mag(gs_);
47 res.out[i] = x[i] * glin;
52 Result operator()(span_real x) {
53 return this->process(x);
57 real_t _compute_gain(
const real_t& x)
const noexcept {
58 const auto xdb = mag2db(dsplib::abs(x) + eps());
60 if (xdb >= (T_ + W_ / 2)) {
62 }
else if ((xdb > (T_ - W_ / 2)) && (xdb < (T_ + W_ / 2))) {
63 xsc = xdb - abs2(xdb - T_ + W_ / 2) / (2 * W_);