shithub: ft²

Download patch

ref: 92084cd0d35baae2154e9d8ea64dd50cf6152dd4
parent: 62bbc39e91d7f624ecf806d8b1b462c28ba206d5
author: Olav Sørensen <olav.sorensen@live.no>
date: Sat Apr 13 10:57:54 EDT 2024

More HPC timer edits

--- a/src/ft2_hpc.c
+++ b/src/ft2_hpc.c
@@ -2,7 +2,7 @@
 ** Hardware Performance Counter delay routines by 8bitbubsy.
 **
 ** These are by no means well written, and are made for specific
-** usage cases. There may be soome hackish design choices here.
+** usage cases. There may be some hackish design choices here.
 **
 ** NOTE: hpc_SetDurationInHz() has quite a bit of overhead, so it's
 **       recommended to have one hpcFreq_t counter for each delay value,
@@ -100,15 +100,15 @@
 	return ((uint64_t)resultHi << 32) | resultLo;
 }
 
-void hpc_SetDurationInHz(hpc_t *hpc, double dHz) // dHz = max 8191.999inf Hz (0.12ms)
+void hpc_SetDurationInHz(hpc_t *hpc, double dHz) // dHz = max 4095.999inf Hz (0.24ms)
 {
 #define BITS_IN_UINT32 32
 
-	/* 19 = Good compensation between fraction bits and max integer size.
-	** Non-realtime OSes probably can't do a thread delay with such a
-	** high precision (0.12ms) anyway.
+	/* 20 = Good compensation between fraction bits and max integer size.
+	** Most non-realtime OSes probably can't do a thread delay with such a
+	** high precision ( 0.24ms, 1000/(2^(32-20)-1) ) anyway.
 	*/
-#define INPUT_FRAC_BITS 19
+#define INPUT_FRAC_BITS 20
 #define INPUT_FRAC_SCALE (1UL << INPUT_FRAC_BITS)
 #define INPUT_INT_MAX ((1UL << (BITS_IN_UINT32-INPUT_FRAC_BITS))-1)
 
@@ -125,7 +125,7 @@
 	hpc->resetFrame = ((uint64_t)fpHz * (60 * 30)) / INPUT_FRAC_SCALE; // reset counters every half an hour
 }
 
-void hpc_SetDurationInMs(hpc_t *hpc, double dMs) // dMs = minimum 0.12208521548 ms
+void hpc_SetDurationInMs(hpc_t *hpc, double dMs) // dMs = minimum 0.2442002442 ms
 {
 	hpc_SetDurationInHz(hpc, 1000.0 / dMs);
 }
--- a/src/ft2_hpc.h
+++ b/src/ft2_hpc.h
@@ -20,8 +20,8 @@
 extern hpcFreq_t hpcFreq;
 
 void hpc_Init(void);
-void hpc_SetDurationInHz(hpc_t *hpc, double dHz); // dHz = max 8191.999inf Hz (0.12ms)
-void hpc_SetDurationInMs(hpc_t *hpc, double dMs); // dMs = minimum 0.12208521548 ms
+void hpc_SetDurationInHz(hpc_t *hpc, double dHz); // dHz = max 4095.999inf Hz (0.24ms)
+void hpc_SetDurationInMs(hpc_t *hpc, double dMs); // dMs = minimum 0.2442002442 ms
 void hpc_ResetCounters(hpc_t *hpc);
 void hpc_Wait(hpc_t *hpc);