util.js 724 B

123456789101112131415161718192021222324252627282930
  1. const cyrb53 = function(str, seed = 0) {
  2. let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
  3. for (let i = 0, ch; i < str.length; i++) {
  4. ch = str.charCodeAt(i);
  5. h1 = Math.imul(h1 ^ ch, 2654435761);
  6. h2 = Math.imul(h2 ^ ch, 1597334677);
  7. }
  8. h1 = Math.imul(h1 ^ (h1>>>16), 2246822507) ^ Math.imul(h2 ^ (h2>>>13), 3266489909);
  9. h2 = Math.imul(h2 ^ (h2>>>16), 2246822507) ^ Math.imul(h1 ^ (h1>>>13), 3266489909);
  10. return 4294967296 * (2097151 & h2) + (h1>>>0);
  11. };
  12. const hash = cyrb53
  13. function clamp(min, max, val) {
  14. if (val < min) return min;
  15. if (val > max) return max;
  16. return val;
  17. }
  18. function last(list) {
  19. return list[list.length - 1];
  20. }
  21. function pitchPercent(pitch) {
  22. return clamp(0, 1, (pitch - 50) / 250);
  23. }