goldfire / howler.js

Javascript audio library for the modern web.
https://howlerjs.com
MIT License
23.36k stars 2.21k forks source link

HowlerJS 2.0 causes Chrome Tab to crash #426

Closed lTyl closed 8 years ago

lTyl commented 8 years ago

Hey,

I am trying to use Howler to help manage both music tracks and sound tracks for a video game project. We have about 35MB of music and 10~MB of Sounds.

Our old method of handling music in-game basically involved caching our files in a _clips object, then we could play the sound via it's named ID. When I implemented the same system with Howler (All sounds and music pre-loaded from game start), the RAM usage spiked to 2gb+ for the tab running Howler, and would crash with an "Aww Snap" error, most likely due to lack of RAM.

Next I tried audio sprites and packed all of our music into a single file using audiosprite. RAM usage would hover around 600mb for the Howler tab (Big improvement!), but it would crash roughly 15-20 seconds after the initial load, with the same Chrome "Aww Snap!" error.

Using a single sound or music file works fine (But our RAM usage doubles with only a single music track). I really want to take advantage of the improved Audio features Howler makes readily available, but it seems Web Audio is very memory hungry. Why is this?

Will I have to build an AudioManager class to dynamically load/unload music and sound files to keep RAM usage within reasonable limits? Where can I find how much RAM I can expect Howler/Web Audio to consume per MB of data/file/instance? How much garbage am I creating every time I call the unload() method?

mzgoddard commented 8 years ago

@lTyl have you tried using the buffer flag on your music? Its recommended that Web Audio buffers are not longer than 45 seconds. Howler's buffer flag will instruct it to use an Audio Tag for that Howl instead of Web Audio (you can use web audio and audio tags together by creating other howls without the buffer flag). The way Howler uses Web Audio, it decodes your sound effects into their raw format (this is the most common use case for Web Audio). Thats ok for small tracks but has issues with large tracks. For your music you'll probably want the buffer flag.

If your 10 MB of sounds is a non-wav format, like I'm guessing your music is as well, you may need to manage what is and isn't in loaded.

goldfire commented 8 years ago

Yes, @mzgoddard is correct, you'll need to use HTML5 Audio for the music tracks. We have around 25MB of music in CasinoRPG and don't have any crashing issues when only using Web Audio for sound effects. On 1.x you'll set buffer to true and on 2.0 you'll set html5 to true.

lTyl commented 8 years ago

For HTML5 audio for music tracks, do the seek or audios price functionality still work? We have distinct tracks that have defined intros, endings and looping portions.

Another issue we're having with html5 audio (which is what we are using entirely right now) is the music tracks do not loop seamlessly; there is a very slight pause when the track starts over from the beginning. Using Web Audio makes this delay disappear and our music loops properly

lTyl commented 8 years ago

Audio price should be audiosprite. Darn auto correct on mobile :(

goldfire commented 8 years ago

In 2.0 core everything is supported the same by both.