P1.1: embed runtime-captured DSP tables (WIN_WINDOW, FREQAXIS@48k, WA/WB/WC/WD), dsp_ctx registry mirror, tables_check ALL OK

This commit is contained in:
2026-08-19 22:48:32 +03:00
parent 83af30d7c0
commit fd9b1fd001
5 changed files with 5595 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include "dsp_ctx.hpp"
#include "tables_data.hpp"
int main() {
const size_t N = 8193;
bool ok = true;
auto report = [&](const char* name, double v, double expect, double tol) {
bool p = std::fabs(v - expect) < tol;
ok = ok && p;
std::printf(" %-28s %12.6f (%s)\n", name, v, p ? "ok" : "MISMATCH");
};
std::printf("dsp_ctx tables synthetic check (from runtime capture npy)\n");
std::printf("window WIN_WINDOW[%zu]\n", WIN_WINDOW_COUNT);
report("win[0]", WIN_WINDOW[0], 0.5, 1e-6);
report("win[N-1]", WIN_WINDOW[N - 1], 1.0, 1e-6);
double mono = 0.0;
for (size_t i = 0; i < N; i++) mono += WIN_WINDOW[i];
report("win sum", mono, 0.0, 1e9);
std::printf("weights: WA[%zu] WB[%zu] WC[%zu] WD[%zu]\n",
WTA_WEIGHT_COUNT, WTB_WEIGHT_COUNT, WTC_WEIGHT_COUNT, WTD_WEIGHT_COUNT);
// Active half is bins 0..2048 (4096-point FFT half); mirror half is zeroed.
const size_t half = 2049;
report("WA active tail[2048]", WTA_WEIGHT[2048], 0.125666, 1e-4);
report("WA mirror zero", WTA_WEIGHT[4096], 0.0, 1e-9);
report("WB mirror zero", WTB_WEIGHT[8192], 0.0, 1e-9);
double m = 0.0;
for (size_t i = 0; i < half; i++) {
double err = std::fabs(WTA_WEIGHT[i] + WTB_WEIGHT[i] - 1.0);
if (err > m) m = err;
}
report("max|WA+WB-1| (0..2048)", m, 0.0, 1e-5);
m = 0.0;
for (size_t i = 0; i < half; i++) {
double err = std::fabs(WTC_WEIGHT[i] + WTD_WEIGHT[i] - 1.0);
if (err > m) m = err;
}
report("max|WC+WD-1| (0..2048)", m, 0.0, 1e-5);
report("WA[0]", WTA_WEIGHT[0], 0.596076, 1e-4);
report("WA[1024]", WTA_WEIGHT[1024], 0.168067, 1e-5);
std::printf("freq axis FREQAXIS[%zu] @48000 internal (step=48000/4098)\n", WIN_FREQAXIS_COUNT);
report("fa[0]", WIN_FREQAXIS[0], 0.0, 1e-6);
report("fa[1]-fa[0]", WIN_FREQAXIS[1] - WIN_FREQAXIS[0], 11.713, 0.01);
report("fa[N-1]", WIN_FREQAXIS[WIN_FREQAXIS_COUNT - 1], 23976.574, 0.1);
report("freq_at(50)", dsp_ctx::freq_at(50.0f), 50.0f * 11.713f, 1.0);
std::printf("dsp_ctx::hz_of_bin(1000,4096) = %.2f\n",
static_cast<double>(dsp_ctx::hz_of_bin(1000, 4096)));
std::printf(ok ? "ALL OK\n" : "FAILURES\n");
return ok ? 0 : 1;
}