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