/* eslint-disable */ // ZzFX - Zuper Zmall Zound Zynth - v1.3.2 by Frank Force // https://github.com/KilledByAPixel/ZzFX // // MIT License - Copyright (c) 2019 Frank Force // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software. The above copyright notice and this // permission notice shall be included in all copies or substantial portions // of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY // KIND. // // Local adaptation (soundboard experiment): the upstream ZzFXMicro build // creates its own AudioContext and plays straight to the hardware output. // This build splits synthesis (zzfxG, byte-for-byte the upstream v1.3.2 // sample generator) from playback (zzfxP), and playback goes through a // caller-provided AudioContext + destination node, so candidate sounds ride // the game's shared master gain / sfx bus like the runtime sounds do. export const zzfxR = 44100; // sample rate export const zzfxV = 0.3; // default volume scale // Generate samples for a ZzFX sound. Parameter order: // volume, randomness, frequency, attack, sustain, release, shape, shapeCurve, // slide, deltaSlide, pitchJump, pitchJumpTime, repeatTime, noise, modulation, // bitCrush, delay, sustainVolume, decay, tremolo, filter export const zzfxG = (p=1,k=.05,b=220,e=0,r=0,t=.1,q=0,D=1,u=0,y=0,v=0,z=0,l=0,E=0,A=0,F=0,c=0,w=1,m=0,B=0,N=0)=>{ let M=Math,d=2*M.PI,R=zzfxR,G=u*=500*d/R/R,C=b*=(1-k+2*k*M.random(k=[]))*d/R, g=0,H=0,a=0,n=1,I=0,J=0,f=0,h=N<0?-1:1,x=d*h*N*2/R,L=M.cos(x),Z=M.sin,K=Z(x)/4,O=1+K, X=-2*L/O,Y=(1-K)/O,P=(1+h*L)/2/O,Q=-(h+L)/O,S=P,T=0,U=0,V=0,W=0; e=R*e+9;m*=R;r*=R;t*=R;c*=R;y*=500*d/R**3;A*=d/R;v*=d/R;z*=R;l=R*l|0;p*=zzfxV; for(h=e+m+r+t+c|0;aa?0:(az&&(b+=v,C+=v,n=0), !l||++I%l||(b=C,u=G,n=n||1); return k; }; // Play generated samples through the given context/destination. export function zzfxP(ctx, destination, samples) { const buf = ctx.createBuffer(1, samples.length, zzfxR); buf.getChannelData(0).set(samples); const src = ctx.createBufferSource(); src.buffer = buf; src.connect(destination); src.start(); return src; } // Convenience: synthesize + play in one call. export const zzfx = (ctx, destination, ...params) => zzfxP(ctx, destination, zzfxG(...params));