From 11612fce272a82e52a1fbc528ee9c0c3f1b4753c Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 20 Feb 2018 10:30:51 +0100 Subject: [PATCH] Reviewed timming system for macOS Apparently, before macOS Sierra version, clock_gettime was not available, using MATCH timming system instead --- src/external/mini_al.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/external/mini_al.h b/src/external/mini_al.h index c9ab40fa1..1374de5b2 100644 --- a/src/external/mini_al.h +++ b/src/external/mini_al.h @@ -1557,6 +1557,10 @@ void mal_pcm_convert(void* pOut, mal_format formatOut, const void* pIn, mal_form #include // For memset() #endif +#if defined(MAL_APPLE) && (__MAC_OS_X_VERSION_MIN_REQUIRED < 101200) +#include // For mach_absolute_time() +#endif + #ifdef MAL_POSIX #include #include @@ -2082,6 +2086,24 @@ double mal_timer_get_time_in_seconds(mal_timer* pTimer) return (counter.QuadPart - pTimer->counter) / (double)g_mal_TimerFrequency.QuadPart; } +#elif defined(MAL_APPLE) && (__MAC_OS_X_VERSION_MIN_REQUIRED < 101200) +static uint64_t g_mal_TimerFrequency = 0; +void mal_timer_init(mal_timer* pTimer) +{ + mach_timebase_info_data_t baseTime; + mach_timebase_info(&baseTime); + g_mal_TimerFrequency = (baseTime.denom * 1e9) / baseTime.numer; + + pTimer->counter = mach_absolute_time(); +} + +double mal_timer_get_time_in_seconds(mal_timer* pTimer) +{ + uint64_t newTimeCounter = mach_absolute_time(); + uint64_t oldTimeCounter = pTimer->counter; + + return (newTimeCounter - oldTimeCounter) / g_mal_TimerFrequency; +} #else void mal_timer_init(mal_timer* pTimer) {