Audio Lag Fix

Discussion in 'JS Plugin Releases (RMMV)' started by Fornoreason1000, Jan 2, 2017.

  1. Fornoreason1000

    Fornoreason1000 Black Sheep Veteran

    Messages:
    138
    Likes Received:
    68
    Location:
    Aldea Kingdom
    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: Aug 14, 2017
    #1
  2. Jonforum

    Jonforum Veteran Veteran

    Messages:
    1,436
    Likes Received:
    1,136
    Location:
    Canada / Québec
    First Language:
    French
    Primarily Uses:
    RMMV
    hi friend


    can you give difference between.
     
    #2
    Fornoreason1000 likes this.
  3. Fornoreason1000

    Fornoreason1000 Black Sheep Veteran

    Messages:
    138
    Likes Received:
    68
    Location:
    Aldea Kingdom
    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: Jan 2, 2017
    #3
    TheTitan99 likes this.
  4. Zalerinian

    Zalerinian Jack of all Errors Veteran

    Messages:
    4,691
    Likes Received:
    914
    Location:
    The Internet.
    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?
     
    #4
    Fornoreason1000 likes this.
  5. Fornoreason1000

    Fornoreason1000 Black Sheep Veteran

    Messages:
    138
    Likes Received:
    68
    Location:
    Aldea Kingdom
    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: Feb 17, 2017
    #5
    TheTitan99 likes this.
  6. moldy

    moldy Veteran Veteran

    Messages:
    185
    Likes Received:
    28
    First Language:
    English
    Holy crap it works! Thanks so much! This audio lag in battle was driving me insane!
     
    #6
    TheTitan99 and Fornoreason1000 like this.
  7. Fornoreason1000

    Fornoreason1000 Black Sheep Veteran

    Messages:
    138
    Likes Received:
    68
    Location:
    Aldea Kingdom
    First Language:
    English
    Primarily Uses:
    RMMV


    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.
     
    #7
    TheTitan99 likes this.
  8. miksva44

    miksva44 Knight449 Veteran

    Messages:
    64
    Likes Received:
    7
    Location:
    Sweden
    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: Jan 4, 2017
    #8
    Fornoreason1000 likes this.
  9. Fornoreason1000

    Fornoreason1000 Black Sheep Veteran

    Messages:
    138
    Likes Received:
    68
    Location:
    Aldea Kingdom
    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. 
     
    #9
    TheTitan99 and miksva44 like this.
  10. miksva44

    miksva44 Knight449 Veteran

    Messages:
    64
    Likes Received:
    7
    Location:
    Sweden
    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.  :)
     
    #10
    Fornoreason1000 likes this.
  11. Tuomo L

    Tuomo L Oldbie Veteran

    Messages:
    2,106
    Likes Received:
    1,055
    Location:
    Finland!
    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.
     
    #11
    Fornoreason1000 likes this.
  12. Fornoreason1000

    Fornoreason1000 Black Sheep Veteran

    Messages:
    138
    Likes Received:
    68
    Location:
    Aldea Kingdom
    First Language:
    English
    Primarily Uses:
    RMMV


    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: Jan 7, 2017
    #12
    TheTitan99 likes this.
  13. Tuomo L

    Tuomo L Oldbie Veteran

    Messages:
    2,106
    Likes Received:
    1,055
    Location:
    Finland!
    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.
     
    #13
  14. moldy

    moldy Veteran Veteran

    Messages:
    185
    Likes Received:
    28
    First Language:
    English
    #14
  15. Tuomo L

    Tuomo L Oldbie Veteran

    Messages:
    2,106
    Likes Received:
    1,055
    Location:
    Finland!
    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.
     
    #15
  16. Fornoreason1000

    Fornoreason1000 Black Sheep Veteran

    Messages:
    138
    Likes Received:
    68
    Location:
    Aldea Kingdom
    First Language:
    English
    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.
     
    Last edited by a moderator: Jan 11, 2017
    #16
    TheTitan99 and Tuomo L like this.
  17. Tuomo L

    Tuomo L Oldbie Veteran

    Messages:
    2,106
    Likes Received:
    1,055
    Location:
    Finland!
    First Language:
    Finnish
    Primarily Uses:
    RMMV


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

    moldy Veteran Veteran

    Messages:
    185
    Likes Received:
    28
    First Language:
    English


    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: Jan 12, 2017
    #18
  19. Leysos

    Leysos Eating Oreos with your wife Veteran

    Messages:
    32
    Likes Received:
    25
    Location:
    Ousai
    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 dayum fine job, and I thank you for your effort. It works flawlessly as intended so far. 
     
    #19
    TheTitan99 likes this.
  20. moldy

    moldy Veteran Veteran

    Messages:
    185
    Likes Received:
    28
    First Language:
    English
    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 ;(
     
    #20

Share This Page