commit ba3a1b37c6c1156fd956d440438b7b358e26d859 parent cb084e38651060eec6062825c98a446bc47a6b68 Author: Olav Sørensen <olav.sorensen@live.no> Date: Mon, 9 Oct 2023 18:13:51 +0200 Update ft2_load_stk.c Diffstat:
M | src/modloaders/ft2_load_stk.c | | | 9 | ++++++--- |
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/modloaders/ft2_load_stk.c b/src/modloaders/ft2_load_stk.c @@ -92,12 +92,15 @@ bool loadSTK(FILE *f, uint32_t filesize) 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);