Add audio responsive pallette by Netmindz

const.h: increase GRADIENT_PALETTE_COUNT
fcn_declare: add getCRGBForBand
FX.h: add getAudioPalette
FX_fcn.cpp: call and getAudioPalette, add Audio Responsive palette
palettes.h: add audio_responsive_gp
util.cpp: add getCRGBForBand
This commit is contained in:
Ewoud
2022-11-18 12:09:47 +01:00
parent 017f0267a2
commit 181f8c546b
9 changed files with 69 additions and 7 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "wled",
"version": "0.14.0.4.1",
"version": "0.14.0.4.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "wled",
"version": "0.14.0.4.1",
"version": "0.14.0.4.2",
"license": "ISC",
"dependencies": {
"clean-css": "^4.2.3",

View File

@@ -1,6 +1,6 @@
{
"name": "wled",
"version": "0.14.0.4.1",
"version": "0.14.0.4.2",
"description": "Tools for WLED project",
"main": "tools/cdata.js",
"directories": {

View File

@@ -633,6 +633,7 @@ typedef struct Segment {
void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB color) {}
void wu_pixel(uint32_t x, uint32_t y, CRGB c) {}
#endif
CRGBPalette16 getAudioPalette(); //WLEDMM netmindz ar palette
} segment;
//static int segSize = sizeof(Segment);

View File

@@ -278,6 +278,8 @@ CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) {
targetPalette = RainbowColors_p; break;
case 12: //Rainbow stripe colors
targetPalette = RainbowStripeColors_p; break;
case 71: //WLEDMM netmindz ar palette +1
targetPalette = getAudioPalette(); break;
default: //progmem palettes
if (pal>245) {
targetPalette = strip.customPalettes[255-pal]; // we checked bounds above
@@ -1137,6 +1139,38 @@ uint32_t Segment::color_from_palette(uint16_t i, bool mapping, bool wrap, uint8_
return RGBW32(fastled_col.r, fastled_col.g, fastled_col.b, 0);
}
//WLEDMM netmindz ar palette
CRGBPalette16 Segment::getAudioPalette() {
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t *fftResult = (uint8_t*)um_data->u_data[2];
uint8_t xyz[12]; // Needs to be 4 times however many colors are being used.
// 3 colors = 12, 4 colors = 16, etc.
CRGB rgb = getCRGBForBand(0, fftResult);
xyz[0] = 0; // anchor of first color - must be zero
xyz[1] = rgb.r;
xyz[2] = rgb.g;
xyz[3] = rgb.b;
rgb = getCRGBForBand(4, fftResult);
xyz[4] = 128;
xyz[5] = rgb.r;
xyz[6] = rgb.g;
xyz[7] = rgb.b;
rgb = getCRGBForBand(8, fftResult);
xyz[8] = 255; // anchor of last color - must be 255
xyz[9] = rgb.r;
xyz[10] = rgb.g;
xyz[11] = rgb.b;
return CRGBPalette16(xyz);
}
///////////////////////////////////////////////////////////////////////////////
// WS2812FX class implementation
@@ -1840,6 +1874,7 @@ uint8_t Bus::_cctBlend = 0;
uint8_t Bus::_gAWM = 255;
const char JSON_mode_names[] PROGMEM = R"=====(["FX names moved"])=====";
//WLEDMM netmindz ar palette add Audio responsive
const char JSON_palette_names[] PROGMEM = R"=====([
"Default","* Random Cycle","* Color 1","* Colors 1&2","* Color Gradient","* Colors Only","Party","Cloud","Lava","Ocean",
"Forest","Rainbow","Rainbow Bands","Sunset","Rivendell","Breeze","Red & Blue","Yellowout","Analogous","Splash",
@@ -1848,5 +1883,5 @@ const char JSON_palette_names[] PROGMEM = R"=====([
"Magenta","Magred","Yelmag","Yelblu","Orange & Teal","Tiamat","April Night","Orangery","C9","Sakura",
"Aurora","Atlantica","C9 2","C9 New","Temperature","Aurora 2","Retro Clown","Candy","Toxy Reaf","Fairy Reaf",
"Semi Blue","Pink Candy","Red Reaf","Aqua Flash","Yelblu Hot","Lite Light","Red Flash","Blink Red","Red Shift","Red Tide",
"Candy2"
"Candy2","Audio Responsive"
])=====";

View File

@@ -5,7 +5,7 @@
* Readability defines and their associated numerical values + compile-time constants
*/
#define GRADIENT_PALETTE_COUNT 58
#define GRADIENT_PALETTE_COUNT 59 //WLEDMM netmindz ar palette +1
//Defaults
#define DEFAULT_CLIENT_SSID "Your_Network"

View File

@@ -334,6 +334,7 @@ int16_t extractModeDefaults(uint8_t mode, const char *segVar);
uint16_t crc16(const unsigned char* data_p, size_t length);
um_data_t* simulateSound(uint8_t simulationId);
void enumerateLedmaps();
CRGB getCRGBForBand(int x, uint8_t *fftResult); //WLEDMM netmindz ar palette
#ifdef WLED_ADD_EEPROM_SUPPORT
//wled_eeprom.cpp

View File

@@ -844,6 +844,14 @@ const byte candy2_gp[] PROGMEM = {
211, 39, 33, 34,
255, 1, 1, 1};
//WLEDMM netmindz ar palette
// Start off as just RGB, but replace in runtime with colors relating to the music
const byte audio_responsive_gp[] PROGMEM = {
0, 255, 0, 0,
125, 0, 255, 0,
255, 0, 0, 255
};
// Single array of defined cpt-city color palettes.
// This will let us programmatically choose one based on
// a number, rather than having to activate each explicitly
@@ -906,7 +914,8 @@ const byte* const gGradientPalettes[] PROGMEM = {
blink_red_gp, //67-54 Blink Red
red_shift_gp, //68-55 Red Shift
red_tide_gp, //69-56 Red Tide
candy2_gp //70-57 Candy2
candy2_gp, //70-57 Candy2
audio_responsive_gp, //71-58 AudioResponsive WLEDMM netmindz ar palette
};
#endif

View File

@@ -513,4 +513,20 @@ void enumerateLedmaps() {
bool isFile = WLED_FS.exists(fileName);
if (isFile) ledMaps |= 1 << i;
}
}
//WLEDMM netmindz ar palette
CRGB getCRGBForBand(int x, uint8_t *fftResult) {
CRGB value;
CHSV hsv;
if(x == 0) {
value = CRGB(fftResult[10]/2, fftResult[4]/2, fftResult[0]/2);
}
else if(x == 255) {
value = CRGB(fftResult[10]/2, fftResult[0]/2, fftResult[4]/2);
}
else {
value = CRGB(fftResult[0]/2, fftResult[4]/2, fftResult[10]/2);
}
return value;
}

View File

@@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2211171
#define VERSION 2211181
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG