80 lines
2.1 KiB
C++
80 lines
2.1 KiB
C++
// src/Processor.h
|
|
|
|
#pragma once
|
|
#include <vector>
|
|
#include <deque>
|
|
#include <complex>
|
|
#include <fftw3.h>
|
|
|
|
class Processor {
|
|
public:
|
|
Processor(int frameSize, int sampleRate);
|
|
~Processor();
|
|
|
|
void setFrameSize(int size);
|
|
void setSampleRate(int rate);
|
|
void setNumBins(int n);
|
|
|
|
// DSP Effects
|
|
void setSmoothing(int historyLength);
|
|
void setExpander(float ratio, float thresholdDb);
|
|
void setHPF(float cutoffFreq);
|
|
|
|
// Cepstral Smoothing (Trig Interpolation)
|
|
void setCepstralParams(int granularity, int detail, float strength);
|
|
|
|
// Input is now double precision complex
|
|
void pushData(const std::vector<std::complex<double>>& data);
|
|
|
|
struct Spectrum {
|
|
std::vector<float> freqs;
|
|
std::vector<float> db;
|
|
std::vector<float> cepstrum; // raw cepstral coefficients (positive quefrencies)
|
|
};
|
|
|
|
Spectrum getSpectrum();
|
|
|
|
private:
|
|
int m_frameSize;
|
|
int m_sampleRate;
|
|
|
|
// FFTW Resources for Main Spectrum (Double Precision)
|
|
fftw_complex* m_in;
|
|
fftw_complex* m_out;
|
|
fftw_plan m_plan;
|
|
std::vector<double> m_window;
|
|
|
|
// FFTW Resources for Cepstral Smoothing (Double Precision)
|
|
fftw_complex* m_cep_in;
|
|
fftw_complex* m_cep_out;
|
|
fftw_plan m_cep_plan_fwd;
|
|
fftw_plan m_cep_plan_inv;
|
|
|
|
// Buffer for the current audio frame
|
|
std::vector<std::complex<double>> m_buffer;
|
|
|
|
// Mapping & Smoothing
|
|
std::vector<double> m_customBins;
|
|
std::vector<double> m_freqsConst;
|
|
|
|
// Moving Average History
|
|
std::deque<std::vector<double>> m_history;
|
|
size_t m_smoothingLength = 3;
|
|
|
|
// Expander Settings
|
|
float m_expandRatio = 1.0f;
|
|
float m_expandThreshold = -60.0f;
|
|
|
|
// HPF Settings
|
|
float m_hpfCutoff = 0.0f;
|
|
|
|
// Cepstral Settings
|
|
int m_granularity = 33;
|
|
int m_detail = 50;
|
|
float m_cepstralStrength = 0.0f;
|
|
|
|
double getInterpolatedDb(const std::vector<double>& freqs, const std::vector<double>& db, double targetFreq);
|
|
|
|
// Internal helper for the Trig Interpolation logic
|
|
std::vector<double> idealizeCurve(const std::vector<double>& magSpectrum);
|
|
}; |