44 |
class RTMathBase { |
class RTMathBase { |
45 |
public: |
public: |
46 |
/** |
/** |
47 |
* Highly accurate time stamp. |
* High resolution time stamp. |
48 |
*/ |
*/ |
49 |
typedef uint32_t time_stamp_t; |
typedef uint32_t time_stamp_t; |
50 |
|
|
51 |
|
typedef uint64_t usecs_t; |
52 |
|
|
53 |
/** |
/** |
54 |
* We read the processor's cycle count register as a reference |
* We read the processor's cycle count register as a reference |
55 |
* for the real time. These are of course only abstract values |
* for the real time. These are of course only abstract values |
56 |
* with arbitrary time entity, but that's not a problem as long |
* with arbitrary time entity, but that's not a problem as long |
57 |
* as we calculate relatively. |
* as we calculate relatively. |
58 |
|
* |
59 |
|
* @see unsafeMicroSeconds() |
60 |
*/ |
*/ |
61 |
static time_stamp_t CreateTimeStamp(); |
static time_stamp_t CreateTimeStamp(); |
62 |
|
|
127 |
return current + (sample - current) / float(n); |
return current + (sample - current) / float(n); |
128 |
} |
} |
129 |
|
|
130 |
|
/** |
131 |
|
* Clock source to use for getting the current time. |
132 |
|
*/ |
133 |
|
enum clock_source_t { |
134 |
|
real_clock, ///< Use this to measure time that passed in reality (no matter if process got suspended). |
135 |
|
process_clock, ///< Use this to measure only the CPU execution time of the current process (if the process got suspended, the clock is paused as well). |
136 |
|
thread_clock, ///< Use this to measure only the CPU execution time of the current thread (if the process got suspended or another thread is executed, the clock is paused as well). |
137 |
|
}; |
138 |
|
|
139 |
|
/** |
140 |
|
* Returns a time stamp of the current time in microseconds (in |
141 |
|
* probably real-time @b unsafe way). There is no guarantee about |
142 |
|
* what the returned amount of microseconds relates to (i.e. |
143 |
|
* microseconds since epoch, microseconds since system uptime, ...). |
144 |
|
* So you should only use it to calculate time differences between |
145 |
|
* values taken with this method. |
146 |
|
* |
147 |
|
* @b CAUTION: This method may not @b NOT be real-time safe! On some |
148 |
|
* systems it could be RT safe, but there is no guarantee whatsoever! |
149 |
|
* So this method should only be used for debugging, benchmarking and |
150 |
|
* other developing purposes ! |
151 |
|
* |
152 |
|
* For creating time stamps in real-time context, use |
153 |
|
* CreateTimeStamp() instead. |
154 |
|
* |
155 |
|
* @param source - the actual clock to use for getting the current |
156 |
|
* time, note that the various clock sources may not |
157 |
|
* be implemented on all systems |
158 |
|
* @returns time stamp in microseconds |
159 |
|
* |
160 |
|
* @see CreateTimeStamp() |
161 |
|
*/ |
162 |
|
static usecs_t unsafeMicroSeconds(clock_source_t source); |
163 |
|
|
164 |
private: |
private: |
165 |
static float* pCentsToFreqTable; |
static float* pCentsToFreqTable; |
166 |
|
|