|
|
|
@ -35,24 +35,17 @@ namespace nqr
|
|
|
|
|
|
|
|
|
|
|
|
static inline void linear_resample(const double rate, const std::vector<float> & input, std::vector<float> & output, size_t samplesToProcess)
|
|
|
|
static inline void linear_resample(const double rate, const std::vector<float> & input, std::vector<float> & output, size_t samplesToProcess)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
float * source = const_cast<float *>(input.data());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double virtualReadIndex = 0;
|
|
|
|
double virtualReadIndex = 0;
|
|
|
|
|
|
|
|
double a, b, i, sample;
|
|
|
|
// Linear Interpolate
|
|
|
|
uint32_t n = samplesToProcess - 1;
|
|
|
|
int n = samplesToProcess - 1;
|
|
|
|
|
|
|
|
while (n--)
|
|
|
|
while (n--)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
unsigned readIndex = static_cast<unsigned>(virtualReadIndex);
|
|
|
|
uint32_t readIndex = static_cast<uint32_t>(virtualReadIndex);
|
|
|
|
double interpolationFactor = virtualReadIndex - readIndex;
|
|
|
|
i = virtualReadIndex - readIndex;
|
|
|
|
|
|
|
|
a = input[readIndex + 0];
|
|
|
|
double sample1 = source[readIndex];
|
|
|
|
b = input[readIndex + 1];
|
|
|
|
double sample2 = source[readIndex + 1];
|
|
|
|
sample = (1.0 - i) * a + i * b; // linear interpolate
|
|
|
|
|
|
|
|
|
|
|
|
double sample = (1.0 - interpolationFactor) * sample1 + interpolationFactor * sample2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output.push_back(sample);
|
|
|
|
output.push_back(sample);
|
|
|
|
|
|
|
|
|
|
|
|
virtualReadIndex += rate;
|
|
|
|
virtualReadIndex += rate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|