shithub: ft²

Download patch

ref: cef9c3e7d4d76dc8a9311e49d0bcfe35ada651a9
parent: 3af99afd1fb732d735c34c02c926ca4d7ba5b061
author: Olav Sørensen <[email protected]>
date: Thu Nov 24 15:12:22 EST 2022

Remove extra mem alloc alignment (unnecessary)

--- a/src/ft2_audio.c
+++ b/src/ft2_audio.c
@@ -269,8 +269,7 @@
 	// if destination volume and current volume is the same (and we have no sample trigger), don't do ramp
 	if (fVolumeL == v->fVolumeL && fVolumeR == v->fVolumeR && !(status & IS_Trigger))
 	{
-		// there is no volume change
-		v->volumeRampLength = 0;
+		v->volumeRampLength = 0; // there is no volume change
 	}
 	else
 	{
@@ -982,41 +981,28 @@
 
 static bool setupAudioBuffers(void)
 {
-	const uint32_t sampleSize = sizeof (float);
+	audio.fMixBufferL = (float *)calloc(MAX_WAV_RENDER_SAMPLES_PER_TICK, sizeof (float));
+	audio.fMixBufferR = (float *)calloc(MAX_WAV_RENDER_SAMPLES_PER_TICK, sizeof (float));
 
-	audio.fMixBufferLUnaligned = (float *)MALLOC_PAD(MAX_WAV_RENDER_SAMPLES_PER_TICK * sampleSize, 256);
-	audio.fMixBufferRUnaligned = (float *)MALLOC_PAD(MAX_WAV_RENDER_SAMPLES_PER_TICK * sampleSize, 256);
-
-	if (audio.fMixBufferLUnaligned == NULL || audio.fMixBufferRUnaligned == NULL)
+	if (audio.fMixBufferL == NULL || audio.fMixBufferR == NULL)
 		return false;
 
-	// make aligned main pointers
-	audio.fMixBufferL = (float *)ALIGN_PTR(audio.fMixBufferLUnaligned, 256);
-	audio.fMixBufferR = (float *)ALIGN_PTR(audio.fMixBufferRUnaligned, 256);
-
-	// clear buffers
-	memset(audio.fMixBufferL, 0, MAX_WAV_RENDER_SAMPLES_PER_TICK * sampleSize);
-	memset(audio.fMixBufferR, 0, MAX_WAV_RENDER_SAMPLES_PER_TICK * sampleSize);
-
 	return true;
 }
 
 static void freeAudioBuffers(void)
 {
-	if (audio.fMixBufferLUnaligned != NULL)
+	if (audio.fMixBufferL != NULL)
 	{
-		free(audio.fMixBufferLUnaligned);
-		audio.fMixBufferLUnaligned = NULL;
+		free(audio.fMixBufferL);
+		audio.fMixBufferL = NULL;
 	}
 
-	if (audio.fMixBufferRUnaligned != NULL)
+	if (audio.fMixBufferR != NULL)
 	{
-		free(audio.fMixBufferRUnaligned);
-		audio.fMixBufferRUnaligned = NULL;
+		free(audio.fMixBufferR);
+		audio.fMixBufferR = NULL;
 	}
-
-	audio.fMixBufferL = NULL;
-	audio.fMixBufferR = NULL;
 }
 
 void updateSendAudSamplesRoutine(bool lockMixer)
--- a/src/ft2_audio.h
+++ b/src/ft2_audio.h
@@ -40,7 +40,7 @@
 	uint32_t freq, audLatencyPerfValInt, audLatencyPerfValFrac, samplesPerTick, samplesPerTickFrac, musicTimeSpeedVal;
 	uint64_t tickTime64, tickTime64Frac;
 	float fRampQuickVolMul, fRampTickMul, fRampTickMulTab[(MAX_BPM-MIN_BPM)+1];
-	float *fMixBufferL, *fMixBufferR, *fMixBufferLUnaligned, *fMixBufferRUnaligned;
+	float *fMixBufferL, *fMixBufferR;
 	double dHz2MixDeltaMul, dAudioLatencyMs;
 
 	SDL_AudioDeviceID dev;
--- a/src/ft2_header.h
+++ b/src/ft2_header.h
@@ -69,9 +69,6 @@
 // fast 32-bit -> 16-bit clamp
 #define CLAMP16(i) if ((int16_t)(i) != i) i = 0x7FFF ^ (i >> 31)
 
-#define ALIGN_PTR(p, x) (((uintptr_t)(p) + ((x)-1)) & ~((x)-1))
-#define MALLOC_PAD(size, pad) (malloc((size) + (pad)))
-
 #define SWAP16(x) \
 ( \
 	(((uint16_t)((x) & 0x00FF)) << 8) | \
--- a/src/ft2_video.c
+++ b/src/ft2_video.c
@@ -795,13 +795,11 @@
 		video.window = NULL;
 	}
 
-	if (video.frameBufferUnaligned != NULL)
+	if (video.frameBuffer != NULL)
 	{
-		free(video.frameBufferUnaligned);
-		video.frameBufferUnaligned = NULL;
+		free(video.frameBuffer);
+		video.frameBuffer = NULL;
 	}
-
-	video.frameBuffer = NULL;
 }
 
 void setWindowSizeFromConfig(bool updateRenderer)
@@ -1030,15 +1028,12 @@
 	}
 
 	// framebuffer used by SDL (for texture)
-	video.frameBufferUnaligned = (uint32_t *)MALLOC_PAD(SCREEN_W * SCREEN_H * sizeof (int32_t), 256);
-	if (video.frameBufferUnaligned == NULL)
+	video.frameBuffer = (uint32_t *)malloc(SCREEN_W * SCREEN_H * sizeof (int32_t));
+	if (video.frameBuffer == NULL)
 	{
 		showErrorMsgBox("Not enough memory!");
 		return false;
 	}
-
-	// we want an aligned pointer
-	video.frameBuffer = (uint32_t *)ALIGN_PTR(video.frameBufferUnaligned, 256);
 
 	if (!setupSprites())
 		return false;
--- a/src/ft2_video.h
+++ b/src/ft2_video.h
@@ -32,7 +32,6 @@
 	uint8_t upscaleFactor;
 	bool vsync60HzPresent, windowHidden;
 	int32_t renderX, renderY, renderW, renderH, displayW, displayH, windowW, windowH;
-	uint32_t *frameBufferUnaligned;
 	SDL_Renderer *renderer;
 	SDL_Texture *texture;
 	SDL_Surface *iconSurface;