topical media & game development
mobile-query-three-plugins-webaudio-vendor-webaudio.sound.jsfx.js / js
Generate a sound with jsfx.js library
parameter: {Array} lib the library parameters to generate a sound with jsfx
returns: {WebAudio.Sound} for chained API
WebAudio.Sound.fn.generateWithJsfx = function(lib){
// sanity check - all dependancy MUST be loaded
console.assert(jsfx , "jsfx.js MUST be loaded");
console.assert(jsfxlib , "jsfxlib.js from jsfx.js MUST be loaded");
console.assert(audio , "audio.js from jsfx.js MUST be loaded");
// generate the params
var params = jsfxlib.arrayToParams(lib);
// generate the wave itself and return it
var data = jsfx.generate(params);
// Build the AudioBuffer
var buffer = this._webaudio.context().createBuffer(1, data.length, 44100);
var fArray = buffer.getChannelData(0);
for(var i = 0; i < fArray.length; i++){
fArray[i] = data[i];
}
// set the buffer in this sound
this.buffer(buffer);
// for chained API
return this;
};
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.