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
This commit is contained in:
+12
-18
@@ -12,13 +12,13 @@
|
||||
SpectralProcessor::SpectralProcessor(size_t nfft, size_t hop, float sample_rate)
|
||||
: nfft_(nfft), hop_(hop), frame_count_(0), output_pos_(0),
|
||||
detector_(nfft, sample_rate) {
|
||||
window_ = new double[nfft_];
|
||||
window_.resize(nfft_);
|
||||
computeWindow();
|
||||
fft::init_plan(&plan_, static_cast<uint32_t>(std::log2(nfft_)));
|
||||
buf_ = new std::complex<double>[nfft_];
|
||||
tmp_buf_ = new std::complex<double>[nfft_];
|
||||
fir_buf_ = new std::complex<double>[nfft_];
|
||||
fir_freq_ = new std::complex<double>[nfft_];
|
||||
buf_.resize(nfft_);
|
||||
tmp_buf_.resize(nfft_);
|
||||
fir_buf_.resize(nfft_);
|
||||
fir_freq_.resize(nfft_);
|
||||
overlap_.resize(nfft_, 0.0f);
|
||||
mask_.resize(nfft_, 1.0f);
|
||||
|
||||
@@ -30,13 +30,7 @@ SpectralProcessor::SpectralProcessor(size_t nfft, size_t hop, float sample_rate)
|
||||
}
|
||||
}
|
||||
|
||||
SpectralProcessor::~SpectralProcessor() {
|
||||
delete[] window_;
|
||||
delete[] buf_;
|
||||
delete[] tmp_buf_;
|
||||
delete[] fir_buf_;
|
||||
delete[] fir_freq_;
|
||||
}
|
||||
SpectralProcessor::~SpectralProcessor() = default;
|
||||
|
||||
void SpectralProcessor::setDetectorParams(const std::vector<DetectorBand>& bands) {
|
||||
detector_.setParams(bands);
|
||||
@@ -63,8 +57,8 @@ void SpectralProcessor::stftFrame(const float* in, std::complex<double>* out) {
|
||||
}
|
||||
|
||||
void SpectralProcessor::istftFrame(std::complex<double>* in, float* out, float* overlap) {
|
||||
memcpy(tmp_buf_, in, nfft_ * sizeof(std::complex<double>));
|
||||
fft::execute_inverse(&plan_, tmp_buf_);
|
||||
memcpy(tmp_buf_.data(), in, nfft_ * sizeof(std::complex<double>));
|
||||
fft::execute_inverse(&plan_, tmp_buf_.data());
|
||||
static bool wola_computed = false;
|
||||
static float wola_norm = 1.0f;
|
||||
// RT_SYN: 0=synthesis window = analysis window (WOLA), 1=none
|
||||
@@ -279,9 +273,9 @@ void SpectralProcessor::processBlock(float* in, float* out, size_t num_samples,
|
||||
for (size_t f = 0; f < nframes; f++) {
|
||||
size_t offset = f * hop_;
|
||||
if (offset + nfft_ > num_samples) break;
|
||||
stftFrame(in + offset, buf_);
|
||||
stftFrame(in + offset, buf_.data());
|
||||
|
||||
detector_.processFrame(buf_, mask_.data());
|
||||
detector_.processFrame(buf_.data(), mask_.data());
|
||||
|
||||
if (firconv == 3) {
|
||||
// RT_FIRCONV=3 (NOTES 24k): plugin application law decoded live:
|
||||
@@ -296,7 +290,7 @@ void SpectralProcessor::processBlock(float* in, float* out, size_t num_samples,
|
||||
// RT_FIRCONV=2: Full FIR construction pipeline (52b550-52b8bb).
|
||||
// mask → reciprocal (1/mask) → window → normalize → complex multiply.
|
||||
// This replicates the plugin's FFT-conv FIR design path.
|
||||
buildFirFromMask(mask_.data(), fir_freq_, nfft_);
|
||||
buildFirFromMask(mask_.data(), fir_freq_.data(), nfft_);
|
||||
// Complex multiply FIR × audio spectrum
|
||||
for (size_t i = 0; i < nfft_; i++) {
|
||||
buf_[i] *= fir_freq_[i];
|
||||
@@ -317,6 +311,6 @@ void SpectralProcessor::processBlock(float* in, float* out, size_t num_samples,
|
||||
}
|
||||
}
|
||||
|
||||
istftFrame(buf_, out + offset, overlap_.data());
|
||||
istftFrame(buf_.data(), out + offset, overlap_.data());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user