Code sanitation.
Default analog pin -1
This commit is contained in:
parent
d053bc562f
commit
720fae8720
@ -173,7 +173,6 @@ void FFTcode(void * parameter)
|
|||||||
|
|
||||||
// see https://www.freertos.org/vtaskdelayuntil.html
|
// see https://www.freertos.org/vtaskdelayuntil.html
|
||||||
const TickType_t xFrequency = FFT_MIN_CYCLE * portTICK_PERIOD_MS;
|
const TickType_t xFrequency = FFT_MIN_CYCLE * portTICK_PERIOD_MS;
|
||||||
//const TickType_t xFrequency_2 = (FFT_MIN_CYCLE * portTICK_PERIOD_MS) / 2;
|
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
TickType_t xLastWakeTime = xTaskGetTickCount();
|
TickType_t xLastWakeTime = xTaskGetTickCount();
|
||||||
@ -208,8 +207,8 @@ void FFTcode(void * parameter)
|
|||||||
if ((vReal[i] <= (INT16_MAX - 1024)) && (vReal[i] >= (INT16_MIN + 1024))) //skip extreme values - normally these are artefacts
|
if ((vReal[i] <= (INT16_MAX - 1024)) && (vReal[i] >= (INT16_MIN + 1024))) //skip extreme values - normally these are artefacts
|
||||||
if (fabsf((float)vReal[i]) > maxSample) maxSample = fabsf((float)vReal[i]);
|
if (fabsf((float)vReal[i]) > maxSample) maxSample = fabsf((float)vReal[i]);
|
||||||
}
|
}
|
||||||
// release sample to volume reactive effects
|
// release sample to volume reactive effects (not really necessary as float FFT calculation takes only 2ms)
|
||||||
micDataReal = maxSample; // doing this early allows filters (getSample() and agcAvg()) to run on latest values - we'll have up-to-date gain and noise gate values when FFT is done
|
micDataReal = maxSample;
|
||||||
|
|
||||||
// run FFT
|
// run FFT
|
||||||
#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
|
#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
|
||||||
@ -228,10 +227,6 @@ void FFTcode(void * parameter)
|
|||||||
FFT.Compute( FFT_FORWARD ); // Compute FFT
|
FFT.Compute( FFT_FORWARD ); // Compute FFT
|
||||||
FFT.ComplexToMagnitude(); // Compute magnitudes
|
FFT.ComplexToMagnitude(); // Compute magnitudes
|
||||||
#endif
|
#endif
|
||||||
//
|
|
||||||
// vReal[3 .. 255] contain useful data, each a 20Hz interval (60Hz - 5120Hz).
|
|
||||||
// There could be interesting data at bins 0 to 2, but there are too many artifacts.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
|
#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
|
||||||
FFT.majorPeak(FFT_MajorPeak, FFT_Magnitude); // let the effects know which freq was most dominant
|
FFT.majorPeak(FFT_MajorPeak, FFT_Magnitude); // let the effects know which freq was most dominant
|
||||||
@ -240,9 +235,9 @@ void FFTcode(void * parameter)
|
|||||||
#endif
|
#endif
|
||||||
FFT_MajorPeak = constrain(FFT_MajorPeak, 1.0f, 11025.0f); // restrict value to range expected by effects
|
FFT_MajorPeak = constrain(FFT_MajorPeak, 1.0f, 11025.0f); // restrict value to range expected by effects
|
||||||
|
|
||||||
for (int i = 0; i < samplesFFT_2; i++) { // Values for bins 0 and 1 are WAY too large. Might as well start at 3.
|
for (int i = 0; i < samplesFFT_2; i++) { // Values for bins 0 and 1 are WAY too large. Might as well start at 3.
|
||||||
float t = fabsf(vReal[i]); // just to be sure - values in fft bins should be positive any way
|
float t = fabsf(vReal[i]); // just to be sure - values in fft bins should be positive any way
|
||||||
fftBin[i] = t / 16.0f; // Reduce magnitude. Want end result to be linear and ~4096 max.
|
fftBin[i] = t / 16.0f; // Reduce magnitude. Want end result to be linear and ~4096 max.
|
||||||
} // for()
|
} // for()
|
||||||
|
|
||||||
|
|
||||||
@ -294,7 +289,6 @@ void FFTcode(void * parameter)
|
|||||||
fftCalc[15] = fftAddAvg(165,215) * 0.70f; // 50 7106 - 9259 high -- with some damping
|
fftCalc[15] = fftAddAvg(165,215) * 0.70f; // 50 7106 - 9259 high -- with some damping
|
||||||
// don't use the last bins from 216 to 255. They are usually contaminated by aliasing (aka noise)
|
// don't use the last bins from 216 to 255. They are usually contaminated by aliasing (aka noise)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else { // noise gate closed
|
} else { // noise gate closed
|
||||||
for (int i=0; i < 16; i++) {
|
for (int i=0; i < 16; i++) {
|
||||||
//fftCalc[i] *= 0.82f; // decay to zero
|
//fftCalc[i] *= 0.82f; // decay to zero
|
||||||
@ -316,7 +310,7 @@ void FFTcode(void * parameter)
|
|||||||
|
|
||||||
// smooth results - rise fast, fall slower
|
// smooth results - rise fast, fall slower
|
||||||
if(fftCalc[i] > fftAvg[i]) // rise fast
|
if(fftCalc[i] > fftAvg[i]) // rise fast
|
||||||
fftAvg[i] = fftCalc[i] *0.75f + 0.25f*fftAvg[i]; // will need approx 2 cycles (50ms) for converging against fftCalc[i]
|
fftAvg[i] = fftCalc[i] *0.75f + 0.25f*fftAvg[i]; // will need approx 2 cycles (50ms) for converging against fftCalc[i]
|
||||||
else { // fall slow
|
else { // fall slow
|
||||||
if (decayTime < 1000) fftAvg[i] = fftCalc[i]*0.22f + 0.78f*fftAvg[i]; // approx 5 cycles (225ms) for falling to zero
|
if (decayTime < 1000) fftAvg[i] = fftCalc[i]*0.22f + 0.78f*fftAvg[i]; // approx 5 cycles (225ms) for falling to zero
|
||||||
else if (decayTime < 2000) fftAvg[i] = fftCalc[i]*0.17f + 0.83f*fftAvg[i]; // default - approx 9 cycles (225ms) for falling to zero
|
else if (decayTime < 2000) fftAvg[i] = fftCalc[i]*0.17f + 0.83f*fftAvg[i]; // default - approx 9 cycles (225ms) for falling to zero
|
||||||
@ -336,29 +330,27 @@ void FFTcode(void * parameter)
|
|||||||
switch (FFTScalingMode) {
|
switch (FFTScalingMode) {
|
||||||
case 1:
|
case 1:
|
||||||
// Logarithmic scaling
|
// Logarithmic scaling
|
||||||
currentResult *= 0.42; // 42 is the answer ;-)
|
currentResult *= 0.42; // 42 is the answer ;-)
|
||||||
currentResult -= 8.0; // this skips the lowest row, giving some room for peaks
|
currentResult -= 8.0; // this skips the lowest row, giving some room for peaks
|
||||||
if (currentResult > 1.0)
|
if (currentResult > 1.0) currentResult = logf(currentResult); // log to base "e", which is the fastest log() function
|
||||||
currentResult = logf(currentResult); // log to base "e", which is the fastest log() function
|
else currentResult = 0.0; // special handling, because log(1) = 0; log(0) = undefined
|
||||||
else currentResult = 0.0; // special handling, because log(1) = 0; log(0) = undefined
|
currentResult *= 0.85f + (float(i)/18.0f); // extra up-scaling for high frequencies
|
||||||
currentResult *= 0.85f + (float(i)/18.0f); // extra up-scaling for high frequencies
|
|
||||||
currentResult = mapf(currentResult, 0, LOG_256, 0, 255); // map [log(1) ... log(255)] to [0 ... 255]
|
currentResult = mapf(currentResult, 0, LOG_256, 0, 255); // map [log(1) ... log(255)] to [0 ... 255]
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// Linear scaling
|
// Linear scaling
|
||||||
currentResult *= 0.30f; // needs a bit more damping, get stay below 255
|
currentResult *= 0.30f; // needs a bit more damping, get stay below 255
|
||||||
currentResult -= 4.0; // giving a bit more room for peaks
|
currentResult -= 4.0; // giving a bit more room for peaks
|
||||||
if (currentResult < 1.0f) currentResult = 0.0f;
|
if (currentResult < 1.0f) currentResult = 0.0f;
|
||||||
currentResult *= 0.85f + (float(i)/1.8f); // extra up-scaling for high frequencies
|
currentResult *= 0.85f + (float(i)/1.8f); // extra up-scaling for high frequencies
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// square root scaling
|
// square root scaling
|
||||||
currentResult *= 0.38f;
|
currentResult *= 0.38f;
|
||||||
currentResult -= 6.0f;
|
currentResult -= 6.0f;
|
||||||
if (currentResult > 1.0)
|
if (currentResult > 1.0) currentResult = sqrtf(currentResult);
|
||||||
currentResult = sqrtf(currentResult);
|
else currentResult = 0.0; // special handling, because sqrt(0) = undefined
|
||||||
else currentResult = 0.0; // special handling, because sqrt(0) = undefined
|
currentResult *= 0.85f + (float(i)/4.5f); // extra up-scaling for high frequencies
|
||||||
currentResult *= 0.85f + (float(i)/4.5f); // extra up-scaling for high frequencies
|
|
||||||
currentResult = mapf(currentResult, 0.0, 16.0, 0.0, 255.0); // map [sqrt(1) ... sqrt(256)] to [0 ... 255]
|
currentResult = mapf(currentResult, 0.0, 16.0, 0.0, 255.0); // map [sqrt(1) ... sqrt(256)] to [0 ... 255]
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -394,7 +386,7 @@ class AudioReactive : public Usermod {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
#ifndef AUDIOPIN
|
#ifndef AUDIOPIN
|
||||||
int8_t audioPin = 36;
|
int8_t audioPin = -1;
|
||||||
#else
|
#else
|
||||||
int8_t audioPin = AUDIOPIN;
|
int8_t audioPin = AUDIOPIN;
|
||||||
#endif
|
#endif
|
||||||
@ -615,7 +607,6 @@ class AudioReactive : public Usermod {
|
|||||||
|
|
||||||
if((fabs(sampleReal) < 2.0f) || (sampleMax < 1.0f)) {
|
if((fabs(sampleReal) < 2.0f) || (sampleMax < 1.0f)) {
|
||||||
// MIC signal is "squelched" - deliver silence
|
// MIC signal is "squelched" - deliver silence
|
||||||
//multAgcTemp = multAgc; // keep old control value (no change)
|
|
||||||
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.01) control_integrated = 0.0;
|
if (fabs(control_integrated) < 0.01) control_integrated = 0.0;
|
||||||
@ -623,27 +614,26 @@ class AudioReactive : public Usermod {
|
|||||||
} else {
|
} else {
|
||||||
// compute new setpoint
|
// compute new setpoint
|
||||||
if (tmpAgc <= agcTarget0Up[AGC_preset])
|
if (tmpAgc <= agcTarget0Up[AGC_preset])
|
||||||
multAgcTemp = agcTarget0[AGC_preset] / sampleMax; // Make the multiplier so that sampleMax * multiplier = first setpoint
|
multAgcTemp = agcTarget0[AGC_preset] / sampleMax; // Make the multiplier so that sampleMax * multiplier = first setpoint
|
||||||
else
|
else
|
||||||
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;
|
||||||
|
|
||||||
// compute error terms
|
// compute error terms
|
||||||
control_error = multAgcTemp - lastMultAgc;
|
control_error = multAgcTemp - lastMultAgc;
|
||||||
|
|
||||||
if (((multAgcTemp > 0.085f) && (multAgcTemp < 6.5f)) //integrator anti-windup by clamping
|
if (((multAgcTemp > 0.085f) && (multAgcTemp < 6.5f)) //integrator anti-windup by clamping
|
||||||
&& (multAgc*sampleMax < agcZoneStop[AGC_preset])) //integrator ceiling (>140% of max)
|
&& (multAgc*sampleMax < agcZoneStop[AGC_preset])) //integrator ceiling (>140% of max)
|
||||||
control_integrated += control_error * 0.002 * 0.25; // 2ms = intgration time; 0.25 for damping
|
control_integrated += control_error * 0.002 * 0.25; // 2ms = intgration time; 0.25 for damping
|
||||||
else
|
else
|
||||||
control_integrated *= 0.9; // spin down that beasty integrator
|
control_integrated *= 0.9; // spin down that beasty integrator
|
||||||
|
|
||||||
// apply PI Control
|
// apply PI Control
|
||||||
tmpAgc = sampleReal * lastMultAgc; // check "zone" of the signal using previous gain
|
tmpAgc = sampleReal * lastMultAgc; // check "zone" of the signal using previous gain
|
||||||
if ((tmpAgc > agcZoneHigh[AGC_preset]) || (tmpAgc < soundSquelch + agcZoneLow[AGC_preset])) { // upper/lower emergy zone
|
if ((tmpAgc > agcZoneHigh[AGC_preset]) || (tmpAgc < soundSquelch + agcZoneLow[AGC_preset])) { // upper/lower emergy zone
|
||||||
multAgcTemp = lastMultAgc + agcFollowFast[AGC_preset] * agcControlKp[AGC_preset] * control_error;
|
multAgcTemp = lastMultAgc + agcFollowFast[AGC_preset] * agcControlKp[AGC_preset] * control_error;
|
||||||
multAgcTemp += agcFollowFast[AGC_preset] * agcControlKi[AGC_preset] * control_integrated;
|
multAgcTemp += agcFollowFast[AGC_preset] * agcControlKi[AGC_preset] * control_integrated;
|
||||||
} else { // "normal zone"
|
} else { // "normal zone"
|
||||||
@ -673,9 +663,6 @@ class AudioReactive : public Usermod {
|
|||||||
else
|
else
|
||||||
sampleAgc += agcSampleSmooth[AGC_preset] * (tmpAgc - sampleAgc); // smooth path
|
sampleAgc += agcSampleSmooth[AGC_preset] * (tmpAgc - sampleAgc); // smooth path
|
||||||
|
|
||||||
//userVar0 = sampleAvg * 4;
|
|
||||||
//if (userVar0 > 255) userVar0 = 255;
|
|
||||||
|
|
||||||
last_soundAgc = soundAgc;
|
last_soundAgc = soundAgc;
|
||||||
} // agcAvg()
|
} // agcAvg()
|
||||||
|
|
||||||
@ -711,7 +698,7 @@ class AudioReactive : public Usermod {
|
|||||||
micLev = ((micLev * 8191.0f) + micDataReal) / 8192.0f; // takes a few seconds to "catch up" with the Mic Input
|
micLev = ((micLev * 8191.0f) + micDataReal) / 8192.0f; // takes a few seconds to "catch up" with the Mic Input
|
||||||
if(micIn < micLev) micLev = ((micLev * 31.0f) + micDataReal) / 32.0f; // align MicLev to lowest input signal
|
if(micIn < micLev) micLev = ((micLev * 31.0f) + micDataReal) / 32.0f; // align MicLev to lowest input signal
|
||||||
|
|
||||||
micIn -= micLev; // Let's center it to 0 now
|
micIn -= micLev; // Let's center it to 0 now
|
||||||
// Using an exponential filter to smooth out the signal. We'll add controls for this in a future release.
|
// Using an exponential filter to smooth out the signal. We'll add controls for this in a future release.
|
||||||
float micInNoDC = fabs(micDataReal - micLev);
|
float micInNoDC = fabs(micDataReal - micLev);
|
||||||
expAdjF = (weighting * micInNoDC + (1.0-weighting) * expAdjF);
|
expAdjF = (weighting * micInNoDC + (1.0-weighting) * expAdjF);
|
||||||
@ -725,12 +712,12 @@ class AudioReactive : public Usermod {
|
|||||||
sampleAdj = tmpSample * sampleGain / 40.0f * inputLevel/128.0f + tmpSample / 16.0f; // Adjust the gain. with inputLevel adjustment
|
sampleAdj = tmpSample * sampleGain / 40.0f * inputLevel/128.0f + tmpSample / 16.0f; // Adjust the gain. with inputLevel adjustment
|
||||||
sampleReal = tmpSample;
|
sampleReal = tmpSample;
|
||||||
|
|
||||||
sampleAdj = fmax(fmin(sampleAdj, 255), 0); // Question: why are we limiting the value to 8 bits ???
|
sampleAdj = fmax(fmin(sampleAdj, 255), 0); // Question: why are we limiting the value to 8 bits ???
|
||||||
sampleRaw = (int16_t)sampleAdj; // ONLY update sample ONCE!!!!
|
sampleRaw = (int16_t)sampleAdj; // ONLY update sample ONCE!!!!
|
||||||
|
|
||||||
// keep "peak" sample, but decay value if current sample is below peak
|
// keep "peak" sample, but decay value if current sample is below peak
|
||||||
if ((sampleMax < sampleReal) && (sampleReal > 0.5f)) {
|
if ((sampleMax < sampleReal) && (sampleReal > 0.5f)) {
|
||||||
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 += 0.5f * (sampleReal - sampleMax); // over AGC Zone - get back quickly
|
sampleMax += 0.5f * (sampleReal - sampleMax); // over AGC Zone - get back quickly
|
||||||
@ -751,13 +738,12 @@ 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.
|
||||||
// if (sample > (sampleAvg + maxVol) && millis() > (timeOfPeak + 200)) {
|
if ((maxVol > 0) && (binNum > 1) && (fftBin[binNum] > maxVol) && (millis() > (timeOfPeak + 100))) {
|
||||||
if ((maxVol > 0) && (binNum > 1) && (fftBin[binNum] > maxVol) && (millis() > (timeOfPeak + 100))) { // This goes through ALL of the 255 bins - but ignores stupid settings
|
// This goes through ALL of the 255 bins - but ignores stupid settings
|
||||||
// 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 = true;
|
samplePeak = true;
|
||||||
timeOfPeak = millis();
|
timeOfPeak = millis();
|
||||||
udpSamplePeak = true;
|
udpSamplePeak = true;
|
||||||
//userVar1 = samplePeak;
|
|
||||||
}
|
}
|
||||||
} // getSample()
|
} // getSample()
|
||||||
|
|
||||||
@ -771,7 +757,7 @@ class AudioReactive : public Usermod {
|
|||||||
static unsigned long last_time = 0;
|
static unsigned long last_time = 0;
|
||||||
static float last_volumeSmth = 0.0f;
|
static float last_volumeSmth = 0.0f;
|
||||||
|
|
||||||
if(limiterOn == false) return;
|
if (limiterOn == false) return;
|
||||||
|
|
||||||
long delta_time = millis() - last_time;
|
long delta_time = millis() - last_time;
|
||||||
delta_time = constrain(delta_time , 1, 1000); // below 1ms -> 1ms; above 1sec -> sily lil hick-up
|
delta_time = constrain(delta_time , 1, 1000); // below 1ms -> 1ms; above 1sec -> sily lil hick-up
|
||||||
@ -1043,7 +1029,7 @@ class AudioReactive : public Usermod {
|
|||||||
|
|
||||||
if (audioSyncEnabled & 0x02) disableSoundProcessing = true; // make sure everything is disabled IF in audio Receive mode
|
if (audioSyncEnabled & 0x02) disableSoundProcessing = true; // make sure everything is disabled IF in audio Receive mode
|
||||||
if (audioSyncEnabled & 0x01) disableSoundProcessing = false; // keep running audio IF we're in audio Transmit mode
|
if (audioSyncEnabled & 0x01) disableSoundProcessing = false; // keep running audio IF we're in audio Transmit mode
|
||||||
if(!audioSource->isInitialized()) disableSoundProcessing = true; // no audio source
|
if (!audioSource->isInitialized()) disableSoundProcessing = true; // no audio source
|
||||||
|
|
||||||
|
|
||||||
// Only run the sampling code IF we're not in Receive mode or realtime mode
|
// Only run the sampling code IF we're not in Receive mode or realtime mode
|
||||||
@ -1070,7 +1056,7 @@ class AudioReactive : public Usermod {
|
|||||||
agcAvg(t_now - userloopDelay); // Calculated the PI adjusted value as sampleAvg
|
agcAvg(t_now - userloopDelay); // Calculated the PI adjusted value as sampleAvg
|
||||||
userloopDelay -= 2; // advance "simulated time" by 2ms
|
userloopDelay -= 2; // advance "simulated time" by 2ms
|
||||||
} while (userloopDelay > 0);
|
} while (userloopDelay > 0);
|
||||||
lastUMRun = t_now; // update time keeping
|
lastUMRun = t_now; // update time keeping
|
||||||
|
|
||||||
// update samples for effects (raw, smooth)
|
// update samples for effects (raw, smooth)
|
||||||
volumeSmth = (soundAgc) ? sampleAgc : sampleAvg;
|
volumeSmth = (soundAgc) ? sampleAgc : sampleAvg;
|
||||||
@ -1078,7 +1064,7 @@ class AudioReactive : public Usermod {
|
|||||||
// update FFTMagnitude, taking into account AGC amplification
|
// update FFTMagnitude, taking into account AGC amplification
|
||||||
my_magnitude = FFT_Magnitude; // / 16.0f, 8.0f, 4.0f done in effects
|
my_magnitude = FFT_Magnitude; // / 16.0f, 8.0f, 4.0f done in effects
|
||||||
if (soundAgc) my_magnitude *= multAgc;
|
if (soundAgc) my_magnitude *= multAgc;
|
||||||
if (volumeSmth < 1 ) my_magnitude = 0.001f; // noise gate closed - mute
|
if (volumeSmth < 1 ) my_magnitude = 0.001f; // noise gate closed - mute
|
||||||
|
|
||||||
limitSampleDynamics(); // optional - makes volumeSmth very smooth and fluent
|
limitSampleDynamics(); // optional - makes volumeSmth very smooth and fluent
|
||||||
}
|
}
|
||||||
@ -1239,61 +1225,62 @@ class AudioReactive : public Usermod {
|
|||||||
uiDomString += F(" /><div class=\"sliderdisplay\"></div></div></div>"); //<output class=\"sliderbubble\"></output>
|
uiDomString += F(" /><div class=\"sliderdisplay\"></div></div></div>"); //<output class=\"sliderbubble\"></output>
|
||||||
infoArr.add(uiDomString);
|
infoArr.add(uiDomString);
|
||||||
}
|
}
|
||||||
//else infoArr.add("<br/> <div> </div>"); // no processing - add empty line
|
|
||||||
|
// The following can be used for troubleshooting user errors and is so not enclosed in #ifdef WLED_DEBUG
|
||||||
|
|
||||||
// current Audio input
|
// current Audio input
|
||||||
infoArr = user.createNestedArray(F("Audio Source"));
|
infoArr = user.createNestedArray(F("Audio Source"));
|
||||||
if (audioSyncEnabled & 0x02) {
|
if (audioSyncEnabled & 0x02) {
|
||||||
// UDP sound sync - receive mode
|
// UDP sound sync - receive mode
|
||||||
infoArr.add("UDP sound sync");
|
infoArr.add(F("UDP sound sync"));
|
||||||
if (udpSyncConnected) {
|
if (udpSyncConnected) {
|
||||||
if (millis() - last_UDPTime < 2500)
|
if (millis() - last_UDPTime < 2500)
|
||||||
infoArr.add(" - receiving");
|
infoArr.add(F(" - receiving"));
|
||||||
else
|
else
|
||||||
infoArr.add(" - idle");
|
infoArr.add(F(" - idle"));
|
||||||
} else {
|
} else {
|
||||||
infoArr.add(" - no connection");
|
infoArr.add(F(" - no connection"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Analog or I2S digital input
|
// Analog or I2S digital input
|
||||||
if (audioSource && (audioSource->isInitialized())) {
|
if (audioSource && (audioSource->isInitialized())) {
|
||||||
// audio source sucessfully configured
|
// audio source sucessfully configured
|
||||||
if(audioSource->getType() == AudioSource::Type_I2SAdc) {
|
if (audioSource->getType() == AudioSource::Type_I2SAdc) {
|
||||||
infoArr.add("ADC analog");
|
infoArr.add(F("ADC analog"));
|
||||||
} else {
|
} else {
|
||||||
infoArr.add("I2S digital");
|
infoArr.add(F("I2S digital"));
|
||||||
}
|
}
|
||||||
// input level or "silence"
|
// input level or "silence"
|
||||||
if (maxSample5sec > 1.0) {
|
if (maxSample5sec > 1.0) {
|
||||||
float my_usage = 100.0f * (maxSample5sec / 255.0f);
|
float my_usage = 100.0f * (maxSample5sec / 255.0f);
|
||||||
snprintf(myStringBuffer, 15, " - peak %3d%%", int(my_usage));
|
snprintf_P(myStringBuffer, 15, PSTR(" - peak %3d%%"), int(my_usage));
|
||||||
infoArr.add(myStringBuffer);
|
infoArr.add(myStringBuffer);
|
||||||
} else {
|
} else {
|
||||||
infoArr.add(" - quiet");
|
infoArr.add(F(" - quiet"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// error during audio source setup
|
// error during audio source setup
|
||||||
infoArr.add("not initialized");
|
infoArr.add(F("not initialized"));
|
||||||
infoArr.add(" - check GPIO config");
|
infoArr.add(F(" - check GPIO config"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sound processing (FFT and input filters)
|
// Sound processing (FFT and input filters)
|
||||||
infoArr = user.createNestedArray(F("Sound Processing"));
|
infoArr = user.createNestedArray(F("Sound Processing"));
|
||||||
if (audioSource && (disableSoundProcessing == false)) {
|
if (audioSource && (disableSoundProcessing == false)) {
|
||||||
infoArr.add("running");
|
infoArr.add(F("running"));
|
||||||
} else {
|
} else {
|
||||||
infoArr.add("suspended");
|
infoArr.add(F("suspended"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// AGC or manual Gain
|
// AGC or manual Gain
|
||||||
if((soundAgc==0) && (disableSoundProcessing == false) && !(audioSyncEnabled & 0x02)) {
|
if ((soundAgc==0) && (disableSoundProcessing == false) && !(audioSyncEnabled & 0x02)) {
|
||||||
infoArr = user.createNestedArray(F("Manual Gain"));
|
infoArr = user.createNestedArray(F("Manual Gain"));
|
||||||
float myGain = ((float)sampleGain/40.0f * (float)inputLevel/128.0f) + 1.0f/16.0f; // non-AGC gain from presets
|
float myGain = ((float)sampleGain/40.0f * (float)inputLevel/128.0f) + 1.0f/16.0f; // non-AGC gain from presets
|
||||||
infoArr.add(roundf(myGain*100.0f) / 100.0f);
|
infoArr.add(roundf(myGain*100.0f) / 100.0f);
|
||||||
infoArr.add("x");
|
infoArr.add("x");
|
||||||
}
|
}
|
||||||
if(soundAgc && (disableSoundProcessing == false) && !(audioSyncEnabled & 0x02)) {
|
if (soundAgc && (disableSoundProcessing == false) && !(audioSyncEnabled & 0x02)) {
|
||||||
infoArr = user.createNestedArray(F("AGC Gain"));
|
infoArr = user.createNestedArray(F("AGC Gain"));
|
||||||
infoArr.add(roundf(multAgc*100.0f) / 100.0f);
|
infoArr.add(roundf(multAgc*100.0f) / 100.0f);
|
||||||
infoArr.add("x");
|
infoArr.add("x");
|
||||||
@ -1302,15 +1289,14 @@ class AudioReactive : public Usermod {
|
|||||||
// UDP Sound Sync status
|
// UDP Sound Sync status
|
||||||
infoArr = user.createNestedArray(F("UDP Sound Sync"));
|
infoArr = user.createNestedArray(F("UDP Sound Sync"));
|
||||||
if (audioSyncEnabled) {
|
if (audioSyncEnabled) {
|
||||||
if (audioSyncEnabled & 0x01) {
|
if (audioSyncEnabled & 0x01) {
|
||||||
infoArr.add("send mode");
|
infoArr.add(F("send mode"));
|
||||||
} else if (audioSyncEnabled & 0x02) {
|
} else if (audioSyncEnabled & 0x02) {
|
||||||
infoArr.add("receive mode");
|
infoArr.add(F("receive mode"));
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
infoArr.add("off");
|
infoArr.add("off");
|
||||||
if (audioSyncEnabled && !udpSyncConnected) infoArr.add(" <i>(unconnected)</i>");
|
if (audioSyncEnabled && !udpSyncConnected) infoArr.add(" <i>(unconnected)</i>");
|
||||||
//if (!udpSyncConnected) infoArr.add(" <i>(unconnected)</i>");
|
|
||||||
|
|
||||||
#ifdef WLED_DEBUG
|
#ifdef WLED_DEBUG
|
||||||
infoArr = user.createNestedArray(F("Sampling time"));
|
infoArr = user.createNestedArray(F("Sampling time"));
|
||||||
|
Loading…
Reference in New Issue
Block a user