ar_energy: fix a math error

fixing mis-optimized math when calculating energy.
energy = sum(amplitude^2). this is not the same as sum(amplitude)^2.

Example:
1+5+7 = 13; 13 * 13 = 169
1*1 + 5*5 + 7*7 = 75
This commit is contained in:
Frank
2024-04-10 13:42:21 +02:00
parent 03cbc52c65
commit 70bfbd5a43

View File

@@ -15,7 +15,7 @@ class AutoPlaylistUsermod : public Usermod {
#if 0
// experimental parameters by softhack007 - more balanced but need testing
const uint_fast32_t MAX_DISTANCE_TRACKER = 184; // maximum accepted distance_tracker
const uint_fast32_t ENERGY_SCALE = 24000;
const uint_fast32_t ENERGY_SCALE = 14000;
const float FILTER_SLOW1 = 0.0075f; // for "slow" energy
const float FILTER_SLOW2 = 0.005f; // for "slow" lfc / zcr
const float FILTER_FAST1 = 0.2f; // for "fast" energy
@@ -112,10 +112,10 @@ class AutoPlaylistUsermod : public Usermod {
energy = 0;
for (int i=0; i < NUM_GEQ_CHANNELS; i++) {
energy += fftResult[i];
uint_fast32_t amplitude = fftResult[i];
energy += amplitude * amplitude;
}
energy *= energy;
energy /= ENERGY_SCALE; // scale down so we get 0 sometimes
uint8_t lfc = fftResult[0];