annotate dsp/rateconversion/Resampler.h @ 364:01d7da967123

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