Jump to content

How to properly work with audio


Maras
 Share

Recommended Posts

Apparently the best way to work with audio files is to have just one audio file containing all sounds, is that right?

 

Are there any other tools for it than audiosprite? And after I generate the file, is there some native way how to make markers from the generated JSON?

 

And when do you merge these audio files? I would do it in final stage of production and before that just use separate files, but is there some other, automated, way?

 

Thanks!

Link to comment
Share on other sites

The audisprite markers are easy to create from the tools jukebox json output. Just couple of lines, if you can get the json data to JavaScript object easily (I'm embedding my data to avoid server requests).

 

I played with it a bit and I think I will go with this approach. (+ keep them separated until I am satisfied with all sound effects)

 

I will put the markers directly into my code to avoid another json file. I just wanted to make sure that audio sprites is how it's done. 

 

Thanks!

Link to comment
Share on other sites

Well I just tried markers and it works well on desktop.

 

Although on my tablet it's a disaster. It's also delayed and it plays the start of the whole sound file with increased speed instead of the part where it should be for a short duration (at least the duration should be correct).

 

If I tap more than once before the sound ends, it plays the whole file to end (also with increased speed).

 

Separate sound file was just delayed for a first time it was used (then it worked without delay), so that could be hacked some other way (perhaps playing the sounds in background with 0 volume).

 

Also the sound does not work at all in desktop IE11.

 

You can test it here:

http://play.gamesacross.com/newgame/ (press the play button to play the sound)

 

Any ideas?

 

 

Thanks!

Link to comment
Share on other sites

I have trouble using audio as well.

 

I have an audio spritesheet and a JSON file for indicating markers.

 

In order to play audio, i read the JSON file, add an audio and add markers from the JSON, with this piece of code.

        var fx = game.add.audio(key);        var audiosprite = game.cache.getJSON(json);        for (var sprite in audiosprite.spritemap) {            var start = audiosprite.spritemap[sprite].start;            var end = audiosprite.spritemap[sprite].end;            //var loop = audiosprite.spritemap[sprite].loop;            fx.addMarker(sprite, start, end - start);        }

The problem is when I enter a new state the audio is gone, so I call this in the beginning of every state. Is that a proper approach or is there a better way?

Link to comment
Share on other sites

So it looks like the problem is audiosprite + .mp3. 

 

If I use this: 

this.load.audio("sounds", ["_game/assets/sounds/sounds.mp3", "_game/assets/sounds/sounds.ogg"], true);

or

this.load.audio("sounds", "_game/assets/sounds/sounds.mp3", true); 

It's broken. If I use this:

this.load.audio("sounds", "_game/assets/sounds/sounds.ogg", true); 

Everything works fine. Separate mp3 audiofiles works fine too.

 

Tested on Samsung GT-i8190n (No sound while using mp3 audiosprite) and Lenovo IdeaTabA1000-F (sounds go crazy while using mp3 audiosprite).

 

I also just found quite simple fix - putting ogg file first and mp3 file second. But does it fix everything? It seems that every device is behaving a bit differently (starting with preloader and ending with sounds)

Like this:

this.load.audio("sounds", ["_game/assets/sounds/sounds.mp3", "_game/assets/sounds/sounds.ogg"], true);

 

 

 

 

I have trouble using audio as well.

 

I have an audio spritesheet and a JSON file for indicating markers.

 

In order to play audio, i read the JSON file, add an audio and add markers from the JSON, with this piece of code.

        var fx = game.add.audio(key);        var audiosprite = game.cache.getJSON(json);        for (var sprite in audiosprite.spritemap) {            var start = audiosprite.spritemap[sprite].start;            var end = audiosprite.spritemap[sprite].end;            //var loop = audiosprite.spritemap[sprite].loop;            fx.addMarker(sprite, start, end - start);        }

The problem is when I enter a new state the audio is gone, so I call this in the beginning of every state. Is that a proper approach or is there a better way?

 

I use TypeScript, so I just simply store the sounds in global variable. (not global in final JS)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...