ref: ba3a1b37c6c1156fd956d440438b7b358e26d859
parent: cb084e38651060eec6062825c98a446bc47a6b68
author: Olav Sørensen <olav.sorensen@live.no>
date: Mon Oct 9 14:14:18 EDT 2023
Update ft2_load_stk.c
--- a/src/modloaders/ft2_load_stk.c
+++ b/src/modloaders/ft2_load_stk.c
@@ -92,12 +92,15 @@
if (h.CIAVal != 120) // 120 is a special case and means 50Hz (125BPM)
{
+ if (h.CIAVal > 220)
+ h.CIAVal = 220;
+
// convert UST tempo to BPM
uint16_t ciaPeriod = (240 - h.CIAVal) * 122;
- double dHz = 709379.0 / ciaPeriod;
- int32_t BPM = (int32_t)((dHz * 2.5) + 0.5);
+
+ double dHz = 709379.0 / (ciaPeriod+1); // +1, CIA triggers on underflow
- songTmp.BPM = (uint16_t)BPM;
+ songTmp.BPM = (uint16_t)((dHz * (125.0 / 50.0)) + 0.5);
}
memcpy(songTmp.name, h.name, 20);