alowaniak / music-replacer

Replace OSRS music tracks with user defined music
BSD 2-Clause "Simplified" License
9 stars 5 forks source link

Starting a track / looping causes lag #9

Open featurecat opened 1 year ago

featurecat commented 1 year ago

To reproduce, override any track with a short 2-second-long track. Enable looping, the game will have frequent FPS drops.

SHvalross commented 1 year ago

Just started using the plug-in and also noticed this.

fuzxi commented 1 year ago

This seems to occur when an overridden track restarts, and the track is in mp3 format. Wav files do not seem to have this issue.

featurecat commented 1 year ago

Thanks fuzxi. I'll try it out. I came up with this command to convert all tracks in the folder to wav using ffmpeg (Windows cmd): for /r %i in (*) do ffmpeg -i "%i" -vn -acodec pcm_s16le -ar 44100 -ac 2 "%~ni.wav" (https://ffmpeg.org/download.html, https://superuser.com/questions/609740/extracting-wav-from-mp4-while-preserving-the-highest-possible-quality)

Unfortunately, now music-replacer runs out of memory when trying to load large tracks.

featurecat commented 1 year ago

Amascut's Promise was the longest track, and that was causing an out of memory issue. I fixed it by just allocating more memory to RuneLite. You can do this at your own risk by:

  1. Going to %APPDATA%\..\Local\RuneLite (has a lot of DLLs)
  2. Backup config.json
  3. Replace "-Xmx512M" with "-Xmx1g" or your preferred memory usage. I also set "-Xms512m" but I'm not sure if it's useful.
  4. Save the file, right click config.json, select Properties, and enable Read-only.

TLDR: using wav files instead of mp3s fixes the issue, but for long tracks you'll need to allocate more memory to RuneLite.

Actually: Using wav actually seems to be laggier during the actual track so mp3 just ends up being better. The RuneLite memory trick is interesting though.

alowaniak commented 1 year ago

The plugin is currently copying the track it's going to play on the client thread which isn't a very smart move. I'm pretty sure it'll happen for both wav and mp3 and since wav tends to be bigger the move will take longer. The reason it's semi needed is because otherwise you get problems removing/overriding a playing track because the file is still in use. Ideally either the move wouldn't be done at all, or done on a separate thread. I'm not sure when I'll have(/make) time for it to fix it though.