calculations based on normalized FFT results
This commit is contained in:
@@ -502,16 +502,12 @@ void FFTcode(void * parameter)
|
|||||||
// WLED-MM/TroyHacks: Calculate zero crossings
|
// WLED-MM/TroyHacks: Calculate zero crossings
|
||||||
//
|
//
|
||||||
zeroCrossingCount = 0;
|
zeroCrossingCount = 0;
|
||||||
energy = 0;
|
|
||||||
|
|
||||||
for (int i=0; i < samplesFFT; i++) {
|
for (int i=0; i < samplesFFT; i++) {
|
||||||
if (i < (samplesFFT)-2) {
|
if (i < (samplesFFT)-2) {
|
||||||
if((vReal[i] >= 0 && vReal[i+1] < 0) || (vReal[i+1] < 0 && vReal[i+1] >= 0)) {
|
if((vReal[i] >= 0 && vReal[i+1] < 0) || (vReal[i+1] < 0 && vReal[i+1] >= 0)) {
|
||||||
zeroCrossingCount++;
|
zeroCrossingCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// WLED-MM/TroyHacks: Calculate energy
|
|
||||||
energy += (vReal[i] * vReal[i])/10000000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(WLED_DEBUG) || defined(SR_DEBUG)|| defined(SR_STATS)
|
#if defined(WLED_DEBUG) || defined(SR_DEBUG)|| defined(SR_STATS)
|
||||||
@@ -646,17 +642,6 @@ void FFTcode(void * parameter)
|
|||||||
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
|
||||||
FFT_MajPeakSmth = FFT_MajPeakSmth + 0.42 * (FFT_MajorPeak - FFT_MajPeakSmth); // I like this "swooping peak" look
|
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
|
} else { // skip second run --> clear fft results, keep peaks
|
||||||
memset(vReal, 0, sizeof(vReal));
|
memset(vReal, 0, sizeof(vReal));
|
||||||
}
|
}
|
||||||
@@ -802,6 +787,21 @@ void FFTcode(void * parameter)
|
|||||||
autoResetPeak();
|
autoResetPeak();
|
||||||
detectSamplePeak();
|
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
|
// we have new results - notify UDP sound send
|
||||||
haveNewFFTResult = true;
|
haveNewFFTResult = true;
|
||||||
|
|
||||||
|
|||||||
@@ -121,12 +121,15 @@ class AutoPlaylistUsermod : public Usermod {
|
|||||||
// the current music, especially after track changes or during
|
// the current music, especially after track changes or during
|
||||||
// sparce intros and breakdowns.
|
// sparce intros and breakdowns.
|
||||||
if (change_interval > ideal_change_min && distance_tracker < 1000) {
|
if (change_interval > ideal_change_min && distance_tracker < 1000) {
|
||||||
// change_threshold++;
|
|
||||||
change_threshold += distance_tracker/10;
|
change_threshold += distance_tracker>10?distance_tracker/10:1;
|
||||||
USER_PRINTF("Increasing change_threshold to: %d\n",change_threshold);
|
|
||||||
USER_PRINT (" lowest recorded distance was: ");
|
USER_PRINT ("The lowest recorded distance was: ");
|
||||||
USER_PRINTLN(distance_tracker);
|
USER_PRINTLN(distance_tracker);
|
||||||
|
USER_PRINTF("Increasing change_threshold to: %d\n",change_threshold);
|
||||||
|
|
||||||
distance_tracker = UINT_FAST32_MAX;
|
distance_tracker = UINT_FAST32_MAX;
|
||||||
|
|
||||||
}
|
}
|
||||||
change_timer = millis();
|
change_timer = millis();
|
||||||
}
|
}
|
||||||
@@ -136,11 +139,9 @@ class AutoPlaylistUsermod : public Usermod {
|
|||||||
if (distance <= change_threshold && change_interval > change_lockout && volumeSmth > 0.1) {
|
if (distance <= change_threshold && change_interval > change_lockout && volumeSmth > 0.1) {
|
||||||
|
|
||||||
if (change_interval > ideal_change_max) {
|
if (change_interval > ideal_change_max) {
|
||||||
// change_threshold += 1;
|
change_threshold += distance_tracker>10?distance_tracker/10:1;
|
||||||
change_threshold += distance/10;
|
|
||||||
} else if (change_interval < ideal_change_min) {
|
} else if (change_interval < ideal_change_min) {
|
||||||
// change_threshold -= 1;
|
change_threshold -= distance_tracker>10?distance_tracker/10:1;
|
||||||
change_threshold -= distance/10;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
distance_tracker = UINT_FAST32_MAX;
|
distance_tracker = UINT_FAST32_MAX;
|
||||||
@@ -162,7 +163,7 @@ class AutoPlaylistUsermod : public Usermod {
|
|||||||
do {
|
do {
|
||||||
newpreset = autoChangeIds.at(random(0, autoChangeIds.size())); // random() is *exclusive* of the last value, so it's OK to use the full size.
|
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);
|
applyPreset(newpreset);
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ void WS2812FX::setUpMatrix() {
|
|||||||
return;
|
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
|
//WLEDMM recreate customMappingTable if more space needed
|
||||||
if (Segment::maxWidth * Segment::maxHeight > customMappingTableSize) {
|
if (Segment::maxWidth * Segment::maxHeight > customMappingTableSize) {
|
||||||
|
|||||||
Reference in New Issue
Block a user