Skip to content

Commit 70bfbd5

Browse files
committed
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
1 parent 03cbc52 commit 70bfbd5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

usermods/usermod_v2_auto_playlist/usermod_v2_auto_playlist.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AutoPlaylistUsermod : public Usermod {
1515
#if 0
1616
// experimental parameters by softhack007 - more balanced but need testing
1717
const uint_fast32_t MAX_DISTANCE_TRACKER = 184; // maximum accepted distance_tracker
18-
const uint_fast32_t ENERGY_SCALE = 24000;
18+
const uint_fast32_t ENERGY_SCALE = 14000;
1919
const float FILTER_SLOW1 = 0.0075f; // for "slow" energy
2020
const float FILTER_SLOW2 = 0.005f; // for "slow" lfc / zcr
2121
const float FILTER_FAST1 = 0.2f; // for "fast" energy
@@ -112,10 +112,10 @@ class AutoPlaylistUsermod : public Usermod {
112112
energy = 0;
113113

114114
for (int i=0; i < NUM_GEQ_CHANNELS; i++) {
115-
energy += fftResult[i];
115+
uint_fast32_t amplitude = fftResult[i];
116+
energy += amplitude * amplitude;
116117
}
117118

118-
energy *= energy;
119119
energy /= ENERGY_SCALE; // scale down so we get 0 sometimes
120120

121121
uint8_t lfc = fftResult[0];

0 commit comments

Comments
 (0)