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