calculations based on normalized FFT results

This commit is contained in:
Troy
2024-03-25 08:19:05 -04:00
parent 901e4fa83e
commit 5ff44755d8
3 changed files with 28 additions and 27 deletions

View File

@@ -498,20 +498,16 @@ 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;
energy = 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++;
}
}
// WLED-MM/TroyHacks: Calculate energy
energy += (vReal[i] * vReal[i])/10000000;
}
#if defined(WLED_DEBUG) || defined(SR_DEBUG)|| defined(SR_STATS)
@@ -645,17 +641,6 @@ void FFTcode(void * parameter)
#endif
FFT_MajorPeak = constrain(FFT_MajorPeak, 1.0f, 11025.0f); // restrict value to range expected by effects
FFT_MajPeakSmth = FFT_MajPeakSmth + 0.42 * (FFT_MajorPeak - FFT_MajPeakSmth); // I like this "swooping peak" look
// WLED-MM/TroyHacks: Calculate Low-Frequency Content
//
lowFreqencyContent = fftAddAvg(2,4)/1000;
// USER_PRINT("ZCR = ");
// USER_PRINT(zeroCrossingCount);
// USER_PRINT(" Energy = ");
// USER_PRINT(" LFC = ");
// USER_PRINT(lowFreqencyContent);
// USER_PRINTLN();
} else { // skip second run --> clear fft results, keep peaks
memset(vReal, 0, sizeof(vReal));
@@ -801,7 +786,22 @@ void FFTcode(void * parameter)
// run peak detection
autoResetPeak();
detectSamplePeak();
// WLED-MM/TroyHacks: Calculate Energy & Low-Frequency Content
//
energy = 0;
for (int i=0; i < NUM_GEQ_CHANNELS; i++) {
energy += fftResult[i];
}
energy *= energy;
energy /= 10000;
lowFreqencyContent = fftResult[0];
// WLED-MM/TroyHacks: Ideally these numbers are roughly in the same rations
// ...but more importantly hitting a zero point at a regular interval
//
// USER_PRINTF("ZCR: %3lu Energy: %5lu LFC: %4lu\n",(unsigned long)zeroCrossingCount,(unsigned long)energy,(unsigned long)lowFreqencyContent)
// we have new results - notify UDP sound send
haveNewFFTResult = true;

View File

@@ -121,12 +121,15 @@ class AutoPlaylistUsermod : public Usermod {
// the current music, especially after track changes or during
// sparce intros and breakdowns.
if (change_interval > ideal_change_min && distance_tracker < 1000) {
// change_threshold++;
change_threshold += distance_tracker/10;
USER_PRINTF("Increasing change_threshold to: %d\n",change_threshold);
USER_PRINT (" lowest recorded distance was: ");
change_threshold += distance_tracker>10?distance_tracker/10:1;
USER_PRINT ("The lowest recorded distance was: ");
USER_PRINTLN(distance_tracker);
USER_PRINTF("Increasing change_threshold to: %d\n",change_threshold);
distance_tracker = UINT_FAST32_MAX;
}
change_timer = millis();
}
@@ -136,11 +139,9 @@ class AutoPlaylistUsermod : public Usermod {
if (distance <= change_threshold && change_interval > change_lockout && volumeSmth > 0.1) {
if (change_interval > ideal_change_max) {
// change_threshold += 1;
change_threshold += distance/10;
change_threshold += distance_tracker>10?distance_tracker/10:1;
} else if (change_interval < ideal_change_min) {
// change_threshold -= 1;
change_threshold -= distance/10;
change_threshold -= distance_tracker>10?distance_tracker/10:1;
}
distance_tracker = UINT_FAST32_MAX;
@@ -162,7 +163,7 @@ class AutoPlaylistUsermod : public Usermod {
do {
newpreset = autoChangeIds.at(random(0, autoChangeIds.size())); // random() is *exclusive* of the last value, so it's OK to use the full size.
}
while (currentPreset == newpreset);
while (currentPreset == newpreset); // make sure we get a different random preset.
applyPreset(newpreset);

View File

@@ -64,7 +64,7 @@ void WS2812FX::setUpMatrix() {
return;
}
USER_PRINTF("setUpMatrix %d x %d\n", Segment::maxWidth, Segment::maxHeight);
// TroyHacks temp commented out, FIXME and put back: USER_PRINTF("setUpMatrix %d x %d\n", Segment::maxWidth, Segment::maxHeight);
//WLEDMM recreate customMappingTable if more space needed
if (Segment::maxWidth * Segment::maxHeight > customMappingTableSize) {