@@ -77,13 +77,14 @@ class InsulatorSpectrumEffect : public LEDStripEffect, public BeatEffectBase, pu
7777
7878 virtual void Draw () override
7979 {
80- auto peaks = g_Analyzer.GetPeakData ();
80+ // Use const reference to avoid copying PeakData
81+ const PeakData & peaks = g_Analyzer.Peaks ();
8182
8283 for (int band = 0 ; band < min (NUM_BANDS, NUM_FANS); band++)
8384 {
8485 CRGB color = ColorFromPalette (_Palette, ::map (band, 0 , min (NUM_BANDS, NUM_FANS), 0 , 255 ) + beatsin8 (1 ) );
8586 color = color.fadeToBlackBy (255 - 255 * peaks[band]);
86- color = color.fadeToBlackBy ((2.0 - g_Analyzer._VURatio ) * 228 );
87+ color = color.fadeToBlackBy ((2.0 - g_Analyzer.VURatio () ) * 228 );
8788 DrawRingPixels (0 , FAN_SIZE * peaks[band], color, NUM_FANS-1 -band, 0 );
8889 }
8990
@@ -104,7 +105,7 @@ class InsulatorSpectrumEffect : public LEDStripEffect, public BeatEffectBase, pu
104105
105106
106107 // REVIEW(davepl) This might look interesting if it didn't erase...
107- bool bFlash = g_Analyzer._VURatio > 1.99 && span > 1.9 && elapsed > 0.25 ;
108+ bool bFlash = g_Analyzer.VURatio () > 1.99 && span > 1.9 && elapsed > 0.25 ;
108109
109110 _allParticles.push_back (SpinningPaletteRingParticle (iInsulator, 0 , _Palette, 256.0 /FAN_SIZE, 4 , -0.5 , RING_SIZE_0, 0 , LINEARBLEND, true , 1.0 , bFlash ? max (0 .12f , elapsed/8 ) : 0 ));
110111 }
@@ -116,7 +117,7 @@ class VUMeter
116117
117118 // DrawVUPixels
118119 //
119- // Draw i-th pixel in row y
120+ // Draw i-th pixel in row yVU
120121
121122 virtual void DrawVUPixels (std::vector<std::shared_ptr<GFXBase>> & GFX, int i, int yVU, int fadeBy = 0 , const CRGBPalette16 * pPalette = nullptr )
122123 {
@@ -153,7 +154,7 @@ class VUMeter
153154 const int MAX_FADE = 256 ;
154155
155156 int xHalf = GFX[0 ]->width ()/2 -1 ;
156- int bars = g_Analyzer._VURatioFade / 2.0 * xHalf;
157+ int bars = g_Analyzer.VURatioFade () / 2.0 * xHalf;
157158 bars = min (bars, xHalf);
158159
159160 EraseVUMeter (GFX, bars, yVU);
@@ -163,14 +164,14 @@ class VUMeter
163164 msPeakVU = millis ();
164165 iPeakVUy = bars;
165166 }
166- else if (millis () - msPeakVU > MS_PER_SECOND / 2 )
167+ else if (millis () - msPeakVU > MILLIS_PER_SECOND / 2 )
167168 {
168169 iPeakVUy = 0 ;
169170 }
170171
171172 if (iPeakVUy > 1 )
172173 {
173- int fade = MAX_FADE * (millis () - msPeakVU) / (float ) MS_PER_SECOND * 2 ;
174+ int fade = MAX_FADE * (millis () - msPeakVU) / (float ) MILLIS_PER_SECOND * 2 ;
174175 DrawVUPixels (GFX, iPeakVUy, yVU, fade);
175176 DrawVUPixels (GFX, iPeakVUy-1 , yVU, fade);
176177 }
@@ -206,7 +207,7 @@ class VUMeterVertical : public VUMeter
206207 const int MAX_FADE = 256 ;
207208
208209 int size = GFX[0 ]->width ();
209- int bars = g_Analyzer._VURatioFade / 2.0 * size;
210+ int bars = g_Analyzer.VURatioFade () / 2.0 * size;
210211 bars = min (bars, size);
211212
212213 EraseVUMeter (GFX, bars, yVU);
@@ -216,14 +217,14 @@ class VUMeterVertical : public VUMeter
216217 msPeakVU = millis ();
217218 iPeakVUy = bars;
218219 }
219- else if (millis () - msPeakVU > MS_PER_SECOND / 2 )
220+ else if (millis () - msPeakVU > MILLIS_PER_SECOND / 2 )
220221 {
221222 iPeakVUy = 0 ;
222223 }
223224
224225 if (iPeakVUy > 1 )
225226 {
226- int fade = MAX_FADE * (millis () - msPeakVU) / (float ) MS_PER_SECOND * 2 ;
227+ int fade = MAX_FADE * (millis () - msPeakVU) / (float ) MILLIS_PER_SECOND * 2 ;
227228 DrawVUPixels (GFX, iPeakVUy, yVU, fade);
228229 DrawVUPixels (GFX, iPeakVUy-1 , yVU, fade);
229230 }
@@ -333,18 +334,18 @@ class SpectrumAnalyzerEffect : public LEDStripEffect, virtual public VUMeter
333334 // bar 16, for example, it will take all of bar 4 and none of bar 5. For bar 17, it will take 3/4 of bar 4 and 1/4 of bar 5.
334335
335336 int ib = iBar % barsPerBand;
336- value = (g_Analyzer._peak1Decay [ iBand] * (barsPerBand - ib) + g_Analyzer._peak1Decay [ iNextBand] * (ib) ) / barsPerBand * (pGFXChannel->height () - 1 );
337- value2 = (g_Analyzer._peak2Decay [ iBand] * (barsPerBand - ib) + g_Analyzer._peak2Decay [ iNextBand] * (ib) ) / barsPerBand * pGFXChannel->height ();
337+ value = (g_Analyzer.Peak2Decay ( iBand) * (barsPerBand - ib) + g_Analyzer.Peak2Decay ( iNextBand) * (ib) ) / barsPerBand * (pGFXChannel->height () - 1 );
338+ value2 = (g_Analyzer.Peak2Decay ( iBand) * (barsPerBand - ib) + g_Analyzer.Peak2Decay ( iNextBand) * (ib) ) / barsPerBand * pGFXChannel->height ();
338339 }
339340 else
340341 {
341342 // One to one case, just use the actual band value we mapped to
342343
343- value = g_Analyzer._peak1Decay [ iBand] * (pGFXChannel->height () - 1 );
344- value2 = g_Analyzer._peak2Decay [ iBand] * pGFXChannel->height ();
344+ value = g_Analyzer.Peak2Decay ( iBand) * (pGFXChannel->height () - 1 );
345+ value2 = g_Analyzer.Peak2Decay ( iBand) * pGFXChannel->height ();
345346 }
346347
347- debugV (" Band: %d, Value: %f\n " , iBar, g_Analyzer._peak1Decay [ iBar] );
348+ debugV (" Band: %d, Value: %f\n " , iBar, g_Analyzer.Peak2Decay ( iBar) );
348349
349350 if (value > pGFXChannel->height ())
350351 value = pGFXChannel->height ();
@@ -389,11 +390,11 @@ class SpectrumAnalyzerEffect : public LEDStripEffect, virtual public VUMeter
389390 {
390391 const int PeakFadeTime_ms = 1000 ;
391392
392- unsigned long msPeakAge = millis () - g_Analyzer._lastPeak1Time [ iBand] ;
393+ unsigned long msPeakAge = millis () - g_Analyzer.LastPeak1Time ( iBand) ;
393394 if (msPeakAge > PeakFadeTime_ms)
394395 msPeakAge = PeakFadeTime_ms;
395396
396- float agePercent = (float ) msPeakAge / (float ) MS_PER_SECOND ;
397+ float agePercent = (float ) msPeakAge / (float ) MILLIS_PER_SECOND ;
397398 uint8_t fadeAmount = std::min (255 .0f , agePercent * 256 );
398399 colorHighlight.fadeToBlackBy (fadeAmount);
399400 pGFXChannel->drawLine (xOffset, max (0 , yOffset-1 ), xOffset + barWidth - 1 , max (0 , yOffset-1 ), colorHighlight);
@@ -487,8 +488,8 @@ class SpectrumAnalyzerEffect : public LEDStripEffect, virtual public VUMeter
487488 {
488489 // The peaks and their decay rates are global, so we load up our values every time we display so they're current
489490
490- g_Analyzer. _peak1DecayRate = _peak1DecayRate;
491- g_Analyzer._peak2DecayRate = _peak2DecayRate;
491+ // Load decay rates into analyzer
492+ g_Analyzer.SetPeakDecayRates (_peak1DecayRate, _peak2DecayRate) ;
492493 }
493494
494495 virtual void Draw () override
@@ -628,8 +629,8 @@ class WaveformEffect : public LEDStripEffect
628629 {
629630 int top = g_ptrSystem->EffectManager ().IsVUVisible () ? 1 : 0 ;
630631 g ()->MoveInwardX (top); // Start on Y=1 so we don't shift the VU meter
631- DrawSpike (MATRIX_WIDTH-1 , g_Analyzer._VURatio /2.0 );
632- DrawSpike (0 , g_Analyzer._VURatio /2.0 );
632+ DrawSpike (MATRIX_WIDTH-1 , g_Analyzer.VURatio () /2.0 );
633+ DrawSpike (0 , g_Analyzer.VURatio () /2.0 );
633634 }
634635};
635636
@@ -704,7 +705,7 @@ class GhostWave : public WaveformEffect
704705
705706 // VURatio is too fast, VURatioFade looks too slow, but averaged between them is just right
706707
707- float audioLevel = (g_Analyzer._VURatioFade + g_Analyzer._VURatio ) / 2 ;
708+ float audioLevel = (g_Analyzer.VURatioFade () + g_Analyzer.VURatio () ) / 2 ;
708709
709710 // Offsetting by 0.25, which is a very low ratio, helps keep the line thin when sound is low
710711 // audioLevel = (audioLevel - 0.25) / 1.75;
@@ -800,7 +801,7 @@ class SpectrumBarEffect : public LEDStripEffect, public BeatEffectBase
800801 {
801802 // Draw the spike
802803
803- auto value = g_Analyzer.BeatEnhance (SPECTRUMBARBEAT_ENHANCE) * g_Analyzer._peak1Decay [ iBand] ;
804+ auto value = g_Analyzer.BeatEnhance (SPECTRUMBARBEAT_ENHANCE) * g_Analyzer.Peak2Decay ( iBand) ;
804805 auto top = std::max (0 .0f , halfHeight - value * halfHeight);
805806 auto bottom = std::min (MATRIX_HEIGHT-1 .0f , halfHeight + value * halfHeight + 1 );
806807 auto x1 = halfWidth - ((iBand * 2 + offset) % halfWidth);
@@ -826,8 +827,7 @@ class SpectrumBarEffect : public LEDStripEffect, public BeatEffectBase
826827
827828 // Set the peak decay rates to something that looks good for this effect
828829
829- g_Analyzer._peak1DecayRate = kPeakDecaySpectrumBar ;
830- g_Analyzer._peak2DecayRate = kPeakDecaySpectrumBar ;
830+ g_Analyzer.SetPeakDecayRates (kPeakDecaySpectrumBar , kPeakDecaySpectrumBar );
831831
832832 // This effect doesn't clear during drawing, so we need to clear to start the frame
833833
0 commit comments