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:
parent
1cf4200051
commit
81e3259535
1 changed files with 3 additions and 3 deletions
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue