23 |
|
|
24 |
#include "RTMath.h" |
#include "RTMath.h" |
25 |
|
|
26 |
|
// for unsafeMicroSeconds() implementation |
27 |
|
#if !defined(WIN32) && !defined(__APPLE__) |
28 |
|
# include <time.h> |
29 |
|
#endif |
30 |
|
|
31 |
static float CentsToFreqTable[CONFIG_MAX_PITCH * 1200 * 2 + 1]; // +-1200 cents per octave |
static float CentsToFreqTable[CONFIG_MAX_PITCH * 1200 * 2 + 1]; // +-1200 cents per octave |
32 |
|
|
33 |
float* RTMathBase::pCentsToFreqTable(InitCentsToFreqTable()); |
float* RTMathBase::pCentsToFreqTable(InitCentsToFreqTable()); |
82 |
#endif |
#endif |
83 |
} |
} |
84 |
|
|
85 |
|
RTMathBase::usecs_t RTMathBase::unsafeMicroSeconds(clock_source_t source) { |
86 |
|
#if defined(WIN32) |
87 |
|
LARGE_INTEGER t; |
88 |
|
LARGE_INTEGER f; |
89 |
|
QueryPerformanceCounter(&t); |
90 |
|
if (!QueryPerformanceFrequency(&f)) return 0; |
91 |
|
return usecs_t( double(t) / double(f) * 1000000.0 ); |
92 |
|
#elif defined(__APPLE__) |
93 |
|
static mach_timebase_info_data_t tb; |
94 |
|
double t = mach_absolute_time(); |
95 |
|
// if this method is run for the first time, get the internal time base |
96 |
|
if (!tb.denom) mach_timebase_info(&tb); // get nanoseconds per tick |
97 |
|
// convert from internal (abstract) time value to microseconds |
98 |
|
return usecs_t( t * double(tb.numer) / double(tb.denom) / 1000.0 ); |
99 |
|
#else |
100 |
|
timespec t; |
101 |
|
clockid_t cid; |
102 |
|
switch (source) { |
103 |
|
case process_clock: cid = CLOCK_PROCESS_CPUTIME_ID; break; |
104 |
|
case thread_clock: cid = CLOCK_THREAD_CPUTIME_ID; break; |
105 |
|
case real_clock: cid = CLOCK_MONOTONIC; break; |
106 |
|
default: return 0; |
107 |
|
} |
108 |
|
clock_gettime(cid, &t); |
109 |
|
return usecs_t( (double(t.tv_sec) * 1000000000.0 + double(t.tv_nsec)) / 1000.0 ); |
110 |
|
#endif |
111 |
|
} |
112 |
|
|
113 |
/** |
/** |
114 |
* Will automatically be called once to initialize the 'Cents to frequency |
* Will automatically be called once to initialize the 'Cents to frequency |
115 |
* ratio' table. |
* ratio' table. |