javascript - Web Audio Api, setting the gain -


i have been looking @ web audio api , not able audio gain work. have fiddle set here, can understand application of function: http://jsfiddle.net/mnu70gy3/

i hoping dynamically create tone on click event, not able have tone fade out. below relevant code:

var audioctx = new audiocontext(); var osc = {};  // set object oscillators var gainnodes = {};  // set object gains var now; function tone(id,freq) {      // create osc / set gain / connect osc     gainnodes.id = audioctx.creategain();     osc.id = audioctx.createoscillator();     osc.id.connect(audioctx.destination);      // set frequency     osc.id.frequency.value = freq;      // set gain @ 1 , fade 0 in 1 second     gainnodes.id.gain.value = 1.0;     gainnodes.id.gain.setvalueattime(0, audioctx.currenttime + 1);      // start , connect     osc.id.start(0);     osc.id.connect(audioctx.destination);  } 

any thoughts on if can done?

in code connect oscillator destination twice. instead of connecting oscillator -> gain -> destination

gainnodes.id = audioctx.creategain(); osc.id = audioctx.createoscillator(); osc.id.connect(gainnodes.id);  // set frequency , gain osc.id.frequency.value = freq; gainnodes.id.gain.value = 1.0; gainnodes.id.gain.setvalueattime(0, audioctx.currenttime + 1);  // start , connect osc.id.start(0); gainnodes.id.connect(audioctx.destination); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -