| 94 | } |
| 95 | |
| 96 | bool FxEngine::draw(fl::u32 now, fl::span<CRGB> finalBuffer) { |
| 97 | mTimeFunction.update(now); |
| 98 | fl::u32 warpedTime = mTimeFunction.time(); |
| 99 | |
| 100 | // Swap audio double-buffers: back → front, then clear back for next frame. |
| 101 | mAudioFront.swap(mAudioBack); |
| 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) { |
| 108 | fl::task::Scheduler::instance().update(); |
| 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 | } |
| 149 | |
| 150 | } // namespace fl |
nothing calls this directly
no test coverage detected