mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-20 22:16:49 +01:00
audio: Moved the resampler state up to double precision.
Fixes more buffer overflows.
This commit is contained in:
parent
b2f5123b65
commit
9bd2c6b491
@ -485,8 +485,8 @@ SDL_ResampleAudio(const int chans, const int inrate, const int outrate,
|
|||||||
float *outbuf, const int outbuflen)
|
float *outbuf, const int outbuflen)
|
||||||
{
|
{
|
||||||
const double finrate = (double) inrate;
|
const double finrate = (double) inrate;
|
||||||
const float outtimeincr = 1.0f / ((float) outrate);
|
const double outtimeincr = 1.0 / ((float) outrate);
|
||||||
const float ratio = ((float) outrate) / ((float) inrate);
|
const double ratio = ((float) outrate) / ((float) inrate);
|
||||||
const int paddinglen = ResamplerPadding(inrate, outrate);
|
const int paddinglen = ResamplerPadding(inrate, outrate);
|
||||||
const int framelen = chans * (int)sizeof (float);
|
const int framelen = chans * (int)sizeof (float);
|
||||||
const int inframes = inbuflen / framelen;
|
const int inframes = inbuflen / framelen;
|
||||||
@ -494,16 +494,16 @@ SDL_ResampleAudio(const int chans, const int inrate, const int outrate,
|
|||||||
const int maxoutframes = outbuflen / framelen;
|
const int maxoutframes = outbuflen / framelen;
|
||||||
const int outframes = SDL_min(wantedoutframes, maxoutframes);
|
const int outframes = SDL_min(wantedoutframes, maxoutframes);
|
||||||
float *dst = outbuf;
|
float *dst = outbuf;
|
||||||
float outtime = 0.0f;
|
double outtime = 0.0;
|
||||||
int i, j, chan;
|
int i, j, chan;
|
||||||
|
|
||||||
for (i = 0; i < outframes; i++) {
|
for (i = 0; i < outframes; i++) {
|
||||||
const int srcindex = (int) (outtime * inrate);
|
const int srcindex = (int) (outtime * inrate);
|
||||||
const float intime = ((float) srcindex) / finrate;
|
const double intime = ((double) srcindex) / finrate;
|
||||||
const float innexttime = ((float) (srcindex + 1)) / finrate;
|
const double innexttime = ((double) (srcindex + 1)) / finrate;
|
||||||
const float interpolation1 = SDL_max(0.0f, 1.0f - (innexttime - outtime) / (innexttime - intime));
|
const double interpolation1 = 1.0 - ((innexttime - outtime) / (innexttime - intime));
|
||||||
const int filterindex1 = (int) (interpolation1 * RESAMPLER_SAMPLES_PER_ZERO_CROSSING);
|
const int filterindex1 = (int) (interpolation1 * RESAMPLER_SAMPLES_PER_ZERO_CROSSING);
|
||||||
const float interpolation2 = SDL_max(0.0f, 1.0f - interpolation1);
|
const double interpolation2 = 1.0 - interpolation1;
|
||||||
const int filterindex2 = (int) (interpolation2 * RESAMPLER_SAMPLES_PER_ZERO_CROSSING);
|
const int filterindex2 = (int) (interpolation2 * RESAMPLER_SAMPLES_PER_ZERO_CROSSING);
|
||||||
|
|
||||||
for (chan = 0; chan < chans; chan++) {
|
for (chan = 0; chan < chans; chan++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user