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
This commit is contained in:
+10
-14
@@ -2,26 +2,22 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <complex>
|
||||
|
||||
struct Peak {
|
||||
size_t bin;
|
||||
float freq;
|
||||
float magnitude;
|
||||
float reduction;
|
||||
};
|
||||
#include <vector>
|
||||
|
||||
class Detector {
|
||||
public:
|
||||
Detector();
|
||||
Detector(size_t nfft, float sample_rate);
|
||||
void setParams(float sharpness, float selectivity, float depth);
|
||||
size_t detectPeaks(const std::complex<double>* spectrum, size_t n,
|
||||
float sample_rate, Peak* peaks, size_t max_peaks);
|
||||
|
||||
void processFrame(const std::complex<double>* spectrum, float* mask);
|
||||
|
||||
private:
|
||||
size_t nfft_;
|
||||
float sample_rate_;
|
||||
float sharpness_;
|
||||
float selectivity_;
|
||||
float depth_;
|
||||
|
||||
float computeReduction(float magnitude, float freq);
|
||||
};
|
||||
|
||||
std::vector<float> envelope_;
|
||||
std::vector<float> prev_mask_;
|
||||
std::vector<float> smooth_buf_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user