280 prepared_.store(
false, std::memory_order_relaxed);
283 mixMaxStep_ =
static_cast<T
>(1.0 / std::max(1.0, sampleRate_ * 0.02));
288 osFactor_ = osRequested_;
296 const double osRate = sampleRate_ *
static_cast<double>(osFactor_);
297 const double coreRate = osRate *
static_cast<double>(steps_);
298 const double tolerance = fourLevel_ ? kFourLevelTolerance : kExactTolerance;
299 stepped_.assign(
static_cast<size_t>(numChannels_), {});
300 calib_.setTolerance(tolerance);
301 calib2_.setTolerance(tolerance);
304 const int period = fourLevel_ ? kCarrierPeriod : 0;
305 calib_.setPredictorPeriod(period);
306 calib2_.setPredictorPeriod(period);
309 oversampler_ = std::make_unique<Oversampling<T>>(
313 oversampler_->prepare(spec);
317 oversampler_.reset();
324 hysteresis_.assign(
static_cast<size_t>(numChannels_), {});
325 hysteresisN_.assign(
static_cast<size_t>(numChannels_), {});
326 for (
auto& h : hysteresis_)
329 h.setTolerance(tolerance);
330 h.setPredictorPeriod(period);
331 h.setParameters(3.5e5, 2.2e4, 1.6e-3, 2.7e4, 0.17);
333 for (
auto& h : hysteresisN_)
336 h.setTolerance(tolerance);
337 h.setPredictorPeriod(period);
338 h.setParameters(3.5e5, 2.2e4, 1.6e-3, 2.7e4, 0.17);
341 recordHF_.assign(
static_cast<size_t>(numChannels_), {});
342 recordLF_.assign(
static_cast<size_t>(numChannels_), {});
343 playHF_.assign(
static_cast<size_t>(numChannels_), {});
344 playLF_.assign(
static_cast<size_t>(numChannels_), {});
345 headBump_.assign(
static_cast<size_t>(numChannels_), {});
346 overBiasLp_.assign(
static_cast<size_t>(numChannels_), 0.0);
347 inputAc_.assign(
static_cast<size_t>(numChannels_), {});
348 inputAcPole_ = std::exp(-2.0 * std::numbers::pi * kInputCouplingHz / sampleRate_);
349 recTrim_.assign(
static_cast<size_t>(numChannels_), {});
350 playTrim_.assign(
static_cast<size_t>(numChannels_), {});
351 ironLp_.assign(
static_cast<size_t>(numChannels_), 0.0);
352 ironA_ = 1.0 - std::exp(-2.0 * std::numbers::pi * kIronCornerHz / sampleRate_);
355 const size_t channels =
static_cast<size_t>(numChannels_);
356 hissHF_.assign(channels, {});
357 hissLF_.assign(channels, {});
358 xtHp_.assign(channels, {});
359 trPre_.assign(channels, {});
360 trPost_.assign(channels, {});
361 trMean_.assign(channels, 0.0);
362 asymMean_.assign(channels, 0.0);
363 recordHeld_.assign(channels, 0.0);
364 recordFall_ = std::exp(-1.0 / (kRecordPeakSeconds * sampleRate_ *
static_cast<double>(std::max(1, osFactor_))));
365 wet_.assign(channels, 0.0);
366 headContour_.assign(channels, {});
367 recNet_.assign(channels, {});
368 playNet_.assign(channels, {});
374 const double wc = 2.0 * sampleRate_ * std::tan(std::numbers::pi * std::min(10000.0, 0.45 * sampleRate_) / sampleRate_);
375 const ShelfSection hp = firstOrder(1.0, 0.0, 1.0, wc, sampleRate_);
376 for (
auto& s : xtHp_) s = hp;
377 xtNorm_ = 1.0 / std::max(1e-9, shelfMagnitude(hp, 2.0 * std::numbers::pi * 1000.0 / sampleRate_));
378 const double w1 = 2.0 * std::numbers::pi * kTransformerCornerHz;
379 const double w2 = 2.0 * std::numbers::pi * std::min(4000.0, 0.45 * sampleRate_);
380 const ShelfSection pre = firstOrder(0.0, w1, 1.0, w1, sampleRate_);
381 const ShelfSection post = firstOrder(1.0 / w1, 1.0, 1.0 / w2, 1.0, sampleRate_);
382 for (
auto& s : trPre_) s = pre;
383 for (
auto& s : trPost_) s = post;
388 outHp_.assign(
static_cast<size_t>(numChannels_), {});
391 for (
auto& h : outHp_)
392 h = PeakSection { hc.b0, hc.b1, hc.b2, hc.a1, hc.a2, 0.0, 0.0 };
398 firLen_ = std::max(kFirLenAt48k,
399 64 *
static_cast<int>(std::lround(sampleRate_ / 48000.0)) - 1);
400 firCenter_ = (firLen_ - 1) / 2;
402 while (firHalf_ < firLen_ + 1) firHalf_ <<= 1;
403 firState_.assign(
static_cast<size_t>(numChannels_),
404 std::vector<T>(
static_cast<size_t>(2 * firHalf_), T(0)));
406 firTaps_.assign(
static_cast<size_t>(firLen_), T(0));
408 const int grid = firLen_ + 1;
409 cosTable_.resize(
static_cast<size_t>(grid));
410 for (
int m = 0; m < grid; ++m)
411 cosTable_[
static_cast<size_t>(m)] =
412 std::cos(2.0 * std::numbers::pi * m /
static_cast<double>(grid));
413 designMags_.assign(
static_cast<size_t>(grid / 2 + 1), 0.0);
414 designTaps_.assign(
static_cast<size_t>(firLen_), 0.0);
416 overBiasX1_.assign(
static_cast<size_t>(numChannels_), 0.0);
422 delayCenter_ = std::max(96,
static_cast<int>(96.0 * sampleRate_ / 48000.0)) - (steps_ > 1 ? kStepDelay / osFactor_ : 0);
426 while (dsz < 5 * delayCenter_ + 16) dsz <<= 1;
427 delayMask_ = dsz - 1;
428 delayRing_.assign(
static_cast<size_t>(numChannels_),
429 std::vector<T>(
static_cast<size_t>(dsz), T(0)));
433 const double dt = 1.0 / sampleRate_;
435 const double dControl =
static_cast<double>(kTransportControl) * dt;
436 driftA_ = std::exp(-2.0 * std::numbers::pi * 0.10 * dControl);
437 scrapeA1_ = std::exp(-2.0 * std::numbers::pi * 90.0 * dControl);
438 scrapeA2_ = std::exp(-2.0 * std::numbers::pi * 40.0 * dControl);
441 tapeTransport_.prepare(sampleRate_,
static_cast<double>(delayCenter_), speedIps_ > 0.0 ? speedIps_ : 15.0);
442 tapeTransport_.setLimits(3.0,
static_cast<double>(delayMask_ - 4));
443 asymMeanA_ = std::exp(-2.0 * std::numbers::pi * 10.0 * dt /
static_cast<double>(osFactor_));
444 trMeanA_ = std::exp(-2.0 * std::numbers::pi * 5.0 * dt);
446 latency_ = (oversampler_ ? oversampler_->getLatency() : 0) + firCenter_ + delayCenter_
447 + (steps_ > 1 ? kStepDelay / osFactor_ : 0);
451 if (dryThroughFilters_) dryPath_.prepare(spec, *oversampler_);
452 dryScratch_.resize(numChannels_, maxBlock_);
453 dryDelay_ = latency_ - (dryThroughFilters_ ? oversampler_->getLatency() : 0);
455 while (drySize_ < latency_ + maxBlock_ + 1) drySize_ <<= 1;
456 dryRing_.assign(
static_cast<size_t>(numChannels_),
457 std::vector<T>(
static_cast<size_t>(drySize_), T(0)));
459 for (
auto* lead : { &dryInputLead_, &dryOutputLead_, &dryIronLead_ }) lead->prepare(sampleRate_, numChannels_);
460 dryInputLead_.
setCorner(kInputCouplingHz);
465 dirty_.store(
false, std::memory_order_relaxed);
467 circuitActive_ =
false;
468 speedTransportActive_ =
false;
474 stepCalibration(calN_);
478 prepared_.store(
true, std::memory_order_relaxed);
485 if (!prepared_.load(std::memory_order_relaxed))
return;
487 for (
auto& d : dryRing_) std::fill(d.begin(), d.end(), T(0));
491 tapeTransport_.reset();
497 currentMix_ = mix_.load(std::memory_order_relaxed);
498 aimDryPhase(currentMix_);
499 for (
auto* lead : { &dryInputLead_, &dryOutputLead_, &dryIronLead_ })
507 modPhaseFlut2_ = 0.0;
509 scrapeLp1_ = scrapeLp2_ = 0.0;
510 modFrom_ = modTo_ = 0.0;
516 rngNoise_ = 0x2468beefu;
520 std::fill(recordHeld_.begin(), recordHeld_.end(), 0.0);
523 for (
auto& p : recordPeak_) p.store(T(0), std::memory_order_relaxed);
524 if (oversampler_) oversampler_->reset();
537 if (!std::isfinite(driveDb))
return;
538 driveDb_.store(std::clamp(driveDb, T(-12), T(24)), std::memory_order_relaxed);
539 dirty_.store(
true, std::memory_order_release);
553 if (!std::isfinite(bias))
return;
554 bias_.store(std::clamp(bias, T(0), T(1)), std::memory_order_relaxed);
555 dirty_.store(
true, std::memory_order_release);
573 if (factor < 1 || factor > 16 || (factor & (factor - 1)) != 0)
return;
574 if (factor == osRequested_ && !osAutomatic_)
return;
575 osAutomatic_ =
false;
576 osRequested_ = factor;
578 if (prepared_.load(std::memory_order_relaxed))
598 if (on == osAutomatic_)
return;
600 if (on && prepared_.load(std::memory_order_relaxed))
632 if (four == fourLevel_)
return;
634 if (prepared_.load(std::memory_order_relaxed))
661 mode =
static_cast<OversamplingMode>(std::clamp(
static_cast<int>(mode), 0, 1));
662 if (mode == osMode_)
return;
664 if (prepared_.load(std::memory_order_relaxed))
678 const int v = std::clamp(
static_cast<int>(s),
681 speed_.store(v, std::memory_order_relaxed);
682 dirty_.store(
true, std::memory_order_release);
689 const int v = std::clamp(
static_cast<int>(s),
692 standard_.store(v, std::memory_order_relaxed);
693 dirty_.store(
true, std::memory_order_release);
700 if (!std::isfinite(amount))
return;
701 loss_.store(std::clamp(amount, T(0), T(1)), std::memory_order_relaxed);
702 dirty_.store(
true, std::memory_order_release);
709 if (!std::isfinite(amount))
return;
710 headBumpAmt_.store(std::clamp(amount, T(0), T(1)), std::memory_order_relaxed);
711 dirty_.store(
true, std::memory_order_release);
718 if (!std::isfinite(amount))
return;
719 wowFlutter_.store(std::clamp(amount, T(0), T(1)), std::memory_order_relaxed);
732 if (!std::isfinite(dbfs))
return;
733 noiseDb_.store(std::clamp(dbfs, T(-200), T(-20)), std::memory_order_relaxed);
740 if (!std::isfinite(mix))
return;
741 mix_.store(std::clamp(mix, T(0), T(1)), std::memory_order_relaxed);
747 transport_.store(std::clamp(
static_cast<int>(t), 0, 1), std::memory_order_relaxed);
759 if (!std::isfinite(dbfs))
return;
760 humDb_.store(std::clamp(dbfs, T(-200), T(-20)), std::memory_order_relaxed);
761 mains_.store(std::clamp(
static_cast<int>(mains), 0, 1), std::memory_order_relaxed);
774 if (std::isfinite(dB)) channelBleedDb_.store(std::clamp(dB, T(-200), T(-20)), std::memory_order_relaxed);
786 if (std::isfinite(amount)) evenHarmonics_.store(std::clamp(amount, T(0), T(1)), std::memory_order_relaxed);
804 if (std::isfinite(amount)) outputIron_.store(std::clamp(amount, T(0), T(1)), std::memory_order_relaxed);
810 headModel_.store(std::clamp(
static_cast<int>(m), 0, 1), std::memory_order_relaxed);
811 dirty_.store(
true, std::memory_order_release);
817 electronics_.store(std::clamp(
static_cast<int>(e), 0, 1), std::memory_order_relaxed);
818 dirty_.store(
true, std::memory_order_release);
831 if (!std::isfinite(hfDb) || !std::isfinite(lfDb))
return;
832 alignHf_.store(std::clamp(hfDb, T(-6), T(6)), std::memory_order_relaxed);
833 alignLf_.store(std::clamp(lfDb, T(-6), T(6)), std::memory_order_relaxed);
834 dirty_.store(
true, std::memory_order_release);
851 if (!std::isfinite(dB))
return;
852 recordEmphasis_.store(std::clamp(dB, T(-6), T(6)), std::memory_order_relaxed);
853 dirty_.store(
true, std::memory_order_release);
856 [[nodiscard]] T
getRecordEmphasis() const noexcept {
return recordEmphasis_.load(std::memory_order_relaxed); }
868 if (channel < 0 || channel >= kMaxRecordPeaks)
return T(0);
869 return recordPeak_[
static_cast<size_t>(channel)].load(std::memory_order_relaxed);
882 if (std::isfinite(amount)) alignTolerance_.store(std::clamp(amount, T(0), T(1)), std::memory_order_relaxed);
893 formulation_.store(std::clamp(
static_cast<int>(f), 0, 2), std::memory_order_relaxed);
894 dirty_.store(
true, std::memory_order_release);
900 trackFormat_.store(std::clamp(
static_cast<int>(f), 0, 2), std::memory_order_relaxed);
901 dirty_.store(
true, std::memory_order_release);
917 if (!std::isfinite(dB))
return;
918 calLevel_.store(std::clamp(dB, T(0), T(9)), std::memory_order_relaxed);
919 dirty_.store(
true, std::memory_order_release);
925 monitor_.store(std::clamp(
static_cast<int>(m), 0, 2), std::memory_order_relaxed);
926 dirty_.store(
true, std::memory_order_release);
930 [[nodiscard]] T
getHum() const noexcept {
return humDb_.load(std::memory_order_relaxed); }
931 [[nodiscard]]
Mains getMains() const noexcept {
return static_cast<Mains>(mains_.load(std::memory_order_relaxed)); }
932 [[nodiscard]] T
getChannelBleed() const noexcept {
return channelBleedDb_.load(std::memory_order_relaxed); }
933 [[nodiscard]] T
getEvenHarmonics() const noexcept {
return evenHarmonics_.load(std::memory_order_relaxed); }
934 [[nodiscard]] T
getOutputIron() const noexcept {
return outputIron_.load(std::memory_order_relaxed); }
937 [[nodiscard]] T
getAlignmentHf() const noexcept {
return alignHf_.load(std::memory_order_relaxed); }
938 [[nodiscard]] T
getAlignmentLf() const noexcept {
return alignLf_.load(std::memory_order_relaxed); }
941 [[nodiscard]] T
getCalibrationLevel() const noexcept {
return calLevel_.load(std::memory_order_relaxed); }
944 [[nodiscard]] T
getDrive() const noexcept {
return driveDb_.load(std::memory_order_relaxed); }
945 [[nodiscard]] T
getBias() const noexcept {
return bias_.load(std::memory_order_relaxed); }
948 return static_cast<Speed>(speed_.load(std::memory_order_relaxed));
952 return static_cast<Standard>(standard_.load(std::memory_order_relaxed));
954 [[nodiscard]] T
getLossEffects() const noexcept {
return loss_.load(std::memory_order_relaxed); }
955 [[nodiscard]] T
getHeadBump() const noexcept {
return headBumpAmt_.load(std::memory_order_relaxed); }
956 [[nodiscard]] T
getWowFlutter() const noexcept {
return wowFlutter_.load(std::memory_order_relaxed); }
957 [[nodiscard]] T
getNoise() const noexcept {
return noiseDb_.load(std::memory_order_relaxed); }
958 [[nodiscard]] T
getMix() const noexcept {
return mix_.load(std::memory_order_relaxed); }
962 [[nodiscard]]
int getLatency() const noexcept {
return latency_; }
968 [[nodiscard]] std::vector<uint8_t>
getState()
const
973 w.
write(
"drive",
static_cast<float>(driveDb_.load(std::memory_order_relaxed)));
974 w.
write(
"bias",
static_cast<float>(bias_.load(std::memory_order_relaxed)));
975 w.
write(
"speed", speed_.load(std::memory_order_relaxed));
976 w.
write(
"standard", standard_.load(std::memory_order_relaxed));
977 w.
write(
"loss",
static_cast<float>(loss_.load(std::memory_order_relaxed)));
978 w.
write(
"headBump",
static_cast<float>(headBumpAmt_.load(std::memory_order_relaxed)));
979 w.
write(
"wowFlutter",
static_cast<float>(wowFlutter_.load(std::memory_order_relaxed)));
980 w.
write(
"noise",
static_cast<float>(noiseDb_.load(std::memory_order_relaxed)));
981 w.
write(
"mix",
static_cast<float>(mix_.load(std::memory_order_relaxed)));
982 w.
write(
"oversampling", osRequested_);
983 w.
write(
"biasShape", fourLevel_ ? 1 : 0);
984 w.
write(
"oversamplingAuto", osAutomatic_);
985 w.
write(
"oversamplingMode",
static_cast<int32_t
>(osMode_));
986 w.
write(
"transport", transport_.load(std::memory_order_relaxed));
987 w.
write(
"humDb",
static_cast<float>(humDb_.load(std::memory_order_relaxed)));
988 w.
write(
"mains", mains_.load(std::memory_order_relaxed));
989 w.
write(
"channelBleed",
static_cast<float>(channelBleedDb_.load(std::memory_order_relaxed)));
990 w.
write(
"evenHarmonics",
static_cast<float>(evenHarmonics_.load(std::memory_order_relaxed)));
991 w.
write(
"outputIron",
static_cast<float>(outputIron_.load(std::memory_order_relaxed)));
992 w.
write(
"headModel", headModel_.load(std::memory_order_relaxed));
993 w.
write(
"electronics", electronics_.load(std::memory_order_relaxed));
994 w.
write(
"alignHf",
static_cast<float>(alignHf_.load(std::memory_order_relaxed)));
995 w.
write(
"alignLf",
static_cast<float>(alignLf_.load(std::memory_order_relaxed)));
996 w.
write(
"recordEmphasis",
static_cast<float>(recordEmphasis_.load(std::memory_order_relaxed)));
998 w.
write(
"formulation", formulation_.load(std::memory_order_relaxed));
999 w.
write(
"trackFormat", trackFormat_.load(std::memory_order_relaxed));
1000 w.
write(
"calibrationLevel",
static_cast<float>(calLevel_.load(std::memory_order_relaxed)));
1001 w.
write(
"monitor", monitor_.load(std::memory_order_relaxed));
1026 setAlignment(
static_cast<T
>(r.
read(
"alignHf", 0.0f)),
static_cast<T
>(r.
read(
"alignLf", 0.0f)));
1046 if (!prepared_.load(std::memory_order_relaxed))
return;
1049 const int nCh = std::min(buffer.getNumChannels(), numChannels_);
1050 const int nS = buffer.getNumSamples();
1051 if (nCh == 0 || nS == 0)
return;
1060 for (
int ch = 0; ch < nCh; ++ch)
1062 T* d = buffer.getChannel(ch);
1063 for (
int i = 0; i < nS; ++i)
1064 if (!std::isfinite(d[i])) d[i] = T(0);
1070 if (dirty_.load(std::memory_order_relaxed)
1071 && dirty_.exchange(
false, std::memory_order_acquire))
1074 if (calActive_) calRestart_ =
true;
1075 else startCalibration();
1078 for (
int off = 0; off < nS; off += maxBlock_)
1079 processChunk(buffer.getSubView(off, std::min(maxBlock_, nS - off)), nCh);
1085 const int nS = buffer.getNumSamples();
1086 const T mixTarget = mix_.load(std::memory_order_relaxed);
1087 const T mixStart = currentMix_;
1088 const double wfDepth =
static_cast<double>(wowFlutter_.load(std::memory_order_relaxed));
1089 const bool speedTransport = transport_.load(std::memory_order_relaxed) == 1;
1090 if (speedTransport != speedTransportActive_)
1096 tapeTransport_.setSpeedNow(speedIps_);
1097 tapeTransport_.syncDelay(
static_cast<double>(delayCenter_) + lastMod_);
1099 speedTransportActive_ = speedTransport;
1101 const bool circuit = circuitActive_;
1103 if (hissOn() && hissNormDirty_) computeHissNorm();
1104 const bool hissActive = hiss_.active();
1105 const bool humActive = hum_.active();
1106 const bool xtActive = xt_.active();
1107 const bool trActive = tr_.active();
1108 const bool monitorMoving = monitorRamp_.now != 1.0 || monitorRamp_.target != 1.0;
1109 aimDryPhase(mixTarget);
1110 const double humStep = (mains_.load(std::memory_order_relaxed) == 1 ? 60.0 : 50.0) / sampleRate_;
1111 if (humStep != humStepFor_)
1113 humStepFor_ = humStep;
1114 humRotCos_ = std::cos(2.0 * std::numbers::pi * humStep);
1115 humRotSin_ = std::sin(2.0 * std::numbers::pi * humStep);
1118 const double r = 1.0 / std::sqrt(humCos_ * humCos_ + humSin_ * humSin_);
1125 if (dryThroughFilters_)
1127 for (
int ch = 0; ch < nCh; ++ch)
1128 std::copy_n(buffer.getChannel(ch), nS, dryScratch_.getChannel(ch));
1129 auto dryView = dryScratch_.toView().getSubView(0, nS);
1130 dryPath_.process(dryView);
1132 for (
int ch = 0; ch < nCh; ++ch)
1134 const T* in = dryThroughFilters_ ? dryScratch_.getChannel(ch) : buffer.getChannel(ch);
1135 auto& dry = dryRing_[
static_cast<size_t>(ch)];
1137 for (
int i = 0; i < nS; ++i)
1139 dry[
static_cast<size_t>(dp)] = in[i];
1140 dp = (dp + 1) & (drySize_ - 1);
1147 if ((mixTarget == T(0) && mixStart == T(0)) || (monitorRamp_.now == 0.0 && monitorRamp_.target == 0.0))
1149 for (
int i = 0; i < nS; ++i)
1151 const double inTurn = dryInputLead_.
advance(), outTurn = dryOutputLead_.
advance(), ironTurn = dryIronLead_.
advance();
1152 const int at = (dryPos_ + i - dryDelay_) & (drySize_ - 1);
1153 for (
int ch = 0; ch < nCh; ++ch)
1154 buffer.getChannel(ch)[i] = turnDry(ch, dryRing_[
static_cast<size_t>(ch)][
static_cast<size_t>(at)], inTurn, outTurn, ironTurn);
1156 dryPos_ = (dryPos_ + nS) & (drySize_ - 1);
1157 if (calActive_) stepCalibration(nS * osFactor_ * steps_);
1170 wakeHold_ = latency_ + 1;
1173 const int warm = std::min(wakeHold_, nS);
1183 const double p = inputAcPole_, g = 0.5 * (1.0 + p);
1184 for (
int ch = 0; ch < nCh; ++ch)
1186 T* d = buffer.getChannel(ch);
1187 auto& s = inputAc_[
static_cast<size_t>(ch)];
1188 auto& trim = recTrim_[
static_cast<size_t>(ch)];
1189 for (
int i = 0; i < nS; ++i)
1191 const double x =
static_cast<double>(d[i]);
1192 const double y1 = g * (x - s[0]) + p * s[1];
1195 const double y2 = g * (y1 - s[2]) + p * s[3];
1198 d[i] =
static_cast<T
>(trim.process(y2));
1207 for (
int ch = 0; ch < nCh; ++ch)
1209 T* d = buffer.getChannel(ch);
1210 auto& hf = recordHF_[
static_cast<size_t>(ch)];
1211 auto& lf = recordLF_[
static_cast<size_t>(ch)];
1212 for (
int i = 0; i < nS; ++i)
1213 d[i] =
static_cast<T
>(hf.process(lf.process(
static_cast<double>(d[i]))));
1223 const bool osOn = (oversampler_ !=
nullptr);
1224 auto osView = osOn ? oversampler_->upsample(buffer) : buffer;
1225 const int osN = osView.getNumSamples();
1226 const int phaseStart = biasPhase_;
1230 double hRat = 1.0, mRat = 1.0, bRat = 1.0;
1231 double hEnd = hSm_, mEnd = mSm_, bEnd = bSm_;
1232 if (osN > 0 && (hSm_ != hScale_ || mSm_ != mScale_ || bSm_ != biasAmp_))
1234 const double kSm = 1.0 - std::exp(-
static_cast<double>(osN)
1235 / (kGainRampSeconds * sampleRate_ *
static_cast<double>(osFactor_)));
1236 const auto glide = [kSm](
double from,
double to)
noexcept
1238 const double e = from * std::pow(to / from, kSm);
1239 return std::abs(std::log(e / to)) < 1e-9 ? to : e;
1241 hEnd = glide(hSm_, hScale_);
1242 mEnd = glide(mSm_, mScale_);
1243 bEnd = glide(bSm_, biasAmp_);
1244 const double inv = 1.0 /
static_cast<double>(osN);
1245 hRat = std::pow(hEnd / hSm_, inv);
1246 mRat = std::pow(mEnd / mSm_, inv);
1247 bRat = std::pow(bEnd / bSm_, inv);
1249 const bool ramping = hRat != 1.0 || mRat != 1.0 || bRat != 1.0;
1250 const bool alignOn = updateAlignment(nCh);
1251 const bool asymActive = asym_.active();
1252 LinearRamp asymAfter = asym_;
1253 for (
int ch = 0; ch < nCh; ++ch)
1255 T* d = osView.getChannel(ch);
1256 auto& hp = hysteresis_[
static_cast<size_t>(ch)];
1257 auto& hn = hysteresisN_[
static_cast<size_t>(ch)];
1258 auto&
stepped = stepped_[
static_cast<size_t>(ch)];
1259 auto& rec = recNet_[
static_cast<size_t>(ch)];
1260 auto& play = playNet_[
static_cast<size_t>(ch)];
1261 double& mean = asymMean_[
static_cast<size_t>(ch)];
1262 LinearRamp asym = asym_;
1263 double inScale = hSm_, mS = mSm_, B = bSm_;
1264 int phase = phaseStart;
1265 double held = recordHeld_[
static_cast<size_t>(ch)];
1266 const double biasTrim = alignOn && ch < kMaxAligned ? alignBias_[static_cast<size_t>(ch)] : 1.0;
1267 for (
int i = 0; i < osN; ++i)
1275 double xs =
static_cast<double>(d[i]);
1276 if (circuit) xs = rec[1].processSample(rec[0].processSample(xs, 0), 0);
1280 const double square = xs * xs;
1281 mean = asymMeanA_ * mean + (1.0 - asymMeanA_) * square;
1282 xs += asym.next() * kAsymmetryShare * (square - mean);
1284 const double x = inScale * xs;
1285 held = std::max(std::abs(x), held * recordFall_);
1289 pair = twoSteps(stepped, hp, hn, x, alignOn ? B * biasTrim : B, phase);
1290 phase = (phase + 2) & 7;
1294 const double c = carrier(alignOn ? B * biasTrim : B, biasNominal_, phase);
1295 phase = (phase + 1) & 7;
1296 const double mp =
static_cast<double>(hp.processSample(
static_cast<T
>(x + c)));
1297 const double mn =
static_cast<double>(hn.processSample(
static_cast<T
>(x - c)));
1300 double out = (mS * 0.5) * pair;
1301 if (circuit) out = play[1].processSample(play[0].processSample(out, 0), 0);
1302 d[i] =
static_cast<T
>(out);
1305 if (!std::isfinite(held)) held = 0.0;
1306 recordHeld_[
static_cast<size_t>(ch)] = held;
1307 if (ch < kMaxRecordPeaks)
1308 recordPeak_[
static_cast<size_t>(ch)].store(
static_cast<T
>(held / kRecordFullScale), std::memory_order_relaxed);
1310 if (nCh > 0) asym_ = asymAfter;
1312 for (
int ch = 0; ch < nCh; ++ch)
1313 for (
int s = 0; s < 2; ++s)
1315 recNet_[
static_cast<size_t>(ch)][
static_cast<size_t>(s)].advanceRamp(osN);
1316 playNet_[
static_cast<size_t>(ch)][
static_cast<size_t>(s)].advanceRamp(osN);
1321 biasPhase_ = (phaseStart + osN * steps_) & 7;
1324 if (calActive_) stepCalibration(osN * steps_);
1325 if (osOn) oversampler_->downsample(buffer);
1330 const bool overBiasStart = overBiasOn_ && !overBiasActive_;
1331 overBiasActive_ = overBiasOn_;
1336 for (
int i = 0; i < nS; ++i)
1343 readPos = tapeTransport_.next(wfDepth);
1347 lastMod_ = nextTransportMod(wfDepth);
1348 readPos =
static_cast<double>(delayCenter_) + lastMod_;
1350 const auto readInt =
static_cast<int>(std::floor(readPos));
1351 const T frac =
static_cast<T
>(readPos - readInt);
1352 const double hissAmp = hissActive ? hiss_.next() * hissNorm_ * kUniformToUnitRms : 0.0;
1353 const double trShare = trActive ? tr_.next() : 0.0;
1355 for (
int ch = 0; ch < nCh; ++ch)
1357 T* d = buffer.getChannel(ch);
1365 rngNoise_ = rngNoise_ * 1664525u + 1013904223u;
1366 double n1 = (
static_cast<double>(rngNoise_ >> 8) / 8388608.0 - 1.0) * hissAmp;
1368 n1 = hissLF_[
static_cast<size_t>(ch)].process(hissHF_[
static_cast<size_t>(ch)].process(n1));
1369 in +=
static_cast<T
>(n1);
1373 auto& fir = firState_[
static_cast<size_t>(ch)];
1374 fir[
static_cast<size_t>(firPos_)] = in;
1375 fir[
static_cast<size_t>(firPos_ + firHalf_)] = in;
1376 const T* win = &fir[
static_cast<size_t>(firPos_ + firHalf_ - (firLen_ - 1))];
1381 for (
auto& s : headContour_[static_cast<size_t>(ch)]) y = s.process(y);
1383 y = headBump_[
static_cast<size_t>(ch)].process(y);
1387 auto& dl = delayRing_[
static_cast<size_t>(ch)];
1388 dl[
static_cast<size_t>(delayPos_)] = y;
1389 const int base = delayPos_ - readInt;
1390 const int dm = delayMask_;
1391 const T p0 = dl[
static_cast<size_t>((base + 1) & dm)];
1392 const T p1 = dl[
static_cast<size_t>(base & dm)];
1393 const T p2 = dl[
static_cast<size_t>((base - 1) & dm)];
1394 const T p3 = dl[
static_cast<size_t>((base - 2) & dm)];
1400 const T fm1 = f - T(1), fm2 = f - T(2), fp1 = f + T(1);
1401 w = -f * fm1 * fm2 * T(1.0 / 6.0) * p0 + fp1 * fm1 * fm2 * T(0.5) * p1
1402 - fp1 * f * fm2 * T(0.5) * p2 + fp1 * f * fm1 * T(1.0 / 6.0) * p3;
1407 w = p1 + T(0.5) * frac * (p2 - p0
1408 + frac * (T(2) * p0 - T(5) * p1 + T(4) * p2 - p3
1409 + frac * (T(3) * (p1 - p2) + p3 - p0)));
1415 w =
static_cast<T
>(playLF_[
static_cast<size_t>(ch)].process(
1416 playHF_[
static_cast<size_t>(ch)].process(
static_cast<double>(w))));
1418 w =
static_cast<T
>(playTrim_[
static_cast<size_t>(ch)].process(
static_cast<double>(w)));
1422 const auto c =
static_cast<size_t>(ch);
1423 const double xin =
static_cast<double>(w);
1424 const double hp = alignHpA_ * (alignHpY_[c] + xin - alignHpX_[c]);
1427 w =
static_cast<T
>(alignLevel_[c] * (xin + alignShelf_[c] * hp));
1438 auto& lp = overBiasLp_[
static_cast<size_t>(ch)];
1439 auto& x1 = overBiasX1_[
static_cast<size_t>(ch)];
1440 const double xin =
static_cast<double>(w);
1441 if (overBiasStart && i == 0) { lp = xin; x1 = xin; }
1442 lp = obB0_ * xin + obB1_ * x1 + obP_ * lp;
1444 w =
static_cast<T
>(lp);
1449 w = outHp_[
static_cast<size_t>(ch)].process(w);
1453 const double wd =
static_cast<double>(w);
1454 const double u = trPre_[
static_cast<size_t>(ch)].process(wd);
1455 double& m = trMean_[
static_cast<size_t>(ch)];
1456 m = trMeanA_ * m + (1.0 - trMeanA_) * u * u;
1457 const double bent = trPost_[
static_cast<size_t>(ch)].process(
1458 kTransformerEven * (u * u - m) - kTransformerOdd * u * u * u);
1462 double& low = ironLp_[
static_cast<size_t>(ch)];
1463 const double sum = trShare > 0.0 ? wd + trShare * bent : wd;
1464 low += ironA_ * (sum - low);
1465 if (trShare > 0.0) w =
static_cast<T
>(sum - trShare * low);
1467 wet_[
static_cast<size_t>(ch)] =
static_cast<double>(w);
1472 const double g = xt_.next();
1473 for (
int ch = 0; ch + 1 < nCh; ch += 2)
1475 const double a = wet_[
static_cast<size_t>(ch)], b = wet_[
static_cast<size_t>(ch + 1)];
1476 const double fromA = xtHp_[
static_cast<size_t>(ch)].process(a);
1477 const double fromB = xtHp_[
static_cast<size_t>(ch + 1)].process(b);
1478 wet_[
static_cast<size_t>(ch)] = a + g * fromB;
1479 wet_[
static_cast<size_t>(ch + 1)] = b + g * fromA;
1484 const double amp = hum_.next();
1487 const double s = humSin_ * humRotCos_ + humCos_ * humRotSin_;
1488 humCos_ = humCos_ * humRotCos_ - humSin_ * humRotSin_;
1490 const double h = amp * kHumNorm * (humSin_ + humSin_ * humCos_);
1491 for (
int ch = 0; ch < nCh; ++ch) wet_[static_cast<size_t>(ch)] += h;
1497 const double monitor = i < warm ? 0.0 : (monitorMoving ? monitorRamp_.next() : 1.0);
1498 const T mixVal =
moveTowards(mixStart, mixTarget, mixMaxStep_ *
static_cast<T
>(std::max(0, i + 1 - warm)));
1499 const double inTurn = dryInputLead_.
advance(), outTurn = dryOutputLead_.
advance(), ironTurn = dryIronLead_.
advance();
1500 const bool wetAlone = mixVal == T(1) && monitor == 1.0;
1501 for (
int ch = 0; ch < nCh; ++ch)
1503 T* d = buffer.getChannel(ch);
1504 const auto& dry = dryRing_[
static_cast<size_t>(ch)];
1505 const int dryIdx = (dryPos_ + i - dryDelay_) & (drySize_ - 1);
1506 const T rawDry = dry[
static_cast<size_t>(dryIdx)];
1507 const T turned = turnDry(ch, rawDry, inTurn, outTurn, ironTurn);
1508 const T drySample = wetAlone ? rawDry : turned;
1509 T w =
static_cast<T
>(wet_[
static_cast<size_t>(ch)]);
1511 w =
static_cast<T
>(
static_cast<double>(drySample)
1512 + (
static_cast<double>(w) -
static_cast<double>(drySample)) * monitor);
1513 d[i] = drySample + (w - drySample) * mixVal;
1516 firPos_ = (firPos_ + 1) & (firHalf_ - 1);
1517 delayPos_ = (delayPos_ + 1) & delayMask_;
1519 dryPos_ = (dryPos_ + nS) & (drySize_ - 1);
1520 currentMix_ =
moveTowards(mixStart, mixTarget, mixMaxStep_ *
static_cast<T
>(nS - warm));
1527 void aimDryPhase(T mixTarget)
noexcept
1529 const bool turn = mixTarget > T(0) && monitor_.load(std::memory_order_relaxed) != 2;
1530 const double iron =
static_cast<double>(outputIron_.load(std::memory_order_relaxed));
1531 dryInputLead_.
aim(turn);
1532 dryOutputLead_.
aim(turn);
1535 dryIronLead_.
setCorner(0.5 * kIronCornerHz * std::max(iron, 0.05));
1536 dryIronLead_.
aim(turn && iron >= 0.05);
1540 [[nodiscard]] T turnDry(
int channel, T x,
double inTurn,
double outTurn,
double ironTurn)
noexcept
1553 [[nodiscard]]
int stepsInUse(
double rate)
const noexcept
1555 const bool whole = osFactor_ == 1 || osFactor_ == 2 || osFactor_ == 4;
1556 const double internal = rate *
static_cast<double>(osFactor_);
1557 return fourLevel_ && whole && 4.0 * internal > 0.999999 * kAutomaticInternalRate && internal < 0.999999 * kFourLevelInternalRate ? 2 : 1;
1576 [[nodiscard]]
double twoSteps(Stepped& s, Hysteresis<T>& hp, Hysteresis<T>& hn,
double x,
double amplitude,
int phase)
const noexcept
1578 const auto solve = [&](
double field,
int at)
noexcept
1580 const double c = carrier(amplitude, biasNominal_, at);
1581 return static_cast<double>(hp.processSample(
static_cast<T
>(field + c)))
1582 +
static_cast<double>(hn.processSample(
static_cast<T
>(field - c)));
1584 const double first = (9.0 * (s.in[0] + s.in[1]) - (x + s.in[2])) * 0.0625;
1585 const double second = s.in[0];
1590 const double a = solve(first, phase);
1591 const double out = (3.0 * (a + s.even[4]) - 25.0 * (s.even[0] + s.even[3]) + 150.0 * (s.even[1] + s.even[2])) * (1.0 / 512.0)
1593 const double b = solve(second, (phase + 1) & 7);
1594 s.even[4] = s.even[3];
1595 s.even[3] = s.even[2];
1596 s.even[2] = s.even[1];
1597 s.even[1] = s.even[0];
1599 s.odd[2] = s.odd[1];
1600 s.odd[1] = s.odd[0];
1611 [[nodiscard]]
double carrier(
double amplitude,
double nominal,
int phase)
const noexcept
1613 const double sign = kBiasTable[
static_cast<size_t>(phase)];
1614 if (!fourLevel_)
return amplitude * sign;
1615 return sign * ((phase & 1) ? kOuterLevel * amplitude : kInnerLevel * std::min(amplitude, nominal));
1621 double now = 0.0, target = 0.0, step = 0.0;
1623 void aim(
double to,
double samples)
noexcept
1625 if (to == target)
return;
1627 step = std::abs(to - now) / std::max(1.0, samples);
1629 [[nodiscard]]
double next() noexcept
1632 now = (now < target) ? std::min(target, now + step) : std::max(target, now - step);
1635 [[nodiscard]]
bool active() const noexcept {
return now != 0.0 || target != 0.0; }
1638 [[nodiscard]]
bool hissOn() const noexcept {
return noiseDb_.load(std::memory_order_relaxed) > T(-120); }
1641 void aimRamps(
bool land)
noexcept
1643 const double fs = sampleRate_;
1649 static constexpr double kTrackWidthMm[3] = { 2.0, 6.3, 1.0 };
1650 const int track = std::clamp(trackFormat_.load(std::memory_order_relaxed), 0, 2);
1651 const double offset = 10.0 * std::log10(kTrackWidthMm[0] / kTrackWidthMm[
static_cast<size_t>(track)])
1652 + formulationOf(formulation_.load(std::memory_order_relaxed)).hissDb
1653 -
static_cast<double>(calLevel_.load(std::memory_order_relaxed));
1654 hiss = std::pow(10.0, (
static_cast<double>(noiseDb_.load(std::memory_order_relaxed)) + offset) / 20.0);
1656 const T humDb = humDb_.load(std::memory_order_relaxed);
1657 const double hum = humDb > T(-120) ? std::pow(10.0,
static_cast<double>(humDb) / 20.0) : 0.0;
1658 const T xtDb = channelBleedDb_.load(std::memory_order_relaxed);
1659 const double xt = xtDb > T(-120) ? std::pow(10.0,
static_cast<double>(xtDb) / 20.0) * xtNorm_ : 0.0;
1660 if (xt > 0.0 && !xt_.active())
1661 for (
auto& s : xtHp_) s.clear();
1662 const double monitor = monitor_.load(std::memory_order_relaxed) == 2 ? 0.0 : 1.0;
1663 hiss_.aim(hiss, 0.05 * fs);
1664 hum_.aim(hum, 0.05 * fs);
1665 xt_.aim(xt, 0.05 * fs);
1666 tr_.aim(
static_cast<double>(outputIron_.load(std::memory_order_relaxed)), 0.02 * fs);
1667 asym_.aim(
static_cast<double>(evenHarmonics_.load(std::memory_order_relaxed)), 0.02 * fs *
static_cast<double>(osFactor_));
1668 monitorRamp_.aim(monitor, 0.02 * fs);
1671 hiss_.now = hiss_.target;
1672 hum_.now = hum_.target;
1673 xt_.now = xt_.target;
1674 tr_.now = tr_.target;
1675 asym_.now = asym_.target;
1676 monitorRamp_.now = monitorRamp_.target;
1686 void computeHissNorm() noexcept
1688 hissNormDirty_ =
false;
1689 if (numChannels_ <= 0)
return;
1690 constexpr int kGrid = 256;
1692 for (
int k = 0; k < kGrid; ++k)
1694 const double w = std::numbers::pi * (
static_cast<double>(k) + 0.5) / kGrid;
1695 const double cw = std::cos(w), sw = std::sin(w);
1696 double re = 0.0, im = 0.0, rr = 1.0, ri = 0.0;
1697 for (
int n = 0; n < firLen_; ++n)
1699 re += designTaps_[
static_cast<size_t>(n)] * rr;
1700 im += designTaps_[
static_cast<size_t>(n)] * ri;
1701 const double nr = rr * cw + ri * sw;
1702 ri = ri * cw - rr * sw;
1705 double g2 = (re * re + im * im) * firNorm_ * firNorm_;
1707 for (
const auto& s : headContour_[0]) g2 *= peakMagnitude(s, w) * peakMagnitude(s, w);
1709 g2 *= peakMagnitude(headBump_[0], w) * peakMagnitude(headBump_[0], w);
1710 const double play = shelfMagnitude(playHF_[0], w) * shelfMagnitude(playLF_[0], w);
1714 const double nr = obB0_ + obB1_ * cw, ni = -obB1_ * sw;
1715 const double dr = 1.0 - obP_ * cw, di = obP_ * sw;
1716 g2 *= (nr * nr + ni * ni) / (dr * dr + di * di);
1718 g2 *= peakMagnitude(outHp_[0], w) * peakMagnitude(outHp_[0], w);
1722 hissNorm_ = power > 1e-20 ? 1.0 / std::sqrt(power) : 1.0;
1731 double b0 = 1.0, b1 = 0.0, a1 = 0.0;
1732 double x1 = 0.0, y1 = 0.0;
1734 void clear() noexcept { x1 = 0.0; y1 = 0.0; }
1735 [[nodiscard]]
double process(
double x)
noexcept
1737 const double y = b0 * x + b1 * x1 - a1 * y1;
1747 double b0 = 1.0, b1 = 0.0, b2 = 0.0, a1 = 0.0, a2 = 0.0;
1748 double z1 = 0.0, z2 = 0.0;
1750 void clear() noexcept { z1 = 0.0; z2 = 0.0; }
1751 [[nodiscard]] T process(T x)
noexcept
1753 const double in =
static_cast<double>(x);
1754 const double y = b0 * in + z1;
1755 z1 = b1 * in - a1 * y + z2;
1756 z2 = b2 * in - a2 * y;
1757 return static_cast<T
>(y);
1763 static ShelfSection makeHFShelf(
double t,
double kHi,
double fs,
bool inverse)
noexcept
1765 const double kt = 2.0 * fs * t;
1766 double n0 = kHi * kt + 1.0, n1 = 1.0 - kHi * kt;
1767 double d0 = kt + 1.0, d1 = 1.0 - kt;
1768 if (inverse) { std::swap(n0, d0); std::swap(n1, d1); }
1769 return { n0 / d0, n1 / d0, d1 / d0, 0.0, 0.0 };
1772 static ShelfSection makeLFShelf(
double t,
double kLo,
double fs,
bool inverse)
noexcept
1774 const double kt = 2.0 * fs * t;
1775 double n0 = kt + kLo, n1 = kLo - kt;
1776 double d0 = kt + 1.0, d1 = 1.0 - kt;
1777 if (inverse) { std::swap(n0, d0); std::swap(n1, d1); }
1778 return { n0 / d0, n1 / d0, d1 / d0, 0.0, 0.0 };
1782 static ShelfSection firstOrder(
double n1,
double n0,
double d1,
double d0,
double fs)
noexcept
1784 const double k = 2.0 * fs;
1785 const double a0 = d1 * k + d0;
1786 return { (n1 * k + n0) / a0, (n0 - n1 * k) / a0, (d0 - d1 * k) / a0, 0.0, 0.0 };
1790 [[nodiscard]]
static double shelfMagnitude(
const ShelfSection& s,
double w)
noexcept
1792 const double c = std::cos(w), sn = std::sin(w);
1793 const double nr = s.b0 + s.b1 * c, ni = -s.b1 * sn;
1794 const double dr = 1.0 + s.a1 * c, di = -s.a1 * sn;
1795 return std::sqrt((nr * nr + ni * ni) / std::max(1e-300, dr * dr + di * di));
1799 [[nodiscard]]
static double peakMagnitude(
const PeakSection& s,
double w)
noexcept
1801 const double c1 = std::cos(w), s1 = std::sin(w), c2 = std::cos(2.0 * w), s2 = std::sin(2.0 * w);
1802 const double nr = s.b0 + s.b1 * c1 + s.b2 * c2, ni = -(s.b1 * s1 + s.b2 * s2);
1803 const double dr = 1.0 + s.a1 * c1 + s.a2 * c2, di = -(s.a1 * s1 + s.a2 * s2);
1804 return std::sqrt((nr * nr + ni * ni) / std::max(1e-300, dr * dr + di * di));
1808 struct FormulationParams
1810 double ms, a, alpha, k, c, hissDb;
1813 [[nodiscard]]
static FormulationParams formulationOf(
int f)
noexcept
1815 switch (std::clamp(f, 0, 2))
1817 case 1:
return { 3.5e5 * 1.4125375446227544, 2.2e4 * 1.4125375446227544, 1.6e-3, 2.7e4 * 1.2, 0.17, -1.5 };
1818 case 2:
return { 3.5e5 * 0.7943282347242815, 2.2e4 * 0.7943282347242815, 1.6e-3, 2.7e4 * 0.8, 0.25, 3.0 };
1819 default:
return { 3.5e5, 2.2e4, 1.6e-3, 2.7e4, 0.17, 0.0 };
1826 void clearMachine() noexcept
1828 for (
auto& h : hysteresis_) h.
reset();
1829 for (
auto& h : hysteresisN_) h.
reset();
1830 for (
auto& s : stepped_) s = Stepped {};
1831 for (
auto& f : firState_) std::fill(f.begin(), f.end(), T(0));
1832 for (
auto& d : delayRing_) std::fill(d.begin(), d.end(), T(0));
1833 for (
auto& s : inputAc_) s = {};
1834 for (
auto& s : recTrim_) s.clear();
1835 for (
auto& s : playTrim_) s.clear();
1836 for (
auto& v : ironLp_) v = 0.0;
1837 for (
auto& s : recordHF_) s.clear();
1838 for (
auto& s : recordLF_) s.clear();
1839 for (
auto& s : playHF_) s.clear();
1840 for (
auto& s : playLF_) s.clear();
1841 for (
auto& v : overBiasLp_) v = 0.0;
1842 for (
auto& v : overBiasX1_) v = 0.0;
1845 for (
auto& b : headBump_) b.clear();
1846 for (
auto& hp : outHp_) hp.clear();
1847 for (
auto& s : hissHF_) s.clear();
1848 for (
auto& s : hissLF_) s.clear();
1849 for (
auto& s : xtHp_) s.clear();
1850 for (
auto& s : trPre_) s.clear();
1851 for (
auto& s : trPost_) s.clear();
1852 for (
auto& v : trMean_) v = 0.0;
1853 for (
auto& v : asymMean_) v = 0.0;
1854 for (
auto& v : wet_) v = 0.0;
1855 for (
auto& chain : headContour_) for (auto& s : chain) s.clear();
1856 for (
auto& n : recNet_) for (auto& s : n) s.
reset();
1857 for (
auto& n : playNet_) for (auto& s : n) s.
reset();
1858 if (oversampler_) oversampler_->reset();
1862 [[nodiscard]]
static double speedInIps(
Speed speed)
noexcept
1874 void recomputeLinear() noexcept
1876 const double driveDbV =
static_cast<double>(driveDb_.load(std::memory_order_relaxed));
1877 const double drive = std::pow(10.0, driveDbV / 20.0);
1878 const double bias =
static_cast<double>(bias_.load(std::memory_order_relaxed));
1879 const auto speed =
static_cast<Speed>(speed_.load(std::memory_order_relaxed));
1880 const double ips = speedInIps(speed);
1881 const auto standard =
static_cast<Standard>(standard_.load(std::memory_order_relaxed));
1882 const double lossAmt =
static_cast<double>(loss_.load(std::memory_order_relaxed));
1883 const double bumpAmt =
static_cast<double>(headBumpAmt_.load(std::memory_order_relaxed));
1898 const int form = formulation_.load(std::memory_order_relaxed);
1899 const FormulationParams fp = formulationOf(form);
1900 if (form != formApplied_)
1902 for (
auto& h : hysteresis_) h.setParameters(fp.ms, fp.a, fp.alpha, fp.k, fp.c);
1903 for (
auto& h : hysteresisN_) h.setParameters(fp.ms, fp.a, fp.alpha, fp.k, fp.c);
1904 formApplied_ = form;
1905 hissNormDirty_ =
true;
1908 const double biasB = std::min(6.0, 3.0 * std::pow(9.0, bias - 0.5));
1909 calReq_.biasAmp = biasB * 2.2e4 * (fp.k / 2.7e4);
1910 biasNominal_ = 3.0 * 2.2e4 * (fp.k / 2.7e4);
1911 calReq_.biasNominal = biasNominal_;
1920 const double fc = 22000.0 * (3.5 / std::max(biasB, 3.5));
1921 const double pole = std::exp(-2.0 * std::numbers::pi * fc / sampleRate_);
1922 const double r = 0.5 * sampleRate_ / fc;
1923 const double nyq = 1.0 / std::sqrt(1.0 + r * r);
1924 const double b0 = 0.5 * ((1.0 - pole) + nyq * (1.0 + pole));
1925 const double b1 = 0.5 * ((1.0 - pole) - nyq * (1.0 + pole));
1926 const double share = std::min(1.0, (biasB - 3.0) / 0.5);
1928 obB0_ = (1.0 - share) + share * b0;
1929 obB1_ = share * b1 - (1.0 - share) * pole;
1932 else if (bias < 0.5)
1937 const double lift = std::pow(10.0, kUnderBiasLiftDb * (1.0 - 2.0 * bias) / 20.0);
1938 const double centre = std::clamp(kUnderBiasCentreHz * ips / 15.0, 1000.0, 0.3 * sampleRate_);
1939 const ShelfSection s = makeHFShelf(1.0 / (2.0 * std::numbers::pi * centre * std::sqrt(lift)), lift, sampleRate_,
false);
1947 overBiasOn_ =
false;
1967 constexpr double kHiCap = 4.0;
1968 constexpr double kLoBoost = 2.0;
1969 const double tLo = 3180e-6;
1970 const double hfTrim =
static_cast<double>(alignHf_.load(std::memory_order_relaxed));
1971 const double lfTrim =
static_cast<double>(alignLf_.load(std::memory_order_relaxed));
1972 const double gHf = std::pow(10.0, hfTrim / 20.0), gLf = std::pow(10.0, lfTrim / 20.0);
1976 double trimAt1k = 1.0;
1978 const double gRec = std::pow(10.0,
static_cast<double>(recordEmphasis_.load(std::memory_order_relaxed)) / 20.0);
1979 const double tTrim = 1.0 / (2.0 * std::numbers::pi * kEmphasisTrimHz * std::sqrt(gRec));
1980 const ShelfSection up = makeHFShelf(tTrim, gRec, sampleRate_,
false);
1981 const ShelfSection down = makeHFShelf(tTrim, gRec, sampleRate_,
true);
1982 for (
auto& s : recTrim_)
1984 const double x1 = s.x1, y1 = s.y1;
1989 for (
auto& s : playTrim_)
1991 const double x1 = s.x1, y1 = s.y1;
1996 trimAt1k = shelfMagnitude(up, 2.0 * std::numbers::pi * 1000.0 / sampleRate_);
2009 const double calGain = std::pow(10.0,
static_cast<double>(calLevel_.load(std::memory_order_relaxed)) / 20.0);
2010 calReq_.hScale = drive * 1.2 * 2.2e4 * calGain;
2018 const double w1 = 2.0 * std::numbers::pi * 1000.0 * t2;
2019 const double emph1k = std::sqrt((1.0 + kHiCap * kHiCap * w1 * w1)
2021 calReq_.calAmp = 0.25 * emph1k * trimAt1k;
2022 calReq_.drive = drive;
2025 for (
int ch = 0; ch < numChannels_; ++ch)
2027 auto& rhf = recordHF_[
static_cast<size_t>(ch)];
2028 auto& rlf = recordLF_[
static_cast<size_t>(ch)];
2029 auto& phf = playHF_[
static_cast<size_t>(ch)];
2030 auto& plf = playLF_[
static_cast<size_t>(ch)];
2032 const double sx1 = rhf.x1, sy1 = rhf.y1;
2033 rhf = makeHFShelf(t2, kHiCap, sampleRate_,
false);
2034 rhf.x1 = sx1; rhf.y1 = sy1;
2036 const double lx1 = rlf.x1, ly1 = rlf.y1;
2037 rlf = useLF ? makeLFShelf(tLo, kLoBoost, sampleRate_,
false) : ShelfSection {};
2038 rlf.x1 = lx1; rlf.y1 = ly1;
2040 const double px1 = phf.x1, py1 = phf.y1;
2041 phf = makeHFShelf(t2, kHiCap / gHf, sampleRate_,
true);
2042 phf.x1 = px1; phf.y1 = py1;
2044 const double qx1 = plf.x1, qy1 = plf.y1;
2045 plf = useLF ? makeLFShelf(tLo, kLoBoost / gLf, sampleRate_,
true)
2046 : (lfTrim != 0.0 ? makeLFShelf(tLo, 1.0 / gLf, sampleRate_, true) : ShelfSection {});
2047 plf.x1 = qx1; plf.y1 = qy1;
2051 auto& hhf = hissHF_[
static_cast<size_t>(ch)];
2052 auto& hlf = hissLF_[
static_cast<size_t>(ch)];
2053 const double hx1 = hhf.x1, hy1 = hhf.y1, lx = hlf.x1, ly = hlf.y1;
2054 hhf = phf; hhf.x1 = hx1; hhf.y1 = hy1;
2055 hlf = plf; hlf.x1 = lx; hlf.y1 = ly;
2060 const bool circuitWanted = electronics_.load(std::memory_order_relaxed) == 1;
2063 const double osRate = sampleRate_ *
static_cast<double>(osFactor_);
2064 const double kLoR = useLF ? kLoBoost : 1.0;
2065 const double kHiP = kHiCap / gHf, kLoP = kLoR / gLf;
2066 const AnalogSection rec1 =
AnalogSection::make(kHiCap * t2 * tLo, kHiCap * t2 * kLoR + tLo, kLoR,
2067 t2 * tLo, t2 + tLo, 1.0);
2069 kHiP * t2 * tLo, kHiP * t2 * kLoP + tLo, kLoP);
2070 const double recLimit = std::min(45000.0, 0.45 * osRate), playPole = std::min(50000.0, 0.45 * osRate);
2071 const double corner = 1.0 / (2.0 * std::numbers::pi * t2);
2076 const int ramp =
static_cast<int>(0.05 * osRate);
2077 for (
int ch = 0; ch < numChannels_; ++ch)
2079 auto& rec = recNet_[
static_cast<size_t>(ch)];
2080 auto& play = playNet_[
static_cast<size_t>(ch)];
2081 if (!circuitActive_)
2083 rec[0].setCoeffs(r1); rec[1].setCoeffs(r2); play[0].setCoeffs(q1); play[1].setCoeffs(q2);
2084 for (
auto& s : rec) s.
reset();
2085 for (
auto& s : play) s.
reset();
2089 rec[0].rampCoeffs(r1, ramp); rec[1].rampCoeffs(r2, ramp);
2090 play[0].rampCoeffs(q1, ramp); play[1].rampCoeffs(q2, ramp);
2093 if (!circuitActive_)
2094 for (
auto& s : hissHF_) s.clear();
2096 else if (circuitActive_)
2099 for (
auto& s : recordHF_) s.clear();
2100 for (
auto& s : recordLF_) s.clear();
2101 for (
auto& s : playHF_) s.clear();
2102 for (
auto& s : playLF_) s.clear();
2104 circuitActive_ = circuitWanted;
2109 if (speedTransportActive_ && speedIps_ > 0.0) tapeTransport_.setSpeed(ips);
2110 else tapeTransport_.setSpeedNow(ips);
2112 const double v = ips * 0.0254;
2114 const bool sync = monitor_.load(std::memory_order_relaxed) == 1;
2115 const double gap = sync ? 6.0e-6 : 3.0e-6;
2116 const double spacing = sync ? 1.0e-6 : 0.5e-6;
2117 constexpr double thickness = 1.0e-6;
2119 const int grid = firLen_ + 1;
2120 double* mags = designMags_.data();
2121 for (
int kBin = 0; kBin <= grid / 2; ++kBin)
2123 const double f = kBin * sampleRate_ / grid;
2127 const double lambda = v / f;
2128 const double spacingLoss = std::pow(10.0, -54.6 * (spacing / lambda) / 20.0);
2129 const double gx = std::numbers::pi * gap / lambda;
2130 const double gapLoss = (gx < 1e-9) ? 1.0
2131 : std::abs(std::sin(gx) / gx);
2132 const double tx = 4.0 * std::numbers::pi * thickness / lambda;
2133 const double thickLoss = (tx < 1e-9) ? 1.0 : (1.0 - std::exp(-tx)) / tx;
2134 mag = spacingLoss * gapLoss * thickLoss;
2136 mags[kBin] = (1.0 - lossAmt) + lossAmt * mag;
2145 else if (f > 19500.0)
2146 mags[kBin] *= 0.5 + 0.5 * std::cos(std::numbers::pi * (f - 19500.0) / 2000.0);
2148 double* taps = designTaps_.data();
2149 for (
int n = 0; n < firLen_; ++n)
2153 const int offset = n - firCenter_;
2154 double acc = mags[0];
2155 for (
int kBin = 1; kBin < grid / 2; ++kBin)
2157 const int idx = ((kBin * offset) % grid + grid) % grid;
2158 acc += 2.0 * mags[kBin] * cosTable_[
static_cast<size_t>(idx)];
2160 acc += mags[grid / 2] * ((offset & 1) ? -1.0 : 1.0);
2161 const double hann = 0.5 - 0.5 * cosTable_[
static_cast<size_t>((n + 1) % grid)];
2162 taps[n] = acc * hann / grid;
2167 const double w1k = 2.0 * std::numbers::pi * 1000.0 / sampleRate_;
2168 double re = 0.0, im = 0.0;
2169 for (
int n = 0; n < firLen_; ++n)
2171 re += taps[n] * std::cos(w1k * n);
2172 im -= taps[n] * std::sin(w1k * n);
2174 const double g = std::sqrt(re * re + im * im);
2175 const double norm = (g > 1e-9) ? 1.0 / g : 1.0;
2176 for (
int n = 0; n < firLen_; ++n) taps[n] *= norm;
2179 for (
int n = 0; n < firLen_; ++n)
2180 firTaps_[
static_cast<size_t>(firLen_ - 1 - n)] =
2181 static_cast<T
>(taps[n]);
2188 static constexpr double kContactRatio[3] = { 1.0, 0.8, 1.25 };
2189 const double bumpHz = kBumpHzPerIps * ips
2190 * kContactRatio[
static_cast<size_t>(std::clamp(trackFormat_.load(std::memory_order_relaxed), 0, 2))];
2191 const double bumpDb = 2.5 * bumpAmt;
2193 for (
auto& b : headBump_)
2195 const double pz1 = b.z1, pz2 = b.z2;
2196 b = PeakSection { bc.b0, bc.b1, bc.b2, bc.a1, bc.a2, 0.0, 0.0 };
2203 contourActive_ = headModel_.load(std::memory_order_relaxed) == 1;
2206 static constexpr double kRatio[kContourSections] = { 1.0, 1.45, 1.95, 2.5 };
2207 static constexpr double kShare[kContourSections] = { 1.0, -0.5, 0.28, -0.15 };
2208 static constexpr double kQ[kContourSections] = { 0.9, 2.0, 2.5, 3.0 };
2209 for (
int k = 0; k < kContourSections; ++k)
2211 const size_t kk =
static_cast<size_t>(k);
2213 AnalogSection::peak(bumpHz * kRatio[kk], kQ[kk], kContourDb * bumpAmt * kShare[kk]), sampleRate_);
2214 for (
auto& chain : headContour_)
2216 auto& s = chain[kk];
2217 const double z1 = s.z1, z2 = s.z2;
2218 s = PeakSection { c.b0, c.b1, c.b2, c.a1, c.a2, z1, z2 };
2222 hissNormDirty_ =
true;
2232 void startCalibration() noexcept
2235 const double fs4 = sampleRate_ *
static_cast<double>(osFactor_ * steps_);
2238 calN_ =
static_cast<int>(0.024 * fs4);
2239 calFrom_ = (calN_ * 2) / 3;
2240 calW_ = 2.0 * std::numbers::pi * 1000.0 / fs4;
2241 const FormulationParams& fp = calRun_.form;
2242 calib_.prepare(fs4);
2243 calib_.setParameters(fp.ms, fp.a, fp.alpha, fp.k, fp.c);
2244 calib2_.prepare(fs4);
2245 calib2_.setParameters(fp.ms, fp.a, fp.alpha, fp.k, fp.c);
2247 calRe_ = calIm_ = 0.0;
2254 void stepCalibration(
int budget)
noexcept
2256 const int stop = std::min(calN_, calI_ + std::max(budget, 0));
2257 for (; calI_ < stop; ++calI_)
2259 const int i = calI_;
2260 const double s = std::sin(calW_ * i);
2261 const double x = calRun_.hScale * calRun_.calAmp * s;
2262 const double c = carrier(calRun_.biasAmp, calRun_.biasNominal, i & 7);
2263 const double m = 0.5
2264 * (
static_cast<double>(calib_.processSample(
static_cast<T
>(x + c)))
2265 +
static_cast<double>(calib2_.processSample(
static_cast<T
>(x - c))));
2272 calRe_ += m * std::cos(calW_ * i);
2277 if (calI_ < calN_)
return;
2278 const double fund = 2.0 * std::sqrt(calRe_ * calRe_ + calIm_ * calIm_)
2279 / std::max(1, calMeas_);
2288 const double link = fourLevel_ && calRun_.drive > 1.0 ? kFourLevelDriveLink : kDriveLink;
2289 mScale_ = ((fund > 0.0) ? calRun_.calAmp / fund : 1.0) * std::pow(calRun_.drive, link);
2290 hScale_ = calRun_.hScale;
2291 biasAmp_ = calRun_.biasAmp;
2295 calRestart_ =
false;
2307 [[nodiscard]]
double nextTransportMod(
double depth)
noexcept
2312 modTo_ = transportModAhead(depth);
2314 const double share =
static_cast<double>(++modAt_) /
static_cast<double>(kTransportControl);
2315 if (modAt_ == kTransportControl) modAt_ = 0;
2316 return modFrom_ + (modTo_ - modFrom_) * share;
2319 [[nodiscard]]
double transportModAhead(
double depth)
noexcept
2323 const double dt =
static_cast<double>(kTransportControl) / sampleRate_;
2324 modPhaseWow_ += 0.55 * dt;
2325 modPhaseWow_ -= std::floor(modPhaseWow_);
2326 modPhaseFlut_ += 8.3 * dt;
2327 modPhaseFlut_ -= std::floor(modPhaseFlut_);
2328 modPhaseFlut2_ += 23.0 * dt;
2329 modPhaseFlut2_ -= std::floor(modPhaseFlut2_);
2331 rng_ = rng_ * 1664525u + 1013904223u;
2333 const double n = (
static_cast<double>(rng_ >> 8) / 8388608.0 - 1.0) * 0.25;
2336 driftState_ = driftA_ * driftState_ + (1.0 - driftA_) * n * 600.0;
2337 const double drift = std::clamp(driftState_, -18.0, 18.0);
2340 scrapeLp1_ = scrapeA1_ * scrapeLp1_ + (1.0 - scrapeA1_) * n;
2341 scrapeLp2_ = scrapeA2_ * scrapeLp2_ + (1.0 - scrapeA2_) * n;
2342 const double scrape = (scrapeLp1_ - scrapeLp2_) * 0.6;
2347 const double twoPi = 2.0 * std::numbers::pi;
2352 const double rateScale = sampleRate_ / 48000.0;
2353 const double wow = 27.8 * std::sin(
twoPi * modPhaseWow_);
2354 const double flut = 0.55 * std::sin(
twoPi * modPhaseFlut_);
2355 const double flut2 = 0.066 * std::sin(
twoPi * modPhaseFlut2_);
2357 return 0.4 * depth * rateScale * (drift + wow + flut + flut2 + scrape);
2361 static constexpr int kFirLenAt48k = 63;
2362 static constexpr double kGainRampSeconds = 0.03;
2363 static constexpr double kUniformToUnitRms = 1.7320508075688772;
2364 static constexpr int kContourSections = 4;
2365 static constexpr double kContourDb = 3.0;
2366 static constexpr double kAsymmetryShare = 0.15;
2367 static constexpr double kTransformerCornerHz = 60.0;
2368 static constexpr double kInputCouplingHz = 4.0;
2369 static constexpr double kOutputCouplingHz = 24.0;
2370 static constexpr double kIronCornerHz = 20.0;
2371 static constexpr double kUnderBiasLiftDb = 4.5;
2372 static constexpr double kUnderBiasCentreHz = 6000.0;
2373 static constexpr double kEmphasisTrimHz = 4000.0;
2374 static constexpr double kBumpHzPerIps = 6.0;
2375 static constexpr double kTransformerEven = 0.03;
2376 static constexpr double kTransformerOdd = 0.2;
2377 static constexpr double kHumNorm = 1.2649110640673518;
2380 double sampleRate_ = 48000.0;
2381 int numChannels_ = 0;
2383 std::atomic<bool> prepared_ {
false };
2386 int osRequested_ = 4;
2387 bool fourLevel_ =
true;
2389 static constexpr double kDriveLink = 0.25, kFourLevelDriveLink = 0.23;
2390 static constexpr int kStepDelay = 4;
2391 static constexpr double kExactTolerance = 1e-9, kFourLevelTolerance = 1e-6;
2392 std::vector<Stepped> stepped_;
2393 double biasNominal_ = 3.0 * 2.2e4;
2394 static constexpr double kFourLevelInternalRate = 352800.0;
2395 static constexpr double kInnerLevel = 0.2, kOuterLevel = 0.6;
2397 bool osAutomatic_ =
false;
2399 OversamplingDryPath<T> dryPath_;
2400 AudioBuffer<T> dryScratch_;
2401 detail::DryPhase dryInputLead_, dryOutputLead_, dryIronLead_;
2402 bool dryThroughFilters_ =
false;
2404 static constexpr double kAutomaticInternalRate = 176400.0;
2405 static constexpr int kCarrierPeriod = 4;
2407 std::unique_ptr<Oversampling<T>> oversampler_;
2408 std::vector<Hysteresis<T>> hysteresis_;
2409 std::vector<Hysteresis<T>> hysteresisN_;
2410 Hysteresis<T> calib_;
2411 Hysteresis<T> calib2_;
2430 static constexpr double kBiasTable[8] = {
2431 1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0
2434 std::vector<ShelfSection> recordHF_, recordLF_, playHF_, playLF_;
2435 std::vector<PeakSection> headBump_;
2436 std::vector<PeakSection> outHp_;
2437 std::vector<double> overBiasLp_;
2438 std::vector<double> overBiasX1_;
2439 std::vector<std::array<double, 4>> inputAc_;
2440 double inputAcPole_ = 0.0;
2441 std::vector<ShelfSection> recTrim_, playTrim_;
2442 std::vector<double> ironLp_;
2443 double ironA_ = 0.0;
2444 bool resting_ =
false;
2447 std::vector<T> firTaps_;
2448 std::vector<std::vector<T>> firState_;
2449 std::vector<double> cosTable_, designMags_, designTaps_;
2450 int firLen_ = kFirLenAt48k;
2451 int firCenter_ = (kFirLenAt48k - 1) / 2;
2455 std::vector<std::vector<T>> delayRing_;
2457 int delayCenter_ = 96;
2458 int delayMask_ = 255;
2459 double driftA_ = 0.0, scrapeA1_ = 0.0, scrapeA2_ = 0.0;
2460 static constexpr int kTransportControl = 16;
2461 double modFrom_ = 0.0, modTo_ = 0.0;
2463 double humCos_ = 1.0, humSin_ = 0.0, humRotCos_ = 1.0, humRotSin_ = 0.0, humStepFor_ = -1.0;
2465 std::vector<std::vector<T>> dryRing_;
2468 double hScale_ = 1.0, mScale_ = 1.0;
2470 static constexpr int kMaxAligned = 16;
2471 std::atomic<T> alignTolerance_ { T(0) };
2472 double alignFor_ = 0.0, alignHpA_ = 0.0;
2473 bool alignActive_ =
false;
2474 std::array<double, kMaxAligned> alignBias_ {}, alignShelf_ {}, alignLevel_ {}, alignHpX_ {}, alignHpY_ {};
2477 [[nodiscard]]
static double alignDraw(
int ch,
int quantity)
noexcept
2479 uint64_t x = 0x9E3779B97F4A7C15ull *
static_cast<uint64_t
>(ch * 3 + quantity + 1);
2480 x = (x ^ (x >> 30)) * 0xBF58476D1CE4E5B9ull;
2481 x = (x ^ (x >> 27)) * 0x94D049BB133111EBull;
2483 return static_cast<double>(x >> 11) * (2.0 / 9007199254740992.0) - 1.0;
2487 bool updateAlignment(
int channels)
noexcept
2489 const double tol =
static_cast<double>(alignTolerance_.load(std::memory_order_relaxed));
2490 if (tol != alignFor_)
2493 alignHpA_ = std::exp(-2.0 * 3.141592653589793 * kAlignShelfHz / sampleRate_);
2494 for (
int ch = 0; ch < kMaxAligned; ++ch)
2496 const auto c =
static_cast<size_t>(ch);
2497 alignBias_[c] = 1.0 + kAlignBias * tol * alignDraw(ch, 0);
2498 alignShelf_[c] = std::pow(10.0, kAlignShelfDb * tol * alignDraw(ch, 1) / 20.0) - 1.0;
2499 alignLevel_[c] = std::pow(10.0, kAlignLevelDb * tol * alignDraw(ch, 2) / 20.0);
2503 alignActive_ = tol > 0.0;
2504 return alignActive_;
2506 static constexpr double kAlignBias = 0.08;
2507 static constexpr double kAlignShelfDb = 0.75;
2508 static constexpr double kAlignShelfHz = 6000.0;
2509 static constexpr double kAlignLevelDb = 0.25;
2512 static constexpr int kMaxRecordPeaks = 16;
2513 static constexpr double kRecordPeakSeconds = 0.3;
2514 static constexpr double kRecordFullScale = 1.2 * 2.2e4;
2515 std::vector<double> recordHeld_;
2516 double recordFall_ = 0.9999;
2517 std::array<std::atomic<T>, kMaxRecordPeaks> recordPeak_ {};
2518 double biasAmp_ = 3.0 * 2.2e4;
2519 double hSm_ = 1.0, mSm_ = 1.0, bSm_ = 3.0 * 2.2e4;
2520 bool overBiasOn_ =
false;
2521 bool overBiasActive_ =
false;
2522 double obB0_ = 1.0, obB1_ = 0.0, obP_ = 0.0;
2524 struct CalibrationRequest
2526 double hScale = 1.0, biasAmp = 3.0 * 2.2e4, biasNominal = 3.0 * 2.2e4, calAmp = 0.25, drive = 1.0;
2527 FormulationParams form { 3.5e5, 2.2e4, 1.6e-3, 2.7e4, 0.17, 0.0 };
2529 CalibrationRequest calReq_, calRun_;
2530 bool calActive_ =
false, calRestart_ =
false;
2531 int calN_ = 0, calFrom_ = 0, calI_ = 0, calMeas_ = 0;
2532 double calW_ = 0.0, calRe_ = 0.0, calIm_ = 0.0;
2535 double modPhaseWow_ = 0.0, modPhaseFlut_ = 0.0, modPhaseFlut2_ = 0.0;
2536 double driftState_ = 0.0, scrapeLp1_ = 0.0, scrapeLp2_ = 0.0;
2537 uint32_t rng_ = 0x1357feedu;
2538 uint32_t rngNoise_ = 0x2468beefu;
2540 std::atomic<T> driveDb_ { T(0) };
2541 std::atomic<T> bias_ { T(0.5) };
2542 std::atomic<int> speed_ {
static_cast<int>(
Speed::IPS_15) };
2543 std::atomic<int> standard_ {
static_cast<int>(
Standard::NAB) };
2544 std::atomic<T> loss_ { T(0.5) };
2545 std::atomic<T> headBumpAmt_ { T(0.5) };
2546 std::atomic<T> wowFlutter_ { T(0.15) };
2547 std::atomic<T> noiseDb_ { T(-200) };
2548 std::atomic<T> mix_ { T(1) };
2549 T currentMix_ = T(1);
2550 T mixMaxStep_ = T(1.0 / 960.0);
2551 std::atomic<bool> dirty_ {
true };
2554 std::atomic<int> transport_ { 0 }, mains_ { 0 }, headModel_ { 0 }, electronics_ { 0 };
2555 std::atomic<int> formulation_ { 0 }, trackFormat_ { 0 }, monitor_ { 0 };
2556 std::atomic<T> humDb_ { T(-200) }, channelBleedDb_ { T(-200) }, evenHarmonics_ { T(0) }, outputIron_ { T(0) };
2557 std::atomic<T> alignHf_ { T(0) }, alignLf_ { T(0) }, calLevel_ { T(0) }, recordEmphasis_ { T(0) };
2560 bool speedTransportActive_ =
false, circuitActive_ =
false, contourActive_ =
false, hissNormDirty_ =
true;
2561 int formApplied_ = -1;
2562 double speedIps_ = 0.0, lastMod_ = 0.0;
2563 TapeTransport<T> tapeTransport_;
2564 double hissNorm_ = 1.0, firNorm_ = 1.0, xtNorm_ = 1.0;
2565 double asymMeanA_ = 0.0, trMeanA_ = 0.0;
2566 LinearRamp hiss_, hum_, xt_, tr_, asym_, monitorRamp_ { 1.0, 1.0, 0.0 };
2567 std::vector<double> wet_, asymMean_, trMean_;
2568 std::vector<ShelfSection> hissHF_, hissLF_, xtHp_, trPre_, trPost_;
2569 std::vector<std::array<PeakSection, kContourSections>> headContour_;
2570 std::vector<std::array<NormalizedLadder<double, 1>, 2>> recNet_, playNet_;