shithub: cstory

Download patch

ref: b6f8bf68ecef89da50db0896b200e3f275fc1b19
parent: 5c040608cb9d936c215ed71ea1d702d41d107ef6
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Sep 16 19:08:05 EDT 2019

Minor audio backend cleanup

--- a/src/Backends/Audio/SDL2.cpp
+++ b/src/Backends/Audio/SDL2.cpp
@@ -83,21 +83,16 @@
 
 				for (unsigned int i = 0; i < frames_to_do; ++i)
 				{
-					// Perform linear interpolation
+					// 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;
 
-					// 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
+					// Perform linear interpolation
 					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++ += interpolated_sample * sound->volume_l;
+					*steam_pointer++ += interpolated_sample * sound->volume_r;
 
-					*steam_pointer++ += sample_normalised * sound->volume_l;
-					*steam_pointer++ += sample_normalised * sound->volume_r;
-
 					sound->position += sound->advance_delta;
 				}
 
@@ -109,8 +104,8 @@
 					}
 					else
 					{
-						sound->position = 0.0;
 						sound->playing = FALSE;
+						sound->position = 0.0;
 						break;
 					}
 				}
@@ -257,7 +252,7 @@
 
 	SDL_LockAudioDevice(device_id);
 
-	if (size)
+	if (size != NULL)
 		*size = sound->frames;
 
 	return sound->samples;
--