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@374: c@374: /** c@374: * Construct a Resampler to resample from sourceRate to c@374: * targetRate, using the given filter parameters. c@374: */ c@374: Resampler(int sourceRate, int targetRate, c@374: double snr, double bandwidth); c@374: 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@363: /** c@363: * Carry out a one-off resample of a single block of n c@363: * samples. The output is latency-compensated. c@363: */ c@363: static std::vector resample c@363: (int sourceRate, int targetRate, const double *data, int n); c@363: 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: }; c@362: c@362: Phase *m_phaseData; c@362: int m_phase; c@364: std::vector m_buffer; c@370: int m_bufferOrigin; c@362: c@374: void initialise(double, double); c@366: double reconstructOne(); c@362: }; c@362: c@362: #endif c@362: