Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <center>
- <button>Start Wobble</button>
- <script>
- var context = new AudioContext();
- var frequency;
- document.querySelector("button").addEventListener("click", GenRandomWobble);
- function GenRandomWobble() {
- frequency = Math.floor(Math.random() * 100);
- var Osc1 = context.createOscillator();
- var Osc2 = context.createOscillator();
- Osc1.type = "saw";
- Osc1.frequency.value = frequency;
- Osc1.connect(context.destination);
- Osc2.type = "saw";
- Osc2.frequency.value = frequency;
- Osc1.detune.value = -15;
- Osc2.detune.value=-90;
- Osc2.connect(context.destination);
- Osc1.start(context.currentTime);
- Osc1.stop(context.currentTime + Math.random()*50);
- Osc2.start(context.currentTime + 0);
- Osc2.stop(context.currentTime + Math.random()*50);
- alert('Frequency: '+frequency);
- }
- </script>
- </center>
Advertisement
Add Comment
Please, Sign In to add comment