BrU32

JS Wobble/Bassline Synth w/ Random Speed/Playback!!

Jun 24th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. <center>
  2. <button>Start Wobble</button>
  3. <script>
  4. var context = new AudioContext();
  5. var frequency;
  6. document.querySelector("button").addEventListener("click", GenRandomWobble);
  7. function GenRandomWobble() {
  8. frequency = Math.floor(Math.random() * 100)+50;
  9. var Osc1 = context.createOscillator();
  10. var Osc2 = context.createOscillator();
  11. Osc1.type = "saw";
  12. Osc1.frequency.value = frequency;
  13. Osc1.connect(context.destination);
  14. Osc2.type = "saw";
  15. Osc2.frequency.value = frequency;
  16. Osc2.detune.value = -90;
  17. Osc2.connect(context.destination);
  18. var Timer =Math.floor(Math.random()*60);
  19. Osc1.start(context.currentTime);
  20. Osc1.stop(context.currentTime + Timer);
  21. Osc2.start(context.currentTime + 0);
  22. Osc2.stop(context.currentTime + Timer);
  23. alert('Frequency: '+frequency+ "\n\nSeconds Total: "+Timer);
  24. }
  25. </script>
  26. </center>
Advertisement
Add Comment
Please, Sign In to add comment