shithub: ft²

Download patch

ref: 23923f12dcb6b945dc9f54f5556bd4d7278181cd
parent: 77dc3b3a6f9a1af96ee78511d5ddf485074b6157
author: Olav Sørensen <olav.sorensen@live.no>
date: Mon Aug 3 18:29:45 EDT 2020

Fix some small scaling mistakes

--- a/src/ft2_audio.c
+++ b/src/ft2_audio.c
@@ -1085,10 +1085,7 @@
 	audio.audLatencyPerfValInt = (int32_t)dInt;
 
 	// fractional part (scaled to 0..2^32-1)
-	dFrac *= UINT32_MAX;
-	dFrac += 0.5;
-	if (dFrac > UINT32_MAX)
-		dFrac = UINT32_MAX;
+	dFrac *= UINT32_MAX+1.0;
 	audio.audLatencyPerfValFrac = (uint32_t)dFrac;
 
 	audio.dAudioLatencyMs = dAudioLatencySecs * 1000.0;
--- a/src/ft2_main.c
+++ b/src/ft2_main.c
@@ -97,6 +97,11 @@
 #endif
 
 #ifdef _WIN32
+	
+#ifndef _MSC_VER
+	SetProcessDPIAware();
+#endif
+
 	if (!cpu.hasSSE)
 	{
 		showErrorMsgBox("Your computer's processor doesn't have the SSE instruction set\n" \
@@ -428,11 +433,7 @@
 	video.vblankTimeLen = (int32_t)dInt;
 
 	// fractional part scaled to 0..2^32-1
-	dFrac *= UINT32_MAX;
-	dFrac += 0.5;
-	if (dFrac > UINT32_MAX)
-		dFrac = UINT32_MAX;
-
+	dFrac *= UINT32_MAX+1.0;
 	video.vblankTimeLenFrac = (uint32_t)dFrac;
 }
 
--- a/src/ft2_replayer.c
+++ b/src/ft2_replayer.c
@@ -370,16 +370,12 @@
 
 		audio.dSpeedValTab[i] = dSamplesPerTick;
 
-		// number of samples per tick -> tick length for performance counter (syncing visuals to audio)
+		// BPM -> Hz -> tick length for performance counter (syncing visuals to audio)
 		double dTimeInt;
 		double dTimeFrac = modf(editor.dPerfFreq / dBpmHz, &dTimeInt);
 		const int32_t timeInt = (int32_t)dTimeInt;
 
-		// - fractional part (scaled to 0..2^32-1) -
-		dTimeFrac *= UINT32_MAX;
-		dTimeFrac += 0.5;
-		if (dTimeFrac > UINT32_MAX)
-			dTimeFrac = UINT32_MAX;
+		dTimeFrac *= UINT32_MAX+1.0; // fractional part (scaled to 0..2^32-1)
 
 		audio.tickTimeLengthTab[i] = ((uint64_t)timeInt << 32) | (uint32_t)dTimeFrac;
 
--- a/src/ft2_sample_ed.c
+++ b/src/ft2_sample_ed.c
@@ -10,6 +10,9 @@
 #ifndef _WIN32
 #include <unistd.h> // chdir() in UNICHAR_CHDIR()
 #endif
+#if defined __APPLE__ || defined _WIN32 || defined __amd64__ || (defined __i386__ && defined __SSE2__)
+#include <emmintrin.h>
+#endif
 #include "ft2_header.h"
 #include "ft2_config.h"
 #include "ft2_audio.h"
@@ -254,7 +257,7 @@
 	}
 }
 
-inline int16_t getSampleValue(int8_t *ptr, uint8_t typ, int32_t pos)
+int16_t getSampleValue(int8_t *ptr, uint8_t typ, int32_t pos)
 {
 	assert(pos >= 0);
 	if (ptr == NULL)
@@ -271,7 +274,7 @@
 	}
 }
 
-inline void putSampleValue(int8_t *ptr, uint8_t typ, int32_t pos, int16_t val)
+void putSampleValue(int8_t *ptr, uint8_t typ, int32_t pos, int16_t val)
 {
 	assert(pos >= 0);
 	if (ptr == NULL)
--- a/src/ft2_scopes.c
+++ b/src/ft2_scopes.c
@@ -648,11 +648,7 @@
 	scopeTimeLen = (int32_t)dInt;
 
 	// fractional part (scaled to 0..2^32-1)
-	dFrac *= UINT32_MAX;
-	dFrac += 0.5;
-	if (dFrac > UINT32_MAX)
-		dFrac = UINT32_MAX;
-
+	dFrac *= UINT32_MAX+1.0;
 	scopeTimeLenFrac = (uint32_t)dFrac;
 
 	scopeThread = SDL_CreateThread(scopeThreadFunc, NULL, NULL);