feat(dsp): render48k pipeline + structural chain on 48000/4096 grid
- render48k: resample 44100→48000, process via SpectralProcessor(4096,1024,48000), resample 44100, write 24-bit stereo WAV - FramedDetector: structural chain (fn529fe0 sequence) runs on 48000/4096 grid, bridge path unchanged for 44100/2048 - Structural chain: scale→IIR1→copy→IIR2→mirror→blend→exp2→combine→warp→dry/wet using live tables (kIIR_A1/B1, kIIR_A2/B2, kBand768, kWarp, kRTAtt/kRTRel) - Bridge baseline intact (0.000 dB degradation) - 48k tone test: -20.73 dB vs ref -27.23 dB (6.5 dB error, scale factor not yet calibrated to match bridge domain)
This commit is contained in:
+91
-33
@@ -3,36 +3,21 @@
|
||||
#include "freqpath.hpp"
|
||||
#include "rt_mask_tables.hpp"
|
||||
#include "rt_weights.hpp"
|
||||
#include "fn529fe0.hpp"
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
namespace {
|
||||
|
||||
// sens XML -> internal sens_stored = sens * 2.054 (NOTES_TWIN:74: XML 12 -> 24.65 dB).
|
||||
constexpr float SENS_SCALE = 2.054f;
|
||||
|
||||
// Live-captured BandConfig parameters from DSP snapshot (2026-08-20).
|
||||
// +0x180 (level LUT curve, FUN_180563a60): A = -24.0, B = +28.0, gamma = 1.0, flag = 0.
|
||||
// +0x188 (freq-range shaper, FUN_180563440): A = 16.0, B = 20000.0, gamma = 1.0, flag = 0.
|
||||
// These values are identical for both render_long.rpp and t1kq_only1_1000 configs.
|
||||
// The parametric LUT formula from FUN_180563a60 / FUN_180563440:
|
||||
// t = clamp((x - A) / (B - A), 0.0, 1.0);
|
||||
// val = A + (B - A) * t^gamma
|
||||
// With gamma=1: val = clamp(x, A, B) [linear interpolation between A and B].
|
||||
// The x input is the mask-dependent dB-scaled value (mask * 8.6859 from 0x24c43e0).
|
||||
|
||||
// ctx+0x188 A/B/gamma) evaluated at the measured (xv, C) nodes (al_* dataset +
|
||||
// B.11 anchors). Marked EMPIRICAL (all numbers from the joint dual+al_* fit,
|
||||
// honest trimmed metric); the structural parametric A/B/gamma form is its
|
||||
// source (see NOTE below) but live A/B/gamma for the test configs is unset.
|
||||
constexpr double G_FIT = 0.9963;
|
||||
constexpr double W_FIT = 0.3335;
|
||||
constexpr double A_FIT = 0.9807;
|
||||
constexpr double RP0 = 0.0275; // res^rp(Q) gain term, rp = RP0·Q^drp
|
||||
constexpr double RP0 = 0.0275;
|
||||
constexpr double DRP = 0.2159;
|
||||
|
||||
// LUT knots (xv = log10(level), level = am/res):
|
||||
static constexpr double kLX[12] = { -0.75, -0.5012, -0.5, -0.2012, 0.0988, 0.2488,
|
||||
0.3988, 0.5488, 0.574, 0.61, 0.75, 1.0 };
|
||||
static constexpr double kLY[12] = { 0.4402, 0.366, 0.4552, 0.459, 0.541, 0.576,
|
||||
@@ -41,7 +26,6 @@ static constexpr double kLY[12] = { 0.4402, 0.366, 0.4552, 0.459, 0.541, 0.576,
|
||||
static double lut_pchip(double x) {
|
||||
int n = 12;
|
||||
x = std::min(std::max(x, kLX[0]), kLX[n - 1]);
|
||||
// Monotone cubic Hermite (Fritsch–Carlson), matching scipy PchipInterpolator.
|
||||
double h[12], d[12];
|
||||
for (int i = 0; i < n - 1; i++) h[i] = kLX[i + 1] - kLX[i];
|
||||
for (int i = 0; i < n - 1; i++) d[i] = (kLY[i + 1] - kLY[i]) / h[i];
|
||||
@@ -63,12 +47,74 @@ static double lut_pchip(double x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
// freq-path warp 0x5406a8 (NOTES_LEVEL:181; build_warp): 0.87·K·x/(K+x), K=exp(2.0723).
|
||||
static double warp_c(double f) {
|
||||
double x = f / 2000.0;
|
||||
return 0.87 * 7.942 * x / (7.942 + x);
|
||||
}
|
||||
|
||||
static bool is_internal_grid(size_t nfft, float sample_rate) {
|
||||
return nfft == 4096 && std::abs(sample_rate - 48000.0f) < 1.0f;
|
||||
}
|
||||
|
||||
static void process_band_structural(
|
||||
const float* am,
|
||||
const float* res,
|
||||
const DetectorBand& band,
|
||||
float* mask_out,
|
||||
size_t nfft,
|
||||
float sample_rate
|
||||
) {
|
||||
const size_t half = nfft / 2;
|
||||
const size_t nbin = half + 1;
|
||||
|
||||
static thread_local std::vector<float> band_level;
|
||||
static thread_local std::vector<float> f6f8;
|
||||
static thread_local std::vector<double> acc;
|
||||
|
||||
band_level.resize(nfft);
|
||||
f6f8.resize(nfft);
|
||||
acc.assign(nfft, 0.0);
|
||||
|
||||
constexpr float fVar30 = 1.0f;
|
||||
constexpr float scale_factor = 440.95f / 2048.0f;
|
||||
constexpr float mix = 1.0f;
|
||||
|
||||
for (size_t k = 0; k < nbin; k++) {
|
||||
double res_k = std::max(static_cast<double>(res[k]), 1e-12);
|
||||
double lvl = static_cast<double>(am[k]) / res_k * scale_factor;
|
||||
band_level[k] = static_cast<float>(lvl);
|
||||
}
|
||||
|
||||
fn529fe0::iir1(band_level.data(), kIIR_A1, kIIR_B1, nbin, 0.0);
|
||||
std::copy(band_level.begin(), band_level.begin() + nbin, f6f8.begin());
|
||||
|
||||
fn529fe0::iir1(band_level.data(), kIIR_A2, kIIR_B2, nbin, 0.0);
|
||||
|
||||
for (size_t k = 0; k < half; k++) {
|
||||
band_level[nfft - 1 - k] = band_level[k];
|
||||
}
|
||||
|
||||
for (size_t k = 0; k < nfft; k++) {
|
||||
f6f8[k] = 1.0f * (1.0f - mix) + mix * 0.8f;
|
||||
}
|
||||
|
||||
for (size_t k = 0; k < nfft; k++) {
|
||||
mask_out[k] = static_cast<float>(std::exp2(-static_cast<double>(band_level[k])) * f6f8[k]);
|
||||
}
|
||||
|
||||
fn529fe0::combine_acc(acc.data(), band_level.data(), f6f8.data(),
|
||||
kRTAtt, kRTRel, nfft);
|
||||
|
||||
for (size_t k = 0; k < nfft; k++) {
|
||||
size_t idx = (k < nbin) ? k : (nfft - 1 - k);
|
||||
mask_out[k] *= kBand768[idx] * kWarp[idx];
|
||||
}
|
||||
|
||||
for (size_t k = 0; k < nfft; k++) {
|
||||
mask_out[k] = mask_out[k] * (fVar30 * 1.0f) + (1.0f - fVar30);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
FramedDetector::FramedDetector(size_t nfft, float sample_rate)
|
||||
@@ -86,7 +132,7 @@ void FramedDetector::setParams(const std::vector<DetectorBand>& bands) {
|
||||
|
||||
for (const auto& b : bands_) {
|
||||
std::vector<float> r(half + 1, 1.0f);
|
||||
float sens_lin = std::pow(10.0f, b.sens * SENS_SCALE / 20.0f); // param_5
|
||||
float sens_lin = std::pow(10.0f, b.sens * SENS_SCALE / 20.0f);
|
||||
detkernel::twin_coeff c = detkernel::build_twin_coeff(
|
||||
static_cast<double>(sample_rate_), static_cast<double>(b.fc),
|
||||
static_cast<double>(b.q), sens_lin);
|
||||
@@ -131,21 +177,33 @@ void FramedDetector::processFrame(const std::complex<double>* spectrum, float* m
|
||||
|
||||
for (size_t k = 0; k <= half; k++) mask[k] = 1.0f;
|
||||
|
||||
for (size_t b = 0; b < bands_.size(); b++) {
|
||||
double rp = RP0 * std::pow(static_cast<double>(bands_[b].q), DRP);
|
||||
double fk = 0.0;
|
||||
double fstep = (sample_rate_ * 0.5) / static_cast<double>(half);
|
||||
for (size_t k = 0; k <= half; k++) {
|
||||
double res_k = std::max(static_cast<double>(res_[b][k]), 1e-12);
|
||||
double lvl = static_cast<double>(am_[k]) / res_k;
|
||||
double xv = std::log10(std::max(lvl, 1e-9));
|
||||
double C = G_FIT * lut_pchip(xv) + W_FIT * std::pow(warp_c(fk), A_FIT);
|
||||
double g = std::max(1.0 - C, 1e-9) * std::pow(res_k, rp);
|
||||
mask[k] = std::min(static_cast<float>(g), mask[k]);
|
||||
fk += fstep;
|
||||
if (is_internal_grid(nfft_, sample_rate_)) {
|
||||
for (size_t b = 0; b < bands_.size(); b++) {
|
||||
std::vector<float> band_mask(nfft_, 1.0f);
|
||||
process_band_structural(am_.data(), res_[b].data(), bands_[b],
|
||||
band_mask.data(), nfft_, sample_rate_);
|
||||
for (size_t k = 0; k <= half; k++) {
|
||||
mask[k] = std::min(band_mask[k], mask[k]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (size_t b = 0; b < bands_.size(); b++) {
|
||||
double rp = RP0 * std::pow(static_cast<double>(bands_[b].q), DRP);
|
||||
double fk = 0.0;
|
||||
double fstep = (sample_rate_ * 0.5) / static_cast<double>(half);
|
||||
for (size_t k = 0; k <= half; k++) {
|
||||
double res_k = std::max(static_cast<double>(res_[b][k]), 1e-12);
|
||||
double lvl = static_cast<double>(am_[k]) / res_k;
|
||||
double xv = std::log10(std::max(lvl, 1e-9));
|
||||
double C = G_FIT * lut_pchip(xv) + W_FIT * std::pow(warp_c(fk), A_FIT);
|
||||
double g = std::max(1.0 - C, 1e-9) * std::pow(res_k, rp);
|
||||
mask[k] = std::min(static_cast<float>(g), mask[k]);
|
||||
fk += fstep;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t k = half + 1; k < nfft_; k++) {
|
||||
mask[k] = mask[nfft_ - k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user