Shin Kitsune

KITSUNE Game Design
Veteran
Joined
Oct 15, 2012
Messages
149
Reaction score
37
First Language
ENG/SPA
Primarily Uses
RMMV
While I'm not formally working on RPG Maker MV games atm, I still get to fiddle with it some to get more used to it since I have plans for stuff later.

I know this issue is not very uncommon, yet I haven't found a concrete solution to it anywhere. The music (and sometimes even sounds) delays a few seconds before starting to play, especially in Play Test mode. (The editor's Sound Test thing does not delay as much). And it sometimes hears somewhat choppy.

While it's not critical, the delay still bugs me. Only possible explanation I found over on Steam forums was:

With RPG Maker MV, it seems as though Test Play simulates running a website. So, when a song is taking a while to play, it's because it's simulating downloading the BGM or BGS. At least, that's how it looks.
Is this the reason? Or has someone managed to get over this delay?
 
Last edited by a moderator:

Shin Kitsune

KITSUNE Game Design
Veteran
Joined
Oct 15, 2012
Messages
149
Reaction score
37
First Language
ENG/SPA
Primarily Uses
RMMV
So it appears I'm not the only one with that problem: http://forums.rpgmakerweb.com/index.php?/topic/51100-rmmv-bug-title-music-often-starts-really-late-when-opened-over-web/

Since there is a "Now Loading..." screen, why is the music not prepared in there? It shouldn't be hard to check the Map Events for all the referenced music and prepare it.

Also, as I've written in the linked post the music usually opens quicker when opened in the browser regularly in a new tab, so the loading in an RPG Maker MV game seems to be broken in that it takes unnecessarily long until it starts playing which should be fixed!

A better response from the staff than "hmm well, it's the web nothing we can do" would be appreciated.
Does not seem to be the exact problem.

Whilebyou're experiening it on a web browser, I do while playtesting,which is done locally.
 

gRaViJa

Eniko Ghosts of Grace Dev
Veteran
Joined
Mar 16, 2012
Messages
982
Reaction score
631
First Language
Dutch
Primarily Uses
RMMV
Agreed. This is the most frustrating bug on MV for me.
 

Kenen

Veteran
Veteran
Joined
Apr 3, 2012
Messages
341
Reaction score
253
First Language
English
Primarily Uses
RMMZ
I can't duplicate this problem on a local playtest. To test, I set up a blank map with an auto BGM, and an event that would change the BGM after an action button press. The BGM always switches instantly.

can duplicate it on a project deployed to the web, but it's easily fixed by preloading... Either by a Plugin (http://mvplugins.tordamian.com/plugins/preload-manager/) or manually preloading via events.
 

Shin Kitsune

KITSUNE Game Design
Veteran
Joined
Oct 15, 2012
Messages
149
Reaction score
37
First Language
ENG/SPA
Primarily Uses
RMMV
Agreed. This is the most frustrating bug on MV for me.
I know. While it doesn't really break the engine, it's still annoying.

I can't duplicate this problem on a local playtest. To test, I set up a blank map with an auto BGM, and an event that would change the BGM after an action button press. The BGM always switches instantly.

can duplicate it on a project deployed to the web, but it's easily fixed by preloading... Either by a Plugin (http://mvplugins.tordamian.com/plugins/preload-manager/) or manually preloading via events.
Maybe it depends on the system then? As in, the computer itself? Still, we really need a workaround for it. I doubt the preloader plug-in would help much if the game's being played locally since you're not downloading anything.
 

Kenen

Veteran
Veteran
Joined
Apr 3, 2012
Messages
341
Reaction score
253
First Language
English
Primarily Uses
RMMZ
I was wondering if it might be hardware-related, which still seems strange. I'm uploading a quick video to demo what I mentioned in my post, for you to contrast against, possibly.


Edit: for demo/confirmation purposes, I made a quick video:




Do you get lag when switching to a new BGM in a similar scenario?


Edit: even tried some map transfer events and still no delay while testing locally.
 
Last edited by a moderator:

KisaiTenshi

Veteran
Veteran
Joined
Oct 24, 2015
Messages
310
Reaction score
127
Ok everyone, I think the attached screenshot illustrates this nicely:

attachicon.gif
BGM_delay_bug.png

Even locally, the music is downloaded with HTTP, precisely from the internal web app server that is launched to run your game. And as you can see in the screenshot this process is not very quick (see the red marker) - probably because it still sets off all the overhead of the HTTP protocol of forming a proper request with response and sending it wrapped properly as HTTP response.

I'm pretty sure this is delay we are all seeing, and I made this screenshot on a machine with a considerably fast CPU and a Solid State Disk, so it's most likely worse for all of you folks with older PCs or slower hard disks.

I can only see one feasible solution (given my guess at the problem is correct) consisting of this:

1. the BGM needs to be preloaded (like done with the "Preload Manager" plugin), even when running locally

2. the local nwjs framework used to run your desktop app needs to be convinced to cache the audio and not re-request it from HTTP internally - it doesn't currently do that for some reason, which is the reason why "Plugin Manager" would fix the problem in theory but doesn't in practice. Also see this thread for more details on this..

Summed up: the local version still seems to play a client/server game with itself which seems to add 200ms upwards (I have seen 400ms and more without trying to stress the system in this "Network" debug tab) of "download" delay for longer BGM pieces in a local playtest run, and it doesn't even cache a BGM piece requested a few seconds ago so that the delay doesn't even get better for pieces that were just played a minute ago.

Oh and I'm pretty sure this is all happening by design, so it's most likely not much better in a playtest vs an actual release export...

-----------------------

Possible fix ?!

GalenMereth and me discussed this. If you are insane and want to try the experimental code in your project:

http://forums.rpgmakerweb.com/index.php?/topic/51422-webaudio-cache-experimental/?p=508507

This plugin should completely remove any music or sound delays (at least if audio was triggered by map BGM or event trigger), even when playing in a website.

(it's not in JS releases because it's likely to have bigger bugs, I just wrote it an hour ago)

If anyone is interested in a quick try, tell me if that helps (make sure to add "Preload Manager" first, as written in the instructions). However, don't keep the plugin regularly activated just yet though, it still needs some testing on my side to make sure it works.

You're not understanding the difference beween "file://" and "http://"

file:// is the "loading local from disk" , and as such WebAudio must load the entire file into memory to play it. If you have a mechanical hard drive, this delay will be noticeable, but not nearly as noticeable as loading it from a remote server. If you look at the source code you'll notice that on certain platforms it doesn't use WebAudio at all, but uses the audio tag instead. 

You can not eliminate this delay, at least not without completely re-thinking how to do audio.

http://noisehack.com/custom-audio-effects-javascript-web-audio-api/

Notice what kind of delay there is between clicking on the buttons and the audio. They should all be instant because they are tones being generated BY the web browser.

Your options are either: stream from disk, which accepts the delay of loading, or pre-load the audio which increases memory requirements. The "possible fix" tries to do the latter while aggressively purging from the cache. I don't believe this is a good approach since it will amplify the loading delays on slower systems unless you reduce the number of audio tracks and don't change the tracks frequently. eg it works as long as all the battles are less than the cache purge time.
 

DavidFoxfire

Veteran
Veteran
Joined
Feb 28, 2014
Messages
224
Reaction score
44
Primarily Uses
I tried this Web Cache Audio plugin, and as instructed it works like a charm.

Now if I can have an assortment of "Now Loading" screens for me to pop up by randon :)
 

KisaiTenshi

Veteran
Veteran
Joined
Oct 24, 2015
Messages
310
Reaction score
127
Have you even tried the plugin before writing this post? Yes RPG Maker MV probably doesn't use HTTP internally and I was wrong on that regard, but the plugin still fixes the delay everyone is seeing because it caches the decoded audio since original WebAudio code from RPG Maker decodes again for every time you play the song, which is actually slow.

And yes, it keeps songs in memory but it purges on every map change only (so no, it doesn't purge on battle), so yes it has slightly higher memory requirements, but it won't fill up your entire memory because it purges on map change. It is true it will increase map load times if you combine it with Preload Manager, because that will preload each song used in the map to avoid the lag (obviously, since that is the point).

Try it. It works.

While there might be even better ways to solve it, it still works nicely enough and will neither eat all your memory, nor still exhibit any lag.

Edit: btw, did you know the ImageManager of the engine never appears to unload images ever? Might wanna fix that first :) I'm not saying there is not a better solution, but I'll take slightly increased loading times and memory use (which is not increasing limitless) over the annoying audio lag all day!
I said it's the wrong approach because it's basically going "if not this map, and last accessed > 5 minutes, purge" If you do this on a network connection you're going to constantly be ejecting music and sounds on map load boundaries, resulting in more network delays to recover. This solution is a brute force solution that would only work if the game is played on a system with slow disk access. If it has fast disk access (eg a SSD) it wouldn't be noticeable.

