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