Browse Source

Reviewed timming system for macOS

Apparently, before macOS Sierra version, clock_gettime was not available, using MATCH timming system instead
pull/479/head
Ray 7 years ago
parent
commit
11612fce27
1 changed files with 22 additions and 0 deletions
  1. +22
    -0
      src/external/mini_al.h

+ 22
- 0
src/external/mini_al.h View File

@ -1557,6 +1557,10 @@ void mal_pcm_convert(void* pOut, mal_format formatOut, const void* pIn, mal_form
#include <string.h> // For memset() #include <string.h> // For memset()
#endif #endif
#if defined(MAL_APPLE) && (__MAC_OS_X_VERSION_MIN_REQUIRED < 101200)
#include <mach/mach_time.h> // For mach_absolute_time()
#endif
#ifdef MAL_POSIX #ifdef MAL_POSIX
#include <unistd.h> #include <unistd.h>
#include <dlfcn.h> #include <dlfcn.h>
@ -2082,6 +2086,24 @@ double mal_timer_get_time_in_seconds(mal_timer* pTimer)
return (counter.QuadPart - pTimer->counter) / (double)g_mal_TimerFrequency.QuadPart; 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 #else
void mal_timer_init(mal_timer* pTimer) void mal_timer_init(mal_timer* pTimer)
{ {

Loading…
Cancel
Save