@@ -14,6 +14,7 @@ class AutoPlaylistUsermod : public Usermod {
1414
1515 #if 0
1616 // experimental parameters by softhack007 - more balanced but need testing
17+ const uint_fast32_t MAX_DISTANCE_TRACKER = 184; // maximum accepted distance_tracker
1718 const uint_fast32_t ENERGY_SCALE = 24000;
1819 const float FILTER_SLOW1 = 0.0075f; // for "slow" energy
1920 const float FILTER_SLOW2 = 0.005f; // for "slow" lfc / zcr
@@ -22,6 +23,7 @@ class AutoPlaylistUsermod : public Usermod {
2223 const float FILTER_VOLUME = 0.03f; // for volumeSmth averaging - takes 8-10sec until "silence"
2324 #else
2425 // parameters used by TroyHacks / netmindz - behaviour is mainly driven by "energy"
26+ const uint_fast32_t MAX_DISTANCE_TRACKER = 128 ; // maximum accepted distance_tracker
2527 const uint_fast32_t ENERGY_SCALE = 10000 ;
2628 // softhack007: original code used FILTER_SLOW = 0.002f
2729 const float FILTER_SLOW1 = 0 .01f ; // for "slow" energy
@@ -169,7 +171,7 @@ class AutoPlaylistUsermod : public Usermod {
169171 // the current music, especially after track changes or during
170172 // sparse intros and breakdowns.
171173
172- if (change_interval > ideal_change_min && distance_tracker <= 100 ) {
174+ if (change_interval > ideal_change_min && distance_tracker <= MAX_DISTANCE_TRACKER ) {
173175
174176 change_threshold_change = distance_tracker-change_threshold;
175177 change_threshold = distance_tracker;
@@ -192,9 +194,7 @@ class AutoPlaylistUsermod : public Usermod {
192194
193195 if (distance <= change_threshold && change_interval > change_lockout && volumeSmth > 1 .0f ) {
194196
195- change_threshold_change = change_threshold-(distance*0 .9f );
196-
197- if (change_threshold_change < 1 ) change_threshold_change = 1 ;
197+ change_threshold_change = max (1 .0f , roundf (change_threshold-(distance*0 .9f ))); // exclude negatives, ensure change_threshold_change is always >= 1
198198
199199 if (change_interval > ideal_change_max) {
200200 change_threshold += change_threshold_change; // make changes more sensitive
@@ -245,6 +245,8 @@ class AutoPlaylistUsermod : public Usermod {
245245 // go into freefall - this logic stops that from triggering right
246246 // after change_lockout. Better for smaller change_lockout values.
247247
248+ // SH7: this method is sub-optimal, as its interfering with the "playlist" engine
249+ // we shoud find a better method for triggering playlist changes
248250 applyPreset (newpreset);
249251
250252 #ifdef USERMOD_AUTO_PLAYLIST_DEBUG
@@ -492,7 +494,10 @@ class AutoPlaylistUsermod : public Usermod {
492494 #ifdef USERMOD_AUTO_PLAYLIST_DEBUG
493495 USER_PRINTF (" AutoPlaylist: Applying \" %s\"\n " , name.c_str ());
494496 #endif
495- applyPreset (id, CALL_MODE_NOTIFICATION);
497+ // if (currentPlaylist != id) { // un-comment to only change on "real" changes
498+ unloadPlaylist (); // applying a preset requires to unload previous playlist
499+ applyPreset (id, CALL_MODE_NOTIFICATION);
500+ // }
496501 lastAutoPlaylist = id;
497502 }
498503
0 commit comments