Fornoreason1000

Black Sheep
Regular
Joined
Mar 1, 2014
Messages
206
Reaction score
98
First Language
English
Primarily Uses
RMMV

Audio Lag Fix 0.82 Beta







It's no secret that some people have been experiencing Audio lag within RPG maker specifically the longer BGM Files.
This is mainly due to Audio Buffer not being suited for clips greater than 45 seconds. When Audio begins to play, it is then RPG maker begins loading the file into memory, this takes time especially with BGMs which tend to be larger. they're are two ways to fix this. you can pre-load the file or Stream it from the source. this plugin trys the latter.


I've tested this plugin using a 10 minute stereo track i generated with Audacity. I noticed 1-2 seconds delay on my PC without the plugin. no delay with it on. I had trouble reproducing this effect in the editor. if this plugin doesn't work please let me know. I want to tackle this beat and win!. people with high end PC's may not notice a great deal because their PC's power will make up for the lag.


Known Issuse


  • One issue with this plugin is that Pitch shifting BGM's will no longer work as intended. This is due to the way Audio Element works in the Web Audio API and correct pitch shifting would require granular re-synthesises at run time. With this in Mind it may be sometime until i get that working, in the meantime pitch shifting BGM's will only change playback speed.
  • Another is a small delay when fading out/in that is apparent when moving to a new map. this is caused by a FPS drop when loading a new map on mobile or other low end devices.
  • Does not work on Android
Reporting Bugs


Before reporting a bug, please ensure you have the most Updated version of this script, i usually update it whenever i find a bug i it. make sure RPGmakerMV is also up to date.

Please also include how you can replicate the bug, and what the error console says (push F8 to open the error console). with this information i can track what is happening with the bug and resolve the issue much more quickly.

Terms Of Use
This Plugin is released as is and is permitted to be of use in both commercial and non-commercial products. This Plugin is released for free and is protected by the MIT Licence
 
Last edited:

Fornoreason1000

Black Sheep
Regular
Joined
Mar 1, 2014
Messages
206
Reaction score
98
First Language
English
Primarily Uses
RMMV
Sure
This Plugin does not Preload the Audio nor does it require preload manager.


The plugin you listed, preloads all the Audio and store it in a cache before leaving a loading screen. making the lag look like its disappeared.


This Audio works by using HTMLMediaElement interface of the Web Audio ApI. The reason the Audio Lags is Audio Buffer is designed for small loops under 45 seconds , such short tracks scarcely affect performance. one you start hitting the 2 or 3 minutes the lag shows it ugly head.

HTMLMediaElement on the other hand can handle the longer tracks. but like above my PC is too quick to barely notice the lag, even a 10 minute track. So a few people will need to confirm that it actually does its job. preferably those with mid range to low end PCs.

 
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Regular
Joined
Dec 17, 2012
Messages
4,699
Reaction score
947
First Language
English
Primarily Uses
N/A
Personally, I have never had any issues with audio lag, so I always tend to pay close attention to posts about audio lag. I can't find any instance of an AudioBuffer being created in the code for WebAudio.js, which seems to be the part of MV that you've gone and replaced with your plugin. As far as I can tell, the code I have for WebAudio creates a new HTML Audio element, same as your plugin, so personally, unless I somehow have a different version of the code than you, I'm not sure what the difference is between doing 


var audio = new Audio(url);


and 


var audio = document.createElement('audio');




The only difference I've been able to find is that the new Audio method creates an audio tag with the preload tag of "auto", whereas creating it through the document does not add the preload tag automatically.


Can you clarify on what the difference is, or if I'm if I'm just full of crap?
 

Fornoreason1000

Black Sheep
Regular
Joined
Mar 1, 2014
Messages
206
Reaction score
98
First Language
English
Primarily Uses
RMMV
the Audio Buffer is in the createSourceNode Function in WebAudio.js by calling createBufferSource on the Audio Context


Code:
WebAudio.prototype._createNodes = function() {
    var context = WebAudio._context;
    this._sourceNode = context.createBufferSource();
   //other nodes
};


that's basically the standard practice when creating Audio nodes.

now the difference between the two lines of code


Code:
var audio = new Audio(url);                   //HTMLAudioElement Interface
var audio = document.createElement('audio'); //HTML Audio Element



