DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
ResonanceSuppressor.h
1// DSPark - Professional Audio DSP Framework
2// Copyright (c) 2026 Cristian Moresi - MIT License
3
4#pragma once
5
70#include "../Core/AudioBuffer.h"
71#include "../Core/AudioSpec.h"
72#include "../Core/AuditoryBands.h"
73#include "../Core/DetailAnalysis.h"
74#include "../Core/DetailFilter.h"
75#include "../Core/DspMath.h"
76#include "../Core/KeyEqualizer.h"
77#include "../Core/SpectralFilter.h"
78#include "../Core/StateBlob.h"
79
80#include <algorithm>
81#include <array>
82#include <atomic>
83#include <cmath>
84#include <cstdint>
85#include <numbers>
86#include <vector>
87
88namespace dspark {
89
96template <FloatType T>
98{
99public:
100 enum class Mode { Smooth, Deep };
101 enum class Link { PerBin, MidSide };
102 enum class Quality { Realtime, Offline };
103 static constexpr int kSensitivityBands = 6;
105
107 void prepare(const AudioSpec& spec)
108 {
109 if (!spec.isValid()) return;
110 prepared_ = false;
111 spec_ = spec;
112 const bool offline = quality_.load(std::memory_order_relaxed) == Quality::Offline
113 || (qualityFollowsRender_.load(std::memory_order_relaxed) && offlineRendering_.load(std::memory_order_relaxed));
114 qualityInUse_.store(offline ? Quality::Offline : Quality::Realtime, std::memory_order_relaxed);
115 channels_ = std::min(spec.numChannels, DetailFilter<T>::kMaxChannels);
116 filter_.prepare(spec);
117 analysis_.prepare(spec);
118 analysis_.setExhaustive(offline);
119 hopSeconds_ = static_cast<double>(filter_.getHopSize()) / spec.sampleRate;
120
121 const auto tracks = static_cast<size_t>(channels_ + 1); // the channels, and a pair's mean
122 for (auto* v : { &smoothPower_, &gainDb_, &lasted_ }) v->assign(tracks, std::vector<T>(kSize, T(0)));
123 raw_.assign(2, std::vector<T>(kSize, T(0)));
124 amplitude_.assign(kSize, 0.0);
125 peaks_.assign(kSize, 0);
126 nowLevel_.assign(kSize, T(0));
127 for (auto* v : { &level_, &linked_, &found_, &weight_, &weightNext_, &attack_, &release_, &timeSmooth_, &octave_ })
128 v->assign(kSize, T(0));
129 std::fill(weight_.begin(), weight_.end(), T(1));
130 for (auto* v : { &near_, &pick_, &apart_, &beside_, &reach_, &cut_ }) v->assign(kSize, 0);
131 foundationRise_.assign(kSize, T(1));
132 for (int i = 0; i < kPoints; ++i)
133 {
134 const double hz = DetailFilter<T>::frequency(i);
135 octave_[static_cast<size_t>(i)] = static_cast<T>(std::log2(hz / 1000.0));
136 const double up = std::max(0.0, std::log2(hz / kFoundationHz) / kFoundationOctaves);
137 foundationRise_[static_cast<size_t>(i)] = static_cast<T>(std::min(1.0, up * up));
138 }
139 tiltPerPoint_ = static_cast<T>(kTiltDbPerOctave / pointsPerOctave());
140 earBest_ = 1e9;
141 for (double hz = 1000.0; hz <= 6000.0; hz += 100.0) earBest_ = std::min(earBest_, AuditoryScale::thresholdInQuietDb(hz));
142 sensitivity_.prepare(spec.sampleRate);
143 excess_.clear();
144 shownCurve_ = 0;
145 refreshDetector(mode_.load(std::memory_order_relaxed) == Mode::Deep);
146 refreshTimes();
147 weightPos_ = 0;
148 weightPending_ = false;
149 weightDirty_.store(true, std::memory_order_release);
150 prepared_ = true;
151 }
152
154 void reset() noexcept
155 {
156 filter_.reset();
157 analysis_.reset();
158 for (auto* set : { &smoothPower_, &gainDb_, &lasted_ })
159 for (auto& v : *set) std::fill(v.begin(), v.end(), T(0));
160 shownCurve_ = 0;
161 excess_.clear();
162 }
163
164 // -- Controls ------------------------------------------------------------
165
171 void setDetail(T octaves) noexcept { store(detail_, octaves, kFinestDetail, kWidestDetail); }
173 void setThreshold(T db) noexcept { store(threshold_, db, T(0), T(30)); }
175 void setStrength(T amount) noexcept { store(strength_, amount, T(0), T(1)); }
177 void setRange(T db) noexcept { store(range_, db, T(0), T(48)); }
183 void setWidth(T octaves) noexcept { store(width_, octaves, T(0.05), T(4)); }
185 void setAttack(T ms) noexcept { store(attackMs_, ms, T(0.5), T(500)); timesDirty_.store(true, std::memory_order_release); }
187 void setRelease(T ms) noexcept { store(releaseMs_, ms, T(5), T(2000)); timesDirty_.store(true, std::memory_order_release); }
197 void setMode(Mode m) noexcept { mode_.store(m == Mode::Deep ? Mode::Deep : Mode::Smooth, std::memory_order_relaxed); }
206 void setFoundationGuard(T amount) noexcept { store(guard_, amount, T(0), T(1)); }
208 void setLinkMode(Link l) noexcept { link_.store(l == Link::MidSide ? Link::MidSide : Link::PerBin, std::memory_order_relaxed); }
210 void setLink(T amount) noexcept { store(linkAmount_, amount, T(0), T(1)); }
212 void setSideWeight(T share) noexcept { store(sideWeight_, share, T(0), T(2)); }
214 void setRemovalListen(bool on) noexcept { removalListen_.store(on, std::memory_order_relaxed); }
216 void setFocusListen(bool on) noexcept { focusListen_.store(on, std::memory_order_relaxed); }
223 void setMix(T amount) noexcept { store(mix_, amount, T(0), T(1)); }
230 void setKnee(T db) noexcept { store(knee_, db, T(0), T(12)); }
238 void setPersistence(T ms) noexcept { store(persistenceMs_, ms, T(0), T(500)); }
247 void setQuietLevel(T dbfs) noexcept
248 {
249 if (std::isfinite(dbfs)) quietDb_.store(dbfs < T(-190) ? T(-200) : std::clamp(dbfs, T(-120), T(0)), std::memory_order_relaxed);
250 }
258 void setAuditoryWeighting(bool on) noexcept
259 {
260 auditory_.store(on, std::memory_order_relaxed);
261 weightDirty_.store(true, std::memory_order_release);
262 }
271 void setWidthTaper(T cornerHz, T exponent) noexcept
272 {
273 store(taperHz_, cornerHz, T(200), T(20000));
274 store(taperExponent_, exponent, T(0), T(2));
275 }
283 void setRemovalBand(T lowHz, T highHz) noexcept
284 {
285 if (!std::isfinite(lowHz) || !std::isfinite(highHz)) return;
286 bandLow_.store(std::max(T(0), std::min(lowHz, highHz)), std::memory_order_relaxed);
287 bandHigh_.store(std::max(T(0), std::max(lowHz, highHz)), std::memory_order_relaxed);
288 }
294 void setQuality(Quality q) noexcept { quality_.store(q == Quality::Offline ? Quality::Offline : Quality::Realtime, std::memory_order_relaxed); }
301 void setQualityFollowsRender(bool on) noexcept { qualityFollowsRender_.store(on, std::memory_order_relaxed); }
307 void setOfflineRendering(bool on) noexcept { offlineRendering_.store(on, std::memory_order_relaxed); }
309 void setSensitivityBand(int index, const Band& band) noexcept
310 {
311 sensitivity_.setBand(index, band);
312 weightDirty_.store(true, std::memory_order_release);
313 }
314
315 [[nodiscard]] T getDetail() const noexcept { return detail_.load(std::memory_order_relaxed); }
316
322 void setShortKernel(bool on) noexcept { shortKernel_.store(on, std::memory_order_relaxed); }
324 [[nodiscard]] bool getShortKernel() const noexcept { return shortKernel_.load(std::memory_order_relaxed); }
325 [[nodiscard]] T getThreshold() const noexcept { return threshold_.load(std::memory_order_relaxed); }
326 [[nodiscard]] T getStrength() const noexcept { return strength_.load(std::memory_order_relaxed); }
327 [[nodiscard]] T getRange() const noexcept { return range_.load(std::memory_order_relaxed); }
328 [[nodiscard]] T getWidth() const noexcept { return width_.load(std::memory_order_relaxed); }
329 [[nodiscard]] T getAttack() const noexcept { return attackMs_.load(std::memory_order_relaxed); }
330 [[nodiscard]] T getRelease() const noexcept { return releaseMs_.load(std::memory_order_relaxed); }
331 [[nodiscard]] Mode getMode() const noexcept { return mode_.load(std::memory_order_relaxed); }
332 [[nodiscard]] Link getLinkMode() const noexcept { return link_.load(std::memory_order_relaxed); }
333 [[nodiscard]] T getFoundationGuard() const noexcept { return guard_.load(std::memory_order_relaxed); }
334 [[nodiscard]] T getLink() const noexcept { return linkAmount_.load(std::memory_order_relaxed); }
335 [[nodiscard]] T getSideWeight() const noexcept { return sideWeight_.load(std::memory_order_relaxed); }
336 [[nodiscard]] bool getRemovalListen() const noexcept { return removalListen_.load(std::memory_order_relaxed); }
337 [[nodiscard]] bool getFocusListen() const noexcept { return focusListen_.load(std::memory_order_relaxed); }
338 [[nodiscard]] Quality getQuality() const noexcept { return quality_.load(std::memory_order_relaxed); }
339 [[nodiscard]] bool getQualityFollowsRender() const noexcept { return qualityFollowsRender_.load(std::memory_order_relaxed); }
341 [[nodiscard]] Quality getQualityInUse() const noexcept { return qualityInUse_.load(std::memory_order_relaxed); }
342 [[nodiscard]] T getMix() const noexcept { return mix_.load(std::memory_order_relaxed); }
343 [[nodiscard]] T getKnee() const noexcept { return knee_.load(std::memory_order_relaxed); }
344 [[nodiscard]] T getPersistence() const noexcept { return persistenceMs_.load(std::memory_order_relaxed); }
345 [[nodiscard]] T getQuietLevel() const noexcept { return quietDb_.load(std::memory_order_relaxed); }
346 [[nodiscard]] bool getAuditoryWeighting() const noexcept { return auditory_.load(std::memory_order_relaxed); }
347 [[nodiscard]] T getWidthTaperCorner() const noexcept { return taperHz_.load(std::memory_order_relaxed); }
348 [[nodiscard]] T getWidthTaperExponent() const noexcept { return taperExponent_.load(std::memory_order_relaxed); }
349 [[nodiscard]] T getRemovalBandLow() const noexcept { return bandLow_.load(std::memory_order_relaxed); }
350 [[nodiscard]] T getRemovalBandHigh() const noexcept { return bandHigh_.load(std::memory_order_relaxed); }
351 [[nodiscard]] Band getSensitivityBand(int index) const noexcept { return sensitivity_.getBand(index); }
353 [[nodiscard]] int getLatency() const noexcept { return filter_.getLatency(); }
355 [[nodiscard]] T getReduction(double hz) const noexcept
356 {
357 if (gainDb_.empty() || !(hz > 0.0)) return T(0);
358 return gainDb_[0][static_cast<size_t>(std::clamp(pointOf(hz), 0, kPoints - 1))];
359 }
360
361 // -- Display (any thread) --------------------------------------------------
362
366 [[nodiscard]] static double getDisplayFrequency(int point) noexcept { return SpectralReadout<T>::frequency(point); }
375 [[nodiscard]] T getDisplayReduction(int channel, int point) const noexcept { return filter_.playedValue(channel, point); }
382 [[nodiscard]] T getDisplayExcess(int channel, int point) const noexcept { return excess_.value(channel, point); }
384 [[nodiscard]] T getPeakReduction() const noexcept { return filter_.playedExtreme(); }
385
386 // -- Processing ----------------------------------------------------------
387
389 void processBlock(AudioBufferView<T> buffer) noexcept { run(buffer, nullptr); }
392 {
393 run(buffer, key.getNumSamples() >= buffer.getNumSamples() && key.getNumChannels() > 0 ? &key : nullptr);
394 }
395
396 // -- State ---------------------------------------------------------------
397
398 [[nodiscard]] std::vector<uint8_t> getState() const
399 {
400 StateWriter w(stateId("RSUP"), 2);
401 w.write("detail", static_cast<float>(getDetail()));
402 w.write("shortKernel", getShortKernel());
403 w.write("threshold", static_cast<float>(getThreshold()));
404 w.write("strength", static_cast<float>(getStrength()));
405 w.write("range", static_cast<float>(getRange()));
406 w.write("width", static_cast<float>(getWidth()));
407 w.write("attack", static_cast<float>(getAttack()));
408 w.write("release", static_cast<float>(getRelease()));
409 w.write("mode", static_cast<int32_t>(getMode()));
410 w.write("foundationGuard", static_cast<float>(getFoundationGuard()));
411 w.write("linkMode", static_cast<int32_t>(getLinkMode()));
412 w.write("link", static_cast<float>(getLink()));
413 w.write("sideWeight", static_cast<float>(getSideWeight()));
414 w.write("quality", static_cast<int32_t>(getQuality()));
415 w.write("qualityFollowsRender", getQualityFollowsRender());
416 w.write("mix", static_cast<float>(getMix()));
417 w.write("knee", static_cast<float>(getKnee()));
418 w.write("persistence", static_cast<float>(getPersistence()));
419 w.write("quietLevel", static_cast<float>(getQuietLevel()));
420 w.write("auditory", getAuditoryWeighting());
421 w.write("taperHz", static_cast<float>(getWidthTaperCorner()));
422 w.write("taperExponent", static_cast<float>(getWidthTaperExponent()));
423 sensitivity_.writeState(w, "sens");
424 return w.blob();
425 }
426
432 bool setState(const uint8_t* data, size_t size)
433 {
434 StateReader r(data, size);
435 if (!r.isValid() || r.processorId() != stateId("RSUP")) return false;
436 const bool first = r.processorVersion() < 2;
437 setDetail(static_cast<T>(r.read("detail", 1.0f / 12.0f)));
438 setShortKernel(r.read("shortKernel", false));
439 setThreshold(static_cast<T>(first ? r.read("threshold", 3.0f) + 2.0f : r.read("threshold", 5.0f)));
440 setStrength(static_cast<T>(first ? std::min(1.0f, r.read("strength", 0.7f) / 0.7f) : r.read("strength", 1.0f)));
441 setRange(static_cast<T>(r.read("range", first ? 12.0f : 9.0f)));
442 setWidth(static_cast<T>(r.read("width", 1.0f / 3.0f)));
443 setAttack(static_cast<T>(r.read("attack", 5.0f)));
444 setRelease(static_cast<T>(r.read("release", 80.0f)));
445 setMode(r.read("mode", 0) == 1 ? Mode::Deep : Mode::Smooth);
446 setFoundationGuard(static_cast<T>(r.read("foundationGuard", 1.0f)));
447 setLinkMode(r.read("linkMode", 0) == 1 ? Link::MidSide : Link::PerBin);
448 setLink(static_cast<T>(r.read("link", 1.0f)));
449 setSideWeight(static_cast<T>(r.read("sideWeight", 1.0f)));
450 setQuality(r.read("quality", 0) == 1 ? Quality::Offline : Quality::Realtime);
451 setQualityFollowsRender(r.read("qualityFollowsRender", false));
452 setMix(static_cast<T>(r.read("mix", 1.0f)));
453 setKnee(static_cast<T>(r.read("knee", 0.0f)));
454 setPersistence(static_cast<T>(r.read("persistence", first ? 0.0f : 50.0f)));
455 setQuietLevel(static_cast<T>(r.read("quietLevel", -200.0f)));
456 setAuditoryWeighting(r.read("auditory", false));
457 setWidthTaper(static_cast<T>(r.read("taperHz", 2000.0f)), static_cast<T>(r.read("taperExponent", 0.0f)));
458 sensitivity_.readState(r, "sens");
459 weightDirty_.store(true, std::memory_order_release);
460 timesDirty_.store(true, std::memory_order_release);
461 return true;
462 }
463
464private:
465 static constexpr int kPoints = SpectralReadout<T>::kPoints;
466 static constexpr size_t kSize = static_cast<size_t>(kPoints);
467 static constexpr T kFinestDetail = static_cast<T>(DetailAnalysis<T>::kFinest);
468 static constexpr T kWidestDetail = static_cast<T>(DetailAnalysis<T>::kWidest);
469 static constexpr double kTiltDbPerOctave = 3.010299956639812;
470 static constexpr double kPartialHz = 600.0;
471 static constexpr double kPartialReach = 1.25;
472 static constexpr double kShortestSmoothing = 0.04;
473 static constexpr T kPeakOverSurroundings = T(5);
474 static constexpr double kLowNote = 250.0;
475 static constexpr double kFoundationHz = 70.0;
476 static constexpr double kFoundationOctaves = 2.2;
477 static constexpr T kFoundationFade = T(6);
478 static constexpr T kDeepDepth = T(1.5);
479 static constexpr double kDeepApart = 1.5;
480 static constexpr T kTwin = T(3);
481 static constexpr T kDeepFloor = T(20);
482 static constexpr T kPeerUnder = T(20);
483 static constexpr T kStillSounding = T(0.1);
484
485 static void store(std::atomic<T>& a, T v, T lo, T hi) noexcept
486 {
487 if (std::isfinite(v)) a.store(std::clamp(v, lo, hi), std::memory_order_relaxed);
488 }
489
490 [[nodiscard]] static int pointOf(double hz) noexcept
491 {
492 return static_cast<int>(std::lround((kPoints - 1) * std::log(std::max(hz, 1.0) / 20.0) / std::log(1000.0)));
493 }
494
495 [[nodiscard]] static double pointsPerOctave() noexcept
496 {
497 return (kPoints - 1) * std::numbers::ln2 / std::log(1000.0);
498 }
499
501 void refreshDetector(bool deep) noexcept
502 {
503 lastDeep_ = deep;
504 lastDetail_ = detail_.load(std::memory_order_relaxed);
505 const double fine = deep ? std::max(static_cast<double>(kFinestDetail), 0.5 * static_cast<double>(lastDetail_))
506 : static_cast<double>(lastDetail_);
507 lastWidth_ = width_.load(std::memory_order_relaxed);
508 lastTaperHz_ = taperHz_.load(std::memory_order_relaxed);
509 lastTaperExponent_ = taperExponent_.load(std::memory_order_relaxed);
510 analysis_.setWidth(fine);
511 const double perOctave = pointsPerOctave();
512 for (int i = 0; i < kPoints; ++i)
513 {
514 const auto u = static_cast<size_t>(i);
515 const double hz = DetailFilter<T>::frequency(i), window = std::max(1e-3, analysis_.getWindowSeconds(i));
516 // A line's own lobe, where it is wider than the detail.
517 const double lobe = std::log2(1.0 + 2.0 / (window * hz));
518 const double own = std::max(static_cast<double>(lastDetail_), lobe);
519 double width = static_cast<double>(lastWidth_);
520 if (lastTaperExponent_ > T(0) && hz > static_cast<double>(lastTaperHz_))
521 width *= std::pow(static_cast<double>(lastTaperHz_) / hz, static_cast<double>(lastTaperExponent_));
522 const double onward = std::max(width, std::min(kPartialReach, std::log2(1.0 + kPartialHz / hz)));
523 near_[u] = std::max(3, static_cast<int>(std::ceil(own * perOctave)));
524 pick_[u] = deep ? std::min(near_[u], std::max(2, static_cast<int>(std::ceil(std::max(fine, lobe) * perOctave)))) : near_[u];
525 beside_[u] = near_[u] + std::max(2, static_cast<int>(std::ceil(width * perOctave)));
526 reach_[u] = std::max(beside_[u], near_[u] + static_cast<int>(std::ceil(onward * perOctave)));
527 // Deep leaves a twin's skirt out of what a peak is compared with.
528 apart_[u] = deep ? std::min(beside_[u] - 1, static_cast<int>(std::ceil(kDeepApart * near_[u]))) : near_[u];
529 // The cut: the detail in use across at half its depth, no narrower than the filter plays whole.
530 cut_[u] = std::max({ 3, static_cast<int>(std::ceil(0.9 * fine * perOctave)),
531 static_cast<int>(std::ceil(1.2 * lobe * perOctave)) });
532 timeSmooth_[u] = static_cast<T>(1.0 - std::exp(-hopSeconds_ / std::max(kShortestSmoothing, 0.5 * window)));
533 }
534 }
535
537 void refreshTimes() noexcept
538 {
539 const double a = 0.001 * static_cast<double>(attackMs_.load(std::memory_order_relaxed));
540 const double r = 0.001 * static_cast<double>(releaseMs_.load(std::memory_order_relaxed));
541 for (int i = 0; i < kPoints; ++i)
542 {
543 const double scale = std::exp2(-0.5 * static_cast<double>(octave_[static_cast<size_t>(i)]));
544 attack_[static_cast<size_t>(i)] = static_cast<T>(std::exp(-hopSeconds_ / std::max(1e-4, a * scale)));
545 release_[static_cast<size_t>(i)] = static_cast<T>(std::exp(-hopSeconds_ / std::max(1e-3, r * scale)));
546 }
547 }
548
554 void refreshWeight() noexcept
555 {
556 if (weightDirty_.exchange(false, std::memory_order_acquire))
557 {
558 sensResponse_ = sensitivity_.getResponse();
559 weightAuditory_ = auditory_.load(std::memory_order_relaxed);
560 weightPos_ = 0;
561 weightPending_ = true;
562 }
563 if (!weightPending_) return;
564 const int end = std::min(kPoints, weightPos_ + (kPoints + 7) / 8);
565 for (int i = weightPos_; i < end; ++i)
566 {
567 const double hz = DetailFilter<T>::frequency(i);
568 double w = std::clamp(1.0 + sensResponse_.magnitudeDb(hz) / 12.0, 0.0, 2.0);
569 if (weightAuditory_)
570 w *= std::clamp(std::pow(10.0, -(AuditoryScale::thresholdInQuietDb(hz) - earBest_) / 60.0), 0.05, 1.0);
571 weightNext_[static_cast<size_t>(i)] = static_cast<T>(w);
572 }
573 weightPos_ = end;
574 if (weightPos_ >= kPoints)
575 {
576 weight_.swap(weightNext_);
577 weightPending_ = false;
578 }
579 }
580
581 void run(AudioBufferView<T>& buffer, const AudioBufferView<T>* key) noexcept
582 {
583 if (!prepared_) return;
584 const int nCh = std::min(buffer.getNumChannels(), channels_);
585 const int nS = buffer.getNumSamples();
586 if (nCh <= 0 || nS <= 0) return;
587 if (key != nullptr)
588 {
589 // A key that is the programme itself is read as no key.
590 bool same = true;
591 for (int ch = 0; ch < nCh && same; ++ch)
592 same = key->getChannel(std::min(ch, key->getNumChannels() - 1)) == buffer.getChannel(ch);
593 if (same) key = nullptr;
594 }
595 const bool deep = mode_.load(std::memory_order_relaxed) == Mode::Deep;
596 if (deep != lastDeep_ || detail_.load(std::memory_order_relaxed) != lastDetail_ || width_.load(std::memory_order_relaxed) != lastWidth_
597 || taperHz_.load(std::memory_order_relaxed) != lastTaperHz_ || taperExponent_.load(std::memory_order_relaxed) != lastTaperExponent_)
598 refreshDetector(deep);
599 if (timesDirty_.exchange(false, std::memory_order_acquire)) refreshTimes();
600 refreshWeight();
601
602 // The settings of this block's frames.
603 Settings now;
604 now.midSide = nCh == 2 && link_.load(std::memory_order_relaxed) == Link::MidSide;
605 const T linkAmount = linkAmount_.load(std::memory_order_relaxed);
606 const bool pairAsOne = !now.midSide && nCh == 2 && linkAmount >= T(1);
607 // In between, each channel keeps its own filter and is read that
608 // share of the way to the mean of the two.
609 now.share = !now.midSide && nCh == 2 && linkAmount > T(0) && linkAmount < T(1) ? linkAmount : T(0);
610 now.channels = nCh;
611 now.shared = pairAsOne;
612 now.deep = deep;
613 now.guard = guard_.load(std::memory_order_relaxed);
614 now.depth = deep ? kDeepDepth : T(1);
615 now.focus = focusListen_.load(std::memory_order_relaxed);
616 now.threshold = threshold_.load(std::memory_order_relaxed);
617 now.strength = strength_.load(std::memory_order_relaxed);
618 now.range = range_.load(std::memory_order_relaxed);
619 now.knee = knee_.load(std::memory_order_relaxed);
620 now.side = sideWeight_.load(std::memory_order_relaxed);
621 now.mix = mix_.load(std::memory_order_relaxed);
622 const bool removal = removalListen_.load(std::memory_order_relaxed);
623 now.bandHigh = removal ? bandHigh_.load(std::memory_order_relaxed) : T(0);
624 if (now.bandHigh > T(0))
625 {
626 const T low = bandLow_.load(std::memory_order_relaxed);
627 now.bandFrom = low > T(0) ? std::log2(low / T(1000)) : T(-1e6);
628 now.bandTo = std::log2(now.bandHigh / T(1000));
629 }
630 now.persist = static_cast<T>(0.001 * static_cast<double>(persistenceMs_.load(std::memory_order_relaxed)) / hopSeconds_);
631 const T quiet = quietDb_.load(std::memory_order_relaxed);
632 now.quiet = quiet > T(-190) ? std::pow(T(10), quiet / T(20)) : T(0);
633
634 filter_.setLinked(pairAsOne);
635 filter_.setRemovalListen(removal);
636 analysis_.setLinked(pairAsOne);
637 filter_.setShortKernel(shortKernel_.load(std::memory_order_relaxed));
638 if (now.midSide)
639 {
640 T* l = buffer.getChannel(0);
641 T* r = buffer.getChannel(1);
642 for (int i = 0; i < nS; ++i) { const T m = T(0.5) * (l[i] + r[i]), s = T(0.5) * (l[i] - r[i]); l[i] = m; r[i] = s; }
643 }
644 // A key replaces the programme in what the detector reads (its mid
645 // and side in MidSide are read as its first two channels).
646 filter_.processBlock(
647 buffer,
648 [&](int offset, int count) noexcept {
649 for (int ch = 0; ch < nCh; ++ch)
650 {
651 const T* from = key != nullptr ? key->getChannel(std::min(ch, key->getNumChannels() - 1)) : buffer.getChannel(ch);
652 analysis_.feed(ch, from + offset, count);
653 }
654 },
655 [&](int ch, T* curveDb) noexcept {
656 if (ch == 0) analysis_.update(nCh);
657 design(ch, curveDb, now);
658 });
659 showReduction(now);
660 if (now.midSide)
661 {
662 T* l = buffer.getChannel(0);
663 T* r = buffer.getChannel(1);
664 for (int i = 0; i < nS; ++i) { const T m = l[i], s = r[i]; l[i] = m + s; r[i] = m - s; }
665 }
666 }
667
668 struct Settings
669 {
670 int channels = 0;
671 bool midSide = false, shared = false, deep = false, focus = false;
672 T share = T(0), threshold = T(0), strength = T(0), range = T(0), knee = T(0), side = T(1), mix = T(1);
673 T persist = T(0), quiet = T(0), bandHigh = T(0), bandFrom = T(0), bandTo = T(0);
674 T guard = T(1), depth = T(1);
675 };
676
678 void design(int ch, T* curve, const Settings& now) noexcept
679 {
680 if (now.focus)
681 {
682 for (int i = 0; i < kPoints; ++i)
683 {
684 curve[i] = T(20) * std::log10(std::max(weight_[static_cast<size_t>(i)] * T(0.5), T(1e-6)));
685 found_[static_cast<size_t>(i)] = T(0);
686 }
687 publishExcess(ch, now);
688 return;
689 }
690 const auto c = static_cast<size_t>(ch);
691 const bool linking = now.share > T(0);
692 if (linking && ch == 0)
693 {
694 analysis_.read(0, raw_[0].data());
695 analysis_.read(1, raw_[1].data());
696 for (size_t i = 0; i < kSize; ++i) found_[i] = T(0.5) * (raw_[0][i] + raw_[1][i]);
697 levels(found_.data(), smoothPower_[static_cast<size_t>(channels_)], linked_.data(), now.quiet);
698 }
699 if (!linking) analysis_.read(ch, raw_[0].data());
700 const T* power = linking ? raw_[c].data() : raw_[0].data();
701 levels(power, smoothPower_[c], level_.data(), now.quiet);
702 if (linking)
703 for (size_t i = 0; i < kSize; ++i)
704 {
705 // A share of the way: in decibels, or in amplitude in Deep.
706 T& own = level_[i];
707 if (!now.deep) own += now.share * (linked_[i] - own);
708 else
709 {
710 const T a = std::pow(T(10), own / T(20)), b = std::pow(T(10), linked_[i] / T(20));
711 own = T(20) * std::log10(a + now.share * (b - a));
712 }
713 }
714
715 // Linked, what still sounds on either channel does.
716 const T* sounding = power;
717 const T* smoothed = smoothPower_[c].data();
718 const T* other = linking ? raw_[1 - c].data() : nullptr;
719 findResonances(now, sounding, other, smoothed);
720
721 const T side = now.midSide && ch == 1 ? now.side : T(1);
722 auto& g = gainDb_[c];
723 auto& lasted = lasted_[c];
724 for (int i = 0; i < kPoints; ++i)
725 {
726 const auto u = static_cast<size_t>(i);
727 T found = found_[u];
728 if (now.persist > T(0))
729 {
730 // How many hops it has lasted; one missed costs two.
731 T& age = lasted[u];
732 age = found > T(0) ? std::min(age + T(1), T(2) * now.persist + T(1)) : std::max(age - T(2), T(0));
733 const T x = std::clamp(age / now.persist - T(0.5), T(0), T(1));
734 found *= x * x * (T(3) - T(2) * x);
735 }
736 found *= weight_[u] * side;
737 found_[u] = found;
738 const T target = -now.depth * std::min(now.range, now.strength * found);
739 g[u] = target + (target < g[u] ? attack_[u] : release_[u]) * (g[u] - target);
740 if (target == T(0) && g[u] > T(-1e-4)) g[u] = T(0);
741 curve[i] = g[u];
742 }
743 // The mix, inside the filter: the curve shown is the one applied.
744 if (now.mix < T(1))
745 for (int i = 0; i < kPoints; ++i)
746 if (curve[i] != T(0))
747 curve[i] = T(20) * std::log10(std::max(T(1) - now.mix + now.mix * std::pow(T(10), curve[i] / T(20)), T(1e-6)));
748 // The band the removal is heard in: outside it the filter is left at one.
749 if (now.bandHigh > T(0))
750 for (int i = 0; i < kPoints; ++i)
751 {
752 const T at = octave_[static_cast<size_t>(i)];
753 const T edge = std::clamp(T(0.5) + T(6) * std::min(at - now.bandFrom, now.bandTo - at), T(0), T(1)); // a sixth of an octave at each end
754 const T inside = T(0.5) - T(0.5) * std::cos(std::numbers::pi_v<T> * edge);
755 if (curve[i] != T(0))
756 curve[i] = T(20) * std::log10(std::max(T(1) - inside * (T(1) - std::pow(T(10), curve[i] / T(20))), T(1e-6)));
757 }
758 publishExcess(ch, now);
759 }
760
766 void levels(const T* power, std::vector<T>& smooth, T* out, T quiet) noexcept
767 {
768 T top = T(0);
769 for (size_t i = 0; i < kSize; ++i)
770 {
771 const T p = std::isfinite(power[i]) ? power[i] : T(0);
772 smooth[i] += timeSmooth_[i] * (p - smooth[i]);
773 top = std::max(top, smooth[i]);
774 }
775 floor_ = std::max(top * T(1e-8), T(1e-14));
776 for (size_t i = 0; i < kSize; ++i) out[i] = levelOf(smooth[i], quiet);
777 }
778
780 [[nodiscard]] T levelOf(T power, T quiet) const noexcept
781 {
782 const T p = std::max(power, floor_);
783 return quiet > T(0) ? T(8.6858896380650366) * std::log(std::sqrt(p) + quiet) : T(4.3429448190325183) * std::log(p);
784 }
785
793 T overOf(int i, const T* lv, T at, T least, bool deep, const double* amp, int peaks) const noexcept
794 {
795 const auto u = static_cast<size_t>(i);
796 const int apart = apart_[u], reach = reach_[u], beside = beside_[u];
797 T loudest = T(-1000);
798 for (const int side : { -1, 1 })
799 {
800 if (deep)
801 {
802 // Deep reads the whole reach: the nearer side's largest and
803 // whether it holds a peer, then the farther side's over the
804 // slope unless it did (the same largest in any order).
805 const int last = std::min(reach, side < 0 ? i : kPoints - 1 - i);
806 const int nearEnd = std::min(beside, last);
807 bool peer = false;
808 for (int d = apart + 1; d <= nearEnd; ++d)
809 {
810 const int j = i + side * d;
811 const T v = lv[j];
812 loudest = std::max(loudest, v);
813 peer = peer || (v >= at - kPeerUnder && j > 0 && j < kPoints - 1 && v >= lv[j - 1] && v >= lv[j + 1]);
814 }
815 const int farFrom = std::max(apart, beside) + 1;
816 if (peer)
817 for (int d = farFrom; d <= last; ++d) loudest = std::max(loudest, lv[i + side * d]);
818 else
819 for (int d = farFrom; d <= last; ++d)
820 {
821 const int j = i + side * d;
822 loudest = std::max(loudest, lv[j] + tiltPerPoint_ * static_cast<T>(j - i));
823 }
824 continue;
825 }
826 bool peer = false;
827 for (int d = apart + 1; d <= reach; ++d)
828 {
829 const int j = i + side * d;
830 if (j < 0 || j >= kPoints) break;
831 const T v = lv[j];
832 const bool onward = d > beside;
833 loudest = std::max(loudest, onward && !peer ? v + tiltPerPoint_ * static_cast<T>(j - i) : v);
834 if (at - loudest <= least) break;
835 peer = peer || (!onward && v >= at - kPeerUnder && j > 0 && j < kPoints - 1 && v >= lv[j - 1] && v >= lv[j + 1]);
836 }
837 }
838 if (loudest <= T(-1000) || !deep) return loudest;
839 double sum = 0.0;
840 int count = 0;
841 const int first = std::max(1, i - reach), last = std::min(kPoints - 2, i + reach);
842 const int* listed = peaks_.data();
843 for (int n = static_cast<int>(std::lower_bound(listed, listed + peaks, first) - listed); n < peaks && listed[n] <= last; ++n)
844 {
845 const int j = listed[n];
846 if ((j >= i - apart && j <= i + apart) || lv[j] < loudest - kDeepFloor) continue;
847 sum += amp != nullptr ? amp[static_cast<size_t>(j)] : std::exp(static_cast<double>(lv[j]) * 0.11512925464970229);
848 ++count;
849 }
850 return count > 0 ? std::min(loudest, static_cast<T>(20.0 * std::log10(sum / count))) : loudest; // never over Smooth's
851 }
852
854 void findResonances(const Settings& now, const T* sounding, const T* other, const T* smoothed) noexcept
855 {
856 std::fill(found_.begin(), found_.end(), T(0));
857 const T* level = level_.data();
858 // Deep averages peers in amplitude: each point's once, not once a peak it stands beside.
859 int peaks = 0;
860 if (now.deep)
861 {
862 for (size_t j = 0; j < kSize; ++j) amplitude_[j] = std::exp(static_cast<double>(level[j]) * 0.11512925464970229); // ln(10) / 20
863 for (int j = 1; j < kPoints - 1; ++j)
864 if (level[j] > level[j - 1] && !(level[j] < level[j + 1])) peaks_[static_cast<size_t>(peaks++)] = j;
865 }
866 const T least = now.knee > T(0) ? now.threshold - T(4) * now.knee : now.threshold;
867 bool nowReady = false;
868 for (int i = 1; i < kPoints - 1; ++i)
869 {
870 const T at = level[i];
871 if (!(at > level[i - 1]) || at < level[i + 1]) continue;
872 const auto u = static_cast<size_t>(i);
873 const int own = near_[u], pick = pick_[u];
874 bool out = true;
875 for (int d = 2; d <= own && out; ++d)
876 {
877 // Within a detail Deep allows a twin nearly as loud.
878 const T top = d > pick ? at + kTwin : at;
879 out = (i - d < 0 || level[i - d] < top) && (i + d >= kPoints || level[i + d] <= top);
880 }
881 if (!out) continue;
882 // It ends with its sound, not with the smoothing's tail: after a
883 // sudden drop it is read, with what is beside it, at the levels
884 // they sound at now, so what only grew softer is still taken by
885 // what it still stands out.
886 T latest = T(0);
887 for (int j = std::max(0, i - own / 2); j <= std::min(kPoints - 1, i + own / 2); ++j)
888 latest = std::max(latest, other != nullptr ? std::max(sounding[j], other[j]) : sounding[j]);
889 T heard = at;
890 const T* read = level;
891 if (latest < kStillSounding * smoothed[i])
892 {
893 if (!nowReady)
894 {
895 for (int j = 0; j < kPoints; ++j)
896 {
897 const T p = other != nullptr ? std::max(sounding[j], other[j]) : sounding[j];
898 nowLevel_[static_cast<size_t>(j)] = std::min(level[j], levelOf(p, now.quiet));
899 }
900 nowReady = true;
901 }
902 heard = std::min(at, levelOf(latest, now.quiet));
903 read = nowLevel_.data();
904 }
905 const T over = overOf(i, read, heard, least, now.deep, read == level ? amplitude_.data() : nullptr, peaks);
906 if (over <= T(-1000)) continue;
907 const T excess = heard - over;
908 if (excess <= least) continue;
909 if (isFundamental(i)) continue;
910 const T past = excess - now.threshold;
911 T found = now.knee > T(0) ? T(0.5) * (past + std::sqrt(past * past + now.knee * now.knee)) : past;
912 const T share = foundationShare(i, now.guard);
913 if (share < T(1))
914 {
915 // A share of what would be taken: the range does not undo it.
916 if (now.strength * found > now.range) found = now.range / now.strength;
917 found *= share;
918 if (found <= T(0)) continue;
919 }
920 // A detail wide at half its depth and round: an edge steeper than
921 // the filter's bins would ring past the range.
922 const int half = cut_[u];
923 const T flat = T(1.5);
924 for (int j = std::max(0, i - half); j <= std::min(kPoints - 1, i + half); ++j)
925 {
926 const T d = static_cast<T>(j < i ? i - j : j - i);
927 const T shape = d <= flat ? T(1) : T(0.5) + T(0.5) * std::cos(std::numbers::pi_v<T> * (d - flat) / (static_cast<T>(half) + T(1) - flat));
928 found_[static_cast<size_t>(j)] = std::max(found_[static_cast<size_t>(j)], found * shape);
929 }
930 }
931 }
932
934 [[nodiscard]] bool hasPeak(double point) const noexcept
935 {
936 const int centre = static_cast<int>(std::lround(point));
937 if (centre < 1 || centre > kPoints - 2) return false;
938 const T* level = level_.data();
939 const int own = near_[static_cast<size_t>(centre)], slack = std::max(2, own / 2);
940 const int first = std::max(1, centre - slack), last = std::min(kPoints - 2, centre + slack);
941 int at = -1;
942 for (int j = first; j <= last; ++j)
943 if (level[j] >= level[j - 1] && level[j] >= level[j + 1] && (at < 0 || level[j] > level[at])) at = j;
944 if (at < 0) return false;
945 T sum = T(0);
946 int count = 0;
947 for (int d = own + 1; d <= own + kSurroundings; ++d)
948 {
949 if (at - d >= 0) { sum += level[at - d]; ++count; }
950 if (at + d < kPoints) { sum += level[at + d]; ++count; }
951 }
952 return count > 0 && level[at] - sum / static_cast<T>(count) >= kPeakOverSurroundings;
953 }
954
961 [[nodiscard]] bool isFundamental(int point) const noexcept
962 {
963 const double perOctave = pointsPerOctave(), at = static_cast<double>(point);
964 const bool second = hasPeak(at + perOctave);
965 const bool low = DetailFilter<T>::frequency(point) < kLowNote;
966 if (!second && !low) return false;
967 if (!(second && low) && !hasPeak(at + perOctave * std::log2(3.0))) return false;
968 for (int n = 2; n <= kMostSeries; ++n)
969 {
970 const double root = at - perOctave * std::log2(static_cast<double>(n));
971 if (root < 1.0) break;
972 if (!hasPeak(root)) continue;
973 if (n == 2 || hasPeak(at + perOctave * std::log2((n - 1.0) / n))) return false;
974 }
975 return true;
976 }
977
984 [[nodiscard]] T foundationShare(int point, T guard) const noexcept
985 {
986 const T rise = foundationRise_[static_cast<size_t>(point)];
987 if (rise >= T(1) || guard <= T(0)) return T(1);
988 const T* level = level_.data();
989 const T at = level[point];
990 const int underneath = point - near_[static_cast<size_t>(point)];
991 // A component underneath, not the skirt of this one (a kick is wide).
992 T under = T(-1000), above = T(-1000);
993 for (int j = 1; j < underneath; ++j)
994 if (level[j] >= level[j - 1] && level[j] >= level[j + 1]) under = std::max(under, level[j]);
995 const T alone = std::clamp((at - under - kPeerUnder) / kFoundationFade + T(1), T(0), T(1));
996 if (alone <= T(0)) return T(1);
997 for (int j = point + 1; j < kPoints; ++j) above = std::max(above, level[j]);
998 const T loudest = std::clamp(T(2) - (above - at) / kFoundationFade, T(0), T(1));
999 return T(1) - guard * alone * loudest * (T(1) - rise);
1000 }
1001
1003 void publishExcess(int ch, const Settings& now) noexcept
1004 {
1005 if (ch >= SpectralReadout<T>::kChannels) return;
1006 excess_.publishPoints(ch, found_.data());
1007 if (ch == 0 && (now.shared || now.channels == 1)) excess_.publishPoints(1, found_.data());
1008 }
1009
1011 void showReduction(const Settings& now) noexcept
1012 {
1013 if (!filter_.isDisplayDue(shownCurve_)) return;
1014 shownCurve_ = filter_.getCurveCount();
1015 filter_.publishPlayed(now.shared ? 1 : now.channels);
1016 }
1017
1018 static constexpr int kSurroundings = 24;
1019 static constexpr int kMostSeries = 16;
1020
1021 AudioSpec spec_ {};
1022 int weightPos_ = 0, channels_ = 0, shownCurve_ = 0;
1023 bool prepared_ = false, weightPending_ = false, weightAuditory_ = false, lastDeep_ = false;
1024 double hopSeconds_ = 256.0 / 48000.0;
1025 double earBest_ = 0.0;
1026 T tiltPerPoint_ = T(0);
1027 T floor_ = T(1e-14);
1028 T lastDetail_ = T(1.0 / 12.0), lastWidth_ = T(1.0 / 3.0), lastTaperHz_ = T(2000), lastTaperExponent_ = T(0);
1029 std::atomic<T> detail_ { T(1.0 / 12.0) };
1030 std::atomic<bool> shortKernel_ { false };
1031 std::atomic<T> threshold_ { T(5) }, strength_ { T(1) }, range_ { T(9) }, width_ { T(1.0 / 3.0) };
1032 std::atomic<T> attackMs_ { T(5) }, releaseMs_ { T(80) }, linkAmount_ { T(1) }, sideWeight_ { T(1) };
1033 std::atomic<Mode> mode_ { Mode::Smooth };
1034 std::atomic<T> guard_ { T(1) };
1035 std::atomic<Link> link_ { Link::PerBin };
1036 std::atomic<Quality> quality_ { Quality::Realtime }, qualityInUse_ { Quality::Realtime };
1037 std::atomic<bool> qualityFollowsRender_ { false }, offlineRendering_ { false };
1038 std::atomic<bool> removalListen_ { false }, focusListen_ { false }, timesDirty_ { false }, weightDirty_ { true };
1039 std::atomic<T> mix_ { T(1) }, knee_ { T(0) }, persistenceMs_ { T(50) }, quietDb_ { T(-200) };
1040 std::atomic<bool> auditory_ { false };
1041 std::atomic<T> taperHz_ { T(2000) }, taperExponent_ { T(0) }, bandLow_ { T(0) }, bandHigh_ { T(0) };
1042 DetailFilter<T> filter_;
1043 DetailAnalysis<T> analysis_;
1044 SpectralReadout<T> excess_;
1045 KeyEqualizer<T, 2> sensitivity_;
1046 typename KeyEqualizer<T, 2>::Response sensResponse_ {};
1047 std::vector<std::vector<T>> smoothPower_, gainDb_, raw_;
1048 std::vector<std::vector<T>> lasted_;
1049 std::vector<T> level_, linked_, found_, weight_, weightNext_, attack_, release_, timeSmooth_, octave_;
1050 std::vector<T> nowLevel_;
1051 std::vector<double> amplitude_;
1052 std::vector<int> peaks_;
1053 std::vector<int> near_, beside_, reach_;
1054 std::vector<int> cut_;
1055 std::vector<int> pick_, apart_;
1056 std::vector<T> foundationRise_;
1057};
1058
1059} // namespace dspark
Non-owning view over audio channel data.
Definition AudioBuffer.h:53
Multiresolution power spectrum on the grid of SpectralReadout.
Minimum-phase filtering by a curve on a log-frequency grid, fine in the low end.
static double frequency(int point) noexcept
void writeState(StateWriter &w, const char *prefix) const
Writes the bands under keys that start with a prefix ("<prefix><band>.shape", ".freq",...
Response getResponse(Placement part=Placement::Stereo) const noexcept
The sections of the published bands, designed as the audio thread designs them, for a display.
void readState(const StateReader &r, const char *prefix) noexcept
Reads the bands writeState() wrote (a band that is missing reads as Off, a placement that is missing ...
Band getBand(int band) const noexcept
The published settings of a band (a band out of range reads as Off).
void setBand(int band, const Band &settings) noexcept
Publishes the settings of a band.
void prepare(double sampleRate) noexcept
Prepares the equalizer for a sample rate and clears its memory.
Dynamic suppression of resonances by a minimum-phase filter on a log-frequency grid.
bool getAuditoryWeighting() const noexcept
T getDisplayExcess(int channel, int point) const noexcept
T getDisplayReduction(int channel, int point) const noexcept
void setQuietLevel(T dbfs) noexcept
Level under which the suppressor lets go, -120 to 0 dBFS (off at -200, the default; anything under -1...
void processBlock(AudioBufferView< T > buffer) noexcept
Processes the programme in place, detecting on itself.
void reset() noexcept
Clears the analysis and the filter.
void setStrength(T amount) noexcept
How much of what passes the threshold is taken out, 0 to 1 (default 1).
void setDetail(T octaves) noexcept
The detail: how narrow what is found and cut is, from an octave to 1/24 of one (default 1/12)....
static constexpr int kDisplayPoints
Points of the display curves, evenly in log frequency from 20 Hz to 20 kHz.
bool setState(const uint8_t *data, size_t size)
Restores the settings. A blob of the first version (threshold and strength over the mean of the spect...
T getFoundationGuard() const noexcept
void setSensitivityBand(int index, const Band &band) noexcept
One band of the sensitivity curve (KeyEqualizer bands; the curve is a weight, its gain in dB / 12 + 1...
void setRange(T db) noexcept
Largest reduction, 0 to 48 dB (default 9; Mode::Deep reaches half as far again).
void setRelease(T ms) noexcept
Release at 1 kHz, 5 to 2000 ms (default 80).
T getReduction(double hz) const noexcept
Quality getQuality() const noexcept
void prepare(const AudioSpec &spec)
Allocates for a rate and a layout (an invalid spec is ignored).
Quality getQualityInUse() const noexcept
typename KeyEqualizer< T, 2 >::Band Band
void setQualityFollowsRender(bool on) noexcept
With it on, a prepare() made while the host renders offline takes the Offline quality whatever setQua...
T getWidthTaperExponent() const noexcept
void setFocusListen(bool on) noexcept
Outputs the programme through the sensitivity curve.
Band getSensitivityBand(int index) const noexcept
void setWidthTaper(T cornerHz, T exponent) noexcept
Narrows setWidth() above a corner: it falls as (corner / frequency) to the exponent (0,...
void setRemovalBand(T lowHz, T highHz) noexcept
The band setRemovalListen() plays, in hertz (0 and 0, the default, play all of it): what is taken out...
Link getLinkMode() const noexcept
void setSideWeight(T share) noexcept
In MidSide, the side's reduction as a share of the mid's, 0 to 2 (default 1).
void setShortKernel(bool on) noexcept
Plays kernels of half their transform, tapered over their whole length (off by default; see DetailFil...
void setPersistence(T ms) noexcept
Persistence, 0 to 500 ms (default 50; 0 counts at once): how long a resonance lasts before it counts,...
void setThreshold(T db) noexcept
Over the loudest of its neighbours by this much a peak is a resonance, 0 to 30 dB (default 5).
void setRemovalListen(bool on) noexcept
Outputs what is taken out.
bool getQualityFollowsRender() const noexcept
void setOfflineRendering(bool on) noexcept
Tells the suppressor whether the host renders offline (read by the next prepare(); a plugin forwards ...
void setLinkMode(Link l) noexcept
Stereo handling (PerBin by default).
bool getRemovalListen() const noexcept
static double getDisplayFrequency(int point) noexcept
static constexpr int kSensitivityBands
void processBlock(AudioBufferView< T > buffer, AudioBufferView< T > key) noexcept
Processes the programme in place, detecting on a key (same length).
void setWidth(T octaves) noexcept
How far the neighbours a peak is compared with reach, in octaves beyond the detail,...
void setAuditoryWeighting(bool on) noexcept
Weighs the amount by how well the ear hears each frequency (off by default): a third of the distance ...
void setQuality(Quality q) noexcept
Realtime reads the long windows of the low end in turns, every two or four hops; Offline reads all of...
T getRemovalBandHigh() const noexcept
bool getShortKernel() const noexcept
void setAttack(T ms) noexcept
Attack at 1 kHz, 0.5 to 500 ms (default 5; slower below, faster above, by the square root of the freq...
void setLink(T amount) noexcept
Per-point link, 0 (each channel its own) to 1 (one detector and filter), default 1.
void setKnee(T db) noexcept
Soft knee at the threshold, 0 to 12 dB (0, the default, is the hard knee): the reduction grows smooth...
T getWidthTaperCorner() const noexcept
bool getFocusListen() const noexcept
void setFoundationGuard(T amount) noexcept
How far what carries the programme from under it is spared, 0 to 1 (default 1): what is within 6 dB o...
void setMode(Mode m) noexcept
Smooth (the default) works at the detail set and takes what stands over the loudest of its neighbours...
std::vector< uint8_t > getState() const
void setMix(T amount) noexcept
How much of the filter is applied, 0 to 1 (default 1). The mix is taken inside the filter: its gain b...
A per-bin quantity of the last frame (a gain curve, a reduction), read at fixed points for a display ...
static double frequency(int point) noexcept
static constexpr int kChannels
Curves (channels).
Tolerant reader: missing keys yield defaults, unknown keys are skipped.
Definition StateBlob.h:171
uint16_t processorVersion() const noexcept
Definition StateBlob.h:211
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.
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
double sampleRate
Sample rate in Hz.
Definition AudioSpec.h:45
static double thresholdInQuietDb(double hz) noexcept
The settings of one band.
Static utility for Mid/Side stereo encoding and decoding.
Definition MidSide.h:59