| 28 | DropDetector::~DropDetector() FL_NOEXCEPT = default; |
| 29 | |
| 30 | void DropDetector::update(shared_ptr<Context> context) { |
| 31 | if (!context) { |
| 32 | // Null context - nothing to process |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | mRetainedFFT = context->getFFT(32); |
| 37 | const fft::Bins& fft = *mRetainedFFT; |
| 38 | float rms = context->getRMS(); |
| 39 | u32 timestamp = context->getTimestamp(); |
| 40 | |
| 41 | // Calculate frequency band energies |
| 42 | float bassEnergy = getBassEnergy(fft); |
| 43 | float midEnergy = getMidEnergy(fft); |
| 44 | float trebleEnergy = getTrebleEnergy(fft); |
| 45 | |
| 46 | // Calculate flux values (rate of change) |
| 47 | float energyFlux = calculateEnergyFlux(rms); |
| 48 | float bassFlux = calculateBassFlux(bassEnergy); |
| 49 | |
| 50 | // Calculate spectral novelty (how much spectrum changed) |
| 51 | float spectralNovelty = calculateSpectralNovelty(bassEnergy, midEnergy, trebleEnergy); |
| 52 | |
| 53 | // Calculate drop impact |
| 54 | float impact = calculateDropImpact(energyFlux, bassFlux, spectralNovelty, rms); |
| 55 | |
| 56 | // Check if we should trigger a drop |
| 57 | mDropDetectedThisFrame = false; |
| 58 | if (shouldTriggerDrop(impact, timestamp)) { |
| 59 | // Create drop event |
| 60 | Drop dropEvent; |
| 61 | dropEvent.impact = impact; |
| 62 | dropEvent.bassEnergy = bassEnergy; |
| 63 | dropEvent.energyIncrease = energyFlux; |
| 64 | dropEvent.timestamp = timestamp; |
| 65 | |
| 66 | mLastDrop = dropEvent; |
| 67 | mDropDetectedThisFrame = true; |
| 68 | |
| 69 | FL_DBG("DropDetector: Drop detected! Impact=" << impact |
| 70 | << ", Bass=" << bassEnergy |
| 71 | << ", Energy flux=" << energyFlux); |
| 72 | } |
| 73 | |
| 74 | // Update baselines (exponential moving average) |
| 75 | updateBaselines(rms, bassEnergy); |
| 76 | |
| 77 | // Store current values for next frame |
| 78 | mPrevRMS = rms; |
| 79 | mPrevBassEnergy = bassEnergy; |
| 80 | mPrevMidEnergy = midEnergy; |
| 81 | mPrevTrebleEnergy = trebleEnergy; |
| 82 | } |
| 83 | |
| 84 | void DropDetector::fireCallbacks() { |
| 85 | if (mDropDetectedThisFrame) { |
nothing calls this directly
no test coverage detected