Files
soothe2-re/dsp/framed_model.hpp
T
Matiq ddf2ac2050 P4: lock PRNG prologue + correct constants (DAT_*=1); scale via prng_fvar30
CRITICAL fix: soothe_mem.bin is VA-linear (offset=RVA). DAT_18262b5c8/b704/b700
are INT 1 (cvtdq2ps -> 1.0), NOT the 0.4552/0.6089/0.6070 read earlier via a bad
section offset. Transcribed FUN_180529fe0 PRNG prologue into prng_fvar30():
fVar30=(int)(LUT[s+1]*LUT[s]+0.001). At live state 112 this is deterministically
1.0 over 300 frames, so scale level *= (1/2048)*440.95 is not randomized in
practice. Scale coefficient now computed structurally; t1kq unchanged -0.43 dB.
2026-08-20 16:14:50 +03:00

50 lines
2.0 KiB
C++

#pragma once
#include <cstddef>
#include <complex>
#include <vector>
struct DetectorBand {
float fc; // band center freq (Hz)
float q; // resonance Q
float sens; // XML sens (dB); internal sens_stored = sens * 2.054
float level_scale = 1.0f; // calibration: level = am * res * level_scale
};
// FramedDetector — C++ transcription of the real soothe2 mask-apply chain
// (FUN_180529fe0 mono path, 0x5408b8==0), bit-exact structure.
//
// Per band, per bin (exact decomp /tmp/consumers_out.txt:638-1111):
// 1. scale: x = level * (fVar30/0x1a0) * 0x540870 * 0x54088c
// 2. IIR1 leaky: y[i] = A1[i]*acc + B1[i]*x[i] (A1/B1 ramp attack, live tables)
// 3. IIR2 leaky: same with A2/B2 (slow release)
// 4. blend: b = freqaxis*(1-mix) + mix*0.8; mask = exp2(0.5*(mask-b))
// 5. combine: acc[band] = mask - b; mirror; += w_att*upper; += w_rel*lower; += mask
// 6. warp: mask *= 0x540768[band]; mask *= warp (dual tilt)
// 7. IIR3 leaky: twice with A3/B3
// 8. dry/wet: mask = mask*(fVar30*0x540888) + (1-fVar30)
// final = min over bands.
// PRNG (FUN_180529fe0 prologue :515-583): LCG state 0x2404e0 advances by round
// offsets; fVar30 (scale coeff) = (int)(LUT[s+1]*LUT[s]+0.001), DAT_18262b5c8/
// b704/b700 == 1 (VA-linear dump; earlier 0.4552/0.6089/0.6070 was a bad offset).
// At live state 112 this yields fVar30 == 1.0 deterministically over many frames.
class FramedDetector {
public:
FramedDetector(size_t nfft, float sample_rate);
~FramedDetector();
void setParams(const std::vector<DetectorBand>& bands);
void processFrame(const std::complex<double>* spectrum, float* mask);
private:
size_t nfft_;
float sample_rate_;
double wsum_;
int prng_state_ = 112; // 0x2404e0 (live snapshot value; advances per frame)
std::vector<DetectorBand> bands_;
std::vector<std::vector<float>> res_; // per band, per bin |2B/A|
std::vector<float> am_; // smoothed per-bin amplitude
std::vector<std::vector<float>> track_; // per band, per bin accumulator 0x5407c8
};