Minor audio backend cleanup
This commit is contained in:
parent
5c040608cb
commit
b6f8bf68ec
1 changed files with 8 additions and 13 deletions
|
@ -83,20 +83,15 @@ static void MixSounds(float *stream, unsigned int frames_total)
|
|||
|
||||
for (unsigned int i = 0; i < frames_to_do; ++i)
|
||||
{
|
||||
// Get two samples, and normalise them to 0-1
|
||||
const float sample1 = (sound->samples[(size_t)sound->position] - 128.0f) / 128.0f;
|
||||
const float sample2 = (sound->samples[(size_t)sound->position + 1] - 128.0f) / 128.0f;
|
||||
|
||||
// Perform linear interpolation
|
||||
|
||||
// Get two samples
|
||||
const unsigned char sample1 = sound->samples[(size_t)sound->position];
|
||||
const unsigned char sample2 = sound->samples[(size_t)sound->position + 1];
|
||||
|
||||
// Interpolate
|
||||
const float interpolated_sample = sample1 + ((sample2 - sample1) * (float)fmod(sound->position, 1.0));
|
||||
|
||||
// Normalise to 0-1
|
||||
const float sample_normalised = (interpolated_sample - 128.0f) / 128.0f;
|
||||
|
||||
*steam_pointer++ += sample_normalised * sound->volume_l;
|
||||
*steam_pointer++ += sample_normalised * sound->volume_r;
|
||||
*steam_pointer++ += interpolated_sample * sound->volume_l;
|
||||
*steam_pointer++ += interpolated_sample * sound->volume_r;
|
||||
|
||||
sound->position += sound->advance_delta;
|
||||
}
|
||||
|
@ -109,8 +104,8 @@ static void MixSounds(float *stream, unsigned int frames_total)
|
|||
}
|
||||
else
|
||||
{
|
||||
sound->position = 0.0;
|
||||
sound->playing = FALSE;
|
||||
sound->position = 0.0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -257,7 +252,7 @@ unsigned char* AudioBackend_LockSound(AudioBackend_Sound *sound, size_t *size)
|
|||
|
||||
SDL_LockAudioDevice(device_id);
|
||||
|
||||
if (size)
|
||||
if (size != NULL)
|
||||
*size = sound->frames;
|
||||
|
||||
return sound->samples;
|
||||
|
|
Loading…
Add table
Reference in a new issue