Files
soothe2-re/dsp/dsp_ctx.hpp
T

53 lines
2.2 KiB
C++

#pragma once
#include <cstddef>
#include <cstdint>
#include "tables_data.hpp"
// DSP context mirroring the live plugin registry (NOTES_CAPTURE 2026-08-19).
// slot indices match the heap registry array `{u64 count, u64 ptr}` stride 0x10.
namespace dsp_ctx {
enum RegistrySlot : uint32_t {
R_IDENTITY = 0x00, // 8193, ~1.0
R_WINDOW = 0x01, // 8193 f32 0.5->1.0 — WIN_freq (0x540658 FFT-conv window)
R_LEVELS = 0x02, // 8193, 0 -> ~0.01 (levels/curve)
R_WA = 0x03, // 8193, 0.596->0.126 = rwin_C0
R_WB = 0x04, // 8193, 0.404->0.874 = 1-[03]
R_WC = 0x05, // 8193, 0.0435->0
R_WD = 0x06, // 8193, 0.9565->~1 = 1-[05]
R_AUX = 0x07, // 8193, zeros + small negatives
R_FREQ_AXIS = 0x0d, // 2049, 0..23988Hz @48000 internal
R_LUT_KNEE = 0x0e, // 8193, 2.017->0
R_LUT_KNEE2 = 0x10, // 16384, 1.2914->0
R_FIRSTFIRE = 0x14, // 8193, first-fire IR?
R_RAMP_32768a = 0x17, // 32768, 0.9999->1
R_RAMP_32768b = 0x19, // 32768, 1.2915->1.0
};
// Internal frequency axis (registry[0d]): spacing = 48000/4096 ≈ 11.713 Hz.
constexpr float INTERNAL_SR = 48000.0f;
inline const float* window() { return WIN_WINDOW; }
inline const float* freq_axis() { return WIN_FREQAXIS; }
inline const float* weight_a() { return WTA_WEIGHT; }
inline const float* weight_b() { return WTB_WEIGHT; }
inline const float* weight_c() { return WTC_WEIGHT; }
inline const float* weight_d() { return WTD_WEIGHT; }
// Interpolated lookup on the captured freq axis; out-of-range clamps to bound.
inline float freq_at(float idx) {
const size_t n = WIN_FREQAXIS_COUNT;
if (idx <= 0.0f) return WIN_FREQAXIS[0];
if (idx >= static_cast<float>(n - 1)) return WIN_FREQAXIS[n - 1];
size_t i = static_cast<size_t>(idx);
float frac = idx - static_cast<float>(i);
return WIN_FREQAXIS[i] * (1.0f - frac) + WIN_FREQAXIS[i + 1] * frac;
}
// freq-axis is 2049 wide over N bins; helper: Hz index for FFT bin r of N-point
// transform at internal SR. Matches spacing 48000/N for N=4096.
inline float hz_of_bin(float r, float nfft) {
return r * (INTERNAL_SR / nfft);
}
} // namespace dsp_ctx