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>
struct mSampleBuffer {
int16_t* data;
size_t samples;
int channels;
struct mInterpData {
int16_t (*at)(const void* mInterpData, size_t index);
};
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 {

View File

@ -10,7 +10,7 @@ enum {
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) {
interp->d.interpolate = mInterpolatorSincInterpolate;
@ -46,7 +46,7 @@ void mInterpolatorSincDeinit(struct mInterpolatorSinc* interp) {
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;
ssize_t index = (ssize_t) 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];
kernelSum += kernel;
if (index + i >= 0 && index + i < (ssize_t) data->samples) {
sum += data->data[(index + i) * data->channels] * kernel;
}
sum += data->at(data, index + i) * kernel;
}
return sum / kernelSum;
}