Skip to content

Commit 2f7cbdb

Browse files
committed
LEDOutput
1 parent cb1b618 commit 2f7cbdb

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/AudioLibs/LEDOutput.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ class LEDOutput {
4040
LEDOutput(AudioFFTBase &fft) {
4141
selfLEDOutput = this;
4242
p_fft = &fft;
43-
AudioFFTConfig &fft_cfg = p_fft->config();
44-
fft_cfg.callback = fftCallback;
4543
}
4644

4745
/// Provides the default config object
@@ -58,6 +56,12 @@ class LEDOutput {
5856
LOGE("x or y == 0");
5957
return false;
6058
}
59+
// assign fft callback
60+
AudioFFTConfig &fft_cfg = p_fft->config();
61+
fft_cfg.callback = fftCallback;
62+
63+
// allocate leds
64+
leds.resize(ledCount());
6165

6266
// if the number of bins > number of leds in x position we combine adjecent
6367
// values
@@ -145,12 +149,15 @@ class LEDOutput {
145149
};
146150
};
147151

148-
152+
/// Default update implementation which provides the fft result as "barchart"
149153
void updateLEDOutput(LEDOutputConfig*cfg, LEDOutput *matrix, int max_y){
150154
for (int x = 0; x < cfg->x; x++) {
151155
// max y determined by magnitude
152156
int maxY = mapFloat(matrix->getMagnitude(x), 0.0f, max_y, 0.0f,
153157
static_cast<float>(cfg->y));
158+
if (maxY>cfg->y){
159+
maxY = cfg->y;
160+
}
154161
// update horizontal bar
155162
for (int y = 0; y < maxY; y++) {
156163
int color = cfg->color;

0 commit comments

Comments
 (0)