Skip to content

Commit 6e24850

Browse files
committed
ar_energy: improved energy reconstruction
fftResult[] is indended to look good on GEQ, and has a very "twisted" representation of FFT results only. This change improves reconstruction of signal energy, by on-doing some of the "GEQ enhancements" in fftResults[].
1 parent 70bfbd5 commit 6e24850

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

usermods/usermod_v2_auto_playlist/usermod_v2_auto_playlist.h

Lines changed: 13 additions & 2 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 = 14000;
18+
const uint_fast32_t ENERGY_SCALE = 1500;
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
@@ -24,7 +24,8 @@ class AutoPlaylistUsermod : public Usermod {
2424
#else
2525
// parameters used by TroyHacks / netmindz - behaviour is mainly driven by "energy"
2626
const uint_fast32_t MAX_DISTANCE_TRACKER = 128; // maximum accepted distance_tracker
27-
const uint_fast32_t ENERGY_SCALE = 10000;
27+
//const uint_fast32_t ENERGY_SCALE = 10000;
28+
const uint_fast32_t ENERGY_SCALE = 2000;
2829
// softhack007: original code used FILTER_SLOW = 0.002f
2930
const float FILTER_SLOW1 = 0.01f; // for "slow" energy
3031
const float FILTER_SLOW2 = 0.01f; // for "slow" lfc / zcr
@@ -46,6 +47,9 @@ class AutoPlaylistUsermod : public Usermod {
4647
unsigned long autochange_timer = millis();
4748
float avg_volumeSmth = 0;
4849

50+
// fftesult de-scaling factors: 2.8f / fftResultPink[]
51+
const float fftDeScaler[NUM_GEQ_CHANNELS] = {2.8/2.35, 2.8/1.32, 2.8/1.32, 2.8/1.40, 2.8/1.48, 2.8/1.57, 2.8/1.68, 2.8/1.80, 2.8/1.89, 2.8/1.95, 2.8/2.14, 2.8/2.26, 2.8/2.50, 2.8/2.90, 2.8/4.20, 2.8/6.50};
52+
4953
uint_fast32_t energy = 0;
5054

5155
float avg_long_energy = 250;
@@ -112,8 +116,15 @@ class AutoPlaylistUsermod : public Usermod {
112116
energy = 0;
113117

114118
for (int i=0; i < NUM_GEQ_CHANNELS; i++) {
119+
#if 1
120+
// make an attempt to undo some "trying to look better" FFT manglings in AudioReactive postProcessFFTResults()
121+
float amplitude = float(fftResult[i]) * fftDeScaler[i]; // undo "pink noise" scaling
122+
amplitude /= 0.85f + (float(i)/4.5f); // undo extra up-scaling for high frequencies
123+
energy += roundf(amplitude * amplitude); // calc energy from amplitude
124+
#else
115125
uint_fast32_t amplitude = fftResult[i];
116126
energy += amplitude * amplitude;
127+
#endif
117128
}
118129

119130
energy /= ENERGY_SCALE; // scale down so we get 0 sometimes

0 commit comments

Comments
 (0)