Created
June 23, 2023 10:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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