FastLED 3.9.15
Loading...
Searching...
No Matches

◆ get_interval_frames()

void fl::FrameTracker::get_interval_frames ( fl::u32 now,
fl::u32 * frameNumber,
fl::u32 * nextFrameNumber,
uint8_t * amountOfNextFrame = nullptr ) const

Definition at line 23 of file frame_tracker.cpp.

25 {
26 // Account for any pause time
27 fl::u32 effectiveTime = now;
28
29 // Convert milliseconds to microseconds for precise calculation
30 fl::u64 microseconds = static_cast<fl::u64>(effectiveTime) * 1000ULL;
31
32 // Calculate frame number with proper rounding
33 *frameNumber = microseconds / mMicrosSecondsPerInterval;
34 *nextFrameNumber = *frameNumber + 1;
35
36 // Calculate interpolation amount if requested
37 if (amountOfNextFrame != nullptr) {
38 fl::u64 frame1_start = (*frameNumber * mMicrosSecondsPerInterval);
39 fl::u64 frame2_start = (*nextFrameNumber * mMicrosSecondsPerInterval);
40 fl::u32 rel_time = microseconds - frame1_start;
41 fl::u32 frame_duration = frame2_start - frame1_start;
42 uint8_t progress = uint8_t(linear_map(rel_time, 0, frame_duration, 0, 255));
43 *amountOfNextFrame = progress;
44 }
45}
fl::u32 mMicrosSecondsPerInterval
long linear_map(long x, long in_min, long in_max, long out_min, long out_max)

References mMicrosSecondsPerInterval.