I cannot create two oscillators with independent amplification factors.
In the code below, two buttons are created, each of which reproduces a sinus tone with a different step. When I press the first button, I hear how the tone grows in volume, as it should. But, when I press the second button, the tone reacts as if it is connected to the amplification of the first tone. For example, if I press the second button (turning on the second tone) while the first tone is at volume 1, the second tone will go into volume 1, although it should go around from 0 to 1 to 0 at the rate of 10 seconds.
Can I get only one node gain per audio context? Or is there some other reason that the benefits of these generators are related? Also, after I play the tones once, I cannot play them again, which makes me especially think that I am doing something wrong. :)
Thanks. Below is the link, and the code is below. This is my first post, so let me know if you need anything else. This code must be running on versions of Chrome or Safari that support web audio api.
http://whitechord.org/just_mod/poly_test.html
WAAPI Tests
<button onclick="play()">play one</button> <button onclick="play2()">play two</button> <script> var context; window.addEventListener('load', initAudio, false); function initAudio() { try { context = new webkitAudioContext(); } catch(e) { onError(e); } } function play() { var oscillator = context.createOscillator(); var gainNode = context.createGainNode(); gainNode.gain.value = 0.0; oscillator.connect(gainNode); gainNode.connect(context.destination); oscillator.frequency.value = 700; gainNode.gain.linearRampToValueAtTime(0.0, 0); </script> </body> </html>
source share