is the first one is the basic <audio> HTML element while the other is an interface implemented by the Web Audio API called HTMLAudioElement that accesses <audio>. i found it much easier to use the top example , because it gives access to more functions and properties than creating a <audio> HTML element. I can't tell you if there is a performance difference when it comes to playing Audio. In both cases Pre-load can be accessed and changed anyway.
 
Last edited:

Fornoreason1000

Black Sheep
Regular
Joined
Mar 1, 2014
Messages
206
Reaction score
98
First Language
English
Primarily Uses
RMMV
Holy crap it works! Thanks so much! This audio lag in battle was driving me insane!



That's Awesome, I'm glad to hear it works for you. bear in mind you may experience lag still on the Storm2 and Night BGS. that its because they are over a minute long and this script predominately targets BGM files. I'm working on a solution for this, maybe a small list of BGS names that the script will play different when AudioMananger Encounters them to avoid Lag. Or just play all sounds using this script.
 

miksva44

Knight449
Regular
Joined
Sep 26, 2016
Messages
66
Reaction score
8
First Language
swe/eng
Primarily Uses
RMMV
Hi, hope I get it right this time.  ;)


I added the plugin, It´s the only plugin I use for the moment because I don´t know so much about plugins and scripting.


And what I'm trying to do is to play a "BGM" fade it out, then play a "BGS" and then fade that out and that worked but when I tried starting a different "BGM" after that it crashes "Screenshots"


I tried starting a new game just to test playing fading out and it worked, but not in the game I'm woking on.


And I used the same audio files in the test.


Hmm 2.jpg


Hmm.jpg
 
Last edited by a moderator:

Fornoreason1000

Black Sheep
Regular
Joined
Mar 1, 2014
Messages
206
Reaction score
98
First Language
English
Primarily Uses
RMMV
 Hi , that looks like a bug on my part. its cause by some debug code i left in there which didn't check if the BGM existed before printing its name. Its is a very easy Fix. Also be sure you always have the latest version of the plugin (which is now v0.60). 




I've Updated my script accordingly, please update your script to version 0.60 to remove that bug.  

As for using this plugin, there is really not much to it. It doesn't really have any settings you can adjust. Though I'm planing to include BGS because some of the defaults are kinda long. And maybe ME and SE override for specific files that happen to be quite long. 


Thank you for posting a Error report as well. If that wasn't there it would have taken me significant longer to fix. 
 

miksva44

Knight449
Regular
Joined
Sep 26, 2016
Messages
66
Reaction score
8
First Language
swe/eng
Primarily Uses
RMMV
It´s no inconvenience, not for me anyway´s. I´m grateful for any help I can get, I would be completely lost without it.  :|

But I tried the latest plugin you posted and it worked, so thanks a lot for the help.  :)
 

Tuomo L

Oldbie
Regular
Joined
Aug 6, 2012
Messages
2,505
Reaction score
1,418
First Language
Finnish
Primarily Uses
RMMV
It causes very noticeable delay when it loads audio and there's moments of silence when moving to new map. It works great otherwise but it's a really huge and noticeable problem every time you transition to a new area.
 

Fornoreason1000

Black Sheep
Regular
Joined
Mar 1, 2014
Messages
206
Reaction score
98
First Language
English
Primarily Uses
RMMV
It causes very noticeable delay when it loads audio and there's moments of silence when moving to new map. It works great otherwise but it's a really huge and noticeable problem every time you transition to a new area.



Thanks for informing me of that, unfortunately I've been trying for an hour trying to reproduce that and the audio loads almost instantaneously, this may be due to a difference in PC speeds. Anyway to help me identify this problem,
 


 does this happen all the time regardless of whether the BGM name is that same or not? or does it only happen when the BGM changes?


 Is this observed through an actual server or locally?


do you have any plugins that affect AudioMananger?


do any errors show up in the Dev Console (F8), Errors are in Red. 


if possible could you post a video or even just a sound recording?


Might see if i can reproduce on Android (ZTE Blade 5)

 
 
Last edited by a moderator:

Tuomo L

Oldbie
Regular
Joined
Aug 6, 2012
Messages
2,505
Reaction score
1,418
First Language
Finnish
Primarily Uses
RMMV
It's local. I don't get errors. It happens all the time, regardless of a BGM change or not. Here's what happened during transport from one map to next, the other map having same bgm as the previous map. The only difference is that I stopped BGS during the transition. I then went back to the same map at during which there was no longer the problem. This seems to only occur when entering a new map for the first time.



