annotate dsp/rateconversion/Resampler.h @ 374:3e5f13ac984f

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