annotate dsp/rateconversion/Resampler.h @ 149:734e5fa6f731

Add bandwidth, snr parameters
author Chris Cannam
date Fri, 18 Oct 2013 14:57:48 +0100
parents fe267879e022
children 23558405a7d1
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@149 16
Chris@149 17 /**
Chris@149 18 * Construct a Resampler to resample from sourceRate to
Chris@149 19 * targetRate, using the given filter parameters.
Chris@149 20 */
Chris@149 21 Resampler(int sourceRate, int targetRate,
Chris@149 22 double snr, double bandwidth);
Chris@149 23
Chris@137 24 virtual ~Resampler();
Chris@137 25
Chris@137 26 /**
Chris@137 27 * Read n input samples from src and write resampled data to
Chris@137 28 * dst. The return value is the number of samples written, which
Chris@137 29 * will be no more than ceil((n * targetRate) / sourceRate). The
Chris@137 30 * caller must ensure the dst buffer has enough space for the
Chris@137 31 * samples returned.
Chris@137 32 */
Chris@137 33 int process(const double *src, double *dst, int n);
Chris@137 34
Chris@137 35 /**
Chris@137 36 * Return the number of samples of latency at the output due by
Chris@137 37 * the filter. (That is, the output will be delayed by this number
Chris@137 38 * of samples relative to the input.)
Chris@137 39 */
Chris@137 40 int getLatency() const { return m_latency; }
Chris@137 41
Chris@138 42 /**
Chris@138 43 * Carry out a one-off resample of a single block of n
Chris@138 44 * samples. The output is latency-compensated.
Chris@138 45 */
Chris@138 46 static std::vector<double> resample
Chris@138 47 (int sourceRate, int targetRate, const double *data, int n);
Chris@138 48
Chris@137 49 private:
Chris@137 50 int m_sourceRate;
Chris@137 51 int m_targetRate;
Chris@137 52 int m_gcd;
Chris@137 53 int m_filterLength;
Chris@137 54 int m_bufferLength;
Chris@137 55 int m_latency;
Chris@137 56
Chris@137 57 struct Phase {
Chris@137 58 int nextPhase;
Chris@137 59 std::vector<double> filter;
Chris@137 60 int drop;
Chris@137 61 };
Chris@137 62
Chris@137 63 Phase *m_phaseData;
Chris@137 64 int m_phase;
Chris@139 65 std::vector<double> m_buffer;
Chris@145 66 int m_bufferOrigin;
Chris@137 67
Chris@149 68 void initialise(double, double);
Chris@141 69 double reconstructOne();
Chris@137 70 };
Chris@137 71
Chris@137 72 #endif
Chris@137 73