BrU32

JS Audio API Synth With Random Hertz And Duration Features!!

Jul 6th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. <body onload="chk4.checked=true;
  2. Text1.value=Math.floor(Math.random()*100);
  3. Text2.value=Math.floor(Math.random()*100);" bgcolor="lightblue"/>
  4. <b>
  5. <font color="darkblue">
  6. <center>
  7. Time:(Seconds)<br>
  8. <input type="text" id="Text1" name="Text1" value="100">
  9. <br>Frequency:<br>
  10. <input type="text" id ="Text2" name="Text2" value="100">
  11. <br>
  12. <input type="checkbox" id="chk1" name="chk1" onclick="script:chk2.checked=false;
  13. chk3.checked=false;
  14. chk4.checked=false;"> Triangle
  15. <input type="checkbox" id="chk2" name="chk2" onclick="script:chk1.checked=false;
  16. chk3.checked=false;
  17. chk4.checked=false;"> Square
  18. <input type="checkbox" id="chk3" name="chk3" onclick="script:chk1.checked=false;
  19. chk2.checked=false;
  20. chk4.checked=false;"> Sine
  21. <input type="checkbox" id="chk4" name="chk4" onclick="script:chk1.checked=false;
  22. chk2.checked=false;
  23. chk3.checked=false"> Saw
  24. <br>
  25. <b>
  26. <button onclick="script:
  27. var PlayLen=Text1.value;
  28. var Freq=Text2.value;
  29. var context = new AudioContext();
  30. oscillator=context.createOscillator();
  31. if(chk1.checked==true){
  32. oscillator.type = 'triangle';
  33. }
  34. if(chk2.checked==true){
  35. oscillator.type = 'square';
  36. }
  37. if(chk3.checked==true){
  38. oscillator.type = 'sine';
  39. }
  40. if(chk4.checked==true){
  41. oscillator.type = 'sawtooth';
  42. }
  43. oscillator.frequency.value = Freq;
  44. oscillator.connect(context.destination);
  45. oscillator.start(context.current);
  46. oscillator.stop(PlayLen);
  47. oscillator.disconnect(PlayLen);"><b><font color=darkblue>Play Sound</button>
  48. <button onclick="script:
  49. var PlayLen=Text1.value;
  50. var Freq=Text2.value;
  51. var context = new AudioContext();
  52. oscillator=context.createOscillator();
  53. if(chk1.checked==true){
  54. oscillator.type = 'triangle';
  55. }
  56. if(chk2.checked==true){
  57. oscillator.type = 'square';
  58. }
  59. if(chk3.checked==true){
  60. oscillator.type = 'sine';
  61. }
  62. if(chk4.checked==true){
  63. oscillator.type = 'sawtooth';
  64. }
  65. var var1=Math.floor(Math.random()*100);
  66. var var2=Math.floor(Math.random()*100);
  67. var PlayLen=var1
  68. var Freq=Text1.var2;
  69. Text1.value=var1;
  70. Text2.value=var2;
  71. oscillator.frequency.value = Freq;
  72. oscillator.frequency.value = Freq;
  73. oscillator.connect(context.destination);
  74. oscillator.start(0);
  75. oscillator.stop(PlayLen);
  76. oscillator.disconnect(PlayLen);"><b><font color=darkblue>Gen Random</button>
  77. <button onclick="script:
  78. Text1.value='100';
  79. Text2.value='100';
  80. oscillator.stop(0);
  81. oscillator.disconnect(context.destination);"><b><font color=darkblue>Stop Sound</button>
  82. <button onclick="script:chk1.checked=false
  83. chk2.checked=false
  84. chk3.checked=false
  85. chk4.checked=false
  86. Text1.value='';
  87. Text2.value='';"><font color=darkblue><b>Clear All</button>
  88. </center>
Advertisement
Add Comment
Please, Sign In to add comment