DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
TransformerModel.h
1// DSPark - Professional Audio DSP Framework
2// Copyright (c) 2026 Cristian Moresi - MIT License
3
4#pragma once
5
75#include "../Core/AudioBuffer.h"
76#include "../Core/AudioSpec.h"
77#include "../Core/Biquad.h"
78#include "../Core/DenormalGuard.h"
79#include "../Core/DryWetMixer.h"
80#include "../Core/DspMath.h"
81#include "../Core/Hysteresis.h"
82#include "../Core/Oversampling.h"
83#include "../Core/StateBlob.h"
84
85#include <algorithm>
86#include <atomic>
87#include <cmath>
88#include <cstddef>
89#include <cstdint>
90#include <memory>
91#include <numbers>
92#include <vector>
93
94namespace dspark {
95
102template <FloatType T>
104{
105public:
106 // -- Lifecycle ---------------------------------------------------------------
107
112 void prepare(const AudioSpec& spec)
113 {
114 if (!spec.isValid()) return;
115 prepared_.store(false, std::memory_order_relaxed);
116 spec_ = spec;
117 if (osAutomatic_)
118 osFactor_ = Oversampling<T>::factorForRate(spec.sampleRate, kAutomaticInternalRate);
119 // Everything but the mix runs at the internal rate: the active
120 // oversampling factor times the base rate.
121 sampleRate_ = static_cast<double>(osFactor_) * spec.sampleRate;
122 mixMaxStep_ = static_cast<T>(1.0 / std::max(1.0, spec.sampleRate * 0.02));
123 numChannels_ = spec.numChannels;
124 maxBlock_ = std::max(spec.maxBlockSize, 1);
125
126 if (osFactor_ > 1)
127 {
128 oversampler_ = std::make_unique<Oversampling<T>>(
130 oversampler_->prepare(spec);
131 }
132 else
133 {
134 oversampler_.reset();
135 }
136 latency_ = oversampler_ ? oversampler_->getLatency() : 0;
137 drySize_ = 1;
138 while (drySize_ < latency_ + maxBlock_ + 1) drySize_ <<= 1;
139 dryRing_.assign(static_cast<size_t>(numChannels_),
140 std::vector<T>(static_cast<size_t>(drySize_), T(0)));
141 dryPos_ = 0;
142 dryLead_.prepare(spec.sampleRate, numChannels_);
143
144 channels_.assign(static_cast<size_t>(numChannels_), {});
145 for (auto& ch : channels_)
146 {
147 ch.hyst.prepare(sampleRate_);
148 // Unbiased iron: wider loop than biased tape (low reversible c).
149 // Constant material - set once here, not on every recompute().
150 ch.hyst.setParameters(3.5e5, 2.2e4, 1.6e-3, 3.2e4, 0.25);
151 }
152
153 // The first calibration runs here, on the setup thread; later
154 // parameter changes calibrate incrementally inside processBlock().
155 dirty_.store(false, std::memory_order_relaxed);
156 recomputeLinear();
157 calActive_ = false;
158 calRestart_ = false;
159 startCalibration();
160 stepCalibration(calN_);
161 prepared_.store(true, std::memory_order_relaxed);
162 reset();
163 }
164
166 void reset() noexcept
167 {
168 if (!prepared_.load(std::memory_order_relaxed)) return;
169 for (auto& ch : channels_)
170 {
171 ch.hyst.reset();
172 ch.flux = 0.0;
173 ch.vPrev = 0.0;
174 ch.vPrev2 = 0.0;
175 ch.mPrev = 0.0;
176 ch.hpX = ch.hpY = 0.0;
177 // State only: assigning {} also wiped the bell coefficients, which
178 // removed the resonance until the next parameter change.
179 ch.bell.z1 = ch.bell.z2 = 0.0;
180 }
181 for (auto& d : dryRing_)
182 std::fill(d.begin(), d.end(), T(0));
183 dryPos_ = 0;
184 if (oversampler_) oversampler_->reset();
185 // Seed the anti-zipper ramps at their targets: no fade-in on start.
186 hScaleSm_ = -1.0;
187 mScaleSm_ = -1.0;
188 currentMix_ = mix_.load(std::memory_order_relaxed);
189 dryLead_.aim(currentMix_ > T(0));
190 dryLead_.reset();
191 dryLead_.land();
192 }
193
194 // -- Parameters (thread-safe) ---------------------------------------------------
195
198 void setDrive(T db) noexcept
199 {
200 if (!std::isfinite(db)) return;
201 driveDb_.store(std::clamp(db, T(-12), T(24)), std::memory_order_relaxed);
202 dirty_.store(true, std::memory_order_release);
203 }
204
208 void setCoreSize(T size) noexcept
209 {
210 if (!std::isfinite(size)) return;
211 coreSize_.store(std::clamp(size, T(0), T(1)), std::memory_order_relaxed);
212 dirty_.store(true, std::memory_order_release);
213 }
214
217 void setResonance(T amount) noexcept
218 {
219 if (!std::isfinite(amount)) return;
220 resonance_.store(std::clamp(amount, T(0), T(1)), std::memory_order_relaxed);
221 dirty_.store(true, std::memory_order_release);
222 }
223
229 void setMix(T mix) noexcept
230 {
231 if (!std::isfinite(mix)) return;
232 mix_.store(std::clamp(mix, T(0), T(1)), std::memory_order_relaxed);
233 }
234
235 [[nodiscard]] T getDrive() const noexcept { return driveDb_.load(std::memory_order_relaxed); }
236 [[nodiscard]] T getCoreSize() const noexcept { return coreSize_.load(std::memory_order_relaxed); }
237 [[nodiscard]] T getResonance() const noexcept { return resonance_.load(std::memory_order_relaxed); }
238 [[nodiscard]] T getMix() const noexcept { return mix_.load(std::memory_order_relaxed); }
239
250 void setOversampling(int factor)
251 {
252 if (factor < 1 || factor > 16 || (factor & (factor - 1)) != 0) return;
253 if (factor == osFactor_ && !osAutomatic_) return;
254 osAutomatic_ = false;
255 osFactor_ = factor;
256 if (prepared_.load(std::memory_order_relaxed))
257 prepare(spec_);
258 }
259
274 {
275 if (on == osAutomatic_) return;
276 osAutomatic_ = on;
277 if (on && prepared_.load(std::memory_order_relaxed))
278 prepare(spec_);
279 }
280
282 [[nodiscard]] bool isOversamplingAutomatic() const noexcept { return osAutomatic_; }
283
285 [[nodiscard]] int getOversamplingFactor() const noexcept { return osFactor_; }
286
289 [[nodiscard]] int getLatency() const noexcept { return latency_; }
290
292 [[nodiscard]] int getLatencySamples() const noexcept { return getLatency(); }
293
295 [[nodiscard]] std::vector<uint8_t> getState() const
296 {
297 StateWriter w(stateId("XFMR"), 2);
298 // Explicit float casts: the blob stores float, and with T = double the
299 // unqualified write(key, double) would be ambiguous (float/int32/bool).
300 w.write("drive", static_cast<float>(driveDb_.load(std::memory_order_relaxed)));
301 w.write("coreSize", static_cast<float>(coreSize_.load(std::memory_order_relaxed)));
302 w.write("resonance", static_cast<float>(resonance_.load(std::memory_order_relaxed)));
303 w.write("mix", static_cast<float>(mix_.load(std::memory_order_relaxed)));
304 w.write("oversampling", osFactor_);
305 w.write("oversamplingAuto", osAutomatic_);
306 return w.blob();
307 }
308
313 bool setState(const uint8_t* data, size_t size)
314 {
315 StateReader r(data, size);
316 if (!r.isValid() || r.processorId() != stateId("XFMR")) return false;
317 setDrive(static_cast<T>(r.read("drive", 0.0f)));
318 setCoreSize(static_cast<T>(r.read("coreSize", 0.5f)));
319 setResonance(static_cast<T>(r.read("resonance", 0.3f)));
320 setMix(static_cast<T>(r.read("mix", 1.0f)));
321 setOversampling(r.read("oversampling", 2));
322 setAutomaticOversampling(r.read("oversamplingAuto", false));
323 return true;
324 }
325
326 // -- Processing -------------------------------------------------------------------
327
330 void processBlock(AudioBufferView<T> buffer) noexcept
331 {
332 if (!prepared_.load(std::memory_order_relaxed)) return;
333 DenormalGuard guard;
334
335 const int nCh = std::min(buffer.getNumChannels(), numChannels_);
336 const int nS = buffer.getNumSamples();
337 if (nCh == 0 || nS == 0) return;
338
339 // Acquire pairs with the setters' release stores so the recompute
340 // always sees the values published before the flag.
341 if (dirty_.load(std::memory_order_relaxed)
342 && dirty_.exchange(false, std::memory_order_acquire))
343 {
344 recomputeLinear();
345 if (calActive_) calRestart_ = true;
346 else startCalibration();
347 }
348
349 for (int off = 0; off < nS; off += maxBlock_)
350 processChunk(buffer.getSubView(off, std::min(maxBlock_, nS - off)), nCh);
351 }
352
353private:
354 void processChunk(AudioBufferView<T> buffer, int nCh) noexcept
355 {
356 const int nS = buffer.getNumSamples();
357
358 // Non-finite guard: a NaN/Inf input would poison the leaky
359 // integrator (flux/vPrev), the algebraic inverse (vPrev2/mPrev), the
360 // DC-blocker (hpX/hpY), the bell and the oversampler permanently.
361 // Replace the bad sample with silence (dry too) so a transient glitch
362 // cannot kill the channel for the rest of the stream.
363 for (int ch = 0; ch < nCh; ++ch)
364 {
365 T* d = buffer.getChannel(ch);
366 for (int i = 0; i < nS; ++i)
367 if (!std::isfinite(d[i])) d[i] = T(0);
368 }
369
370 // Rate-limited mix ramp (moveTowards, exact landing; settled it
371 // reduces to the constant, bit-identically). A per-block ramp landed
372 // in 0.7 ms with 32-sample blocks.
373 // A hard flip on the differentiated wet stream clicked at 4.6x the
374 // steady-state sample delta.
375 const T mixTarget = mix_.load(std::memory_order_relaxed);
376 const T mixStart = currentMix_;
377
378 // Dry snapshot, read back delayed to the oversampler's latency.
379 for (int ch = 0; ch < nCh; ++ch)
380 {
381 const T* in = buffer.getChannel(ch);
382 auto& dry = dryRing_[static_cast<size_t>(ch)];
383 int dp = dryPos_;
384 for (int i = 0; i < nS; ++i)
385 {
386 dry[static_cast<size_t>(dp)] = in[i];
387 dp = (dp + 1) & (drySize_ - 1);
388 }
389 }
390
391 const bool osOn = (oversampler_ != nullptr);
392 auto osView = osOn ? oversampler_->upsample(buffer) : buffer;
393 const int osN = osView.getNumSamples();
394
395 // Anti-zipper: GEOMETRIC in-block ramps toward the recompute()
396 // targets (~50 ms across blocks), shared by all channels. Two
397 // reasons: this model differentiates its output (x 2*fs), so a flat
398 // per-block gain step clicks; and (hScale, mScale) is a calibrated
399 // compensation pair spanning orders of magnitude - interpolating it
400 // LINEARLY passes through wildly over-gained states (+24 dB
401 // measured mid-drag), while power-law interpolation keeps the pair
402 // on the calibration curve m ~ C/h^g throughout the transition.
403 if (hScaleSm_ <= 0.0) { hScaleSm_ = hScale_; mScaleSm_ = mScale_; }
404 const double kSm = 1.0 - std::exp(-static_cast<double>(osN) / (0.050 * sampleRate_));
405 const double hEnd = hScaleSm_ * std::pow(hScale_ / hScaleSm_, kSm);
406 const double mEnd = mScaleSm_ * std::pow(mScale_ / mScaleSm_, kSm);
407 const double hRat = std::pow(hEnd / hScaleSm_, 1.0 / static_cast<double>(osN));
408 const double mRat = std::pow(mEnd / mScaleSm_, 1.0 / static_cast<double>(osN));
409
410 for (int ch = 0; ch < nCh; ++ch)
411 {
412 T* d = osView.getChannel(ch);
413 auto& st = channels_[static_cast<size_t>(ch)];
414 double hSm = hScaleSm_, mSm = mScaleSm_;
415
416 for (int i = 0; i < osN; ++i)
417 {
418 hSm *= hRat;
419 mSm *= mRat;
420 const double x = static_cast<double>(d[i]);
421
422 // Leaky trapezoidal integrator: winding voltage -> flux.
423 const double fluxNew = leak_ * st.flux + halfT_ * (x + st.vPrev);
424 st.vPrev = x;
425
426 // Core hysteresis on the flux (JA, unbiased-iron parameters).
427 const double m = mSm * static_cast<double>(
428 st.hyst.processSample(static_cast<T>(hSm * fluxNew)));
429
430 // Algebraic inverse of the integrator (flux -> voltage). The
431 // damped feedback pole (rho < 1) tames z = -1: hysteresis
432 // distortion is new content the inverse never saw, and an
433 // undamped differentiator would ring at Nyquist forever. The
434 // leak alpha still cancels exactly; the only linear residue
435 // is (1+z^-1)/(1+rho z^-1), transparent to within 0.15 dB.
436 double v = (m - leak_ * st.mPrev) * invHalfT_ - kDiffRho * st.vPrev2;
437 st.vPrev2 = v;
438 st.mPrev = m;
439 st.flux = fluxNew;
440
441 // Magnetizing-inductance corner (one-pole high-pass).
442 const double hp = hpA_ * (st.hpY + v - st.hpX);
443 st.hpX = v;
444 st.hpY = hp;
445
446 // Leakage/capacitance bell.
447 d[i] = static_cast<T>(st.bell.process(hp));
448 }
449 }
450 hScaleSm_ = hEnd;
451 mScaleSm_ = mEnd;
452 // Advance a pending calibration by as many internal samples as this
453 // chunk has: bounded work per callback.
454 if (calActive_) stepCalibration(osN);
455 if (osOn) oversampler_->downsample(buffer);
456
457 dryLead_.aim(mixTarget > T(0));
458 for (int i = 0; i < nS; ++i)
459 {
460 const int idx = (dryPos_ + i - latency_) & (drySize_ - 1);
461 const T mixVal = moveTowards(mixStart, mixTarget, mixMaxStep_ * static_cast<T>(i + 1));
462 const double turn = dryLead_.advance();
463 for (int ch = 0; ch < nCh; ++ch)
464 {
465 T* d = buffer.getChannel(ch);
466 const T rawDry = dryRing_[static_cast<size_t>(ch)][static_cast<size_t>(idx)];
467 const T turned = dryLead_.processSample(ch, rawDry, turn);
468 // All wet, the sum keeps the rounding it has with the raw copy.
469 const T drySample = mixVal == T(1) ? rawDry : turned;
470 d[i] = drySample + (d[i] - drySample) * mixVal;
471 }
472 }
473 currentMix_ = moveTowards(mixStart, mixTarget, mixMaxStep_ * static_cast<T>(nS));
474 dryPos_ = (dryPos_ + nS) & (drySize_ - 1);
475 }
476
477 static constexpr double kDiffRho = 0.974;
478
479 struct BellSection
480 {
481 double b0 = 1.0, b1 = 0.0, b2 = 0.0, a1 = 0.0, a2 = 0.0;
482 double z1 = 0.0, z2 = 0.0;
483
484 [[nodiscard]] double process(double x) noexcept
485 {
486 const double y = b0 * x + z1;
487 z1 = b1 * x - a1 * y + z2;
488 z2 = b2 * x - a2 * y;
489 return y;
490 }
491 };
492
493 struct ChannelState
494 {
495 Hysteresis<T> hyst;
496 double flux = 0.0;
497 double vPrev = 0.0;
498 double vPrev2 = 0.0;
499 double mPrev = 0.0;
500 double hpX = 0.0, hpY = 0.0;
501 BellSection bell;
502 };
503
506 void recomputeLinear() noexcept
507 {
508 const double drive = std::pow(10.0, static_cast<double>(
509 driveDb_.load(std::memory_order_relaxed)) / 20.0);
510 const double size = static_cast<double>(coreSize_.load(std::memory_order_relaxed));
511 const double res = static_cast<double>(resonance_.load(std::memory_order_relaxed));
512
513 // The integrator leak keeps the flux bounded; its exact algebraic
514 // inverse cancels it, so the audible LF rolloff comes only from the
515 // explicit magnetizing-corner high-pass below.
516 const double cornerHz = 40.0 * std::pow(0.125, size); // 40 -> 5 Hz
517 leak_ = std::exp(-2.0 * std::numbers::pi * cornerHz / sampleRate_);
518 hpA_ = 1.0 - 2.0 * std::numbers::pi * cornerHz / sampleRate_;
519 // A first-order all-pass at tan(pi/8) of the corner leads by as much
520 // as the one-pole high-pass at that corner, and within a few degrees over it.
521 dryLead_.setCorner((std::numbers::sqrt2 - 1.0) * cornerHz);
522 halfT_ = 0.5 / sampleRate_;
523 invHalfT_ = 2.0 * sampleRate_;
524
525 // Flux scale: 0 dBFS at 30 Hz reaches H = 1.1a at nominal drive and
526 // nominal core; bigger cores take proportionally more flux.
527 const double fluxRef = 1.0 / (2.0 * std::numbers::pi * 30.0);
528 const double headroom = 0.6 + 0.8 * size;
529 calReqH_ = drive * 1.1 * 2.2e4 / (fluxRef * headroom);
530 calReqLeak_ = leak_;
531
532 // HF bell: Jensen-style leakage resonance mapped into the top octave.
533 const double bellHz = std::min(12000.0 + 6000.0 * res, 0.42 * sampleRate_);
534 const double bellDb = 2.5 * res;
535 const auto bc = BiquadCoeffs::makePeak(sampleRate_, bellHz, 0.8, bellDb);
536 for (auto& ch : channels_)
537 {
538 const double pz1 = ch.bell.z1, pz2 = ch.bell.z2;
539 ch.bell = BellSection { bc.b0, bc.b1, bc.b2, bc.a1, bc.a2, 0.0, 0.0 };
540 ch.bell.z1 = pz1;
541 ch.bell.z2 = pz2;
542 }
543 }
544
551 void startCalibration() noexcept
552 {
553 calH_ = calReqH_;
554 calLeak_ = calReqLeak_;
555 cal_.prepare(sampleRate_);
556 cal_.setParameters(3.5e5, 2.2e4, 1.6e-3, 3.2e4, 0.25);
557 calFlux_ = calVPrev_ = calMPrev_ = calVPrev2_ = 0.0;
558 calInSq_ = calOutSq_ = 0.0;
559 calN_ = static_cast<int>(0.04 * sampleRate_); // 2+2 cycles of 100 Hz
560 calI_ = 0;
561 calActive_ = true;
562 }
563
566 void stepCalibration(int budget) noexcept
567 {
568 const int stop = std::min(calN_, calI_ + std::max(budget, 0));
569 for (; calI_ < stop; ++calI_)
570 {
571 const int i = calI_;
572 const double x = 0.25 * std::sin(2.0 * std::numbers::pi * 100.0 * i / sampleRate_);
573 const double fluxNew = calLeak_ * calFlux_ + halfT_ * (x + calVPrev_);
574 calVPrev_ = x;
575 const double m = static_cast<double>(
576 cal_.processSample(static_cast<T>(calH_ * fluxNew)));
577 const double v = (m - calLeak_ * calMPrev_) * invHalfT_ - kDiffRho * calVPrev2_;
578 calVPrev2_ = v;
579 calMPrev_ = m;
580 calFlux_ = fluxNew;
581 if (i >= calN_ / 2)
582 {
583 calInSq_ += x * x;
584 calOutSq_ += v * v;
585 }
586 }
587 if (calI_ < calN_) return;
588 mScale_ = (calOutSq_ > 0.0) ? std::sqrt(calInSq_ / calOutSq_) : 1.0;
589 hScale_ = calH_;
590 calActive_ = false;
591 if (calRestart_)
592 {
593 calRestart_ = false;
594 startCalibration();
595 }
596 }
597
598 // -- Members --------------------------------------------------------------------
599 AudioSpec spec_ {};
600 double sampleRate_ = 48000.0;
601 int numChannels_ = 0;
602 int maxBlock_ = 1;
603 int osFactor_ = 2;
604 bool osAutomatic_ = false;
605 static constexpr double kAutomaticInternalRate = 88200.0;
606 int latency_ = 0;
607 std::unique_ptr<Oversampling<T>> oversampler_;
608 std::vector<std::vector<T>> dryRing_;
609 int drySize_ = 1;
610 int dryPos_ = 0;
611 detail::DryPhase dryLead_;
612 std::atomic<bool> prepared_ { false };
613
614 std::vector<ChannelState> channels_;
615
616 double leak_ = 0.999;
617 double hpA_ = 0.999;
618 double halfT_ = 0.5 / 48000.0;
619 double invHalfT_ = 96000.0;
620 double hScale_ = 1.0;
621 double mScale_ = 1.0;
622 double hScaleSm_ = -1.0;
623 double mScaleSm_ = -1.0;
624 T currentMix_ = T(1);
625 T mixMaxStep_ = T(1.0 / 960.0);
626
627 std::atomic<T> driveDb_ { T(0) };
628 std::atomic<T> coreSize_ { T(0.5) };
629 std::atomic<T> resonance_ { T(0.3) };
630 std::atomic<T> mix_ { T(1) };
631 std::atomic<bool> dirty_ { true };
632
633 // Incremental calibration (audio thread after prepare()).
634 Hysteresis<T> cal_;
635 double calReqH_ = 1.0, calReqLeak_ = 0.999, calH_ = 1.0, calLeak_ = 0.999;
636 double calFlux_ = 0.0, calVPrev_ = 0.0, calMPrev_ = 0.0, calVPrev2_ = 0.0;
637 double calInSq_ = 0.0, calOutSq_ = 0.0;
638 int calN_ = 0, calI_ = 0;
639 bool calActive_ = false, calRestart_ = false;
640};
641
642} // namespace dspark
Non-owning view over audio channel data.
Definition AudioBuffer.h:53
RAII scope guard to disable denormalised (subnormal) floating-point numbers.
Power-of-two oversampling processor with polyphase anti-aliasing.
static constexpr int factorForRate(double sampleRate, double minimumInternalRate=176400.0, int maxFactor=1<< kMaxStages) noexcept
The smallest factor that brings a host rate up to an internal rate.
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
Physical audio-transformer coloration (flux-domain JA hysteresis).
void prepare(const AudioSpec &spec)
Allocates per-channel circuit state. Invalid specs (non-positive or non-finite rate,...
std::vector< uint8_t > getState() const
Serializes the parameter state (setup/UI threads; allocates).
int getLatencySamples() const noexcept
Compatibility alias of getLatency(), in prepared-rate samples.
void setAutomaticOversampling(bool on)
Lets the host rate choose the factor (SETUP THREAD ONLY, as setOversampling()).
void setResonance(T amount) noexcept
Leakage/capacitance HF bell amount [0, 1] (Jensen-style). Non-finite values are ignored.
void setOversampling(int factor)
Configures internal oversampling of the core. SETUP THREAD ONLY: it reallocates the filters and re-ru...
T getMix() const noexcept
int getLatency() const noexcept
Latency in samples: the active oversampler's group delay (0 at 1x). The model itself is minimum-phase...
T getDrive() const noexcept
int getOversamplingFactor() const noexcept
Active oversampling factor (1 = off, 2 = default).
void processBlock(AudioBufferView< T > buffer) noexcept
Processes a block in-place. Pass-through until prepare() succeeds. Blocks longer than the prepared ma...
void setDrive(T db) noexcept
Core drive in dB [-12, +24]; loudness-compensated. Non-finite values are ignored.
void setCoreSize(T size) noexcept
Core size [0, 1]: small chokes at 40 Hz and saturates early, big rings to 5 Hz with more low-end head...
bool isOversamplingAutomatic() const noexcept
Whether the factor follows the host rate (setAutomaticOversampling()).
void reset() noexcept
Clears all signal state. RT-safe.
void setMix(T mix) noexcept
Dry/wet mix [0, 1]; the dry path is delayed to getLatency() and the mix is ramped over at least 20 ms...
bool setState(const uint8_t *data, size_t size)
Restores parameters from a blob (tolerant; rejects foreign ids). Setup thread: a stored oversampling ...
T getResonance() const noexcept
T getCoreSize() const noexcept
void reset() noexcept
Clears the memory (the amount stays).
T processSample(int channel, T x, double amount) noexcept
A sample of a channel, with the amount that advance() returned.
void prepare(double sampleRate, int channels)
Sizes the state (allocates).
void aim(bool on) noexcept
Where the amount goes.
double advance() noexcept
Moves the amount by a frame and returns it.
void land() noexcept
Puts the amount where it goes, without the fade.
void setCorner(double hz) noexcept
Moves the corner (a tangent, when it changes).
Main namespace for the DSPark framework.
T moveTowards(T from, T to, T maxDelta) noexcept
Moves a value toward a target by at most a given distance.
Definition DspMath.h:137
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 makePeak(double sampleRate, double freq, double Q, double gainDb) noexcept
Peak (parametric EQ) filter.
Definition Biquad.h:201