FastLED 3.10.8
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#include "fl/stl/noexcept.h"
5
6namespace fl {
7namespace video {
8
10 // Convert fps to microseconds per frame interval
11 mMicrosSecondsPerInterval = static_cast<fl::u32>(1000000.0f / fps + .5f);
12}
13
14void FrameTracker::get_interval_frames(fl::u32 now, fl::u32 *frameNumber,
15 fl::u32 *nextFrameNumber,
16 u8 *amountOfNextFrame) const FL_NO_EXCEPT {
17 // Account for any pause time
18 fl::u32 effectiveTime = now;
19
20 // Convert milliseconds to microseconds for precise calculation
21 fl::u64 microseconds = static_cast<fl::u64>(effectiveTime) * 1000ULL;
22
23 // Calculate frame number with proper rounding
24 *frameNumber = microseconds / mMicrosSecondsPerInterval;
25 *nextFrameNumber = *frameNumber + 1;
26
27 // Calculate interpolation amount if requested
28 if (amountOfNextFrame != nullptr) {
29 fl::u64 frame1_start =
30 static_cast<fl::u64>(*frameNumber) * mMicrosSecondsPerInterval;
31 fl::u64 frame2_start =
32 static_cast<fl::u64>(*nextFrameNumber) * mMicrosSecondsPerInterval;
33 fl::u32 rel_time = microseconds - frame1_start;
34 fl::u32 frame_duration = frame2_start - frame1_start;
35 u8 progress = map_range<fl::u32, u8>(rel_time, 0, frame_duration, 0, 255);
36 *amountOfNextFrame = progress;
37 }
38}
39
40fl::u32 FrameTracker::get_exact_timestamp_ms(fl::u32 frameNumber) const FL_NO_EXCEPT {
41 fl::u64 microseconds =
42 static_cast<fl::u64>(frameNumber) * mMicrosSecondsPerInterval;
43 return static_cast<fl::u32>(microseconds / 1000) + mStartTime;
44}
45
46} // namespace video
47} // namespace fl
void get_interval_frames(fl::u32 now, fl::u32 *frameNumber, fl::u32 *nextFrameNumber, u8 *amountOfNextFrame=nullptr) const FL_NO_EXCEPT
FrameTracker(float fps) FL_NO_EXCEPT
fl::u32 get_exact_timestamp_ms(fl::u32 frameNumber) const FL_NO_EXCEPT
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
FASTLED_FORCE_INLINE U map_range(T value, T in_min, T in_max, U out_min, U out_max) FL_NO_EXCEPT
Definition math.h:182
Base definition for an LED controller.
Definition crgb.hpp:179