comparison dsp/rateconversion/Resampler.h @ 137:dce8337a83c8

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