Some fixes.
Remove (*) palettes if not all 3 color selectors shown Updated comments
This commit is contained in:
parent
f3364e1327
commit
0daddf9896
@ -536,7 +536,7 @@ class AudioReactive : public Usermod {
|
||||
if (last_soundAgc != soundAgc)
|
||||
control_integrated = 0.0f; // new preset - reset integrator
|
||||
|
||||
// For PI control, we need to have a contant "frequency"
|
||||
// For PI controller, we need to have a constant "frequency"
|
||||
// so let's make sure that the control loop is not running at insane speed
|
||||
static unsigned long last_time = 0;
|
||||
unsigned long time_now = millis();
|
||||
@ -548,8 +548,8 @@ class AudioReactive : public Usermod {
|
||||
//multAgcTemp = multAgc; // keep old control value (no change)
|
||||
tmpAgc = 0;
|
||||
// we need to "spin down" the intgrated error buffer
|
||||
if (fabs(control_integrated) < 0.01f) control_integrated = 0.0f;
|
||||
else control_integrated = control_integrated * 0.91f;
|
||||
if (fabs(control_integrated) < 0.01f) control_integrated = 0.0f;
|
||||
else control_integrated *= 0.91f;
|
||||
} else {
|
||||
// compute new setpoint
|
||||
if (tmpAgc <= agcTarget0Up[AGC_preset])
|
||||
@ -558,7 +558,8 @@ class AudioReactive : public Usermod {
|
||||
multAgcTemp = agcTarget1[AGC_preset] / sampleMax; // Make the multiplier so that sampleMax * multiplier = second setpoint
|
||||
}
|
||||
// limit amplification
|
||||
if (multAgcTemp > 32.0f) multAgcTemp = 32.0f;
|
||||
//multAgcTemp = constrain(multAgcTemp, 0.015625f, 32.0f); // 1/64 < multAgcTemp < 32
|
||||
if (multAgcTemp > 32.0f) multAgcTemp = 32.0f;
|
||||
if (multAgcTemp < 1.0f/64.0f) multAgcTemp = 1.0f/64.0f;
|
||||
|
||||
// compute error terms
|
||||
@ -581,27 +582,29 @@ class AudioReactive : public Usermod {
|
||||
}
|
||||
|
||||
// limit amplification again - PI controler sometimes "overshoots"
|
||||
if (multAgcTemp > 32.0f) multAgcTemp = 32.0f;
|
||||
//multAgcTemp = constrain(multAgcTemp, 0.015625f, 32.0f); // 1/64 < multAgcTemp < 32
|
||||
if (multAgcTemp > 32.0f) multAgcTemp = 32.0f;
|
||||
if (multAgcTemp < 1.0f/64.0f) multAgcTemp = 1.0f/64.0f;
|
||||
}
|
||||
|
||||
// NOW finally amplify the signal
|
||||
tmpAgc = sampleReal * multAgcTemp; // apply gain to signal
|
||||
if(fabs(sampleReal) < 2.0f) tmpAgc = 0; // apply squelch threshold
|
||||
//tmpAgc = constrain(tmpAgc, 0, 255);
|
||||
if (tmpAgc > 255) tmpAgc = 255; // limit to 8bit
|
||||
if (tmpAgc < 1) tmpAgc = 0; // just to be sure
|
||||
if (tmpAgc < 1) tmpAgc = 0; // just to be sure
|
||||
|
||||
// update global vars ONCE - multAgc, sampleAGC, rawSampleAgc
|
||||
multAgc = multAgcTemp;
|
||||
rawSampleAgc = 0.8f * tmpAgc + 0.2f * (float)rawSampleAgc;
|
||||
// update smoothed AGC sample
|
||||
if(fabs(tmpAgc) < 1.0f)
|
||||
if (fabs(tmpAgc) < 1.0f)
|
||||
sampleAgc = 0.5f * tmpAgc + 0.5f * sampleAgc; // fast path to zero
|
||||
else
|
||||
sampleAgc = sampleAgc + agcSampleSmooth[AGC_preset] * (tmpAgc - sampleAgc); // smooth path
|
||||
|
||||
userVar0 = sampleAvg * 4;
|
||||
if (userVar0 > 255) userVar0 = 255;
|
||||
//userVar0 = sampleAvg * 4;
|
||||
//if (userVar0 > 255) userVar0 = 255;
|
||||
|
||||
last_soundAgc = soundAgc;
|
||||
} // agcAvg()
|
||||
@ -656,9 +659,9 @@ class AudioReactive : public Usermod {
|
||||
sampleMax = sampleMax + 0.5f * (sampleReal - sampleMax); // new peak - with some filtering
|
||||
} else {
|
||||
if ((multAgc*sampleMax > agcZoneStop[AGC_preset]) && (soundAgc > 0))
|
||||
sampleMax = sampleMax + 0.5f * (sampleReal - sampleMax); // over AGC Zone - get back quickly
|
||||
sampleMax += 0.5f * (sampleReal - sampleMax); // over AGC Zone - get back quickly
|
||||
else
|
||||
sampleMax = sampleMax * agcSampleDecay[AGC_preset]; // signal to zero --> 5-8sec
|
||||
sampleMax *= agcSampleDecay[AGC_preset]; // signal to zero --> 5-8sec
|
||||
}
|
||||
if (sampleMax < 0.5f) sampleMax = 0.0f;
|
||||
|
||||
@ -677,14 +680,21 @@ class AudioReactive : public Usermod {
|
||||
|
||||
if (userVar1 == 0) samplePeak = 0;
|
||||
// Poor man's beat detection by seeing if sample > Average + some value.
|
||||
// Serial.print(binNum); Serial.print("\t"); Serial.print(fftBin[binNum]); Serial.print("\t"); Serial.print(fftAvg[binNum/16]); Serial.print("\t"); Serial.print(maxVol); Serial.print("\t"); Serial.println(samplePeak);
|
||||
if ((fftBin[binNum] > maxVol) && (millis() > (timeOfPeak + 100))) { // This goe through ALL of the 255 bins
|
||||
// Serial.print(binNum); Serial.print("\t");
|
||||
// Serial.print(fftBin[binNum]);
|
||||
// Serial.print("\t");
|
||||
// Serial.print(fftAvg[binNum/16]);
|
||||
// Serial.print("\t");
|
||||
// Serial.print(maxVol);
|
||||
// Serial.print("\t");
|
||||
// Serial.println(samplePeak);
|
||||
if ((fftBin[binNum] > maxVol) && (millis() > (timeOfPeak + 100))) { // This goes through ALL of the 255 bins
|
||||
// if (sample > (sampleAvg + maxVol) && millis() > (timeOfPeak + 200)) {
|
||||
// Then we got a peak, else we don't. The peak has to time out on its own in order to support UDP sound sync.
|
||||
samplePeak = 1;
|
||||
timeOfPeak = millis();
|
||||
udpSamplePeak = 1;
|
||||
userVar1 = samplePeak;
|
||||
//userVar1 = samplePeak;
|
||||
}
|
||||
} // getSample()
|
||||
|
||||
|
@ -5946,6 +5946,48 @@ static const char *_data_FX_MODE_DRIFT_ROSE PROGMEM = "2D Drift Rose@Fade,Blur;;
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/******************** audio enhanced routines ************************/
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/* use the following code to pass AudioReactive usermod variables to effect
|
||||
|
||||
uint8_t *binNum = (uint8_t*)&SEGENV.aux1, *maxVol = (uint8_t*)(&SEGENV.aux1+1); // just in case assignment
|
||||
uint16_t sample = 0;
|
||||
uint8_t soundAgc = 0, soundSquelch = 10;
|
||||
uint8_t samplePeak = 0;
|
||||
float sampleAgc = 0.0f, sampleAgv = 0.0f, multAgc = 0.0f, sampleReal = 0.0f;
|
||||
float *fftBin = nullptr;
|
||||
double FFT_MajorPeak = 0.0, FFT_Magnitude = 0.0;
|
||||
uint8_t *fftResult = nullptr;
|
||||
uint16_t *myVals = nullptr;
|
||||
um_data_t *um_data;
|
||||
if (usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
|
||||
maxVol = (uint8_t*)um_data->u_data[0]; // requires UI element (SEGMENT.customX?)
|
||||
fftResult = (uint8_t*)um_data->u_data[1];
|
||||
sample = *(uint16_t*)um_data->u_data[2];
|
||||
rawSampleAgc = *(uint16_t*)um_data->u_data[3];
|
||||
samplePeak = *(uint8_t*)um_data->u_data[4];
|
||||
binNum = (uint8_t*)um_data->u_data[5]; // requires UI element (SEGMENT.customX?)
|
||||
FFT_MajorPeak = *(double*)um_data->u_data[6];
|
||||
FFT_Magnitude = *(double*)um_data->u_data[7];
|
||||
sampleAvg = *(float*)um_data->u_data[8];
|
||||
soundAgc = *(uint8_t*)um_data->u_data[9];
|
||||
sampleAgc = *(float*)um_data->u_data[10];
|
||||
multAgc = *(float*)um_data->u_data[11];
|
||||
sampleReal = *(float*)um_data->u_data[12];
|
||||
sampleGain = *(float*)um_data->u_data[13];
|
||||
myVals = (uint16_t*)um_data->u_data[14];
|
||||
soundSquelch = *(uint8_t*)um_data->u_data[15];
|
||||
fftBin = (float*)um_data->u_data[16];
|
||||
inputLevel = (uint8_t*)um_data->u_data[17]; // requires UI element (SEGMENT.customX?)
|
||||
} else {
|
||||
// add support for no audio data
|
||||
uint32_t ms = millis();
|
||||
sample = inoise8(beatsin8(120, 10, 30)*10 + (ms>>14), ms>>3);
|
||||
sample = map(sample, 50, 190, 0, 224);
|
||||
sampleAvg = inoise8(beatsin8(90, 0, 200)*15 + (ms>>10), ms>>3);
|
||||
samplePeak = random8() > 250; // or use: sample==224
|
||||
FFT_MajorPeak = inoise8(beatsin8(90, 0, 200)*15 + (ms>>10), ms>>3);
|
||||
}
|
||||
if (!myVals || !fftBin || ...) return mode_static();
|
||||
*/
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
@ -5965,7 +6007,7 @@ uint16_t WS2812FX::mode_ripplepeak(void) { // * Ripple peak. By A
|
||||
double FFT_MajorPeak = 0.0;
|
||||
um_data_t *um_data;
|
||||
if (usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
|
||||
FFT_MajorPeak = *(double*)um_data->u_data[8];
|
||||
FFT_MajorPeak = *(double*)um_data->u_data[6];
|
||||
binNum = (uint8_t*)um_data->u_data[5];
|
||||
maxVol = (uint8_t*)um_data->u_data[0];
|
||||
samplePeak = *(uint8_t*)um_data->u_data[4];
|
||||
@ -5978,8 +6020,8 @@ uint16_t WS2812FX::mode_ripplepeak(void) { // * Ripple peak. By A
|
||||
|
||||
if (SEGENV.call == 0) SEGENV.aux0 = 255;
|
||||
|
||||
*binNum = SEGMENT.custom2; // Select a bin.
|
||||
*maxVol = SEGMENT.custom3/2; // Our volume comparator.
|
||||
*binNum = SEGMENT.custom2; // Select a bin.
|
||||
*maxVol = SEGMENT.custom3/2; // Our volume comparator.
|
||||
|
||||
fade_out(240); // Lower frame rate means less effective fading than FastLED
|
||||
fade_out(240);
|
||||
@ -6054,7 +6096,7 @@ uint16_t WS2812FX::mode_2DSwirl(void) {
|
||||
float sampleAvg = 0.0f;
|
||||
um_data_t *um_data;
|
||||
if (usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
|
||||
soundAgc = *(uint8_t*)um_data->u_data[9];
|
||||
soundAgc = *(uint8_t*)um_data->u_data[9];
|
||||
rawSampleAgc = *(int16_t*)um_data->u_data[3];
|
||||
sample = *(int16_t*)um_data->u_data[2];
|
||||
sampleAvg = *(float*)um_data->u_data[8];
|
||||
@ -7277,6 +7319,7 @@ uint16_t WS2812FX::mode_waterfall(void) { // Waterfall. By: An
|
||||
um_data_t *um_data;
|
||||
if (usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
|
||||
maxVol = (uint8_t*)um_data->u_data[0];
|
||||
samplePeak = *(uint8_t*)um_data->u_data[4];
|
||||
binNum = (uint8_t*)um_data->u_data[5];
|
||||
FFT_MajorPeak = *(double*)um_data->u_data[6];
|
||||
FFT_Magnitude = *(double*)um_data->u_data[7];
|
||||
|
@ -1328,6 +1328,7 @@ function setSliderAndColorControl(idx, applyDef=false)
|
||||
var cslLabel = '';
|
||||
var sep = '';
|
||||
var hide = true;
|
||||
var cslCnt = 0;
|
||||
for (let i=0; i<gId("csl").children.length; i++) {
|
||||
var btn = gId("csl" + i);
|
||||
// if no controlDefined or coOnOff has a value
|
||||
@ -1345,10 +1346,12 @@ function setSliderAndColorControl(idx, applyDef=false)
|
||||
else if (i==1) btn.innerHTML = "Bg";
|
||||
else btn.innerHTML = "Cs";
|
||||
hide = false;
|
||||
cslCnt++;
|
||||
} else if (!controlDefined /*|| paOnOff.length>0*/) { // if no controls then all buttons should be shown for color 1..3
|
||||
btn.style.display = "inline";
|
||||
btn.innerHTML = `${i+1}`;
|
||||
hide = false;
|
||||
cslCnt++;
|
||||
} else {
|
||||
btn.style.display = "none";
|
||||
if (i>0 && csel==i) selectSlot(0);
|
||||
@ -1382,6 +1385,10 @@ function setSliderAndColorControl(idx, applyDef=false)
|
||||
// if numeric set as selected palette
|
||||
if (paOnOff.length>0 && paOnOff[0]!="" && !isNaN(paOnOff[0]) && parseInt(paOnOff[0])!=selectedPal) obj.seg.pal = parseInt(paOnOff[0]);
|
||||
}
|
||||
// not all color selectors shown, hide palettes created from color selectors
|
||||
for (let e of (gId('pallist').querySelectorAll('.lstI')||[])) {
|
||||
if (cslCnt < 3 && e.querySelector('.lstIname').innerText.indexOf("* ")>=0) e.classList.add('hide'); else e.classList.remove('hide');
|
||||
}
|
||||
if (!isEmpty(obj.seg) && applyDef) requestJson(obj); // update default values (may need throttling on ESP8266)
|
||||
}
|
||||
|
||||
|
3529
wled00/html_ui.h
3529
wled00/html_ui.h
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user