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

◆ draw()

bool fl::FxEngine::draw ( fl::u32 now,
fl::span< CRGB > outputBuffer )

Renders the current effect or transition to the output buffer.

Parameters
nowThe current time in milliseconds.
outputBufferThe buffer to render the effect into.

Definition at line 96 of file fx_engine.cpp.hpp.

96 {
97 mTimeFunction.update(now);
98 fl::u32 warpedTime = mTimeFunction.time();
99
100 // Swap audio double-buffers: back → front, then clear back for next frame.
102 mAudioBack.clear();
103
104 // Bump the task scheduler so the audio auto-pump task runs NOW,
105 // feeding any pending I2S samples into the Processor before we read levels.
106 // Without this, draw() would read stale levels from the previous frame.
107 if (mAudioProcessor) {
109 }
110
111 // If an audio processor is wired, poll it for one frame per draw cycle.
112 if (mAudioProcessor) {
113 AudioFrame af;
114 af.bass = mAudioProcessor->getBassLevel();
115 af.mid = mAudioProcessor->getMidLevel();
116 af.treble = mAudioProcessor->getTrebleLevel();
117 af.volume = mAudioProcessor->getEnergy();
118 af.beat = mAudioProcessor->isVibeBassSpike();
119 af.timestamp = now;
120 mAudioFront.push_back(af);
121 }
122
123 // Build AudioBatch on the stack — shared across both compositor layers.
124 // Passes Processor pointer for lazy access to vibe/equalizer/percussion.
125 fl::span<const AudioFrame> audioSpan(mAudioFront);
126 AudioBatch audioBatch(audioSpan, mAudioProcessor.get());
127 const AudioBatch *audioPtr =
128 (mAudioFront.empty() && !mAudioProcessor) ? nullptr : &audioBatch;
129
130 if (mEffects.empty()) {
131 return false;
132 }
133 if (mDurationSet) {
134 FxPtr fx;
135 bool ok = mEffects.get(mCurrId, &fx);
136 if (!ok) {
137 // something went wrong.
138 return false;
139 }
140 mCompositor.startTransition(now, mDuration, fx);
141 mDurationSet = false;
142 }
143 if (!mEffects.empty()) {
144 float speed = mTimeFunction.scale();
145 mCompositor.draw(now, warpedTime, finalBuffer, speed, audioPtr);
146 }
147 return true;
148}
uint16_t speed
Definition Noise.ino:66
fl::vector< AudioFrame > mAudioBack
Definition fx_engine.h:148
bool mDurationSet
Flag indicating if a new transition has been set.
Definition fx_engine.h:140
FxCompositor mCompositor
Handles effect transitions and rendering.
Definition fx_engine.h:137
int mCurrId
Id of the current effect.
Definition fx_engine.h:138
fl::vector< AudioFrame > mAudioFront
Definition fx_engine.h:147
fl::shared_ptr< fl::audio::Processor > mAudioProcessor
Definition fx_engine.h:151
u16 mDuration
Duration of the current transition.
Definition fx_engine.h:139
IntFxMap mEffects
Collection of effects.
Definition fx_engine.h:136
TimeWarp mTimeFunction
Definition fx_engine.h:134
static Scheduler & instance()

References fl::AudioFrame::bass, fl::AudioFrame::beat, fl::task::Scheduler::instance(), mAudioBack, mAudioFront, mAudioProcessor, mCompositor, mCurrId, mDuration, mDurationSet, mEffects, fl::AudioFrame::mid, mTimeFunction, speed, fl::AudioFrame::timestamp, fl::AudioFrame::treble, fl::task::Scheduler::update(), and fl::AudioFrame::volume.

+ Here is the call graph for this function: