Audio Sprites For BJS

So as @Deltakosh suggested, here is the feature request for “Audio Sprites”. But first a simple example using Howler Js:

Sound Test

Click on the blue cube - it will play the complete audio file. Note the order of sounds - scream comes before the male and them female footsteps. When the file has finished playing (end of the creaking door), click the cube again - now two lots of footsteps together followed by a scream.

Now for files for DK : It contains the audio file with the sounds and a little text file that gives the start point and length of each little sound in the file

The file takes me back a long way. It comes from a VRML multiplayer world I created years ago for Blaxxun. More than one lady got a big scare!

So six sounds in one file. If you need anything else let me know, and good luck David, though you probably don’t need any :slight_smile:

cheers, gryff :slight_smile:

Here we are: Add support for sound sprites · Issue #6491 · BabylonJS/Babylon.js · GitHub

I should be able to work on it today or early next week :slight_smile:

@gryff: Can I store that audio file on the playground? Is there any license associated with it?

Here we are: Play Sounds and Music - Babylon.js Documentation


@Deltakosh : TY David.

Can I store that audio file on the playground? Is there any license associated with it?

I made the file about 2002 -quite a few years ago!. It was built from bits of audio files available as “public domain” or an early version of CC licence. I never purchased any sounds - I always used free stuff. The files were combined 17 years ago (Windows 98!!) so I have no idea any more as to where they actually came from anymore or what the exact licence type was.

You are certainly welcome to use them for the PG - but perhaps I should build a new file with PD sounds?

cheers, gryff :slight_smile:

I stored it…Seems like it is fine :smiley:
let me know if the code works for you

@Deltakosh wrote:

let me know if the code works for you

Well basic code seems to work - just a couple of issues:

  1. In the basic sound file load, the offset and length seem to be defined in “milli” seconds (see sound docs) , but if you want to call a particular sprite elsewhere in the code, you define that sprite call in seconds - had me tearing my hair out.

  2. If you want to play two sprites at the same time and they are a different length then the length used for both sprites is the one that is longer (or seems to be).

Playground Sprite Test

The sound of the shorter sprite gets extended.( you will hear the start of the door creak …)

I tried testing if the order of the calls mattered - switch the “rem” status of lines 21 and 23. It had no effect.

But we certainly are on the road :slight_smile:

Sorry for the slow response - a big family weekend - Father’s Day, my birthday (75), and a wedding anniversary

cheers, gryff :slight_smile:

  1. So true! I will move everything to seconds
  2. bug found! will fix it for next commit

Thanks mate!

@Deltakosh : In the meantime, I kind of tricked the current commit to play something like my original demo with Howler.Js. You just get the extra “foghorn” before the “scream”, and of course that bit of the “creaky door” . Just tested it - no creaky door - you have fixed something David :smiley:

Playground Test

Now works perfectly !!! Brilliant mate! :smiley:

And just out of interest, why is it “onended” and not “onEnded”? I keep thinking of “isVisible” and “isEnabled” … but then I’m not much of a coder :upside_down_face:

cheers, gryff :slight_smile:

Because when that API was created we missed the typo :slight_smile:


I made some time ago a shell process which was going through a folder with sound files in it in order to merge them in one file only and which generated a json beside with the start (in milliseconds) of every sound. The idea was to optimise the load time of the sounds online of course.
Unfortunatly I lost that shell file when my computer crashed a year ago. And I got stuck with the same sound in the game since.

Those sound sprites will definitely help to update them now! :wink:

@Deltakosh : Just let us know if you change it all to seconds as you mentioned above.

cheers, gryff :slight_smile:

I did and it is live

1 Like

@Deltakosh : then somone should change the docs. It still reads :

You can define a sound sprite when creating a sound by defining an offset and a length (in milliseconds)

cheers, gryff :slight_smile:

Oups ;D