Mercurial > hg > qm-dsp
comparison dsp/rateconversion/Resampler.cpp @ 371:33e9e964443c
Cache calculated filters
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Wed, 16 Oct 2013 13:33:36 +0100 |
parents | 50d393750cfd |
children | c1e98c18628a |
comparison
equal
deleted
inserted
replaced
370:50d393750cfd | 371:33e9e964443c |
---|---|
3 #include "Resampler.h" | 3 #include "Resampler.h" |
4 | 4 |
5 #include "qm-dsp/maths/MathUtilities.h" | 5 #include "qm-dsp/maths/MathUtilities.h" |
6 #include "qm-dsp/base/KaiserWindow.h" | 6 #include "qm-dsp/base/KaiserWindow.h" |
7 #include "qm-dsp/base/SincWindow.h" | 7 #include "qm-dsp/base/SincWindow.h" |
8 #include "qm-dsp/thread/Thread.h" | |
8 | 9 |
9 #include <iostream> | 10 #include <iostream> |
10 #include <vector> | 11 #include <vector> |
11 #include <map> | 12 #include <map> |
12 | 13 |
25 Resampler::~Resampler() | 26 Resampler::~Resampler() |
26 { | 27 { |
27 delete[] m_phaseData; | 28 delete[] m_phaseData; |
28 } | 29 } |
29 | 30 |
31 // peakToPole -> length -> beta -> window | |
32 static map<int, map<int, map<double, vector<double> > > > | |
33 knownFilters; | |
34 | |
35 static Mutex | |
36 knownFilterMutex; | |
37 | |
30 void | 38 void |
31 Resampler::initialise() | 39 Resampler::initialise() |
32 { | 40 { |
33 int higher = std::max(m_sourceRate, m_targetRate); | 41 int higher = std::max(m_sourceRate, m_targetRate); |
34 int lower = std::min(m_sourceRate, m_targetRate); | 42 int lower = std::min(m_sourceRate, m_targetRate); |
43 params.length = | 51 params.length = |
44 (params.length % 2 == 0 ? params.length + 1 : params.length); | 52 (params.length % 2 == 0 ? params.length + 1 : params.length); |
45 | 53 |
46 m_filterLength = params.length; | 54 m_filterLength = params.length; |
47 | 55 |
48 KaiserWindow kw(params); | 56 vector<double> filter; |
49 SincWindow sw(m_filterLength, peakToPole * 2); | 57 knownFilterMutex.lock(); |
50 | 58 |
51 vector<double> filter(m_filterLength, 0.0); | 59 if (knownFilters[peakToPole][m_filterLength].find(params.beta) == |
52 for (int i = 0; i < m_filterLength; ++i) filter[i] = 1.0; | 60 knownFilters[peakToPole][m_filterLength].end()) { |
53 sw.cut(filter.data()); | 61 |
54 kw.cut(filter.data()); | 62 KaiserWindow kw(params); |
63 SincWindow sw(m_filterLength, peakToPole * 2); | |
64 | |
65 filter = vector<double>(m_filterLength, 0.0); | |
66 for (int i = 0; i < m_filterLength; ++i) filter[i] = 1.0; | |
67 sw.cut(filter.data()); | |
68 kw.cut(filter.data()); | |
69 | |
70 knownFilters[peakToPole][m_filterLength][params.beta] = filter; | |
71 } | |
72 | |
73 filter = knownFilters[peakToPole][m_filterLength][params.beta]; | |
74 knownFilterMutex.unlock(); | |
55 | 75 |
56 int inputSpacing = m_targetRate / m_gcd; | 76 int inputSpacing = m_targetRate / m_gcd; |
57 int outputSpacing = m_sourceRate / m_gcd; | 77 int outputSpacing = m_sourceRate / m_gcd; |
58 | 78 |
59 #ifdef DEBUG_RESAMPLER | 79 #ifdef DEBUG_RESAMPLER |