Jump to content

Babylon.js and playing sounds


gryff
 Share

Recommended Posts

Anyone who has looked at the code I use for playing sound, music or dialog will notice that I use howler.js for playing sound. Now this New Year, I made a resolution to investigate more the the sound capabilities of BJS - and I have been looking at this tutorial .

 

Now there is one feature that I can't see in the BJS that howler.js has - sound sprites. See here - scroll down to "Define and play a sound sprite" to see an example. All the sounds are contained in one file - but it is possible to play just parts of the file (and if you click the "Play Winner" button and then click the other two buttons you can play all three sounds at the same time - sounds get mixed).

 

So why might this be useful? Well for playing what I call scene environment sounds - like doors opening and closing, footsteps fading away, a scream, a bell sounding, a dog howl etc.

 

Now I have a little collection of these types of sound (between 15 and 20 sounds) the longest of which is about 9 secs and the shortest is 1.2 secs. so rather than load 15 separate files it would be nice to load just one file that I could play small parts of - saves clutter, and download requests.

 

So am I missing/overlooking this type of functionality in BJS with sound? Or is it a feature that could be added?

 

And as a side question, what compressed sound format is playable on all OSs, devices and browsers - or is that a fantasy?

 

cheers, gryff :)

Link to comment
Share on other sites

Hi gryff,

Yes I know howler got that, it wasn't in my priority list. I can put this feature in my backlog if you really think it's important.

For codecs, MP3 seems to be the universal format. One drawback: it doesn't loop perfectly most of the time.

For Babylon, you can find an up to date article on our sound support on my blog: https://blogs.msdn.microsoft.com/davrous

Cheers,

David

Link to comment
Share on other sites

Thank you for the reply David :)

 

And thanks for posting the link to your blog. I have actually been keeping an eye on it - that was how I found out about the Web Audio tab in Firefox. I was also very very impressed with another blog about your efforts at creating a "Breakout" game for the visually impaired using WebGL audio - I would not have known where to start :o

 

I can put this feature in my backlog if you really think it's important.

 

Well I think it could be useful for me - but I don't know what the priorities are for the BJS team. I do believe that, as I said above, it could be useful for environmental and atmospheric sounds - so a variety of gun/weapon sounds, or wind, or doors opening and closing etc. - which can be important in some types of games. I also think it might be useful in short dialog/conversation events.

 

 

Here is a simple example that I created with howler.js. Imagine the back streets of Victorian London :

 

5 Sounds

 

It uses one sound file containing 5 different sounds - a church bell, a foghorn, a woman's scream, man's heavy footsteps and finally a woman's footsteps. Click on the red box  5 times and you can play the 5 sounds individually. On the sixth click sounds 4 and 5 are played together - followed by sound 3. By using the "sound sprite" mechanism, you end up with an atmospheric effect for those backstreets. Now I suppose you can do this with separate audio files - but the scream is only 1.2 secs long.

 

This all stems from watching conference videos about narrative and atmosphere in video games. Anyway, you and DK will decide one way or another. So thanks again for listening.

 

Bonne année!! :)

 

cheers, gryff :)

Link to comment
Share on other sites

Thank you David. And as they say, "You are a gentleman and a scholar". :)

 

Having read you blog about the "Breakout" game and the challenges it presented,  I'm sure you will find a way to implement this sprite feature without too much difficulty.

 

cheers, gryff :)

Link to comment
Share on other sites

Remember that SSSynthesiser, by Surikov?  I do not know why a non-file based use of Web Audio would need to only loop part, but he did it.

https://github.com/surikov/SSSynthesiser.js/blob/master/SSSynthesiser.js

 

I had partially converted it to typescript/BJS when I noticed the loopStart / loopEnd  properties on audioBufferSourceNode.  That looks like it might be the way to implement.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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