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:
parent
c831031ba4
commit
449a09b09e
1 changed files with 10 additions and 19 deletions
|
@ -75,13 +75,7 @@ static void MixSounds(float *stream, unsigned int frames_total)
|
||||||
{
|
{
|
||||||
float *steam_pointer = stream;
|
float *steam_pointer = stream;
|
||||||
|
|
||||||
unsigned int frames_done = 0;
|
for (unsigned int frames_done = 0; frames_done < frames_total; ++frames_done)
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
// Get two samples, and normalise them to 0-1
|
// Get two samples, and normalise them to 0-1
|
||||||
const float sample1 = (sound->samples[(size_t)sound->position] - 128.0f) / 128.0f;
|
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;
|
*steam_pointer++ += interpolated_sample * sound->volume_r;
|
||||||
|
|
||||||
sound->position += sound->advance_delta;
|
sound->position += sound->advance_delta;
|
||||||
}
|
|
||||||
|
|
||||||
if ((size_t)sound->position >= sound->frames)
|
if (sound->position >= sound->frames)
|
||||||
{
|
{
|
||||||
if (sound->looping)
|
if (sound->looping)
|
||||||
{
|
{
|
||||||
|
@ -109,8 +102,6 @@ static void MixSounds(float *stream, unsigned int frames_total)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
frames_done += frames_to_do;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue