Mercurial > hg > constant-q-cpp
diff src/dsp/Resampler.cpp @ 164:1081c73fbbe3
Various changes to make the code compatible with MSVC++ (though we don't provide projects for it yet)
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Fri, 08 Aug 2014 10:07:25 +0100 |
parents | edbec47f4a3d |
children | 5b1a1bbd6e7f |
line wrap: on
line diff
--- a/src/dsp/Resampler.cpp Thu Aug 07 19:19:21 2014 +0100 +++ b/src/dsp/Resampler.cpp Fri Aug 08 10:07:25 2014 +0100 @@ -40,8 +40,6 @@ #include <map> #include <cassert> -#include <pthread.h> - using std::vector; using std::map; using std::cerr; @@ -70,13 +68,6 @@ delete[] m_phaseData; } -// peakToPole -> length -> beta -> window -static map<double, map<int, map<double, vector<double> > > > -knownFilters; - -static pthread_mutex_t -knownFilterMutex = PTHREAD_MUTEX_INITIALIZER; - void Resampler::initialise(double snr, double bandwidth) { @@ -104,26 +95,14 @@ vector<double> filter; - pthread_mutex_lock(&knownFilterMutex); + KaiserWindow kw(params); + SincWindow sw(m_filterLength, m_peakToPole * 2); - if (knownFilters[m_peakToPole][m_filterLength].find(params.beta) == - knownFilters[m_peakToPole][m_filterLength].end()) { - - KaiserWindow kw(params); - SincWindow sw(m_filterLength, m_peakToPole * 2); - - filter = vector<double>(m_filterLength, 0.0); - for (int i = 0; i < m_filterLength; ++i) filter[i] = 1.0; - sw.cut(filter.data()); - kw.cut(filter.data()); - - knownFilters[m_peakToPole][m_filterLength][params.beta] = filter; - } - - filter = knownFilters[m_peakToPole][m_filterLength][params.beta]; + filter = vector<double>(m_filterLength, 0.0); + for (int i = 0; i < m_filterLength; ++i) filter[i] = 1.0; + sw.cut(filter.data()); + kw.cut(filter.data()); - pthread_mutex_unlock(&knownFilterMutex); - int inputSpacing = m_targetRate / m_gcd; int outputSpacing = m_sourceRate / m_gcd; @@ -315,8 +294,16 @@ assert(n + m_bufferOrigin <= (int)m_buffer.size()); - const double *const __restrict__ buf = m_buffer.data() + m_bufferOrigin; - const double *const __restrict__ filt = pd.filter.data(); +#if defined(__MSVC__) +#define R__ __restrict +#elif defined(__GNUC__) +#define R__ __restrict__ +#else +#define R__ +#endif + + const double *const R__ buf(m_buffer.data() + m_bufferOrigin); + const double *const R__ filt(pd.filter.data()); for (int i = 0; i < n; ++i) { // NB gcc can only vectorize this with -ffast-math