@@ -12,7 +12,7 @@ class AutoPlaylistUsermod : public Usermod {
1212
1313 private:
1414
15- #if 0
15+ #if 1
1616 // experimental parameters by softhack007 - more balanced but need testing
1717 const uint_fast32_t MAX_DISTANCE_TRACKER = 184 ; // maximum accepted distance_tracker
1818 const uint_fast32_t ENERGY_SCALE = 1500 ;
@@ -27,11 +27,11 @@ class AutoPlaylistUsermod : public Usermod {
2727 //const uint_fast32_t ENERGY_SCALE = 10000;
2828 const uint_fast32_t ENERGY_SCALE = 2000;
2929 // softhack007: original code used FILTER_SLOW = 0.002f
30- const float FILTER_SLOW1 = 0 .01f ; // for "slow" energy
31- const float FILTER_SLOW2 = 0 .01f ; // for "slow" lfc / zcr
32- const float FILTER_FAST1 = 0 .1f ; // for "fast" energy
33- const float FILTER_FAST2 = 0 .1f ; // for "fast" lfc / zcr
34- const float FILTER_VOLUME = 0 .01f ; // for volumeSmth averaging - takes 12-15sec until "silence"
30+ const float FILTER_SLOW1 = 0.01f; // for "slow" energy
31+ const float FILTER_SLOW2 = 0.01f; // for "slow" lfc / zcr
32+ const float FILTER_FAST1 = 0.1f; // for "fast" energy
33+ const float FILTER_FAST2 = 0.1f; // for "fast" lfc / zcr
34+ const float FILTER_VOLUME = 0.03f ; // for volumeSmth averaging - takes 8-10sec until "silence"
3535 #endif
3636
3737 bool initDone = false ;
@@ -67,7 +67,6 @@ class AutoPlaylistUsermod : public Usermod {
6767
6868 uint_fast32_t distance = 0 ;
6969 uint_fast32_t distance_tracker = UINT_FAST32_MAX;
70- // uint_fast64_t squared_distance = 0;
7170
7271 unsigned long lastchange = millis();
7372
@@ -116,15 +115,13 @@ class AutoPlaylistUsermod : public Usermod {
116115 energy = 0 ;
117116
118117 for (int i=0 ; i < NUM_GEQ_CHANNELS; i++) {
119- # if 1
118+
120119 // make an attempt to undo some "trying to look better" FFT manglings in AudioReactive postProcessFFTResults()
120+
121121 float amplitude = float (fftResult[i]) * fftDeScaler[i]; // undo "pink noise" scaling
122122 amplitude /= 0 .85f + (float (i)/4 .5f ); // undo extra up-scaling for high frequencies
123123 energy += roundf (amplitude * amplitude); // calc energy from amplitude
124- #else
125- uint_fast32_t amplitude = fftResult[i];
126- energy += amplitude * amplitude;
127- #endif
124+
128125 }
129126
130127 energy /= ENERGY_SCALE; // scale down so we get 0 sometimes
@@ -136,14 +133,15 @@ class AutoPlaylistUsermod : public Usermod {
136133 // and the individual vector distances.
137134
138135 if (volumeSmth > 1 .0f ) {
136+
139137 // initialize filters on first run
140138 if (resetFilters) {
141139 avg_short_energy = avg_long_energy = energy;
142140 avg_short_lfc = avg_long_lfc = lfc;
143141 avg_short_zcr = avg_long_zcr = zcr;
144142 resetFilters = false ;
145143 #ifdef USERMOD_AUTO_PLAYLIST_DEBUG
146- USER_PRINTLN (" autoplaylist: filters reset." );
144+ USER_PRINTLN (" AutoPlaylist: Filters reset." );
147145 #endif
148146 }
149147
@@ -162,18 +160,15 @@ class AutoPlaylistUsermod : public Usermod {
162160
163161 }
164162
165- // distance is linear, squared_distance is magnitude.
166- // linear is easier to fine-tune, IMHO.
167163 distance = vector_lfc + vector_energy + vector_zcr;
168- // squared_distance = distance * distance;
169164
170165 long change_interval = millis ()-lastchange;
171166
172167 if (distance < distance_tracker && change_interval > change_lockout && volumeSmth > 1 .0f ) {
173168 distance_tracker = distance;
174169 }
175170
176- // USER_PRINTF("Distance: %3lu - v_lfc: %5lu v_energy: %5lu v_zcr: %5lu\n",(unsigned long)distance,(unsigned long)vector_lfc,(unsigned long)vector_energy,(unsigned long)vector_zcr);
171+ // USER_PRINTF("Distance: %5lu - v_lfc: %5lu v_energy: %5lu v_zcr: %5lu\n",(unsigned long)distance,(unsigned long)vector_lfc,(unsigned long)vector_energy,(unsigned long)vector_zcr);
177172
178173 if ((millis () - change_timer) > ideal_change_min) { // softhack007 same result as "millis() > change_timer + ideal_change_min", but more robust against unsigned overflow
179174
@@ -312,8 +307,6 @@ class AutoPlaylistUsermod : public Usermod {
312307 functionality_enabled = true ;
313308 }
314309
315- // if (!functionality_enabled) return;
316-
317310 if (bri == 0 ) return ;
318311
319312 um_data_t *um_data;
0 commit comments