Advertisement
psub_reborn

Bytebeat Composer Source Code

Jul 13th, 2023
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>>Yourname< BTB Composer</title>
  5.  
  6. <style>
  7. body {
  8. text-align: center;
  9. background-color: #000000;
  10. color: #FFFFFF;
  11. font-family: Consolas, monospace;
  12. }
  13. button {
  14. background-color: transparent;
  15. border: 2px solid white;
  16. color: white;
  17. font-family: Consolas, monospace;
  18. }
  19.  
  20. input[type="text"], textarea {
  21. background-color: transparent;
  22. border: 2px solid white;
  23. color: white;
  24. font-family: Consolas, monospace;
  25. }
  26.  
  27. select, option {
  28. background-color: transparent;
  29. border: 2px solid white;
  30. color: white;
  31. font-family: Consolas, monospace;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <h1>>Yourname< Bytebeat Maker</h1>
  37. <div>
  38. <label for="formula">Code:</label>
  39. <input type="text" id="formula" value="t //simple sawtooth">
  40. </div>
  41. <div>
  42. <label for="sampleRate">Rate:</label>
  43. <select id="sampleRate">
  44. <option value="8000">8000</option>
  45. <option value="11025">11025</option>
  46. <option value="22050">22050</option>
  47. <option value="32000">32000</option>
  48. <option value="44100">44100</option>
  49. <option value="48000">48000</option>
  50. </select>
  51. </div>
  52. <button onclick="play()">Generate</button>
  53. <button onclick="stop()">Stop</button>
  54.  
  55. <div>
  56. </div>
  57. <label>by <a href="https://www.reddit.com/user/yourusername/?sh=true">u/yourusername</a></label>
  58. <script>
  59. var audioCtx;
  60. var source;
  61.  
  62. function play() {
  63. audioCtx = new (window.AudioContext || window.webkitAudioContext)();
  64. source = audioCtx.createBufferSource();
  65. var formula = document.getElementById("formula").value;
  66. var sampleRate = document.getElementById("sampleRate").value;
  67. var buffer = audioCtx.createBuffer(1, audioCtx.sampleRate * 25, sampleRate);
  68. var data = buffer.getChannelData(0);
  69.  
  70. for (var t = 0; t < buffer.length; t++) {
  71. data[t] = (eval(formula)&255)/127-1;
  72. }
  73.  
  74. source.buffer = buffer;
  75. source.connect(audioCtx.destination);
  76. source.start();
  77. }
  78.  
  79. function stop() {
  80. source.stop();
  81. audioCtx.close();
  82. }
  83. </script>
  84. </body>
  85. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement