Merge pull request #3 from netmindz/audio-palette-hue

Audio palette hue
This commit is contained in:
Ewoud
2022-11-19 14:22:27 +01:00
committed by GitHub
6 changed files with 35 additions and 22 deletions

View File

@@ -633,7 +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
uint8_t * getAudioPalette(int pal); //WLEDMM netmindz ar palette
} segment;
//static int segSize = sizeof(Segment);

View File

@@ -279,7 +279,8 @@ CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) {
case 12: //Rainbow stripe colors
targetPalette = RainbowStripeColors_p; break;
case 71: //WLEDMM netmindz ar palette +1
targetPalette = getAudioPalette(); break;
case 72: //WLEDMM netmindz ar palette +1
targetPalette.loadDynamicGradientPalette(getAudioPalette(pal)); break;
default: //progmem palettes
if (pal>245) {
targetPalette = strip.customPalettes[255-pal]; // we checked bounds above
@@ -1140,35 +1141,38 @@ uint32_t Segment::color_from_palette(uint16_t i, bool mapping, bool wrap, uint8_
}
//WLEDMM netmindz ar palette
CRGBPalette16 Segment::getAudioPalette() {
uint8_t * Segment::getAudioPalette(int pal) {
// https://forum.makerforums.info/t/hi-is-it-possible-to-define-a-gradient-palette-at-runtime-the-define-gradient-palette-uses-the/63339
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);
static 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, pal);
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);
rgb = getCRGBForBand(4, fftResult, pal);
xyz[4] = 128;
xyz[5] = rgb.r;
xyz[6] = rgb.g;
xyz[7] = rgb.b;
rgb = getCRGBForBand(8, fftResult);
rgb = getCRGBForBand(8, fftResult, pal);
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);
return xyz;
}
@@ -1883,5 +1887,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","Audio Responsive"
"Candy2","Audio Responsive Ratio","Audio Responsive Hue"
])=====";

View File

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

View File

@@ -334,7 +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
CRGB getCRGBForBand(int x, uint8_t *fftResult, int pal); //WLEDMM netmindz ar palette
#ifdef WLED_ADD_EEPROM_SUPPORT
//wled_eeprom.cpp

View File

@@ -915,7 +915,9 @@ const byte* const gGradientPalettes[] PROGMEM = {
red_shift_gp, //68-55 Red Shift
red_tide_gp, //69-56 Red Tide
candy2_gp, //70-57 Candy2
audio_responsive_gp, //71-58 AudioResponsive WLEDMM netmindz ar palette
// Palette contents not actually used as built on the fly, just here to create menu option
audio_responsive_gp, //71-58 AudioResponsive WLEDMM netmindz ar palette - placeholder1
audio_responsive_gp, //72-59 AudioResponsive WLEDMM netmindz ar palette - placeholder2
};
#endif

View File

@@ -516,17 +516,24 @@ void enumerateLedmaps() {
}
//WLEDMM netmindz ar palette
CRGB getCRGBForBand(int x, uint8_t *fftResult) {
CRGB getCRGBForBand(int x, uint8_t *fftResult, int pal) {
CRGB value;
CHSV hsv;
if(x == 0) {
value = CRGB(fftResult[10]/2, fftResult[4]/2, fftResult[0]/2);
if(pal == 71) { // bit hacky to use palette id here, but don't want to litter the code with lots of different methods. TODO: add enum for palette creation type
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);
}
}
else if(pal == 72) {
int b = map(x, 0, 255, 0, 8); // convert palette position to lower half of freq band
hsv = CHSV(fftResult[b], 255, map(fftResult[b], 0, 255, 30, 255)); // pick hue
hsv2rgb_rainbow(hsv, value); // convert to R,G,B
}
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;
}