annotate dsp/rateconversion/Resampler.h @ 362:3953f3ef1b62

First cut at resampler (not quite correct)
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 11 Oct 2013 18:00:51 +0100
parents
children e89d489af128
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@362 34 private:
c@362 35 int m_sourceRate;
c@362 36 int m_targetRate;
c@362 37 int m_gcd;
c@362 38 int m_filterLength;
c@362 39 int m_bufferLength;
c@362 40 int m_latency;
c@362 41
c@362 42 struct Phase {
c@362 43 int nextPhase;
c@362 44 std::vector<double> filter;
c@362 45 int drop;
c@362 46 int take;
c@362 47 };
c@362 48
c@362 49 Phase *m_phaseData;
c@362 50 int m_phase;
c@362 51 double *m_buffer;
c@362 52
c@362 53 void initialise();
c@362 54 double reconstructOne(const double **);
c@362 55 };
c@362 56
c@362 57 #endif
c@362 58