Some fixes.

Remove (*) palettes if not all 3 color selectors shown
Updated comments
This commit is contained in:
Blaz Kristan 2022-06-17 16:18:35 +02:00
parent f3364e1327
commit 0daddf9896
4 changed files with 3065 additions and 3002 deletions

View File

@ -536,7 +536,7 @@ class AudioReactive : public Usermod {
if (last_soundAgc != soundAgc) if (last_soundAgc != soundAgc)
control_integrated = 0.0f; // new preset - reset integrator 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 // so let's make sure that the control loop is not running at insane speed
static unsigned long last_time = 0; static unsigned long last_time = 0;
unsigned long time_now = millis(); unsigned long time_now = millis();
@ -549,7 +549,7 @@ class AudioReactive : public Usermod {
tmpAgc = 0; tmpAgc = 0;
// we need to "spin down" the intgrated error buffer // we need to "spin down" the intgrated error buffer
if (fabs(control_integrated) < 0.01f) control_integrated = 0.0f; if (fabs(control_integrated) < 0.01f) control_integrated = 0.0f;
else control_integrated = control_integrated * 0.91f; else control_integrated *= 0.91f;
} else { } else {
// compute new setpoint // compute new setpoint
if (tmpAgc <= agcTarget0Up[AGC_preset]) if (tmpAgc <= agcTarget0Up[AGC_preset])
@ -558,6 +558,7 @@ class AudioReactive : public Usermod {
multAgcTemp = agcTarget1[AGC_preset] / sampleMax; // Make the multiplier so that sampleMax * multiplier = second setpoint multAgcTemp = agcTarget1[AGC_preset] / sampleMax; // Make the multiplier so that sampleMax * multiplier = second setpoint
} }
// limit amplification // limit amplification
//multAgcTemp = constrain(multAgcTemp, 0.015625f, 32.0f); // 1/64 < multAgcTemp < 32
if (multAgcTemp > 32.0f) multAgcTemp = 32.0f; if (multAgcTemp > 32.0f) multAgcTemp = 32.0f;
if (multAgcTemp < 1.0f/64.0f) multAgcTemp = 1.0f/64.0f; if (multAgcTemp < 1.0f/64.0f) multAgcTemp = 1.0f/64.0f;
@ -581,6 +582,7 @@ class AudioReactive : public Usermod {
} }
// limit amplification again - PI controler sometimes "overshoots" // limit amplification again - PI controler sometimes "overshoots"
//multAgcTemp = constrain(multAgcTemp, 0.015625f, 32.0f); // 1/64 < multAgcTemp < 32
if (multAgcTemp > 32.0f) multAgcTemp = 32.0f; if (multAgcTemp > 32.0f) multAgcTemp = 32.0f;
if (multAgcTemp < 1.0f/64.0f) multAgcTemp = 1.0f/64.0f; if (multAgcTemp < 1.0f/64.0f) multAgcTemp = 1.0f/64.0f;
} }
@ -588,6 +590,7 @@ class AudioReactive : public Usermod {
// NOW finally amplify the signal // NOW finally amplify the signal
tmpAgc = sampleReal * multAgcTemp; // apply gain to signal tmpAgc = sampleReal * multAgcTemp; // apply gain to signal
if(fabs(sampleReal) < 2.0f) tmpAgc = 0; // apply squelch threshold 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 > 255) tmpAgc = 255; // limit to 8bit
if (tmpAgc < 1) tmpAgc = 0; // just to be sure if (tmpAgc < 1) tmpAgc = 0; // just to be sure
@ -600,8 +603,8 @@ class AudioReactive : public Usermod {
else else
sampleAgc = sampleAgc + agcSampleSmooth[AGC_preset] * (tmpAgc - sampleAgc); // smooth path sampleAgc = sampleAgc + agcSampleSmooth[AGC_preset] * (tmpAgc - sampleAgc); // smooth path
userVar0 = sampleAvg * 4; //userVar0 = sampleAvg * 4;
if (userVar0 > 255) userVar0 = 255; //if (userVar0 > 255) userVar0 = 255;
last_soundAgc = soundAgc; last_soundAgc = soundAgc;
} // agcAvg() } // agcAvg()
@ -656,9 +659,9 @@ class AudioReactive : public Usermod {
sampleMax = sampleMax + 0.5f * (sampleReal - sampleMax); // new peak - with some filtering sampleMax = sampleMax + 0.5f * (sampleReal - sampleMax); // new peak - with some filtering
} else { } else {
if ((multAgc*sampleMax > agcZoneStop[AGC_preset]) && (soundAgc > 0)) 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 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; if (sampleMax < 0.5f) sampleMax = 0.0f;
@ -677,14 +680,21 @@ class AudioReactive : public Usermod {
if (userVar1 == 0) samplePeak = 0; if (userVar1 == 0) samplePeak = 0;
// Poor man's beat detection by seeing if sample > Average + some value. // 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); // Serial.print(binNum); Serial.print("\t");
if ((fftBin[binNum] > maxVol) && (millis() > (timeOfPeak + 100))) { // This goe through ALL of the 255 bins // 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)) { // 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. // 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; samplePeak = 1;
timeOfPeak = millis(); timeOfPeak = millis();
udpSamplePeak = 1; udpSamplePeak = 1;
userVar1 = samplePeak; //userVar1 = samplePeak;
} }
} // getSample() } // getSample()

View File

@ -5946,6 +5946,48 @@ static const char *_data_FX_MODE_DRIFT_ROSE PROGMEM = "2D Drift Rose@Fade,Blur;;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/******************** audio enhanced routines ************************/ /******************** 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; double FFT_MajorPeak = 0.0;
um_data_t *um_data; um_data_t *um_data;
if (usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { 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]; binNum = (uint8_t*)um_data->u_data[5];
maxVol = (uint8_t*)um_data->u_data[0]; maxVol = (uint8_t*)um_data->u_data[0];
samplePeak = *(uint8_t*)um_data->u_data[4]; samplePeak = *(uint8_t*)um_data->u_data[4];
@ -7277,6 +7319,7 @@ uint16_t WS2812FX::mode_waterfall(void) { // Waterfall. By: An
um_data_t *um_data; um_data_t *um_data;
if (usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { if (usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
maxVol = (uint8_t*)um_data->u_data[0]; maxVol = (uint8_t*)um_data->u_data[0];
samplePeak = *(uint8_t*)um_data->u_data[4];
binNum = (uint8_t*)um_data->u_data[5]; binNum = (uint8_t*)um_data->u_data[5];
FFT_MajorPeak = *(double*)um_data->u_data[6]; FFT_MajorPeak = *(double*)um_data->u_data[6];
FFT_Magnitude = *(double*)um_data->u_data[7]; FFT_Magnitude = *(double*)um_data->u_data[7];

View File

@ -1328,6 +1328,7 @@ function setSliderAndColorControl(idx, applyDef=false)
var cslLabel = ''; var cslLabel = '';
var sep = ''; var sep = '';
var hide = true; var hide = true;
var cslCnt = 0;
for (let i=0; i<gId("csl").children.length; i++) { for (let i=0; i<gId("csl").children.length; i++) {
var btn = gId("csl" + i); var btn = gId("csl" + i);
// if no controlDefined or coOnOff has a value // 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 if (i==1) btn.innerHTML = "Bg";
else btn.innerHTML = "Cs"; else btn.innerHTML = "Cs";
hide = false; hide = false;
cslCnt++;
} else if (!controlDefined /*|| paOnOff.length>0*/) { // if no controls then all buttons should be shown for color 1..3 } else if (!controlDefined /*|| paOnOff.length>0*/) { // if no controls then all buttons should be shown for color 1..3
btn.style.display = "inline"; btn.style.display = "inline";
btn.innerHTML = `${i+1}`; btn.innerHTML = `${i+1}`;
hide = false; hide = false;
cslCnt++;
} else { } else {
btn.style.display = "none"; btn.style.display = "none";
if (i>0 && csel==i) selectSlot(0); if (i>0 && csel==i) selectSlot(0);
@ -1382,6 +1385,10 @@ function setSliderAndColorControl(idx, applyDef=false)
// if numeric set as selected palette // 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]); 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) if (!isEmpty(obj.seg) && applyDef) requestJson(obj); // update default values (may need throttling on ESP8266)
} }

File diff suppressed because it is too large Load Diff