Skip to content

Commit a6c1b7b

Browse files
authored
Merge pull request #21 from pedrolcl/replace-compute_tick_conv
better portability for ticks calculation
2 parents f46c9e4 + b7cb15a commit a6c1b7b

3 files changed

Lines changed: 18 additions & 91 deletions

File tree

.github/workflows/win-msvc.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
include:
21-
- { icon: '🟪', arch: "x64", os: "windows-latest" }
21+
- { icon: '🟪', arch: "win64", os: "windows-latest" }
22+
- { icon: '🟫', arch: "win32", os: "windows-latest" }
2223
- { icon: '🟩', arch: "arm64", os: "windows-11-arm" }
2324
runs-on: ${{ matrix.os }}
2425
name: 🚧${{ matrix.icon }} msvc ${{ matrix.arch }}

arm-wt-22k/lib_src/compute_tick_conv.c

Lines changed: 0 additions & 76 deletions
This file was deleted.

arm-wt-22k/lib_src/eas_smf.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
*----------------------------------------------------------------------------
3030
*/
3131

32+
#include <stdint.h> // For uint64_t
33+
#include <limits.h> // For USHRT_MAX
34+
3235
#define LOG_TAG "Sonivox"
3336
#include "log/log.h"
3437

@@ -47,8 +50,6 @@
4750
#include "jet_data.h"
4851
#endif
4952

50-
#include "compute_tick_conv.c"
51-
5253
//3 dls: The timebase for this module is adequate to keep MIDI and
5354
//3 digital audio synchronized for only a few minutes. It should be
5455
//3 sufficient for most mobile applications. If better accuracy is
@@ -882,22 +883,23 @@ static EAS_RESULT SMF_ParseMetaEvent (S_EAS_DATA *pEASData, S_SMF_DATA *pSMFData
882883
return result;
883884
temp = (temp << 8) | c;
884885
}
885-
/* Replaced this horrible obfuscated code:
886+
// note: temp is microseconds per quarter note. if SMF tempo is 120 quarters per minute, then:
887+
// temp = 60'000'000 / 120 = 500'000 (SMF_DEFAULT_TIMEBASE)
888+
// temp will be maximum 28 bits. See also SMF_ParseHeader() and SMF_UpdateTime()
886889
{
887-
// pSMFData->tickConv = (EAS_U16) (((temp * 1024) / pSMFData->ppqn + 500) / 1000);
888-
uint64_t temp64;
889-
if (__builtin_mul_overflow(temp, 1024u, &temp64) ||
890-
pSMFData->ppqn == 0 ||
891-
(temp64 /= pSMFData->ppqn, false) ||
892-
__builtin_add_overflow(temp64, 500, &temp64) ||
893-
(temp64 /= 1000, false) ||
894-
temp64 > 65535) {
895-
pSMFData->tickConv = 65535;
890+
uint64_t temp64 = temp * 1024; // will never overflow
891+
if (pSMFData->ppqn > 0) {
892+
// see https://en.wikipedia.org/wiki/MIDI_beat_clock#Pulses_per_quarter_note
893+
temp64 /= pSMFData->ppqn; // ticks per quarter note, values typically between 24 and 960
894+
temp64 += 500;
895+
temp64 /= 1000;
896+
}
897+
if (temp64 > USHRT_MAX) {
898+
pSMFData->tickConv = 65535; // unlikely!
896899
} else {
897900
pSMFData->tickConv = (EAS_U16) temp64;
898901
}
899-
}*/
900-
pSMFData->tickConv = compute_tick_conv(temp, pSMFData->ppqn);
902+
}
901903
pSMFData->flags |= SMF_FLAGS_HAS_TEMPO;
902904
}
903905

0 commit comments

Comments
 (0)