P2.5: decode twin-mask factory (FUN_18056e3e0 = constant fill 2π/(count·SR)) + band LUT apply (FUN_180563a60: level->gain t^γ/power-law); implement in levelpath.cpp, levelpath_check ALL OK

This commit is contained in:
2026-08-20 01:23:22 +03:00
parent a49e35dc25
commit d3db772121
5 changed files with 142 additions and 24 deletions
+53
View File
@@ -0,0 +1,53 @@
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdint>
#include <vector>
#include "levelpath.hpp"
int main() {
bool ok = true;
auto chk = [&](const char* n, double got, double exp, double tol) {
bool p = std::fabs(got - exp) < tol;
ok = ok && p;
std::printf(" %-28s got=%.6f exp=%.6f (%s)\n", n, got, exp, p ? "ok" : "MISMATCH");
};
// ---- twin_mask_factory (FUN_18056e3e0): fill 2π/(count·SR) ----
{
std::vector<uint8_t> b(0x241000, 0);
*reinterpret_cast<int*>(b.data() + 0x240080) = 1024;
*reinterpret_cast<float*>(b.data() + 0x24) = 48000.0f;
twin_mask_factory(b.data(), 0, 1024);
float expect = static_cast<float>(6.283185307179586 / (1024.0 * 48000.0));
float* mask = reinterpret_cast<float*>(b.data() + 0x4198);
chk("twin_mask_factory fill", mask[0], expect, 1e-9);
chk("twin_mask_factory uniform", mask[511], expect, 1e-9);
}
// ---- band_lut_apply (FUN_180563a60): t^gamma linear curve ----
{
std::vector<uint8_t> b(0x12000, 0);
float bandcfg[8] = {0.0f, 1.0f, 0.0f, 2.0f, 0.0f, 0, 0, 0}; // A=0,B=1,gamma=2,flag=0
*reinterpret_cast<float**>(b.data() + 0x180) = bandcfg;
std::vector<float> level_gain(0x800 * 6, 0.0f);
for (int band = 0; band < 6; band++) {
*reinterpret_cast<float**>(b.data() + 0xe0 + band * 0x18) = level_gain.data() + band * 0x800;
}
double* mask = reinterpret_cast<double*>(b.data() + 0x4198);
// mask[0] = 1.0 -> dB=0 -> t=(0-0)/(1-0)=0 -> val=0^2=0
// mask[1] = 0.3162277 (=-10dB) -> t=(-10-0)/1=-10 -> clamp 0 -> 0
// mask[2] = 1.0 -> 0
for (int i = 0; i < 0x400 * 6; i++) mask[i] = 1.0;
// one bin at dB = +0.5 (mask = 10^(0.5/20) = 1.059254) -> t = 0.5 -> 0.5^2 = 0.25
mask[0] = 1.0592537251772883; // +0.5 dB
band_lut_apply(b.data());
chk("band_lut_apply level_axis[0]", level_gain[0], 0.0f, 1e-6); // bin 0 * 1/1024
chk("band_lut_apply gain[0] t^gamma", level_gain[1], 0.25f, 1e-3); // 0.5^2
// bin at index 512: level = 512/1024 = 0.5
chk("band_lut_apply level_axis[512]", level_gain[1024], 0.5f, 1e-6);
}
std::printf(ok ? "ALL OK\n" : "FAILURES\n");
return ok ? 0 : 1;
}