Files
soothe2-re/dsp/spectral.hpp
T
Matiq 71870129c2 dsp/: add spectral detector with envelope + peak suppression
- Detector computes smoothed spectral envelope
- Finds peaks exceeding envelope
- Creates per-bin suppression mask
- Applies mask in frequency domain before ISTFT
- Default params: sharpness=1.0, selectivity=0.5, depth=0.3

Verified: burst500.wav → output RMS reduced from 0.0678 to 0.0476
2026-08-17 15:49:48 +03:00

37 lines
969 B
C++

#pragma once
#include <cstddef>
#include <cstdint>
#include <complex>
#include <vector>
#include "fft.hpp"
#include "detect.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);
~SpectralProcessor();
void setDetectorParams(float sharpness, float selectivity, float depth);
void processBlock(float* in, float* out, size_t num_samples, size_t num_channels = 1);
private:
size_t nfft_;
size_t hop_;
double* window_;
FFTPlan plan_;
std::complex<double>* buf_;
std::complex<double>* tmp_buf_;
std::vector<float> overlap_;
std::vector<float> mask_;
Detector 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);
};