Skip to content

switch from audren to audout and many other changes#51

Merged
HookedBehemoth merged 19 commits intoHookedBehemoth:masterfrom
ITotalJustice:audout
Jul 19, 2025
Merged

switch from audren to audout and many other changes#51
HookedBehemoth merged 19 commits intoHookedBehemoth:masterfrom
ITotalJustice:audout

Conversation

@ITotalJustice
Copy link
Copy Markdown
Collaborator

  • audren has been removed and replaced with audout due to session exhaustion issue with using audren. I have pulled in SDL2 audio stream for resampling as it's very fast and low overhead. Although i happy to replace it with something else later on.
  • the playlist code has been re-written. Previously, the playlist would continue to allocate a new entry when added with no hard limit. This could result in the audio streams failing to allocate, thus breaking the whole app. And vectors typically do not actually free memory until vector::shrink() is called. The new version has a hard limit of 512 entries. Each entry takes 0.25 kb, so in total 128k. I wasn't sure what the max limit should really be, maybe 256 is more reasonable, and it would save 64k.
  • updated all dr_libs to the latest commit.
  • overall memory usage has been reduced by 56k 0x000d1000 vs 0x000c3000.

this isn't ready to be merged yet as it requires switchbrew/libnx#683 to be in the next release, and by that point switchbrew/libnx#636 may also make it in so i'd need remove the local version of that code.

fixes #10

…duce memory by ~140KiB

- audout doesn't suffer from session exhaution as audren did. this removes the hacky workaround of closing sys-tune
  when a blacklisted game was launched.
  This however created a new problem, we need a new way to resample the audio.
  I am very familar with sdl2 code and know its resampler is pretty good, so i went with that. I will change this later
  on if a better resampler is found.
- playlists are now a fixed size of 256 entries, which uses 64k. (entry_count / 4 = kib).
…st using the wrong index for ipc, ovl focus current song in playlist, sys fix clearAll not resetting the queueIndex.
@ITotalJustice
Copy link
Copy Markdown
Collaborator Author

More changes:

  • option to set a file/folder to load on startup. In the case of a file, the file is simply loaded and starts playback during the nintendo logo. For a folder, the entire folder (non-recursive) is loaded.
  • ovl playlist now focuses on the currently playing song.
  • ovl browser now auto focuses to the first element, rather than being out of focus until a button is pressed.
  • optimised the ovl dir scanning by reading batches of 64 entries at once.
  • optimised ovl loadAll sort function by passing the strings by ref, rather than value.
  • updated the workflow so that it always builds on both push and pull_request, however it only pushes a new build on push.

@ITotalJustice
Copy link
Copy Markdown
Collaborator Author

  • heap was increased to 300k (+100k from last few commits) due to dr_mp3 running out of memory loading certain files. overall we are still using 8k less than the latest release.
  • a file limit has been set to the ovl browser in order to prevent against crashes if the user tries to open a very large folder due to running out of memory. i've set the limit to 2k entries, which should be more than enough. i reasoned that every 3 entries is max 3k so 2k entries would be max 682k, which gives us plenty of headroom.
  • like above, ive set a limit to the loadAll function in ovl so limit itself to 512 entries, as this is the max amount of songs that can be added to a playlist in sys-tune.

…ncrease resample buf size, reduce heap (because we have buffered io), label sdl funcs static, reduce mp3 heap size
…led on.

this allows for a new list to be created, similar to how it works in youtube music.
@ITotalJustice
Copy link
Copy Markdown
Collaborator Author

  • fixes crash when seeking a wav file due to the source->seek() function being called on the main thread which only has 4k stack, increased the stack to 16k.
  • added buffered io. this works like fread where it keeps an internal copy of the last read data, and always reads data in chunks of its internal buffer size unless the data passed into read is bigger than the internal buffer, in that case it's read in place.
  • due to the above change, the mp3 chunk size has been reduced to its minimum of 16k.
  • due to the above change, the heap has been reduced further because we no longer alloc that extra 48k.
  • reduced the latency between songs by making the first sample buffer very small, so it finished reading / decoding a lot faster.
  • the decode function now only resamples the data if the src freq != dst freq. sdl does handle this already, however it still has to make a copy of the data, and the decode loop is potentially ran multiple times. so, in the case that resampling isn't needed, decode is called once.
  • re-shuffled the shuffle playlist when shuffle mode is enabled. this is similar to how it works on yt music.

@HookedBehemoth
Copy link
Copy Markdown
Owner

I'd be more comfortable if the individual patches only addressed individual issues.
To track the heap usage, we could expose mallinfo in an IPC or shim new/delete.
Maybe we even want to use area-allocators for everything we control and let dr_libs use the rest?

@HookedBehemoth HookedBehemoth merged commit 87372bf into HookedBehemoth:master Jul 19, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IAudioRendererManager resource exhaustion in several games

2 participants