From c85b888745d24bce977580daa5324320696e9427 Mon Sep 17 00:00:00 2001 From: Matiq Date: Wed, 2 Sep 2026 23:50:19 +0300 Subject: [PATCH] =?UTF-8?q?=CE=94-rule:=20wire=20distance-aware=20template?= =?UTF-8?q?-local=20gain=20(calibration=20blocked=20on=20ph*.npz)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - delta_gain(bin, kfc, nbin, dist_factor): 1 + (|bin-kfc|/nbin)*RT_DELTA_DIST — template-local (farther peaks → deeper cut), dip width const - delta_mark now stores per-bin gain (was flat 0/1); applied as dm*vlaw_delta - Default RT_DELTA_DIST=0 → identity (no regression) - Gated: bridge 1.594, structural 2.689 unchanged; unit checks PASS - Calibration of dist_factor and STATE-dependence blocked on ph*.npz capture (BLOCKMAP:285 — mask chain runs at load time, wine DR EIO) --- dsp/framed_model.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/dsp/framed_model.cpp b/dsp/framed_model.cpp index 775affa..0a714f4 100644 --- a/dsp/framed_model.cpp +++ b/dsp/framed_model.cpp @@ -54,6 +54,15 @@ static double warp_c(double f) { return 0.87 * 7.942 * x / (7.942 + x); } +// Δ second-peak: template-local gain g(dist) — farther peaks get deeper cut. +// cut(bin) += g * vlaw_delta where g = 1 + (|bin - kfc|/nbin) * RT_DELTA_DIST. +// BLOCKMAP:620 pre-combine 52a397, dip width const (24k-2), template-local (24ll). +static double delta_gain(size_t bin, size_t kfc, size_t nbin, double dist_factor) { + if (dist_factor <= 0.0) return 1.0; + double dist = std::fabs((double)bin - (double)kfc) / (double)nbin; + return 1.0 + dist * dist_factor; +} + static bool is_internal_grid(size_t nfft, float sample_rate) { return nfft == 4096 && std::abs(sample_rate - 48000.0f) < 1.0f; } @@ -240,6 +249,8 @@ static void process_band_structural( double kfc = static_cast(band.fc) / (sample_rate / 2.0) * (nbin - 1); static thread_local std::vector delta_mark; delta_mark.assign(nbin, 0.0f); + // Δ distance factor: template-local gain, env-tunable RT_DELTA_DIST (0=flat 6.92) + static const double delta_dist = getenv("RT_DELTA_DIST") ? atof(getenv("RT_DELTA_DIST")) : 0.0; for (size_t k2 = 1; k2 + 1 < nbin; k2++) { if (raw_level[k2] <= 0.25) continue; if (std::fabs((double)k2 - kfc) <= 8.0) continue; @@ -252,7 +263,8 @@ static void process_band_structural( if (!lmax) continue; for (int d = -3; d <= 3; d++) { int kk = (int)k2 + d; - if (kk >= 0 && kk < (int)nbin) delta_mark[kk] = 1.0f; + if (kk >= 0 && kk < (int)nbin) + delta_mark[kk] = std::max(delta_mark[kk], (float)delta_gain(k2, (size_t)kfc, nbin, delta_dist)); } } // VLAW parameters (configurable via env for per-group fitting) @@ -316,9 +328,11 @@ static void process_band_structural( if (delta_state) { } for (size_t k2 = 0; k2 < nbin; k2++) { + float dm = delta_mark[k2]; // 0=no delta, >0=distance-aware gain (1.0=flat) + double delta_val = (dm > 0.5f) ? (dm * vlaw_delta) : 0.0; band_level[k2] = static_cast(vlaw_mask( static_cast(raw_level[k2]), vlaw_alpha, vlaw_beta, - vlaw_c, delta_mark[k2] ? vlaw_delta : 0.0)); + vlaw_c, delta_val)); } frame_dbg_ctr++; } else