annotate dsp/rateconversion/Resampler.h @ 139:7fe0da91e9c3

Save extra samples from one process to next (+ other fixes and debug out)
author Chris Cannam
date Mon, 14 Oct 2013 08:15:51 +0100
parents e89d489af128
children 54c9e0811ae7
rev   line source
Chris@137 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@137 2
Chris@137 3 #ifndef RESAMPLER_H
Chris@137 4 #define RESAMPLER_H
Chris@137 5
Chris@137 6 #include <vector>
Chris@137 7
Chris@137 8 class Resampler
Chris@137 9 {
Chris@137 10 public:
Chris@137 11 /**
Chris@137 12 * Construct a Resampler to resample from sourceRate to
Chris@137 13 * targetRate.
Chris@137 14 */
Chris@137 15 Resampler(int sourceRate, int targetRate);
Chris@137 16 virtual ~Resampler();
Chris@137 17
Chris@137 18 /**
Chris@137 19 * Read n input samples from src and write resampled data to
Chris@137 20 * dst. The return value is the number of samples written, which
Chris@137 21 * will be no more than ceil((n * targetRate) / sourceRate). The
Chris@137 22 * caller must ensure the dst buffer has enough space for the
Chris@137 23 * samples returned.
Chris@137 24 */
Chris@137 25 int process(const double *src, double *dst, int n);
Chris@137 26
Chris@137 27 /**
Chris@137 28 * Return the number of samples of latency at the output due by
Chris@137 29 * the filter. (That is, the output will be delayed by this number
Chris@137 30 * of samples relative to the input.)
Chris@137 31 */
Chris@137 32 int getLatency() const { return m_latency; }
Chris@137 33
Chris@138 34 /**
Chris@138 35 * Carry out a one-off resample of a single block of n
Chris@138 36 * samples. The output is latency-compensated.
Chris@138 37 */
Chris@138 38 static std::vector<double> resample
Chris@138 39 (int sourceRate, int targetRate, const double *data, int n);
Chris@138 40
Chris@137 41 private:
Chris@137 42 int m_sourceRate;
Chris@137 43 int m_targetRate;
Chris@137 44 int m_gcd;
Chris@137 45 int m_filterLength;
Chris@137 46 int m_bufferLength;
Chris@137 47 int m_latency;
Chris@137 48
Chris@137 49 struct Phase {
Chris@137 50 int nextPhase;
Chris@137 51 std::vector<double> filter;
Chris@137 52 int drop;
Chris@137 53 int take;
Chris@137 54 };
Chris@137 55
Chris@137 56 Phase *m_phaseData;
Chris@137 57 int m_phase;
Chris@139 58 std::vector<double> m_buffer;
Chris@137 59
Chris@137 60 void initialise();
Chris@139 61 double reconstructOne(const double *);
Chris@137 62 };
Chris@137 63
Chris@137 64 #endif
Chris@137 65