FastLED 3.9.15
Loading...
Searching...
No Matches
frame_tracker.cpp.hpp
Go to the documentation of this file.
2#include "fl/stl/int.h"
3#include "fl/math/math.h"
4
5namespace fl {
6namespace video {
7
9 // Convert fps to microseconds per frame interval
10 mMicrosSecondsPerInterval = static_cast<fl::u32>(1000000.0f / fps + .5f);
11}
12
13void FrameTracker::get_interval_frames(fl::u32 now, fl::u32 *frameNumber,
14 fl::u32 *nextFrameNumber,
15 u8 *amountOfNextFrame) const {
16 // Account for any pause time
17 fl::u32 effectiveTime = now;
18
19 // Convert milliseconds to microseconds for precise calculation
20 fl::u64 microseconds = static_cast<fl::u64>(effectiveTime) * 1000ULL;
21
22 // Calculate frame number with proper rounding
23 *frameNumber = microseconds / mMicrosSecondsPerInterval;
24 *nextFrameNumber = *frameNumber + 1;
25
26 // Calculate interpolation amount if requested
27 if (amountOfNextFrame != nullptr) {
28 fl::u64 frame1_start = (*frameNumber * mMicrosSecondsPerInterval);
29 fl::u64 frame2_start = (*nextFrameNumber * mMicrosSecondsPerInterval);
30 fl::u32 rel_time = microseconds - frame1_start;
31 fl::u32 frame_duration = frame2_start - frame1_start;
32 u8 progress = map_range<fl::u32, u8>(rel_time, 0, frame_duration, 0, 255);
33 *amountOfNextFrame = progress;
34 }
35}
36
37fl::u32 FrameTracker::get_exact_timestamp_ms(fl::u32 frameNumber) const {
38 fl::u64 microseconds = frameNumber * mMicrosSecondsPerInterval;
39 return static_cast<fl::u32>(microseconds / 1000) + mStartTime;
40}
41
42} // namespace video
43} // namespace fl
fl::u32 get_exact_timestamp_ms(fl::u32 frameNumber) const
void get_interval_frames(fl::u32 now, fl::u32 *frameNumber, fl::u32 *nextFrameNumber, u8 *amountOfNextFrame=nullptr) const
unsigned char u8
Definition stdint.h:131
FASTLED_FORCE_INLINE U map_range(T value, T in_min, T in_max, U out_min, U out_max) FL_NOEXCEPT
Definition math.h:174
fl::u64 u64
Definition s16x16x4.h:221
Base definition for an LED controller.
Definition crgb.hpp:179