Backends/Audio/SoftwareMixer: Optimized fmod(x, 1.0) to x - trunc(x)

Signed-off-by: Gabriel Ravier <gabravier@gmail.com>
This commit is contained in:
Gabriel Ravier 2020-04-05 23:04:59 +02:00
parent 1cf4200051
commit 81e3259535

View file

@ -1,6 +1,6 @@
#include "SoftwareMixer.h"
#include <math.h>
#include <cmath>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@ -154,7 +154,7 @@ ATTRIBUTE_HOT void Mixer_MixSounds(float *stream, unsigned int frames_total)
const float sample2 = (sound->samples[(size_t)sound->position + 1] - 128.0f) / 128.0f;
// Perform linear interpolation
const float interpolated_sample = sample1 + ((sample2 - sample1) * fmod(sound->position, 1.0));
const float interpolated_sample = sample1 + (sample2 - sample1) * (sound->position - std::trunc(sound->position));
*steam_pointer++ += interpolated_sample * sound->volume_l;
*steam_pointer++ += interpolated_sample * sound->volume_r;
@ -165,7 +165,7 @@ ATTRIBUTE_HOT void Mixer_MixSounds(float *stream, unsigned int frames_total)
{
if (sound->looping)
{
sound->position = fmod(sound->position, (double)sound->frames);
sound->position = std::fmod(sound->position, (double)sound->frames);
}
else
{