Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Usermod - Auto Playlist #124

Merged
merged 68 commits into from
Apr 16, 2024
Merged

Conversation

netmindz
Copy link
Collaborator

@netmindz netmindz commented Mar 5, 2024

New usermod to automatically flip between your "ambient" or "music" playlist when the music starts

Also optional to flip which music effect is running based on audio data rather than fixed time interval

@netmindz netmindz mentioned this pull request Mar 8, 2024
@netmindz
Copy link
Collaborator Author

As this a branch pull request rather than a pull request from a fork, my intention was that you @troyhacks could make any changes you wished as well, I was looking just to handle replacing your hard coded values with the right usermod UI bits, the actual analysis side is up to you 😀

@troyhacks
Copy link
Collaborator

As this a branch pull request rather than a pull request from a fork, my intention was that you @troyhacks could make any changes you wished as well, I was looking just to handle replacing your hard coded values with the right usermod UI bits, the actual analysis side is up to you 😀

Perfect, thank you!

Testing right now and it seems to be working in theory - but the automatic changes are happening MUCH more quickly in your implementation. Debugging that now. :)

@troyhacks
Copy link
Collaborator

troyhacks commented Mar 23, 2024

As this a branch pull request rather than a pull request from a fork, my intention was that you @troyhacks could make any changes you wished as well, I was looking just to handle replacing your hard coded values with the right usermod UI bits, the actual analysis side is up to you 😀

Ok, it's all done and working! Thank you for this - just what I needed to get it across the finish line.

Pulling the volume into the usermod was super useful too - I was able to stop the analysis from going crazy during silence.

Overall the "Troy's extra data" in the AR usermod havebeen thoroughly tested and vetted and ensured it's doing what it's supposed to and with the correct values. zeroCrossingCount I think was almost a made-up number before (oops) - but now it's exactly what it says.

The one issue I had was bridging the data via um_data - I could NOT get the nested "extra" array to work, so I passed the values individually instead. C++ syntax is kinda voodoo to me so that might be my fault - if you wanna take a stab and putting it back, go nuts. Works for me as it is. 😄

I added the AutoChange tuning parameters to the usermod data. Save the usermod once after updating it and the new data should be populated when you go back into it.

@troyhacks
Copy link
Collaborator

troyhacks commented Apr 5, 2024

Added new logic for functionality_enabled which differs from enabled

enabled now tracks the overall state of the usermod from settings - if you disable it in settings, it stays disabled.

functionality_enabled tracks the internal state of the usermod functionality, so we can disable ourselves internally without disabling the entire undermod.

Using functionality_enabled also allows some instances where we can "go thru the motions" of the AutoChange logic without actually changing presets. This allows the AutoChange data to stay hot when audio is present even when functionality_enabled is false.

When the AutoChange data is kept fresh, there's less frantic changes when we go back into AutoChange mode.

wled00/usermods_list.cpp Outdated Show resolved Hide resolved
* prevent infinite loop in case that there is only one preset in a playlist
* fixing two typos
* initialize slow and fast filters with current values (first call only) - reduces time for filter stabilization

* use slightly optimized variant of "rolling average" filter (result is exactly the same)
  --> replaced `xX = xX * (1-a) + newX * a;`  by  `xX = xX + a * (newX - Xx);`

* use constants for filter parameters (for tinkering and improved readability)
USER_PRINTF("Loading presets from playlist: %3d\n", currentPlaylist);
#endif

JsonObject playtlistOjb = doc.to<JsonObject>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen some "WS buffer allocation failed." errors during testing auto_playlist. Could it be that JsonObject playtlistOjb or autoChangeIds.push_back leave memory leaks behind?

@ewoudwijma @troyhacks @netmindz I'm not so experienced with ArduinoJSON and std:vector - would be great if one of you could scrutinize this part.

softhack007 and others added 5 commits April 9, 2024 19:23
* use named constant instead of "100"
* make change_threshold_change more robust against negatives
* unloadPlaylist() before activating a new playlist
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
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[].
@troyhacks
Copy link
Collaborator

Accepted what @softhack007 has suggested - honestly most of the numbers were pulled out of thin air originally, so any scrutinized numbers should be better - and tested fine too.

I'm good with this as it stands if everyone else is.

@softhack007
Copy link
Collaborator

@troyhacks glad i did't actually "kill the magic" with my changes :-)

From my side, i'm still looking for a way to "halt" a running playlist when auto-change is active. So that the auto-change progress is not gettig in conflict with the playlist mechanism that has its own timers for changing / shuffling / repeating.

* adding suspendPlaylist() to playlist engine code
* autoplaylist usermod calls suspendPlaylist() before switching to another preset
* fix a potential overflow on `lfc` (uint8_t -> uint16_t)
* reduce from 3 lines to two lines
* don't add to info when usermod is disabled in UM settings
* show current playlist id
@softhack007
Copy link
Collaborator

Small info page rework.

Old: image

New: image

Copy link
Collaborator

@softhack007 softhack007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now :-)

@netmindz netmindz merged commit 0f79e9b into MoonModules:mdev Apr 16, 2024
31 checks passed
@netmindz netmindz deleted the auto-playlist branch April 16, 2024 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants