Advertisement
BrU32

JS Cuztomizable Mouse Synth

Oct 18th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. <script>
  2. var audioCtx=new AudioContext();
  3. var oscillator = audioCtx.createOscillator();
  4. var gainNode = audioCtx.createGain();
  5. oscillator.connect(gainNode);
  6. gainNode.connect(audioCtx.destination);
  7. var WIDTH = window.innerWidth;
  8. var HEIGHT = window.innerHeight;
  9. var FreqMax = prompt('Enter Max Freq:');
  10. var VolMax = prompt("Enter Max Vol:");
  11. var Freq = prompt("Enter Freq");
  12. var Vol = 0.1;
  13. oscillator.type = 'sawtooth';
  14. oscillator.frequency.value = Freq;
  15. oscillator.start();
  16. gainNode.gain.value = Vol;
  17. var CurX;
  18. var CurY;
  19. document.onmousemove = updatePage;
  20. function updatePage(e) {
  21. CurX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  22. CurY = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
  23. oscillator.frequency.value = (CurX/WIDTH) * FreqMax;
  24. gainNode.gain.value = (CurY/HEIGHT) * VolMax;
  25. canvasDraw();
  26. }
  27. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement