Sync audio_rective changes from auto-playlist branch

This commit is contained in:
Will Tatam
2024-03-28 19:40:59 +00:00
parent 9923a7a7d8
commit 9eabbf3789

View File

@@ -141,9 +141,7 @@ static uint8_t fftResult[NUM_GEQ_CHANNELS]= {0}; // Our calculated freq. chann
static float fftCalc[NUM_GEQ_CHANNELS] = {0.0f}; // Try and normalize fftBin values to a max of 4096, so that 4096/16 = 256. (also used by dynamics limiter)
static float fftAvg[NUM_GEQ_CHANNELS] = {0.0f}; // Calculated frequency channel results, with smoothing (used if dynamics limiter is ON)
unsigned int zeroCrossingCount = 0;
unsigned int energy = 0;
unsigned int lowFreqencyContent = 0;
uint_fast16_t zeroCrossingCount = 0;
// TODO: probably best not used by receive nodes
static float agcSensitivity = 128; // AGC sensitivity estimation, based on agc gain (multAgc). calculated by getSensitivity(). range 0..255
@@ -499,6 +497,17 @@ void FFTcode(void * parameter)
// get a fresh batch of samples from I2S
if (audioSource) audioSource->getSamples(vReal, samplesFFT);
// WLED-MM/TroyHacks: Calculate zero crossings
//
zeroCrossingCount = 0;
for (int i=0; i < samplesFFT; i++) {
if (i < (samplesFFT)-2) {
if((vReal[i] >= 0 && vReal[i+1] < 0) || (vReal[i+1] < 0 && vReal[i+1] >= 0)) {
zeroCrossingCount++;
}
}
}
#if defined(WLED_DEBUG) || defined(SR_DEBUG)|| defined(SR_STATS)
// debug info in case that stack usage changes
static unsigned int minStackFree = UINT32_MAX;
@@ -555,17 +564,7 @@ void FFTcode(void * parameter)
// pick our our current mic sample - we take the max value from all samples that go into FFT
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]);
// WLED-MM/TroyHacks: Calculate zero crossings
if (i < samplesFFT-2) {
if (vReal[i] * vReal[i+1] < 0) {
zeroCrossingCount++;
}
}
// WLED-MM/TroyHacks: Calculate energy
energy += vReal[i] * vReal[i];
}
energy /= 100000; // WLED-MM/TroyHacks: scale this down becasue we're gonna make it bigger later
// release highest sample to volume reactive effects early - not strictly necessary here - could also be done at the end of the function
// early release allows the filters (getSample() and agcAvg()) to work with fresh values - we will have matching gain and noise gate values when we want to process the FFT results.
@@ -661,8 +660,6 @@ void FFTcode(void * parameter)
vReal[i] = t / 16.0f; // Reduce magnitude. Want end result to be scaled linear and ~4096 max.
} // for()
lowFreqencyContent = fftAddAvg(1,9); // WLED-MM/TroyHacks: Calculate Low-Frequency Content
// mapping of FFT result bins to frequency channels
//if (fabsf(sampleAvg) > 0.25f) { // noise gate open
if (fabsf(volumeSmth) > 0.25f) { // noise gate open
@@ -1763,10 +1760,8 @@ class AudioReactive : public Usermod {
um_data->u_type[9] = UMT_FLOAT;
um_data->u_data[10] = &agcSensitivity; // used (New)
um_data->u_type[10] = UMT_FLOAT;
unsigned int* extra[3] = {&zeroCrossingCount, &energy, &lowFreqencyContent};
um_data->u_data[11] = extra; //
um_data->u_type[11] = UMT_INT16_ARR;
um_data->u_data[11] = &zeroCrossingCount;
um_data->u_type[11] = UMT_UINT16;
#else
// ESP8266
// See https://github.com/MoonModules/WLED/pull/60#issuecomment-1666972133 for explanation of these alternative sources of data