Skip to content

Commit e462b21

Browse files
authored
Merge pull request #744 from PlummersSoftwareLLC/audioupdates
Optimizations and audio gating
2 parents d98d838 + 86c88b7 commit e462b21

17 files changed

+191
-345
lines changed

build_all.sh

Lines changed: 0 additions & 134 deletions
This file was deleted.

build_results.csv

Lines changed: 0 additions & 1 deletion
This file was deleted.

include/effects/matrix/PatternAnimatedGIF.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class PatternAnimatedGIF : public LEDStripEffect
154154
static void screenClearCallback(void)
155155
{
156156
auto& g = *(g_ptrSystem->EffectManager().g());
157-
g.fillScreen(g.to16bit(g_gifDecoderState._bkColor));
157+
g.Clear(g_gifDecoderState._bkColor);
158158
}
159159

160160
// We decide when to update the screen, so this is a no-op

include/effects/strip/fireeffect.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "musiceffect.h"
3636
#include "soundanalyzer.h"
3737
#include "systemcontainer.h"
38+
#include <numeric>
3839

3940
class FireEffect : public LEDStripEffect
4041
{
@@ -181,9 +182,9 @@ class FireEffect : public LEDStripEffect
181182

182183
for (int i = 0; i < LEDCount; i++)
183184
{
184-
auto sum = 0;
185-
for (int j = 0; j < CellsPerLED; j++)
186-
sum += heat[i*CellsPerLED + j];
185+
auto begin = &heat[i * CellsPerLED];
186+
auto end = begin + CellsPerLED;
187+
int sum = std::accumulate(begin, end, 0);
187188
auto avg = sum / CellsPerLED;
188189

189190
#if LANTERN
@@ -760,9 +761,9 @@ class BaseFireEffect : public LEDStripEffect
760761
int cellsPerLED = CellCount / LEDCount;
761762
for (int i = 0; i < LEDCount; i++)
762763
{
763-
int sum = 0;
764-
for (int iCell = 0; iCell < cellsPerLED; iCell++)
765-
sum += heat[i * cellsPerLED + iCell];
764+
auto begin = &heat[i * cellsPerLED];
765+
auto end = begin + cellsPerLED;
766+
int sum = std::accumulate(begin, end, 0);
766767
int avg = sum / cellsPerLED;
767768
CRGB color = MapHeatToColor(heat[avg]);
768769
int j = bReversed ? (LEDCount - 1 - i) : i;

include/effects/strip/meteoreffect.h

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
#pragma once
3333

34+
#include "ledstripeffect.h"
35+
3436
class MeteorChannel
3537
{
3638
std::vector<float> hue;
@@ -98,19 +100,19 @@ class MeteorChannel
98100
bLeft[iMeteor] = !bLeft[iMeteor];
99101
}
100102

101-
virtual void Draw(std::shared_ptr<GFXBase> pGFX)
103+
virtual void Draw(LEDStripEffect* owner)
102104
{
105+
auto pGFX = owner->g(0);
103106
static CHSV hsv;
104107
hsv.val = 255;
105108
hsv.sat = 255;
106109

107-
for (int j = 0; j<pGFX->GetLEDCount(); j++) // fade brightness all LEDs one step
110+
// Fade brightness on all channels
111+
for (int j = 0; j < pGFX->GetLEDCount(); j++)
108112
{
109-
if ((!meteorRandomDecay) || (random_range(0, 10)>2)) // BUGBUG Was 5 for everything before atomlight
113+
if ((!meteorRandomDecay) || (random_range(0, 10) > 2))
110114
{
111-
CRGB c = pGFX->getPixel(j);
112-
c.fadeToBlackBy(meteorTrailDecay);
113-
pGFX->setPixel(j, c);
115+
owner->fadePixelToBlackOnAllChannelsBy(j, meteorTrailDecay);
114116
}
115117
}
116118

@@ -123,32 +125,35 @@ class MeteorChannel
123125
spd *= g_Analyzer.VURatio();
124126
#endif
125127

126-
iPos[i] = (bLeft[i]) ? iPos[i]-spd : iPos[i]+spd;
127-
if (iPos[i]< meteorSize)
128+
iPos[i] = (bLeft[i]) ? iPos[i] - spd : iPos[i] + spd;
129+
if (iPos[i] < meteorSize)
128130
{
129131
bLeft[i] = false;
130132
iPos[i] = meteorSize;
131133
}
132134
if (iPos[i] >= pGFX->GetLEDCount())
133135
{
134136
bLeft[i] = true;
135-
iPos[i] = pGFX->GetLEDCount()-1;
137+
iPos[i] = pGFX->GetLEDCount() - 1;
136138
}
137139

138-
for (int j = 0; j < meteorSize; j++) // Draw the meteor head
140+
// Draw the meteor head across all channels
141+
for (int j = 0; j < meteorSize; j++)
139142
{
140-
int x = iPos[i] - j;
141-
if ((x <= pGFX->GetLEDCount()) && (x >= 1))
143+
int x = static_cast<int>(iPos[i]) - j;
144+
if ((x <= static_cast<int>(pGFX->GetLEDCount())) && (x >= 1))
142145
{
143146
CRGB rgb;
144147
hue[i] = hue[i] + 0.025f;
145148
if (hue[i] > 255.0f)
146149
hue[i] -= 255.0f;
147-
hsv.hue = hue[i];
150+
hsv.hue = static_cast<uint8_t>(hue[i]);
148151
hsv2rgb_rainbow(hsv, rgb);
152+
153+
// Blend with current pixel from primary device, then set on all channels
149154
CRGB c = pGFX->getPixel(x);
150-
nblend(c, rgb , 75);
151-
pGFX->setPixel(x, c);
155+
nblend(c, rgb, 75);
156+
owner->setPixelOnAllChannels(x, c);
152157
}
153158
}
154159
}
@@ -223,7 +228,8 @@ class MeteorEffect : public LEDStripEffect
223228

224229
void Draw() override
225230
{
226-
for (int i = 0; i < _Meteors.size(); i++)
227-
_Meteors[i].Draw(_GFX[i]);
231+
// Draw once using channel 0 state while writing to all channels
232+
if (!_Meteors.empty())
233+
_Meteors[0].Draw(this);
228234
}
229235
};

0 commit comments

Comments
 (0)