Mercurial > hg > qm-dsp
comparison dsp/rateconversion/Resampler.cpp @ 374:3e5f13ac984f
Add bandwidth, snr parameters
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Fri, 18 Oct 2013 14:57:48 +0100 |
parents | 395771a6db7f |
children | 23558405a7d1 |
comparison
equal
deleted
inserted
replaced
373:395771a6db7f | 374:3e5f13ac984f |
---|---|
19 | 19 |
20 Resampler::Resampler(int sourceRate, int targetRate) : | 20 Resampler::Resampler(int sourceRate, int targetRate) : |
21 m_sourceRate(sourceRate), | 21 m_sourceRate(sourceRate), |
22 m_targetRate(targetRate) | 22 m_targetRate(targetRate) |
23 { | 23 { |
24 initialise(); | 24 initialise(100, 0.02); |
25 } | |
26 | |
27 Resampler::Resampler(int sourceRate, int targetRate, | |
28 double snr, double bandwidth) : | |
29 m_sourceRate(sourceRate), | |
30 m_targetRate(targetRate) | |
31 { | |
32 initialise(snr, bandwidth); | |
25 } | 33 } |
26 | 34 |
27 Resampler::~Resampler() | 35 Resampler::~Resampler() |
28 { | 36 { |
29 delete[] m_phaseData; | 37 delete[] m_phaseData; |
35 | 43 |
36 static Mutex | 44 static Mutex |
37 knownFilterMutex; | 45 knownFilterMutex; |
38 | 46 |
39 void | 47 void |
40 Resampler::initialise() | 48 Resampler::initialise(double snr, double bandwidth) |
41 { | 49 { |
42 int higher = std::max(m_sourceRate, m_targetRate); | 50 int higher = std::max(m_sourceRate, m_targetRate); |
43 int lower = std::min(m_sourceRate, m_targetRate); | 51 int lower = std::min(m_sourceRate, m_targetRate); |
44 | 52 |
45 m_gcd = MathUtilities::gcd(lower, higher); | 53 m_gcd = MathUtilities::gcd(lower, higher); |
46 | 54 |
47 int peakToPole = higher / m_gcd; | 55 int peakToPole = higher / m_gcd; |
48 | 56 |
49 KaiserWindow::Parameters params = | 57 KaiserWindow::Parameters params = |
50 KaiserWindow::parametersForBandwidth(100, 0.02, peakToPole); | 58 KaiserWindow::parametersForBandwidth(snr, bandwidth, peakToPole); |
51 | 59 |
52 params.length = | 60 params.length = |
53 (params.length % 2 == 0 ? params.length + 1 : params.length); | 61 (params.length % 2 == 0 ? params.length + 1 : params.length); |
54 | 62 |
55 params.length = | 63 params.length = |
267 | 275 |
268 for (int i = 0; i < n; ++i) { | 276 for (int i = 0; i < n; ++i) { |
269 // NB gcc can only vectorize this with -ffast-math | 277 // NB gcc can only vectorize this with -ffast-math |
270 v += buf[i] * filt[i]; | 278 v += buf[i] * filt[i]; |
271 } | 279 } |
280 | |
272 m_bufferOrigin += pd.drop; | 281 m_bufferOrigin += pd.drop; |
273 m_phase = pd.nextPhase; | 282 m_phase = pd.nextPhase; |
274 return v; | 283 return v; |
275 } | 284 } |
276 | 285 |