shithub: pt2-clone

Download patch

ref: 02664d922f41be9050be714cedb677bc010ae903
parent: 4e82d65435225806294ee0c51ca0fd9318eec355
author: Olav Sørensen <olav.sorensen@live.no>
date: Mon Aug 3 18:29:29 EDT 2020

Fix some small scaling mistakes (+ code cleanup)

--- a/src/pt2_audio.c
+++ b/src/pt2_audio.c
@@ -81,10 +81,7 @@
 	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;
 	audLatencyPerfValFrac = (uint32_t)dFrac;
 }
 
@@ -776,8 +773,8 @@
 	RCHighPassFilter(&filterHi, dOut, dOut);
 
 	// normalize and flip phase (A500/A1200 has an inverted audio signal)
-	dOut[0] *= (-INT16_MAX / (double)AMIGA_VOICES);
-	dOut[1] *= (-INT16_MAX / (double)AMIGA_VOICES);
+	dOut[0] *= -INT16_MAX / (double)AMIGA_VOICES;
+	dOut[1] *= -INT16_MAX / (double)AMIGA_VOICES;
 
 	// left channel - 1-bit triangular dithering (high-pass filtered)
 	dPrng = random32() * (0.5 / INT32_MAX); // -0.5..0.5
@@ -817,8 +814,8 @@
 	RCHighPassFilter(&filterHi, dOut, dOut);
 
 	// normalize and flip phase (A500/A1200 has an inverted audio signal)
-	dOut[0] *= (-INT16_MAX / (double)AMIGA_VOICES);
-	dOut[1] *= (-INT16_MAX / (double)AMIGA_VOICES);
+	dOut[0] *= -INT16_MAX / (double)AMIGA_VOICES;
+	dOut[1] *= -INT16_MAX / (double)AMIGA_VOICES;
 
 	// left channel - 1-bit triangular dithering (high-pass filtered)
 	dPrng = random32() * (0.5 / INT32_MAX); // -0.5..0.5
@@ -851,8 +848,8 @@
 	// process high-pass filter
 	RCHighPassFilter(&filterHi, dOut, dOut);
 
-	dOut[0] *= (-INT16_MAX / (double)AMIGA_VOICES);
-	dOut[1] *= (-INT16_MAX / (double)AMIGA_VOICES);
+	dOut[0] *= -INT16_MAX / (double)AMIGA_VOICES;
+	dOut[1] *= -INT16_MAX / (double)AMIGA_VOICES;
 
 	// left channel - 1-bit triangular dithering (high-pass filtered)
 	dPrng = random32() * (0.5 / INT32_MAX); // -0.5..0.5
@@ -888,8 +885,8 @@
 	// process high-pass filter
 	RCHighPassFilter(&filterHi, dOut, dOut);
 
-	dOut[0] *= (-INT16_MAX / (double)AMIGA_VOICES);
-	dOut[1] *= (-INT16_MAX / (double)AMIGA_VOICES);
+	dOut[0] *= -INT16_MAX / (double)AMIGA_VOICES;
+	dOut[1] *= -INT16_MAX / (double)AMIGA_VOICES;
 
 	// left channel - 1-bit triangular dithering (high-pass filtered)
 	dPrng = random32() * (0.5 / INT32_MAX); // -0.5..0.5
@@ -917,8 +914,8 @@
 	dOut[1] = dMixBufferR[i];
 
 	// normalize (don't flip the phase this time)
-	dOut[0] *= (INT16_MAX / (double)AMIGA_VOICES);
-	dOut[1] *= (INT16_MAX / (double)AMIGA_VOICES);
+	dOut[0] *= INT16_MAX / (double)AMIGA_VOICES;
+	dOut[1] *= INT16_MAX / (double)AMIGA_VOICES;
 
 	dOut[0] = (dOut[0] + dOut[1]) * 0.5; // mix to mono
 
@@ -1279,16 +1276,12 @@
 	{
 		const double dBpmHz = i / 2.5;
 
-		// 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-32] = ((uint64_t)timeInt << 32) | (uint32_t)dTimeFrac;
 	}
--- a/src/pt2_keyboard.c
+++ b/src/pt2_keyboard.c
@@ -3453,7 +3453,7 @@
 	}
 
 	// repeat keys at 49.92Hz (Amiga PAL) rate
-	const uint64_t keyRepeatDelta = (uint64_t)(((UINT32_MAX + 1.0) * (AMIGA_PAL_VBLANK_HZ / (double)VBLANK_HZ)) + 0.5);
+	const uint64_t keyRepeatDelta = (uint64_t)(((UINT32_MAX+1.0) * (AMIGA_PAL_VBLANK_HZ / (double)VBLANK_HZ)) + 0.5);
 
 	keyb.repeatFrac += keyRepeatDelta; // 32.32 fixed-point counter
 	if (keyb.repeatFrac > 0xFFFFFFFF)
--- a/src/pt2_main.c
+++ b/src/pt2_main.c
@@ -163,6 +163,11 @@
 #endif
 
 #ifdef _WIN32
+
+#ifndef _MSC_VER
+	SetProcessDPIAware();
+#endif
+
 	if (!SDL_HasSSE())
 	{
 		showErrorMsgBox("Your computer's processor doesn't have the SSE+SSE2 instruction set\n" \
--- a/src/pt2_scopes.c
+++ b/src/pt2_scopes.c
@@ -372,11 +372,8 @@
 	// integer part
 	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;
+	// fractional part (scaled to 0..2^32-1)
+	dFrac *= UINT32_MAX+1.0;
 	scopeTimeLenFrac = (uint32_t)dFrac;
 
 	scopeThread = SDL_CreateThread(scopeThreadFunc, NULL, NULL);
--- a/src/pt2_visuals.c
+++ b/src/pt2_visuals.c
@@ -209,11 +209,8 @@
 	// integer part
 	editor.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;
+	// fractional part (scaled to 0..2^32-1)
+	dFrac *= UINT32_MAX+1.0;
 	editor.vblankTimeLenFrac = (uint32_t)dFrac;
 }
 
@@ -2189,7 +2186,7 @@
 	// sink stuff @ 49.92Hz (Amiga PAL) rate
 
 	static uint64_t counter50Hz;
-	const uint64_t counter50HzDelta = (uint64_t)(((UINT32_MAX + 1.0) * (AMIGA_PAL_VBLANK_HZ / (double)VBLANK_HZ)) + 0.5);
+	const uint64_t counter50HzDelta = (uint64_t)(((UINT32_MAX+1.0) * (AMIGA_PAL_VBLANK_HZ / (double)VBLANK_HZ)) + 0.5);
 
 	counter50Hz += counter50HzDelta; // 32.32 fixed-point counter
 	if (counter50Hz > 0xFFFFFFFF)