I am working on a project where I am currently trying to generate tone using audio context. Here is what I came up so far:
$("#btn").click(function(){
var context = new (window.AudioContext || window.webkitAudioContext)();
var osc = context.createOscillator(); // instantiate an oscillator
osc.type = 'sine'; // this is the default - also square, sawtooth, triangle
osc.frequency.value = 440; // Hz
osc.connect(context.destination); // connect it to the destination
osc.start(); // start the oscillator
osc.stop(context.currentTime + 1);
})
I got the solution from stackoverflow. It perfectly makes the tone I am looking for. However, it only works for only less than six activation. In other words, when I click the button(with id === "btn") more than six times, it no longer makes the tone.
Here is jsFiddle.net link that has the same syntax as above click here
Can you help me fix the problem?