Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zoolu-got-rhythm/9d60fb074763f22509dfb47923097ff3 to your computer and use it in GitHub Desktop.
Save zoolu-got-rhythm/9d60fb074763f22509dfb47923097ff3 to your computer and use it in GitHub Desktop.
increase frequency of sine wave over time in web audio api
function increaseFreq(osc, nOfTimesToIncreaseFreq, delayInSeconds, riseInFrequency){
for(let i = 0; i < nOfTimesToIncreaseFreq; i++){
osc.frequency.setValueAtTime(200 + (i*riseInFrequency) , audioCtx.currentTime + (i * delayInSeconds)); // value in hertz
}
}
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// create Oscillator node
const oscillator = audioCtx.createOscillator();
oscillator.type = "sine";
increaseFreq(oscillator, 40, 0.2, 10);
oscillator.connect(audioCtx.destination);
oscillator.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment