Δ-rule: wire distance-aware template-local gain (calibration blocked on ph*.npz)

- 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)
This commit is contained in:
2026-09-02 23:50:19 +03:00
parent a881ee280a
commit c85b888745
+16 -2
View File
@@ -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<double>(band.fc) / (sample_rate / 2.0) * (nbin - 1);
static thread_local std::vector<float> 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<float>(vlaw_mask(
static_cast<double>(raw_level[k2]), vlaw_alpha, vlaw_beta,
vlaw_c, delta_mark[k2] ? vlaw_delta : 0.0));
vlaw_c, delta_val));
}
frame_dbg_ctr++;
} else