DSE-AudioLagFix.js:403
DSE-AudioLagFix.js:461 now playing bgm.2000_Town1.ogg
DSE-AudioLagFix.js:562 removing nodes
DSE-AudioLagFix.js:502 creating nodesbgm.2000_Town1.ogg
DSE-AudioLagFix.js:551 connecting nodes
DSE-AudioLagFix.js:287 new stream Audio for: audio/bgs/People1.ogg
DSE-AudioLagFix.js:403
DSE-AudioLagFix.js:461 now playing bgs.People1.ogg
DSE-AudioLagFix.js:562 removing nodes
DSE-AudioLagFix.js:502 creating nodesbgs.People1.ogg
DSE-AudioLagFix.js:551 connecting nodes
DSE-AudioLagFix.js:425 fadeing out
pixi.js:24821 Deprecation Warning: DisplayObjectContainer has been shortened to Container, please use Container from now on.
pixi.js:24821 Deprecation Warning: DisplayObjectContainer has been shortened to Container, please use Container from now on.
DSE-AudioLagFix.js:579 stopping audio stream: bgs.People1.ogg
DSE-AudioLagFix.js:562 removing nodes
DSE-AudioLagFix.js:583 removing stream HTML object
DSE-AudioLagFix.js:287 new stream Audio for: audio/bgs/People1.ogg
DSE-AudioLagFix.js:403
DSE-AudioLagFix.js:461 now playing bgs.People1.ogg
DSE-AudioLagFix.js:562 removing nodes
DSE-AudioLagFix.js:502 creating nodesbgs.People1.ogg
DSE-AudioLagFix.js:551 connecting nodes
DSE-AudioLagFix.js:440 Seeking...
DSE-AudioLagFix.js:445 Seeking...
DSE-AudioLagFix.js:440 Seeking...
DSE-AudioLagFix.js:445 Seeking...
DSE-AudioLagFix.js:579 stopping audio stream: bgm.2000_Town1.ogg
DSE-AudioLagFix.js:562 removing nodes
DSE-AudioLagFix.js:583 removing stream HTML object
DSE-AudioLagFix.js:579 stopping audio stream: bgs.People1.ogg
DSE-AudioLagFix.js:562 removing nodes
DSE-AudioLagFix.js:583 removing stream HTML object




It happens during the fadeing out part. The display object container warning is unrelated to this plugin and it's related to TerraxLightning.
 

Tuomo L

Oldbie
Regular
Joined
Aug 6, 2012
Messages
2,505
Reaction score
1,418
First Language
Finnish
Primarily Uses
RMMV
I noticed even more serious bug than the small delay. This audio lag fix removes any possible loop points from tracks, forcing them to play through and then start from the beginning of the song instead of looping more naturally.
 

Fornoreason1000

Black Sheep
Regular
Joined
Mar 1, 2014
Messages
206
Reaction score
98
First Language
English
Primarily Uses
RMMV
Any way we could have compatibility with Izy's Vehicle Radio plugin? :D

Should already be compatibility,  he uses Game_Map class to play BGMS's which of course is compatible with this plugin.

I noticed even more serious bug than the small delay. This audio lag fix removes any possible loop points from tracks, forcing them to play through and then start from the beginning of the song instead of looping more naturally.

Yes, Looping is a feature of the original Web Audio class RPGMaker comes with, a feature i have forgot re-implemented yet but I am working on it.


The main reason Looping is does not exist with this plugin is in order to access tags from Audio files you need to completely decode them, which was originally causing the lag in the first place defeating the purpose of this plugin. 


This doesn't mean it isn't possible to use the loading tags it just means you may have to use another method of looping. one possible way is to explicitly state the loops in a setting(can become tedious and cryptic, every time you change the audio loop you have to change this). Another way is to try to pre-load all the Audio then set loops for them(bad, very slow and inefficient). small meta files that specify audio settings(beginner users have no easy way of creating these, though notepad should suffice).  



I find it strange the skipping/lag only happens to new maps, whatever the cause may be, originally i though it may be the Audio stopping for no reason. or a sever CPU overhead issue causing the skipping.  


i will work on fixing both these issue on my next update.
 
Last edited by a moderator:

Tuomo L

Oldbie
Regular
Joined
Aug 6, 2012
Messages
2,505
Reaction score
1,418
First Language
Finnish
Primarily Uses
RMMV
Should already be compatibility,  he uses Game_Map class to play BGMS's which of course is compatible with this plugin.


