BrU32

JS Web Audio API UK Hardcore Bassline Gen

Jun 23rd, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 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);
  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. Osc1.detune.value = -15;
  17. Osc2.detune.value=-90;
  18. Osc2.connect(context.destination);
  19. Osc1.start(context.currentTime);
  20. Osc1.stop(context.currentTime + Math.random()*50);
  21. Osc2.start(context.currentTime + 0);
  22. Osc2.stop(context.currentTime + Math.random()*50);
  23. alert('Frequency: '+frequency);
  24. }
  25. </script>
  26. </center>
Advertisement
Add Comment
Please, Sign In to add comment