Files
soothe2-re/dsp/spectral.hpp
T
Matiq 2f854cd1da spectral: vectors instead of new[]; vlaw: extract law + vlaw_check target
- spectral.cpp: window_/buf_/tmp_buf_/fir_buf_/fir_freq_ as std::vector (no
  exception-leak in ctor, destructor = default)
- framed_model.hpp: extract vlaw_cut/vlaw_mask inline (BLOCKMAP:314 softplus)
- dsp/vlaw_check.cpp: unit test for law (monotonic, zero-level, delta, ref,
  comb-neutral) — PASS
- CMake: add vlaw_check target
- Guard: corpus --compare d=+0.000, fn529fe0_check PASS, twin_check PASS
2026-09-02 23:19:34 +03:00

51 lines
1.6 KiB
C++

#pragma once
#include <cstddef>
#include <cstdint>
#include <complex>
#include <vector>
#include "fft.hpp"
#include "framed_model.hpp"
constexpr size_t DEFAULT_NFFT = 2048;
constexpr size_t DEFAULT_HOP = 512;
class SpectralProcessor {
public:
SpectralProcessor(size_t nfft = DEFAULT_NFFT, size_t hop = DEFAULT_HOP,
float sample_rate = 44100.0f);
~SpectralProcessor();
void setDetectorParams(const std::vector<DetectorBand>& bands);
void processBlock(float* in, float* out, size_t num_samples, size_t num_channels = 1);
private:
size_t nfft_;
size_t hop_;
std::vector<double> window_;
FFTPlan plan_;
std::vector<std::complex<double>> buf_;
std::vector<std::complex<double>> tmp_buf_;
std::vector<std::complex<double>> fir_buf_;
std::vector<std::complex<double>> fir_freq_;
std::vector<double> fir_window_;
std::vector<float> overlap_;
std::vector<float> mask_;
FramedDetector detector_;
size_t frame_count_;
size_t output_pos_;
void computeWindow();
void stftFrame(const float* in, std::complex<double>* out);
void istftFrame(std::complex<double>* in, float* out, float* overlap);
// FIR construction from detector mask (52b550-52b8bb pipeline):
// mask → log → sign-invert → EXP → twiddle ops → window → normalize
// Produces frequency-domain FIR kernel for complex multiply application.
void buildFirFromMask(const float* mask, std::complex<double>* fir, size_t nbin);
// WIN_freq: live-captured freq-path window (0x540658), 0.5→1.0
std::vector<float> win_freq_;
bool win_freq_loaded_ = false;
void loadWinFreq();
};