Files
soothe2-re/dsp/spectral.hpp
T

37 lines
972 B
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);
~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_;
double* window_;
FFTPlan plan_;
std::complex<double>* buf_;
std::complex<double>* tmp_buf_;
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);
};