mirror of https://github.com/mgba-emu/mgba.git
Util: Change mInterpolator data API
This commit is contained in:
parent
e8c6613b12
commit
b62ae33f38
|
@ -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 {
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue