Mercurial > hg > qm-dsp
diff dsp/rateconversion/Resampler.cpp @ 138:e89d489af128
Add one-shot resample function
author | Chris Cannam |
---|---|
date | Sun, 13 Oct 2013 12:47:50 +0100 |
parents | dce8337a83c8 |
children | 7fe0da91e9c3 |
line wrap: on
line diff
--- a/dsp/rateconversion/Resampler.cpp Fri Oct 11 18:00:51 2013 +0100 +++ b/dsp/rateconversion/Resampler.cpp Sun Oct 13 12:47:50 2013 +0100 @@ -7,6 +7,9 @@ #include "qm-dsp/base/SincWindow.h" #include <iostream> +#include <vector> + +using std::vector; Resampler::Resampler(int sourceRate, int targetRate) : m_sourceRate(sourceRate), @@ -145,3 +148,23 @@ return m; } +std::vector<double> +Resampler::resample(int sourceRate, int targetRate, const double *data, int n) +{ + Resampler r(sourceRate, targetRate); + + int latency = r.getLatency(); + + int m = int(ceil((n * targetRate) / sourceRate)); + int m1 = m + latency; + int n1 = int((m1 * sourceRate) / targetRate); + + vector<double> pad(n1 - n, 0.0); + vector<double> out(m1, 0.0); + + int got = r.process(data, out.data(), n); + got += r.process(pad.data(), out.data() + got, pad.size()); + + return vector<double>(out.begin() + latency, out.begin() + got); +} +