Chris@137: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@137: Chris@137: #ifndef RESAMPLER_H Chris@137: #define RESAMPLER_H Chris@137: Chris@137: #include Chris@137: Chris@137: class Resampler Chris@137: { Chris@137: public: Chris@137: /** Chris@137: * Construct a Resampler to resample from sourceRate to Chris@137: * targetRate. Chris@137: */ Chris@137: Resampler(int sourceRate, int targetRate); Chris@137: virtual ~Resampler(); Chris@137: Chris@137: /** Chris@137: * Read n input samples from src and write resampled data to Chris@137: * dst. The return value is the number of samples written, which Chris@137: * will be no more than ceil((n * targetRate) / sourceRate). The Chris@137: * caller must ensure the dst buffer has enough space for the Chris@137: * samples returned. Chris@137: */ Chris@137: int process(const double *src, double *dst, int n); Chris@137: Chris@137: /** Chris@137: * Return the number of samples of latency at the output due by Chris@137: * the filter. (That is, the output will be delayed by this number Chris@137: * of samples relative to the input.) Chris@137: */ Chris@137: int getLatency() const { return m_latency; } Chris@137: Chris@138: /** Chris@138: * Carry out a one-off resample of a single block of n Chris@138: * samples. The output is latency-compensated. Chris@138: */ Chris@138: static std::vector resample Chris@138: (int sourceRate, int targetRate, const double *data, int n); Chris@138: Chris@137: private: Chris@137: int m_sourceRate; Chris@137: int m_targetRate; Chris@137: int m_gcd; Chris@137: int m_filterLength; Chris@137: int m_bufferLength; Chris@137: int m_latency; Chris@137: Chris@137: struct Phase { Chris@137: int nextPhase; Chris@137: std::vector filter; Chris@137: int drop; Chris@137: }; Chris@137: Chris@137: Phase *m_phaseData; Chris@137: int m_phase; Chris@139: std::vector m_buffer; Chris@137: Chris@137: void initialise(); Chris@141: double reconstructOne(); Chris@137: }; Chris@137: Chris@137: #endif Chris@137: