rezoner / playground

Playground.js is a framework for your javascript based games. It gives you out-of-box access to essentials like mouse, keyboard, sound and well designed architecture that you can expand to your needs.
MIT License
466 stars 50 forks source link

SoundOnDemand - Alternative sound engine #4

Closed rezoner closed 9 years ago

rezoner commented 9 years ago

EDIT: The work is done - see http://playgroundjs.com/libs

Below is a draft usage of a new sound engine I am working on.

It will most likely come as a standalone library and plugin to integrate with playground's loader flow

API and features by example:

Setup / channels


/* audio engine */

this.audio = new SoundOnDemand();

/* separate audio channels */

this.audio.channel("sound");
this.audio.channel("music");
this.audio.channel("enviro").reverb(0.5);

/* as you can see you can push your gui bleeps through a clean channel, but if a player is in a cave his footsteps could go through reverbed enviro channel */

/* set master volume */

this.audio.volume(0.5);

/* set channel volume */

this.audio.channel("music").volume(0.5);

/* enqueue sound to be played in next frame or when ready
   con: 1/60 delay
   pro: ondemand loading
*/

this.audio.channel("sound").play("explosion").rate(0.8).volume(1.0);

/* the new engine will load sounds on demand - and play them ASAP - 
    of course manual preloading is still possible */

Other features

It take more time to write app.audio.channel("sound").play(...) but there is nothing to stop you from saving a channel this.sound = this.audio.channel("sound")

Variable names reasoning: