24 |
#define __LS_EVENT_H__ |
#define __LS_EVENT_H__ |
25 |
|
|
26 |
#include "../../common/global.h" |
#include "../../common/global.h" |
27 |
|
#include "../../common/RTMath.h" |
28 |
|
|
29 |
namespace LinuxSampler { |
namespace LinuxSampler { |
30 |
|
|
41 |
void UpdateFragmentTime(uint SamplesToProcess); |
void UpdateFragmentTime(uint SamplesToProcess); |
42 |
Event CreateEvent(); |
Event CreateEvent(); |
43 |
protected: |
protected: |
44 |
typedef uint32_t time_stamp_t; ///< We read the processor's cycle count register as a reference for the real time. These are of course only abstract values with arbitrary time entity, but that's not a problem as we calculate relatively. |
typedef RTMath::time_stamp_t time_stamp_t; |
45 |
inline uint ToFragmentPos(time_stamp_t TimeStamp) { |
inline int32_t ToFragmentPos(time_stamp_t TimeStamp) { |
46 |
return uint ((TimeStamp - FragmentTime.begin) * FragmentTime.sample_ratio); |
return int32_t (int32_t(TimeStamp - FragmentTime.begin) * FragmentTime.sample_ratio); |
47 |
} |
} |
48 |
friend class Event; |
friend class Event; |
49 |
private: |
private: |
54 |
time_stamp_t end; ///< Real time stamp of the end of this audio fragment cycle. |
time_stamp_t end; ///< Real time stamp of the end of this audio fragment cycle. |
55 |
float sample_ratio; ///< (Samples per cycle) / (Real time duration of cycle) |
float sample_ratio; ///< (Samples per cycle) / (Real time duration of cycle) |
56 |
} FragmentTime; |
} FragmentTime; |
|
time_stamp_t CreateTimeStamp(); |
|
57 |
}; |
}; |
58 |
|
|
59 |
/** |
/** |
105 |
} Sysex; |
} Sysex; |
106 |
} Param; |
} Param; |
107 |
|
|
108 |
inline uint FragmentPos() { |
inline int32_t FragmentPos() { |
109 |
if (iFragmentPos >= 0) return (uint) iFragmentPos; |
if (iFragmentPos >= 0) return iFragmentPos; |
110 |
return (uint) (iFragmentPos = pEventGenerator->ToFragmentPos(TimeStamp)); |
iFragmentPos = pEventGenerator->ToFragmentPos(TimeStamp); |
111 |
|
if (iFragmentPos < 0) iFragmentPos = 0; // if event arrived shortly before the beginning of current fragment |
112 |
|
return iFragmentPos; |
113 |
|
} |
114 |
|
inline void ResetFragmentPos() { |
115 |
|
iFragmentPos = -1; |
116 |
} |
} |
117 |
protected: |
protected: |
118 |
typedef EventGenerator::time_stamp_t time_stamp_t; |
typedef EventGenerator::time_stamp_t time_stamp_t; |
121 |
private: |
private: |
122 |
EventGenerator* pEventGenerator; ///< Creator of the event. |
EventGenerator* pEventGenerator; ///< Creator of the event. |
123 |
time_stamp_t TimeStamp; ///< Time stamp of the event's occurence. |
time_stamp_t TimeStamp; ///< Time stamp of the event's occurence. |
124 |
int iFragmentPos; ///< Position in the current fragment this event refers to. |
int32_t iFragmentPos; ///< Position in the current fragment this event refers to. |
125 |
}; |
}; |
126 |
|
|
127 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |