// Update is called once per frame void Update() { float[] currSpectrum = analyzer.getSpectrum(); float rangeTotal = 0; // Sum total of values in desired range for (int i = rangeStart; i < rangeEnd; i++) { rangeTotal += Mathf.Clamp((50 + i * i) * currSpectrum[i], 0, 50); } // Update moving average with current value updateMovingAverage(rangeTotal); // Take the total of the current moving average float sumOfTotals = sumQueue(movingAverage); if (sumOfTotals > maxLevel) { sumOfTotals = maxLevel; } react(sumOfTotals, maxLevel); }