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

◆ driveBpmLocked()

float animartrix_ring::SoundOrchestrator::driveBpmLocked ( fl::u32 nowMs,
float manualSpeedScalar )
private

Definition at line 194 of file sound_orchestrator.cpp.

194 {
195 if (!mProcessor) return manualSpeedScalar;
196
197 // Baseline speed scales gently with BPM so faster songs read faster.
198 const float bpm = mProcessor->getBPM();
199 // Normalize BPM to a 0.6..1.6 multiplier around the nominal 120 BPM.
200 float bpmScale = 1.0f;
201 if (bpm > 1.0f) {
202 bpmScale = bpm / 120.0f;
203 if (bpmScale < 0.6f) bpmScale = 0.6f;
204 if (bpmScale > 1.6f) bpmScale = 1.6f;
205 }
206
207 // Pulse: kick/snare/downbeat events bump speed briefly and decay.
208 // Downbeats hit hardest (palette-level event); kicks medium; snares light.
209 auto pulseFromEvent = [&](fl::u32 t, float weight) -> float {
210 if (t == 0) return 0.0f;
211 const fl::u32 dt = nowMs - t;
212 if (dt >= mCfg.pulseDecayMs) return 0.0f;
213 const float k = 1.0f - (static_cast<float>(dt) / mCfg.pulseDecayMs);
214 return weight * k * k; // ease-out square
215 };
216 const float kickPulse = pulseFromEvent(mLastKickMs, 0.50f);
217 const float snarePulse = pulseFromEvent(mLastSnareMs, 0.25f);
218 const float downbeatPulse = pulseFromEvent(mLastDownbeatMs, 0.80f);
219 float pulse = kickPulse + snarePulse + downbeatPulse;
220 if (pulse > 1.5f) pulse = 1.5f;
221
222 // measurePhase smoothly fills the inter-beat gap so visuals breathe
223 // between pulses rather than freezing. Phase is 0..1 within the measure.
224 const float phase = mProcessor->getMeasurePhase(); // 0..1
225 // Sine bow so phase contributes gently throughout the measure.
226 const float phaseBow = 0.15f * fl::sin(phase * 6.2831853f);
227
228 float speed = mCfg.bpmLockedBaseSpeed * bpmScale + pulse + phaseBow;
229 if (speed < 0.2f) speed = 0.2f;
230 return speed * manualSpeedScalar;
231}
void bpm()
uint16_t speed
Definition Noise.ino:66
fl::shared_ptr< fl::audio::Processor > mProcessor
static uint32_t t
Definition Luminova.h:55
enable_if< is_fixed_point< T >::value, T >::type sin(T angle) FL_NOEXCEPT

References bpm(), mCfg, mLastDownbeatMs, mLastKickMs, mLastSnareMs, mProcessor, fl::sin(), speed, and t.

Referenced by tick().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: