-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add new effect for a single EQ bar with peak marker and decay #4760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
95b2b8b
dbf1bb6
2137729
ca096fc
63fd020
803cc20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7248,6 +7248,91 @@ uint16_t mode_2DGEQ(void) { // By Will Tatam. Code reduction by Ewoud Wijma. | |||||||||||||||||||||||||||||||||||||||||||||
} // mode_2DGEQ() | ||||||||||||||||||||||||||||||||||||||||||||||
static const char _data_FX_MODE_2DGEQ[] PROGMEM = "GEQ@Fade speed,Ripple decay,# of bands,,,Color bars;!,,Peaks;!;2f;c1=255,c2=64,pal=11,si=0"; // Beatsin | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
///////////////////////// | ||||||||||||||||||||||||||||||||||||||||||||||
// Single EQ Bar // | ||||||||||||||||||||||||||||||||||||||||||||||
///////////////////////// | ||||||||||||||||||||||||||||||||||||||||||||||
uint16_t mode_single_eqbar(void) { | ||||||||||||||||||||||||||||||||||||||||||||||
if (!SEGENV.allocateData(sizeof(uint16_t))) return mode_static(); | ||||||||||||||||||||||||||||||||||||||||||||||
uint16_t *prevBarHeight = (uint16_t*)SEGENV.data; | ||||||||||||||||||||||||||||||||||||||||||||||
if (SEGENV.call == 0) *prevBarHeight = 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
// Grab audio data - we only need the fftResult here, as we want the frequency data | ||||||||||||||||||||||||||||||||||||||||||||||
um_data_t *um_data = getAudioData(); | ||||||||||||||||||||||||||||||||||||||||||||||
uint8_t *fftResult = (uint8_t*)um_data->u_data[2]; | ||||||||||||||||||||||||||||||||||||||||||||||
if (!fftResult) return mode_static(); | ||||||||||||||||||||||||||||||||||||||||||||||
bool is2d = (strip.isMatrix || SEGMENT.is2D()); | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
// User controls. Speed is referenced directly instead of creating a new varible. | ||||||||||||||||||||||||||||||||||||||||||||||
uint8_t freqBin = map(SEGMENT.custom1, 0, 255, 0, 15); // 0-15 (or up to available bins) | ||||||||||||||||||||||||||||||||||||||||||||||
uint8_t peakDecay = SEGMENT.intensity; | ||||||||||||||||||||||||||||||||||||||||||||||
if (peakDecay > 0){ | ||||||||||||||||||||||||||||||||||||||||||||||
// Grab the intensity value for peak decay speed, bound it between 1 and 32, invert for ease of use. | ||||||||||||||||||||||||||||||||||||||||||||||
peakDecay = map(255 - SEGMENT.intensity, 1, 255, 1, 32); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
int barHeight = 0; | ||||||||||||||||||||||||||||||||||||||||||||||
if (strip.isMatrix || SEGMENT.is2D()){ | ||||||||||||||||||||||||||||||||||||||||||||||
barHeight = map(fftResult[freqBin], 0, 255, 0, SEG_H); // Grab new bar height | ||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||
barHeight = map(fftResult[freqBin], 0, 255, 0, SEGLEN); // Grab new bar height | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
if (barHeight > *prevBarHeight) *prevBarHeight = barHeight; // Update the previous bar height if the new height is greater | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
SEGMENT.fade_out(SEGMENT.speed); // Always fade out existing bars according to speed slider. | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
// Draw the main bar (but not peak pixel) | ||||||||||||||||||||||||||||||||||||||||||||||
for (int i = 0; i < barHeight; i++) { | ||||||||||||||||||||||||||||||||||||||||||||||
if (is2d){ | ||||||||||||||||||||||||||||||||||||||||||||||
// If we are in a matrix or 2D segment, draw the bar vertically | ||||||||||||||||||||||||||||||||||||||||||||||
for (int j = 0; j < SEG_W; j++) { | ||||||||||||||||||||||||||||||||||||||||||||||
SEGMENT.setPixelColorXY(j, i, SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||
// Otherwise draw the bar horizontally | ||||||||||||||||||||||||||||||||||||||||||||||
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
if (peakDecay == 0){ | ||||||||||||||||||||||||||||||||||||||||||||||
// No peak pixel if decay is set to zero, just draw the peak pixel of the bar. | ||||||||||||||||||||||||||||||||||||||||||||||
if (barHeight > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||
if (is2d) { | ||||||||||||||||||||||||||||||||||||||||||||||
for (int j = 0; j < SEG_W; j++) { | ||||||||||||||||||||||||||||||||||||||||||||||
SEGMENT.setPixelColorXY(j, barHeight, SEGMENT.color_from_palette(barHeight, true, PALETTE_SOLID_WRAP, 0)); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||
SEGMENT.setPixelColor(barHeight, SEGMENT.color_from_palette(barHeight, true, PALETTE_SOLID_WRAP, 0)); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+7297
to
+7304
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix potential out-of-bounds access for peak pixel. When drawing the peak pixel at if (peakDecay == 0){
// No peak pixel if decay is set to zero, just draw the peak pixel of the bar.
- if (barHeight > 0) {
+ if (barHeight > 0 && barHeight < (is2d ? SEG_H : SEGLEN)) {
if (is2d) {
for (int j = 0; j < SEG_W; j++) {
SEGMENT.setPixelColorXY(j, barHeight, SEGMENT.color_from_palette(barHeight, true, PALETTE_SOLID_WRAP, 0));
}
} else {
SEGMENT.setPixelColor(barHeight, SEGMENT.color_from_palette(barHeight, true, PALETTE_SOLID_WRAP, 0));
}
}
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||
// Decrement prevBarHeight according to peakDecay | ||||||||||||||||||||||||||||||||||||||||||||||
if (*prevBarHeight > 0 && (SEGENV.call % (peakDecay > 1 ? peakDecay : 1)) == 0) (*prevBarHeight)--; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
// Set peak pixel and clear pixels over peak (otherwise they would fadewith value from speed slider) | ||||||||||||||||||||||||||||||||||||||||||||||
if (*prevBarHeight > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
if (is2d) { | ||||||||||||||||||||||||||||||||||||||||||||||
for (int j = 0; j < SEG_W; j++) { | ||||||||||||||||||||||||||||||||||||||||||||||
SEGMENT.setPixelColorXY(j, *prevBarHeight, SEGCOLOR(2)); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||
SEGMENT.setPixelColor(*prevBarHeight, SEGCOLOR(2)); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+7311
to
+7320
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add bounds checking for peak pixel drawing. The peak pixel is drawn at // Set peak pixel and clear pixels over peak (otherwise they would fadewith value from speed slider)
- if (*prevBarHeight > 0) {
+ if (*prevBarHeight > 0 && *prevBarHeight < (is2d ? SEG_H : SEGLEN)) {
if (is2d) {
for (int j = 0; j < SEG_W; j++) {
SEGMENT.setPixelColorXY(j, *prevBarHeight, SEGCOLOR(2));
}
} else {
SEGMENT.setPixelColor(*prevBarHeight, SEGCOLOR(2));
}
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||
if (*prevBarHeight < SEGLEN) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
if (is2d) { | ||||||||||||||||||||||||||||||||||||||||||||||
for (int j = 0; j < SEG_W; j++) { | ||||||||||||||||||||||||||||||||||||||||||||||
SEGMENT.setPixelColorXY(j, *prevBarHeight + 1, BLACK); // clear next pixel immediately. | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||
SEGMENT.setPixelColor(*prevBarHeight + 1, BLACK); // clear next pixel immediately. | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+7321
to
+7330
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix inconsistent bounds checking for 2D vs 1D modes. The bounds check uses - if (*prevBarHeight < SEGLEN) {
+ if (*prevBarHeight < (is2d ? SEG_H - 1 : SEGLEN - 1)) {
if (is2d) {
for (int j = 0; j < SEG_W; j++) {
SEGMENT.setPixelColorXY(j, *prevBarHeight + 1, BLACK); // clear next pixel immediately.
}
} else {
SEGMENT.setPixelColor(*prevBarHeight + 1, BLACK); // clear next pixel immediately.
}
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
return FRAMETIME; | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
static const char _data_FX_MODE_SINGLE_EQBAR[] PROGMEM = "Single EQ Bar@Fade speed,Peak decay,Frequency bin;!,,Peaks;!;!;12vf;sx=128,ix=170,c1=128,si=0"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
///////////////////////// | ||||||||||||||||||||||||||||||||||||||||||||||
// ** 2D Funky plank // | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -10818,5 +10903,6 @@ addEffect(FX_MODE_PS1DSONICSTREAM, &mode_particle1DsonicStream, _data_FX_MODE_PS | |||||||||||||||||||||||||||||||||||||||||||||
addEffect(FX_MODE_PS1DSONICBOOM, &mode_particle1DsonicBoom, _data_FX_MODE_PS_SONICBOOM); | ||||||||||||||||||||||||||||||||||||||||||||||
addEffect(FX_MODE_PS1DSPRINGY, &mode_particleSpringy, _data_FX_MODE_PS_SPRINGY); | ||||||||||||||||||||||||||||||||||||||||||||||
#endif // WLED_DISABLE_PARTICLESYSTEM1D | ||||||||||||||||||||||||||||||||||||||||||||||
addEffect(FX_MODE_SINGLE_EQBAR, &mode_single_eqbar, _data_FX_MODE_SINGLE_EQBAR); | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -374,6 +374,7 @@ extern byte realtimeMode; // used in getMappedPixelIndex() | |
#define FX_MODE_PS1DSPRINGY 216 | ||
#define FX_MODE_PARTICLEGALAXY 217 | ||
#define MODE_COUNT 218 | ||
#define FX_MODE_SINGLE_EQBAR 219 | ||
|
||
Comment on lines
376
to
378
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MODE_COUNT is now off-by-one – update to reflect the new effect ID
Suggested fix: -#define MODE_COUNT 218
+#define MODE_COUNT 220 // 0 … 219 Also confirm that any build-time assertions or size-dependent allocations relying on 🤖 Prompt for AI Agents
|
||
|
||
#define BLEND_STYLE_FADE 0x00 // universal | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add bounds checking for frequency bin access.
The frequency bin mapping doesn't ensure the selected bin is within the available FFT data range, which could lead to out-of-bounds access.
🤖 Prompt for AI Agents