Fix an occational invalid memory read

Stupid floating-point rounding errors. Had to undo a fancy
optimisation to avoid it.
This commit is contained in:
Clownacy 2020-01-09 09:10:24 +00:00
parent c831031ba4
commit 449a09b09e

View file

@ -75,13 +75,7 @@ static void MixSounds(float *stream, unsigned int frames_total)
{
float *steam_pointer = stream;
unsigned int frames_done = 0;
while (frames_done != frames_total)
{
const unsigned int frames_to_do = MIN((unsigned int)ceil((sound->frames - sound->position) / sound->advance_delta), frames_total - frames_done);
for (unsigned int i = 0; i < frames_to_do; ++i)
for (unsigned int frames_done = 0; frames_done < frames_total; ++frames_done)
{
// Get two samples, and normalise them to 0-1
const float sample1 = (sound->samples[(size_t)sound->position] - 128.0f) / 128.0f;
@ -94,9 +88,8 @@ static void MixSounds(float *stream, unsigned int frames_total)
*steam_pointer++ += interpolated_sample * sound->volume_r;
sound->position += sound->advance_delta;
}
if ((size_t)sound->position >= sound->frames)
if (sound->position >= sound->frames)
{
if (sound->looping)
{
@ -109,8 +102,6 @@ static void MixSounds(float *stream, unsigned int frames_total)
break;
}
}
frames_done += frames_to_do;
}
}
}