Yes, Looping is a feature of the original Web Audio class RPGMaker comes with, a feature i have forgot re-implemented yet but I am working on it.


The main reason Looping is does not exist with this plugin is in order to access tags from Audio files you need to completely decode them, which was originally causing the lag in the first place defeating the purpose of this plugin. 


This doesn't mean it isn't possible to use the loading tags it just means you may have to use another method of looping. one possible way is to explicitly state the loops in a setting(can become tedious and cryptic, every time you change the audio loop you have to change this). Another way is to try to pre-load all the Audio then set loops for them(bad, very slow and inefficient). small meta files that specify audio settings(beginner users have no easy way of creating these, though notepad should suffice).  



I find it strange the skipping/lag only happens to new maps, whatever the cause may be, originally i though it may be the Audio stopping for no reason. or a sever CPU overhead issue causing the skipping.  


i will work on fixing both these issue on my next update.



Would the metadata information of Loopstart and Looplength suffice to tell the correct loop points without causing too much of a problem?
 

moldy

Regular
Regular
Joined
Nov 15, 2015
Messages
283
Reaction score
54
First Language
English
Primarily Uses
Should already be compatibility,  he uses Game_Map class to play BGMS's which of course is compatible with this plugin.


Yes, Looping is a feature of the original Web Audio class RPGMaker comes with, a feature i have forgot re-implemented yet but I am working on it.


The main reason Looping is does not exist with this plugin is in order to access tags from Audio files you need to completely decode them, which was originally causing the lag in the first place defeating the purpose of this plugin. 


This doesn't mean it isn't possible to use the loading tags it just means you may have to use another method of looping. one possible way is to explicitly state the loops in a setting(can become tedious and cryptic, every time you change the audio loop you have to change this). Another way is to try to pre-load all the Audio then set loops for them(bad, very slow and inefficient). small meta files that specify audio settings(beginner users have no easy way of creating these, though notepad should suffice).  



I find it strange the skipping/lag only happens to new maps, whatever the cause may be, originally i though it may be the Audio stopping for no reason. or a sever CPU overhead issue causing the skipping.  


i will work on fixing both these issue on my next update.



Hmmm it's weird. The vehicles music won't play at all for me. I've tried rearranging the plugin order but to no avail. Here's what my console says:

vehicle.png
 
Last edited by a moderator:

Leysos

Chaotic!
Regular
Joined
Jul 4, 2016
Messages
42
Reaction score
55
First Language
English
Primarily Uses
RMMV
Now all we need is an official fix so we can be rid of it in the editor. It's been a year and some change, now. I understand the devs are hard at work on other stuff as-is, but... it's disheartening, to say the least. Still, as much as I wish we didn't need a plugin like this in the first place, you've done a damn fine job, and I thank you for your effort. It works flawlessly as intended so far. 
 

moldy

Regular
Regular
Joined
Nov 15, 2015
Messages
283
Reaction score
54
First Language
English
Primarily Uses
Could someone else verify if they can get this plugin to work with Izy's Radio Vehicle? I really don't want to abandon either plugin ;(
 

Latest Threads

Latest Posts

Latest Profile Posts

I was planning on getting new character management feature into Character Generator, but my recent illness has delayed this somewhat. I will try and get it done today (which would be a miracle) but if not, I will have to complete the whole lot by Tuesday. This should hopefully be fine and all other feature updates should not have their target dates affected.
Everybody: "Hey, weren't you supposed to be making a game"?

Me. "MUST MAKE MOAR CUTSCENES!!1"
I've been watching videos about the videogame streamer Open Hand charity scandal, and the rabbit hole keeps getting deeper. At first it was just a lot of donated money being grossly neglected for years, and now there's a lot of money unaccounted for, which could turn this into a legitimate IRS crackdown.
Let's have some fun with my advent calendar. What would you like to see for Day 3: land, sea, or air? :rheh:
I've been thinking about doing a jokey submission for the Christmas jam in which, like a cartoon special where all the characters "play" a counterpart in A Christmas Carol, my MagiCats would each play a role from the C.A. Smith story The Coming of the White Worm, with Cyprian as Evagh, Rousalie as Dooni and so forth. But in the end, I figure all my development efforts should go toward the game proper.

Forum statistics

Threads
136,704
Messages
1,268,950
Members
180,420
Latest member
vonilt
Top