Util: Change mInterpolator data API

This commit is contained in:
Vicki Pfau 2024-04-12 23:17:07 -07:00
parent e8c6613b12
commit b62ae33f38
2 changed files with 6 additions and 10 deletions

View File

@ -8,14 +8,12 @@
#include <mgba-util/common.h> #include <mgba-util/common.h>
struct mSampleBuffer { struct mInterpData {
int16_t* data; int16_t (*at)(const void* mInterpData, size_t index);
size_t samples;
int channels;
}; };
struct mInterpolator { struct mInterpolator {
int16_t (*interpolate)(const struct mInterpolator* interp, const struct mSampleBuffer* data, double time, double sampleStep); int16_t (*interpolate)(const struct mInterpolator* interp, const struct mInterpData* data, double time, double sampleStep);
}; };
struct mInterpolatorSinc { struct mInterpolatorSinc {

View File

@ -10,7 +10,7 @@ enum {
mSINC_WIDTH = 8, mSINC_WIDTH = 8,
}; };
static int16_t mInterpolatorSincInterpolate(const struct mInterpolator*, const struct mSampleBuffer* data, double time, double sampleStep); static int16_t mInterpolatorSincInterpolate(const struct mInterpolator*, const struct mInterpData*, double time, double sampleStep);
void mInterpolatorSincInit(struct mInterpolatorSinc* interp, unsigned resolution, unsigned width) { void mInterpolatorSincInit(struct mInterpolatorSinc* interp, unsigned resolution, unsigned width) {
interp->d.interpolate = mInterpolatorSincInterpolate; interp->d.interpolate = mInterpolatorSincInterpolate;
@ -46,7 +46,7 @@ void mInterpolatorSincDeinit(struct mInterpolatorSinc* interp) {
free(interp->windowLut); free(interp->windowLut);
} }
int16_t mInterpolatorSincInterpolate(const struct mInterpolator* interpolator, const struct mSampleBuffer* data, double time, double sampleStep) { int16_t mInterpolatorSincInterpolate(const struct mInterpolator* interpolator, const struct mInterpData* data, double time, double sampleStep) {
struct mInterpolatorSinc* interp = (struct mInterpolatorSinc*) interpolator; struct mInterpolatorSinc* interp = (struct mInterpolatorSinc*) interpolator;
ssize_t index = (ssize_t) time; ssize_t index = (ssize_t) time;
double subsample = time - floor(time); double subsample = time - floor(time);
@ -75,9 +75,7 @@ int16_t mInterpolatorSincInterpolate(const struct mInterpolator* interpolator, c
kernel = interp->sincLut[sinc] * interp->windowLut[window]; kernel = interp->sincLut[sinc] * interp->windowLut[window];
kernelSum += kernel; kernelSum += kernel;
if (index + i >= 0 && index + i < (ssize_t) data->samples) { sum += data->at(data, index + i) * kernel;
sum += data->data[(index + i) * data->channels] * kernel;
}
} }
return sum / kernelSum; return sum / kernelSum;
} }