Advertisement
SthephanShi

End of Ice Age

May 2nd, 2022
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. t /= 44100, // Sample rate
  2. bpm = 105, // Song speed
  3. len = 256, // Song length
  4. b = (bpm * t / 60) % len,
  5.  
  6. // Notes
  7. C = 262, Db = 277, D = 294, Eb = 311, EE = 330, F = 349,
  8. Gb = 370, G = 392, Ab = 415, A = 440, Bb = 466, B = 494,
  9.  
  10. // Notes arrays
  11. intro = [C, D, G, C, D, G, C, D, A, C, D, A, A, A, A,, D, G, B, D, G, B, D, G, A, C, G, A, A, A, A],
  12. song1 = [,, G,, Gb, A,, Gb, B,, G, B,,, A,,,, C * 2,, B, D * 2,, B, EE * 2,,B, EE * 2,,, D * 2],
  13. song2 = [C, D, G, D, Gb, A, EE, G, B, D, Gb, A, C * 2, D, G, D * 2, Gb, B, EE * 2, G, B, D * 2, Gb, A],
  14.  
  15. // Wave modifier
  16. wave = amp => amp * 1E-4 * sin(44 * t),
  17.  
  18. // Square arpeggiators
  19. arp1 = (arr, echo) => (i = b - echo, w = b % 8 > 6, (w ? 12 : 24) * (2 * (t + (w && wave(4))) *
  20.     arr[int(2 * i) % 32] % 2 | 0)),
  21. arp2 = (arr, shift, echo) => (i = b - shift - echo, 24 * ((i & 16 ? 4 : 2) * t *
  22.     arr[int(2 * i) % 32] % 2 | 0)),
  23. arp3 = (arr, shift, echo) => (i = b - shift - echo, 24 * ((i & 16 ? 4 : 2) * (t + ((i & 32) && wave(5))) *
  24.     arr[3 * ((i >> 1) % 8) + int((i & 64 ? 22 : 2) * i) % 3] % 2 | 0)),
  25. arpEcho = (fn, ...args) =>
  26.     fn(...args, 0) + .8 * fn(...args, .4) + .6 * fn(...args, .8) + .4 * fn(...args, 1.2),
  27.  
  28. // Square bass pad
  29. pad = (pitch, echo) => 18 * int(.7 * (pitch * (t + wave(5)) * [
  30.     C, D, EE, D, C, D, B / 2, C
  31. ][((b - echo) >> 1) % 8] % 2)),
  32.  
  33. // Triangle pad
  34. tri = (pitch, echo) => .3 * (abs(((255 * pitch * (t + wave(4)) * [
  35.     D, Gb, G, B, EE, Gb, G, Gb,
  36.     D, EE, G, A, EE, Gb, G, Gb
  37. ][((b - echo) >> 1) % 16]) & 255) - 128)),
  38.  
  39. // Noise for drums
  40. noise = (arr, speed, len, pitch) =>
  41.     arr[int(speed * b) % len] * (int(1E5 * sin(int(t * pitch) ** 2)) & 255),
  42.  
  43. // Kick
  44. (((b > 80 && b < 128) || (b > 160 && b < 192)) &&
  45.     53 * int(b * (256 >> 32 * b) % 2)) +
  46. // Hi-hats
  47. (((b > 64 && b < 128) || (b > 144 && b < 192)) &&
  48.     noise('1000000010000000111111001000100010000000111111001000000011111000', 16, 64, 3E4) / 8) +
  49. // Snare
  50. (((b > 80 && b < 128) || (b > 160 && b < 192)) &&
  51.     noise('0010', 2, 4, 35E2)) / 5 +
  52. // Explosions
  53. (((b > 128 && b < 160)) &&
  54.     noise('30020010010010003222111111111000', 8, 32, 20E2) / 8) +
  55. // Bass pad
  56. (b > 32 &&
  57.     .6 * pad(1, 0) + pad(1.5, 1) + .8 * pad(2, 1)) +
  58. // Lead intro
  59. (b < 32 &&
  60.     arpEcho(arp1, intro)) +
  61. // Lead song #1
  62. ((b > 32 && b < 65 || b > 192 && b < 225) &&
  63.     arpEcho(arp2, song1, b > 192 ? 192 : 32)) +
  64. // Lead song #2
  65. (b > 64 && b < 193 &&
  66.     arpEcho(arp3, song2, 64)) +
  67. // Triangle
  68. (b > 192 &&
  69.     tri(1, 0) + .8 * tri(1, .4) + .6 * tri(2, 1) + .4 * tri(1, 1.2));
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement