BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

resample.hpp (1528B)


      1 #pragma once
      2 
      3 #include "filters/filter.hpp"
      4 #include "filters/experiments.hpp"
      5 
      6 namespace bogaudio {
      7 namespace dsp {
      8 
      9 struct Decimator {
     10 	Decimator() {}
     11 	virtual ~Decimator() {}
     12 
     13 	virtual void setParams(float sampleRate, int factor) = 0;
     14 	virtual float next(const float* buf) = 0;
     15 };
     16 
     17 struct LPFDecimator : Decimator {
     18 	int _factor;
     19 	MultipoleFilter _filter;
     20 
     21 	LPFDecimator(float sampleRate = 1000.0f, int factor = 8) {
     22 		setParams(sampleRate, factor);
     23 	}
     24 	void setParams(float sampleRate, int factor) override;
     25 	float next(const float* buf) override;
     26 };
     27 
     28 struct CICDecimator : Decimator {
     29 	typedef int64_t T;
     30 	static constexpr T scale = ((T)1) << 32;
     31 	int _stages;
     32 	T* _integrators;
     33 	T* _combs;
     34 	int _factor = 0;
     35 	float _gainCorrection;
     36 
     37 	CICDecimator(int stages = 4, int factor = 8);
     38 	virtual ~CICDecimator();
     39 
     40 	void setParams(float sampleRate, int factor) override;
     41 	float next(const float* buf) override;
     42 };
     43 
     44 struct Interpolator {
     45 	Interpolator() {}
     46 	virtual ~Interpolator() {}
     47 
     48 	virtual void setParams(float sampleRate, int factor) = 0;
     49 	virtual void next(float sample, float* buf) = 0;
     50 };
     51 
     52 struct CICInterpolator : Interpolator {
     53 	typedef int64_t T;
     54 	static constexpr T scale = ((T)1) << 32;
     55 	int _stages;
     56 	T* _integrators;
     57 	T* _combs;
     58 	T* _buffer;
     59 	int _factor = 0;
     60 	float _gainCorrection;
     61 
     62 	CICInterpolator(int stages = 4, int factor = 8);
     63 	virtual ~CICInterpolator();
     64 
     65 	void setParams(float sampleRate, int factor) override;
     66 	void next(float sample, float* buf) override;
     67 };
     68 
     69 } // namespace dsp
     70 } // namespace bogaudio