#include <cassert>
#include "PolyphaseResamplerStereo.h"
using namespace RESAMPLER_OUTER_NAMESPACE::resampler;
#define STEREO 2
PolyphaseResamplerStereo::PolyphaseResamplerStereo(const MultiChannelResampler::Builder &builder)
: PolyphaseResampler(builder) {
assert(builder.getChannelCount() == STEREO);
}
void PolyphaseResamplerStereo::writeFrame(const float *frame) {
if (--mCursor < 0) {
mCursor = getNumTaps() - 1;
}
float *dest = &mX[mCursor * STEREO];
const int offset = mNumTaps * STEREO;
const float left = frame[0];
const float right = frame[1];
dest[0] = left;
dest[1] = right;
dest[offset] = left;
dest[1 + offset] = right;
}
void PolyphaseResamplerStereo::readFrame(float *frame) {
float left = 0.0;
float right = 0.0;
const float *coefficients = &mCoefficients[mCoefficientCursor];
float *xFrame = &mX[mCursor * STEREO];
const int numLoops = mNumTaps >> 2; for (int i = 0; i < numLoops; i++) {
float coefficient = *coefficients++;
left += *xFrame++ * coefficient;
right += *xFrame++ * coefficient;
coefficient = *coefficients++; left += *xFrame++ * coefficient;
right += *xFrame++ * coefficient;
coefficient = *coefficients++; left += *xFrame++ * coefficient;
right += *xFrame++ * coefficient;
coefficient = *coefficients++; left += *xFrame++ * coefficient;
right += *xFrame++ * coefficient;
}
mCoefficientCursor = (mCoefficientCursor + mNumTaps) % mCoefficients.size();
frame[0] = left;
frame[1] = right;
}