A better approach would be to read the WebAudio API documentation

https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer

The AudioBuffer interface represents a short audio asset residing in memory, created from an audio file using the AudioContext.decodeAudioData() method, or from raw data using AudioContext.createBuffer(). Once put into an AudioBuffer, the audio can then be played by being passed into an AudioBufferSourceNode.Objects of these types are designed to hold small audio snippets, typically less than 45 s. For longer sounds, objects implementing the MediaElementAudioSourceNode are more suitable. The buffer contains data in the following format:  non-interleaved IEEE754 32-bit linear PCM with a nominal range between -1 and +1, that is, 32bits floating point buffer, with each samples between -1.0 and 1.0. If the AudioBuffer has multiple channels, they are stored in separate buffer.
You'll note that MediaElementAudioSourceNode isn't referenced at all in RPG Maker MV.

This is the difference between what it's doing "for all sounds" and what it should be doing for streaming sounds. Because what it's doing now requires the entire sound to be decoded into memory, every time. MediaElementAudioSourceNode uses the audio tag in the DOM. If you poke through the code you'll notice it only attempts to use the audio tag for Android Chrome.

So if you want to be specific about the problem, the problem is that it's trying to "Stream" music by loading the entire track into memory, and this plugin doesn't solve that problem, rather it adds another layer to the WebAudio loading handling to try and unload. If you for some reason decided to put a 12 minute audio track into the game, it's still going to take 127MB of RAM. The correct way to solve this would be to recognize the difference between a BGM file and all other files and treat the BGM as streamable. My guess as to why they didn't may have more to do with what would happen if you played it over the network, or maybe they can't read the metadata if done this way for looping. 

The alternate approach would be to actually design BGM usage around short looping tracks.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,512
Reaction score
11,998
First Language
English
Primarily Uses
RMVXA
The problem with the lag on music was one reason why I reversed my decision to convert my current project from Ace to MV.

What isn't clear to me from the discussion so far is, does this solve the problem for the eventual player?  Suggestions like tinkering with hardware might work for the developer, but we clearly cannot expect our players to do this, so until there is an assurance about the player's experience, I think a number of people will hang back from using MV.
 

Shin Kitsune

KITSUNE Game Design
Veteran
Joined
Oct 15, 2012
Messages
149
Reaction score
37
First Language
ENG/SPA
Primarily Uses
RMMV
Well, the preloading system works fine for the map music itself. But when a battle starts, the music still takes seconds to play.
 

zharth

Veteran
Veteran
Joined
Feb 11, 2014
Messages
39
Reaction score
13
First Language
English
Primarily Uses
I was wondering if it might be hardware-related, which still seems strange. I'm uploading a quick video to demo what I mentioned in my post, for you to contrast against, possibly.
I envy the music transitions you're getting in this video. I made a video to demonstrate what it's like for me, with huge delays. It only affects BGMs - not MEs or SEs or BGSs. And it's the same whether I change the BGM within a map, or if I switch from one map to another, or even when the title screen loads at the beginning. The BGM always takes a few seconds to start playing after everything else has commenced. All while testing locally.
 

Latest Threads

Latest Posts

Latest Profile Posts

$Syringer.png
toying with a brand new monster design
Another doodle! Green-haired girl has no name yet, so, any suggestions?
She is about the same age as Nikki, and she is the last one of her clan, known for their innate skills in manipulating both ice and fire. She is a bit stubborn, as well as having a soft spot for kids.
Mystery messages from my AI assistant. :kaojoy:
1632842960834.png
Made some updates to a previous project I was working on. Trying to mimic the 16 bit Squaresoft aesthetic.

Forum statistics

Threads
115,436
Messages
1,089,899
Members
150,206
Latest member
V_1_
Top