DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
DeEsser.h
1// DSPark - Professional Audio DSP Framework
2// Copyright (c) 2026 Cristian Moresi - MIT License
3
4#pragma once
5
46#include "../Core/AudioBuffer.h"
47#include "../Core/AudioSpec.h"
48#include "../Core/Biquad.h"
49#include "../Core/DenormalGuard.h"
50#include "../Core/DspMath.h"
51#include "../Core/NormalizedLadder.h"
52#include "../Core/StateBlob.h"
53
54#include <algorithm>
55#include <array>
56#include <atomic>
57#include <cmath>
58#include <cstddef>
59#include <cstdint>
60#include <vector>
61
62namespace dspark {
63
74template <FloatType T>
76{
77public:
78 enum class DetectionMode
79 {
80 Bandpass,
82 };
83
92 void prepare(const AudioSpec& spec)
93 {
94 if (!spec.isValid()) return; // release-safe: keep previous state
95
96 sampleRate_ = spec.sampleRate;
97 numChannels_ = spec.numChannels;
98
99 removalScratch_.assign(static_cast<size_t>(std::min(numChannels_, kMaxChannels)),
100 std::vector<T>(static_cast<size_t>(std::max(1, spec.maxBlockSize)), T(0)));
101 mixScratch_.assign(static_cast<size_t>(kMaxChannels),
102 std::vector<T>(static_cast<size_t>(std::max(1, spec.maxBlockSize)), T(0)));
103 mixWeights_ = mixScratch_;
104 endDesigned_ = false;
105 updateEnvelopeCoeffs();
106 coefSmoothCoeff_ = static_cast<T>(1.0 - std::exp(-1.0 / (sampleRate_ * 0.001)));
107 autoFall_ = std::pow(10.0, -kAutoRefFallDb / (20.0 * sampleRate_));
108
109 reset();
110
111 filterParamsDirty_.store(true, std::memory_order_release);
112 updateFiltersIfDirty();
113 }
114
119 void processBlock(AudioBufferView<T> buffer) noexcept
120 {
121 if (removalListen_.load(std::memory_order_relaxed) && !removalScratch_.empty())
122 {
123 // Removal listen: the input minus the de-essed signal (no latency),
124 // in chunks as long as the scratch.
125 const int nCh = std::min(buffer.getNumChannels(), static_cast<int>(removalScratch_.size()));
126 const int step = static_cast<int>(removalScratch_[0].size());
127 for (int off = 0; off < buffer.getNumSamples(); off += step)
128 {
129 const int m = std::min(step, buffer.getNumSamples() - off);
130 auto part = buffer.getSubView(off, m);
131 for (int ch = 0; ch < nCh; ++ch) std::copy_n(part.getChannel(ch), m, removalScratch_[static_cast<size_t>(ch)].data());
132 processWet(part);
133 for (int ch = 0; ch < nCh; ++ch)
134 {
135 T* d = part.getChannel(ch);
136 const T* in = removalScratch_[static_cast<size_t>(ch)].data();
137 for (int i = 0; i < m; ++i) d[i] = in[i] - d[i];
138 }
139 }
140 return;
141 }
142 processWet(buffer);
143 }
144
149 void setRemovalListen(bool on) noexcept { removalListen_.store(on, std::memory_order_relaxed); }
151 [[nodiscard]] bool isRemovalListen() const noexcept { return removalListen_.load(std::memory_order_relaxed); }
152
154 enum class Structure
155 {
156 DirectForm,
157 Ladder
158 };
159
171 void setStructure(Structure structure) noexcept
172 {
173 structure_.store(static_cast<Structure>(std::clamp(static_cast<int>(structure), 0, 1)), std::memory_order_relaxed);
174 }
175
177 [[nodiscard]] Structure getStructure() const noexcept { return structure_.load(std::memory_order_relaxed); }
178
208 void setMixedBell(bool on) noexcept { mixedWanted_.store(on, std::memory_order_relaxed); }
209
211 [[nodiscard]] bool isMixedBell() const noexcept { return mixedWanted_.load(std::memory_order_relaxed); }
212
213private:
214 void processWet(AudioBufferView<T> buffer) noexcept
215 {
216 int numCh = std::min(buffer.getNumChannels(), std::min(numChannels_, kMaxChannels));
217 int numSamples = buffer.getNumSamples();
218 if (numSamples == 0 || numCh == 0) return;
219 DenormalGuard guard;
220
221 updateFiltersIfDirty();
222
223 // A change of structure restarts the bell's memory.
224 const bool ladder = structure_.load(std::memory_order_relaxed) == Structure::Ladder;
225 if (ladder != ladderActive_)
226 {
227 ladderActive_ = ladder;
228 for (int ch = 0; ch < kMaxChannels; ++ch)
229 {
230 reduction_[ch].reset();
231 ladder_[ch].reset();
232 ladder_[ch].setCoeffs(reduction_[ch].getCoeffs());
233 }
234 }
235
236 if (envCoefsDirty_.exchange(false, std::memory_order_acquire))
237 updateEnvelopeCoeffs();
238
239 T thresh = threshold_.load(std::memory_order_relaxed);
240 T maxRed = maxReduction_.load(std::memory_order_relaxed);
241 auto mode = detectionMode_.load(std::memory_order_relaxed);
242 relative_ = autoThreshold_.load(std::memory_order_relaxed);
243
244 constexpr int kCoefRefreshInterval = 16;
245 const T coefSmooth = coefSmoothCoeff_;
246 T blockMaxGr = T(0);
247
248 // A change of engine restarts the filter memories.
249 const bool mixed = mixedWanted_.load(std::memory_order_relaxed) && !mixScratch_.empty();
250 if (mixed != mixedActive_)
251 {
252 mixedActive_ = mixed;
253 end_.reset();
254 for (int ch = 0; ch < kMaxChannels; ++ch)
255 {
256 reduction_[ch].reset();
257 ladder_[ch].reset();
258 }
259 }
260
261 if (mixedActive_)
262 {
263 designEnd(static_cast<double>(maxRed));
264 const int step = static_cast<int>(mixScratch_[0].size());
265 for (int off = 0; off < numSamples; off += step)
266 {
267 const int m = std::min(step, numSamples - off);
268 auto part = buffer.getSubView(off, m);
269 if (mode == DetectionMode::Derivative)
270 processInternal<true, true>(part, numCh, m, thresh, maxRed, coefSmooth, kCoefRefreshInterval, blockMaxGr);
271 else
272 processInternal<false, true>(part, numCh, m, thresh, maxRed, coefSmooth, kCoefRefreshInterval, blockMaxGr);
273 mixEnd(part, numCh, m);
274 }
275 }
276 // Branch hoisting: Process samples depending on the mode to avoid inner-loop conditionals.
277 else if (mode == DetectionMode::Derivative)
278 {
279 processInternal<true>(buffer, numCh, numSamples, thresh, maxRed, coefSmooth, kCoefRefreshInterval, blockMaxGr);
280 }
281 else
282 {
283 processInternal<false>(buffer, numCh, numSamples, thresh, maxRed, coefSmooth, kCoefRefreshInterval, blockMaxGr);
284 }
285
286 gainReduction_.store(blockMaxGr, std::memory_order_relaxed);
287 }
288
289public:
291 void reset() noexcept
292 {
293 for (int ch = 0; ch < kMaxChannels; ++ch)
294 {
295 detector_[ch].reset();
296 reduction_[ch].reset();
297 ladder_[ch].reset();
298 smoothedGrDb_[ch] = T(0);
299 derivShift_[ch].fill(T(0));
300 }
301 end_.reset();
302 envelope_ = T(0);
303 autoRef_ = kAutoRefFloor;
304 refreshCounter_ = 0;
305 gainReduction_.store(T(0), std::memory_order_relaxed);
306 }
307
308 // Setters
309
311 void setAttack(T ms) noexcept
312 {
313 if (!std::isfinite(ms)) return;
314 attackMs_.store(std::clamp(ms, T(0.1), T(20)), std::memory_order_relaxed);
315 envCoefsDirty_.store(true, std::memory_order_release);
316 }
317
319 void setRelease(T ms) noexcept
320 {
321 if (!std::isfinite(ms)) return;
322 releaseMs_.store(std::clamp(ms, T(1), T(500)), std::memory_order_relaxed);
323 envCoefsDirty_.store(true, std::memory_order_release);
324 }
325
332 void setFrequency(T hz) noexcept
333 {
334 if (!std::isfinite(hz)) return;
335 frequency_.store(hz, std::memory_order_relaxed);
336 filterParamsDirty_.store(true, std::memory_order_release);
337 }
338
340 void setBandwidth(T octaves) noexcept
341 {
342 if (!std::isfinite(octaves)) return;
343 T bw = std::max(octaves, T(0.1));
344 T q = T(1) / (T(2) * std::sinh(T(0.34657359) * bw));
345 bandwidth_.store(q, std::memory_order_relaxed);
346 filterParamsDirty_.store(true, std::memory_order_release);
347 }
348
350 void setThreshold(T db) noexcept
351 {
352 if (!std::isfinite(db)) return;
353 threshold_.store(db, std::memory_order_relaxed);
354 }
355
368 void setAutoThreshold(bool on) noexcept { autoThreshold_.store(on, std::memory_order_relaxed); }
369
371 [[nodiscard]] bool isAutoThreshold() const noexcept { return autoThreshold_.load(std::memory_order_relaxed); }
372
374 void setReduction(T db) noexcept
375 {
376 if (!std::isfinite(db)) return;
377 maxReduction_.store(std::abs(db), std::memory_order_relaxed);
378 }
379
381 void setDetectionMode(DetectionMode mode) noexcept
382 {
383 const int v = std::clamp(static_cast<int>(mode),
384 static_cast<int>(DetectionMode::Bandpass),
385 static_cast<int>(DetectionMode::Derivative));
386 detectionMode_.store(static_cast<DetectionMode>(v), std::memory_order_relaxed);
387 }
388
389 // Getters
390 [[nodiscard]] T getGainReductionDb() const noexcept { return gainReduction_.load(std::memory_order_relaxed); }
391 [[nodiscard]] T getFrequency() const noexcept { return frequency_.load(std::memory_order_relaxed); }
392 [[nodiscard]] T getThreshold() const noexcept { return threshold_.load(std::memory_order_relaxed); }
393 [[nodiscard]] DetectionMode getDetectionMode() const noexcept { return detectionMode_.load(std::memory_order_relaxed); }
394 [[nodiscard]] T getAttack() const noexcept { return attackMs_.load(std::memory_order_relaxed); }
395 [[nodiscard]] T getRelease() const noexcept { return releaseMs_.load(std::memory_order_relaxed); }
396
398 [[nodiscard]] T getBandwidth() const noexcept
399 {
400 return static_cast<T>(std::asinh(1.0 / (2.0 * static_cast<double>(
401 bandwidth_.load(std::memory_order_relaxed)))) / 0.34657359);
402 }
403
405 [[nodiscard]] T getReduction() const noexcept { return maxReduction_.load(std::memory_order_relaxed); }
406
408 [[nodiscard]] std::vector<uint8_t> getState() const
409 {
410 // The blob stores float (setState reads float back); the explicit
411 // casts also keep this overload resolvable when T is double.
412 StateWriter w(stateId("DEES"), 1);
413 w.write("frequency", static_cast<float>(frequency_.load(std::memory_order_relaxed)));
414 // bandwidth_ stores Q = 1/(2 sinh(ln2/2 * oct)); serialize back in octaves.
415 w.write("bandwidth", static_cast<float>(getBandwidth()));
416 w.write("threshold", static_cast<float>(threshold_.load(std::memory_order_relaxed)));
417 w.write("reduction", static_cast<float>(maxReduction_.load(std::memory_order_relaxed)));
418 w.write("attack", static_cast<float>(attackMs_.load(std::memory_order_relaxed)));
419 w.write("release", static_cast<float>(releaseMs_.load(std::memory_order_relaxed)));
420 w.write("detection", static_cast<int32_t>(detectionMode_.load(std::memory_order_relaxed)));
421 w.write("structure", static_cast<int32_t>(getStructure()));
422 w.write("autoThreshold", autoThreshold_.load(std::memory_order_relaxed));
423 w.write("mixedBell", isMixedBell());
424 return w.blob();
425 }
426
428 bool setState(const uint8_t* data, size_t size)
429 {
430 StateReader r(data, size);
431 if (!r.isValid() || r.processorId() != stateId("DEES")) return false;
432 setFrequency(static_cast<T>(r.read("frequency", 7000.0f)));
433 // Missing key: the constructor default, Q = 2 (0.714 octaves). The
434 // fallback used to be 2 octaves, a different filter.
435 setBandwidth(static_cast<T>(r.read("bandwidth", 0.7140373f)));
436 setThreshold(static_cast<T>(r.read("threshold", -20.0f)));
437 setReduction(static_cast<T>(r.read("reduction", 12.0f)));
438 setAttack(static_cast<T>(r.read("attack", 0.5f)));
439 setRelease(static_cast<T>(r.read("release", 20.0f)));
440 setDetectionMode(static_cast<DetectionMode>(r.read("detection", 0)));
441 setStructure(static_cast<Structure>(r.read("structure", 0)));
442 setAutoThreshold(r.read("autoThreshold", false));
443 setMixedBell(r.read("mixedBell", false));
444 return true;
445 }
446
447private:
448 template <bool IsDerivative, bool Mixed = false>
449 void processInternal(AudioBufferView<T>& buffer, int numCh, int numSamples,
450 T thresh, T maxRed, T coefSmooth, int refreshInterval, T& blockMaxGr) noexcept
451 {
452 for (int i = 0; i < numSamples; ++i)
453 {
454 T maxLevel = T(0);
455 T maxInput = T(0);
456
457 // 1. Stereo-linked detection
458 for (int ch = 0; ch < numCh; ++ch)
459 {
460 T dataIn = buffer.getChannel(ch)[i];
461 if (!std::isfinite(dataIn)) dataIn = T(0); // would latch in the detector
462 maxInput = std::max(maxInput, std::abs(dataIn));
463 T level = T(0);
464
465 if constexpr (IsDerivative)
466 {
467 auto& sr = derivShift_[ch];
468 for (int k = kDerivLen - 1; k > 0; --k) sr[k] = sr[k - 1];
469 sr[0] = detector_[ch].processSample(dataIn, 0);
470
471 T sumDiffs = T(0);
472 for (int k = 0; k < kDerivLen - 1; ++k)
473 {
474 sumDiffs += std::abs(sr[k] - sr[k + 1]);
475 }
476 level = sumDiffs / T(kDerivLen - 1);
477 }
478 else
479 {
480 level = std::abs(detector_[ch].processSample(dataIn, 0));
481 }
482
483 if (level > maxLevel) maxLevel = level;
484 }
485
486 // 2. Single linked envelope
487 T coeff = (maxLevel > envelope_) ? attackCoeff_ : releaseCoeff_;
488 envelope_ += coeff * (maxLevel - envelope_);
489
490 // 3. Compute GR
491 T envDb = gainToDecibels(envelope_ + T(1e-30));
492 T threshNow = thresh;
493 if (relative_)
494 {
495 // The threshold counts from a reference that follows the
496 // whole input: up at once, down 1 dB per second.
497 autoRef_ = std::max({ static_cast<double>(maxInput), autoRef_ * autoFall_, kAutoRefFloor });
498 threshNow = thresh + gainToDecibels(static_cast<T>(autoRef_));
499 }
500 T overDb = envDb - threshNow;
501 T grDb = (overDb > T(0)) ? -std::min(overDb, maxRed) : T(0);
502
503 if (-grDb > blockMaxGr) blockMaxGr = -grDb;
504
505 // 4. Apply processing per channel. The refresh grid is a
506 // free-running counter (not the block index), so the output
507 // does not depend on how the host cuts the stream.
508 if constexpr (Mixed)
509 {
510 // Mixed: only the share of the fixed end filter is computed
511 // here; mixEnd() runs the filter over the chunk afterwards.
512 (void)refreshInterval;
513 for (int ch = 0; ch < numCh; ++ch)
514 {
515 T& smoothedGr = smoothedGrDb_[ch];
516 smoothedGr += coefSmooth * (grDb - smoothedGr);
517 double w = 0.0;
518 if (smoothedGr < T(0) && endShare_ > 0.0)
519 w = std::clamp((1.0 - std::pow(10.0, static_cast<double>(smoothedGr) / 20.0)) / endShare_, 0.0, 1.0);
520 mixWeights_[static_cast<size_t>(ch)][static_cast<size_t>(i)] = static_cast<T>(w);
521 }
522 }
523 else
524 {
525 const bool refresh = (refreshCounter_ & static_cast<unsigned>(refreshInterval - 1)) == 0u;
526 ++refreshCounter_;
527 for (int ch = 0; ch < numCh; ++ch)
528 {
529 T& smoothedGr = smoothedGrDb_[ch];
530 smoothedGr += coefSmooth * (grDb - smoothedGr);
531
532 if (refresh)
533 {
534 // Channels share the linked gain: design once per frame.
535 if (ch > 0 && smoothedGr == smoothedGrDb_[0])
536 {
537 reduction_[ch].setCoeffsNow(reduction_[0].getCoeffs());
538 if (ladderActive_) ladder_[ch].setLadder(ladder_[0].getLadder());
539 }
540 else
541 updateDynamicPeakCoeffs(ch, smoothedGr);
542 }
543
544 T* channelData = buffer.getChannel(ch);
545 const T x = channelData[i];
546 // A non-finite sample passes without entering the filter state.
547 if (!std::isfinite(x)) continue;
548 channelData[i] = ladderActive_ ? static_cast<T>(ladder_[ch].processSample(static_cast<double>(x), 0))
549 : reduction_[ch].processSample(x, 0);
550 }
551 }
552 }
553 }
554
559 void updateFiltersIfDirty() noexcept
560 {
561 if (!filterParamsDirty_.exchange(false, std::memory_order_acquire))
562 return;
563
564 T freq = frequency_.load(std::memory_order_relaxed);
565 T bw = bandwidth_.load(std::memory_order_relaxed);
566
567 // One shared effective frequency for BOTH filters. The bandpass
568 // factory clamps internally, but the precomputed peak terms did not:
569 // beyond Nyquist sin(w0) goes negative, alpha flips sign and the
570 // dynamic bell turns unstable under gain reduction.
571 const double fEff = std::clamp(static_cast<double>(freq), 1.0,
572 std::max(1.0, sampleRate_ * 0.499));
573
574 // Stream-owner direct writes (setCoeffsNow): prepare() and the audio
575 // thread are the only callers, and the coefficients are for their own
576 // use (docs/threading.md, the origin rule).
577 // Matched to the analog band-pass, like the bell it drives: a
578 // bilinear one narrows toward Nyquist and would hear less than the
579 // bell cuts, right where the sibilance is.
580 auto c = BiquadCoeffs::makeBandPassMatched(sampleRate_, fEff, static_cast<double>(bw));
581 for (int ch = 0; ch < kMaxChannels; ++ch)
582 detector_[ch].setCoeffsNow(c);
583
584 peakFreq_ = fEff;
585 peakQ_ = static_cast<double>(bw);
586 }
587
593 void updateDynamicPeakCoeffs(int ch, T gainDb) noexcept
594 {
595 // Stream-owner direct write: computed on the audio thread for its own
596 // use, so it bypasses the staged cross-thread channel.
597 const BiquadCoeffs c = BiquadCoeffs::makePeakMatched(sampleRate_, peakFreq_, peakQ_, static_cast<double>(gainDb));
598 reduction_[ch].setCoeffsNow(c);
599 if (ladderActive_) ladder_[ch].setCoeffs(c);
600 }
601
610 void designEnd(double rangeDb) noexcept
611 {
612 if (endDesigned_ && peakFreq_ == endFreq_ && peakQ_ == endQ_ && rangeDb == endRange_) return;
613 const BiquadCoeffs half = BiquadCoeffs::makePeakMatched(sampleRate_, peakFreq_, peakQ_, -0.5 * rangeDb);
614 const double reach = 1.0 + std::pow(10.0, -rangeDb / 40.0);
615 BiquadCoeffs end = half;
616 end.b0 = 1.0 + reach * (half.b0 - 1.0);
617 end.b1 = half.a1 + reach * (half.b1 - half.a1);
618 end.b2 = half.a2 + reach * (half.b2 - half.a2);
619 if (endDesigned_) end_.rampCoeffs(end, static_cast<int>(std::lround(kMixedRampMs * 0.001 * sampleRate_)));
620 else end_.setCoeffs(end);
621 endDesigned_ = true;
622 endFreq_ = peakFreq_;
623 endQ_ = peakQ_;
624 endRange_ = rangeDb;
625 endShare_ = rangeDb > 0.0 ? 1.0 - std::pow(10.0, -rangeDb / 20.0) : 0.0;
626 }
627
633 void mixEnd(AudioBufferView<T>& part, int numCh, int n) noexcept
634 {
635 T* copies[kMaxChannels] = {};
636 for (int ch = 0; ch < numCh; ++ch)
637 {
638 const T* x = part.getChannel(ch);
639 T* c = mixScratch_[static_cast<size_t>(ch)].data();
640 for (int i = 0; i < n; ++i) c[i] = std::isfinite(x[i]) ? x[i] : T(0);
641 copies[ch] = c;
642 }
643 end_.processBlock(AudioBufferView<T>(copies, numCh, n));
644 for (int ch = 0; ch < numCh; ++ch)
645 {
646 T* y = part.getChannel(ch);
647 const T* e = copies[ch];
648 const T* w = mixWeights_[static_cast<size_t>(ch)].data();
649 for (int i = 0; i < n; ++i)
650 if (w[i] > T(0) && std::isfinite(y[i])) y[i] += w[i] * (e[i] - y[i]);
651 }
652 }
653
654 void updateEnvelopeCoeffs() noexcept
655 {
656 if (sampleRate_ <= 0.0) return;
657 const double atkSec = static_cast<double>(attackMs_.load(std::memory_order_relaxed)) * 0.001;
658 const double relSec = static_cast<double>(releaseMs_.load(std::memory_order_relaxed)) * 0.001;
659 attackCoeff_ = static_cast<T>(1.0 - std::exp(-1.0 / (sampleRate_ * std::max(atkSec, 1e-6))));
660 releaseCoeff_ = static_cast<T>(1.0 - std::exp(-1.0 / (sampleRate_ * std::max(relSec, 1e-6))));
661 }
662
663 static constexpr int kMaxChannels = 2;
664 static constexpr int kDerivLen = 8;
665
666 double sampleRate_ = 44100.0;
667 int numChannels_ = 0;
668
669 std::atomic<T> frequency_ { T(7000) };
670 std::atomic<T> bandwidth_ { T(2) };
671 std::atomic<T> threshold_ { T(-20) };
672 std::atomic<T> maxReduction_ { T(12) };
673 std::atomic<T> attackMs_ { T(0.5) };
674 std::atomic<T> releaseMs_ { T(20) };
675 std::atomic<DetectionMode> detectionMode_ { DetectionMode::Bandpass };
676
677 std::atomic<bool> envCoefsDirty_ { false };
678 std::atomic<bool> filterParamsDirty_ { true };
679
680 T attackCoeff_ = T(0);
681 T releaseCoeff_ = T(0);
682 T coefSmoothCoeff_ = T(0);
683 std::atomic<T> gainReduction_ { T(0) };
684
685 Biquad<T, 1> detector_[kMaxChannels]{};
686 Biquad<T, 1> reduction_[kMaxChannels]{};
687 NormalizedLadder<T, 1> ladder_[kMaxChannels]{};
688 std::atomic<Structure> structure_ { Structure::DirectForm };
689 bool ladderActive_ = false;
690
691 // Mixed bell (setMixedBell()).
692 static constexpr double kMixedRampMs = 20.0;
693 std::atomic<bool> mixedWanted_ { false };
694 bool mixedActive_ = false;
695 NormalizedLadder<T, kMaxChannels> end_;
696 std::vector<std::vector<T>> mixScratch_;
697 std::vector<std::vector<T>> mixWeights_;
698 bool endDesigned_ = false;
699 double endFreq_ = 0.0, endQ_ = 0.0, endRange_ = 0.0;
700 double endShare_ = 0.0;
701
702 // Automatic threshold (setAutoThreshold()).
703 static constexpr double kAutoRefFallDb = 1.0;
704 static constexpr double kAutoRefFloor = 1e-5;
705 std::atomic<bool> autoThreshold_ { false };
706 std::atomic<bool> removalListen_ { false };
707 std::vector<std::vector<T>> removalScratch_;
708 bool relative_ = false;
709 double autoRef_ = kAutoRefFloor;
710 double autoFall_ = 1.0;
711
712 T envelope_{T(0)}; // Stereo-linked envelope
713 T smoothedGrDb_[kMaxChannels]{};
714
715 std::array<std::array<T, kDerivLen>, kMaxChannels> derivShift_ {};
716
717 // Bell design inputs (clamped centre and Q), set with the detector.
718 double peakFreq_ = 7000.0;
719 double peakQ_ = 2.0;
720 unsigned refreshCounter_ = 0;
721};
722
723} // namespace dspark
Non-owning view over audio channel data.
Definition AudioBuffer.h:53
void setCoeffsNow(const BiquadCoeffs &c) noexcept
Stream-owner direct set: makes c the active set immediately.
Definition Biquad.h:963
void reset() noexcept
Resets all per-channel filter states to zero to avoid ringing/clicks.
Definition Biquad.h:1003
T processSample(T input, int channel) noexcept
Processes a single sample for a specific channel.
Definition Biquad.h:1029
Stereo-linked, CPU-optimized dynamic-EQ de-esser.
Definition DeEsser.h:76
T getAttack() const noexcept
Definition DeEsser.h:394
void setAutoThreshold(bool on) noexcept
Counts the threshold from the level of the whole input.
Definition DeEsser.h:368
void setRemovalListen(bool on) noexcept
Removal listen: the output is what the de-esser takes out. A monitoring control, not in the state.
Definition DeEsser.h:149
bool isAutoThreshold() const noexcept
Whether the threshold counts from the level of the input (see setAutoThreshold()).
Definition DeEsser.h:371
DetectionMode getDetectionMode() const noexcept
Definition DeEsser.h:393
T getReduction() const noexcept
Definition DeEsser.h:405
T getThreshold() const noexcept
Definition DeEsser.h:392
bool setState(const uint8_t *data, size_t size)
Restores parameters from a blob (tolerant; rejects foreign ids).
Definition DeEsser.h:428
void setMixedBell(bool on) noexcept
Runs the cut as one fixed filter mixed by the reduction.
Definition DeEsser.h:208
std::vector< uint8_t > getState() const
Serializes the parameter state (setup/UI threads; allocates).
Definition DeEsser.h:408
bool isMixedBell() const noexcept
Definition DeEsser.h:211
void setThreshold(T db) noexcept
Sets the detection threshold in dBFS. Non-finite values are ignored.
Definition DeEsser.h:350
void setReduction(T db) noexcept
Sets the maximum gain reduction in dB (sign is ignored). Non-finite values are ignored.
Definition DeEsser.h:374
void setAttack(T ms) noexcept
Sets the detector attack, clamped to [0.1, 20] ms. Non-finite values are ignored.
Definition DeEsser.h:311
void setDetectionMode(DetectionMode mode) noexcept
Sets the detection mode. Out-of-range values are clamped so the getter stays honest.
Definition DeEsser.h:381
void prepare(const AudioSpec &spec)
Prepares the de-esser state and filters.
Definition DeEsser.h:92
void reset() noexcept
Resets internal DSP state.
Definition DeEsser.h:291
T getGainReductionDb() const noexcept
Definition DeEsser.h:390
void setStructure(Structure structure) noexcept
Chooses how the cut bell is realised.
Definition DeEsser.h:171
void processBlock(AudioBufferView< T > buffer) noexcept
Processes audio in-place. Stereo-linked to preserve imaging.
Definition DeEsser.h:119
T getRelease() const noexcept
Definition DeEsser.h:395
Structure
How the cut bell is realised (see setStructure()).
Definition DeEsser.h:155
@ Ladder
Normalized ladder: passive while the reduction moves the bell.
@ DirectForm
Direct form (the default).
void setRelease(T ms) noexcept
Sets the detector release, clamped to [1, 500] ms. Non-finite values are ignored.
Definition DeEsser.h:319
void setBandwidth(T octaves) noexcept
Sets the detection/cut bandwidth in octaves (floored at 0.1). Non-finite values are ignored.
Definition DeEsser.h:340
void setFrequency(T hz) noexcept
Sets the sibilance centre frequency in Hz.
Definition DeEsser.h:332
@ Bandpass
Standard bandpass filter detection.
@ Derivative
Sum of absolute derivatives. Sensitive to sustained high frequencies.
T getFrequency() const noexcept
Definition DeEsser.h:391
bool isRemovalListen() const noexcept
Definition DeEsser.h:151
Structure getStructure() const noexcept
Definition DeEsser.h:177
T getBandwidth() const noexcept
Definition DeEsser.h:398
RAII scope guard to disable denormalised (subnormal) floating-point numbers.
void reset() noexcept
Clears the memory of every channel. Coefficients and ramp are kept.
void setCoeffs(const BiquadCoeffs &b) noexcept
Makes a biquad's response the section's own from the next sample; ends a ramp.
void setLadder(const Coeffs &l) noexcept
Sets rotations and taps directly from the next sample; ends a ramp.
void rampCoeffs(const BiquadCoeffs &target, int samples) noexcept
Moves the rotations and the taps linearly to those of a biquad.
double processSample(double input, int channel) noexcept
One sample of one channel, in double, with the coefficients as they are.
void processBlock(AudioBufferView< T > buffer) noexcept
Runs a block through the section, in place.
Tolerant reader: missing keys yield defaults, unknown keys are skipped.
Definition StateBlob.h:171
float read(const char *key, float defaultValue) const
Reads a float, or defaultValue when the key is absent.
Definition StateBlob.h:214
bool isValid() const noexcept
Definition StateBlob.h:209
uint32_t processorId() const noexcept
Definition StateBlob.h:210
Serializes key/value parameters into a versioned blob.
Definition StateBlob.h:53
std::vector< uint8_t > blob() const
Finalizes and returns the blob.
Definition StateBlob.h:112
void write(const char *key, float value)
Writes a float parameter.
Definition StateBlob.h:71
Main namespace for the DSPark framework.
T gainToDecibels(T gain, T minusInfinityDb=T(-100)) noexcept
Converts a linear gain value to decibels.
Definition DspMath.h:92
constexpr uint32_t stateId(const char(&tag)[5]) noexcept
Builds a FOURCC processor id, e.g. dspark::stateId("COMP").
Definition StateBlob.h:672
Describes the audio environment for a DSP processor.
Definition AudioSpec.h:37
constexpr bool isValid() const noexcept
Checks if the specification contains valid, processable parameters.
Definition AudioSpec.h:71
int numChannels
Number of audio channels (e.g., 1 = mono, 2 = stereo).
Definition AudioSpec.h:58
int maxBlockSize
Maximum number of samples per processing block.
Definition AudioSpec.h:53
double sampleRate
Sample rate in Hz.
Definition AudioSpec.h:45
static BiquadCoeffs makePeakMatched(double sampleRate, double freq, double Q, double gainDb) noexcept
Analog-matched ("de-cramped") peaking filter (Vicanek design).
Definition Biquad.h:248
static BiquadCoeffs makeBandPassMatched(double sampleRate, double freq, double Q=0.7071067811865476) noexcept
Analog-matched band-pass, 0 dB at the centre (Vicanek 2016).
Definition Biquad.h:370