Resampler.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 /*
3  QM DSP Library
4 
5  Centre for Digital Music, Queen Mary, University of London.
6  This file by Chris Cannam.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version. See the file
12  COPYING included with this distribution for more information.
13 */
14 
15 #ifndef QM_DSP_RESAMPLER_H
16 #define QM_DSP_RESAMPLER_H
17 
18 #include <vector>
19 
30 class Resampler
31 {
32 public:
37  Resampler(int sourceRate, int targetRate);
38 
43  Resampler(int sourceRate, int targetRate,
44  double snr, double bandwidth);
45 
46  virtual ~Resampler();
47 
55  int process(const double *src, double *dst, int n);
56 
61  std::vector<double> process(const double *src, int n);
62 
68  int getLatency() const { return m_latency; }
69 
74  static std::vector<double> resample
75  (int sourceRate, int targetRate, const double *data, int n);
76 
77 private:
80  int m_gcd;
82  int m_latency;
83  double m_peakToPole;
84 
85  struct Phase {
86  int nextPhase;
87  std::vector<double> filter;
88  int drop;
89  };
90 
92  int m_phase;
93  std::vector<double> m_buffer;
95 
96  void initialise(double, double);
97  double reconstructOne();
98 };
99 
100 #endif
101 
std::vector< double > filter
Definition: Resampler.h:87
void initialise(double, double)
Definition: Resampler.cpp:60
int m_latency
Definition: Resampler.h:82
double reconstructOne()
Definition: Resampler.cpp:277
int m_phase
Definition: Resampler.h:92
Resampler resamples a stream from one integer sample rate to another (arbitrary) rate, using a kaiser-windowed sinc filter.
Definition: Resampler.h:30
int getLatency() const
Return the number of samples of latency at the output due by the filter.
Definition: Resampler.h:68
virtual ~Resampler()
Definition: Resampler.cpp:54
int m_sourceRate
Definition: Resampler.h:78
int m_filterLength
Definition: Resampler.h:81
int m_gcd
Definition: Resampler.h:80
int process(const double *src, double *dst, int n)
Read n input samples from src and write resampled data to dst.
Definition: Resampler.cpp:303
Phase * m_phaseData
Definition: Resampler.h:91
int m_bufferOrigin
Definition: Resampler.h:94
int m_targetRate
Definition: Resampler.h:79
std::vector< double > m_buffer
Definition: Resampler.h:93
Resampler(int sourceRate, int targetRate)
Construct a Resampler to resample from sourceRate to targetRate.
Definition: Resampler.cpp:36
static std::vector< double > resample(int sourceRate, int targetRate, const double *data, int n)
Carry out a one-off resample of a single block of n samples.
Definition: Resampler.cpp:346
double m_peakToPole
Definition: Resampler.h:83