diff --git a/ZzFX.js b/ZzFX.js index 4a98d82..e6793dc 100644 --- a/ZzFX.js +++ b/ZzFX.js @@ -129,7 +129,7 @@ BuildSamples const modPhase = sign(modulation) * PI2/4 let startFrequency = frequency *= (1 + random(randomness)) * PI2 / sampleRate; - attack = 50 + attack * sampleRate | 0; + attack = 99 + attack * sampleRate | 0; sustain = sustain * sampleRate | 0; release = release * sampleRate | 0; delay = delay * sampleRate | 0; @@ -369,7 +369,7 @@ let zzfxP = // play a sound ) => { // init parameters - attack = 50 + attack * sampleRate | 0; + attack = 99 + attack * sampleRate | 0; sustain = sustain * sampleRate | 0; release = release * sampleRate | 0; delay = delay * sampleRate | 0; diff --git a/ZzFX.micro.js b/ZzFX.micro.js index 79468f8..28d7357 100644 --- a/ZzFX.micro.js +++ b/ZzFX.micro.js @@ -12,7 +12,7 @@ // ZzFXMicro - Zuper Zmall Zound Zynth zzfxV=.3 // volume zzfx= // play sound -(I=1,J=.05,g=220,f=0,h=0,m=.1,n=0,K=1,r=0,z=0,t=0,A=0,u=0,B=0,v=0,L=0,e=0,d=2*Math.PI,b=44100,w=p=>2*p*Math.random()-p,C=p=>0{f=50+f*b|0;h=h*b|0;m=m*b|0;e=e*b|0;z*=500*d/b**3;l=f+h+m+e;v*=d/b;t*=d/b;A*=b;for(u*=b;c100*L&&(H=0,a=E*g*Math.sin(F*v-N),a=n?1c?0:(cA&&(D+=t,g+=t,k=0),u&&++G>u&&(g=D,r=M,G=1,k=k||1);x=zzfxX.createBuffer(1,q.length,b);x.getChannelData(0).set(q);y.buffer=x;y.connect(zzfxX.destination);y.start()} +(I=1,J=.05,g=220,f=0,h=0,m=.1,n=0,K=1,r=0,z=0,t=0,A=0,u=0,B=0,v=0,L=0,e=0,d=2*Math.PI,b=44100,w=p=>2*p*Math.random()-p,C=p=>0{f=99+f*b|0;h=h*b|0;m=m*b|0;e=e*b|0;z*=500*d/b**3;l=f+h+m+e;v*=d/b;t*=d/b;A*=b;for(u*=b;c100*L&&(H=0,a=E*g*Math.sin(F*v-N),a=n?1c?0:(cA&&(D+=t,g+=t,k=0),u&&++G>u&&(g=D,r=M,G=1,k=k||1);x=zzfxX.createBuffer(1,q.length,b);x.getChannelData(0).set(q);y.buffer=x;y.connect(zzfxX.destination);y.start()} zzfxX=new AudioContext // fix compatibility issues with old web audio (optional) diff --git a/ZzFX.min.js b/ZzFX.min.js index f76732f..6a86622 100644 --- a/ZzFX.min.js +++ b/ZzFX.min.js @@ -1,2 +1,2 @@ // ZzFX - Zuper Zmall Zound Zynth - MIT License - Copyright 2019 Frank Force -class _ZZFX{constructor(){this.x=this.CreateAudioContext(),this.samples=0,this.volume=.3,this.sampleRate=44100}Play(t){if(!t||"object"!=typeof t){var e=this.BuildSound();t=this.BuildSound(...arguments);for(const a in t)void 0===t[a]&&(t[a]=e[a])}return e=this.SoundToArray(t),e=this.BuildSamples(...e,this.volume),this.PlaySamples(e)}PlaySamples(t){const e=this.x.createBuffer(1,t.length,this.sampleRate),a=this.x.createBufferSource();return e.getChannelData(0).set(t),a.buffer=e,a.connect(this.x.destination),a.start(),this.samples=t,a}BuildSamples(t,e,a,s,n,o,i,r,u,h,d,l,c,m,p,f,M,S=1){const B=2*Math.PI;var C=this.sampleRate;const x=u*=500*B/C**2,v=(0100*f&&(P=0,F=Z*a*Math.sin(b*p-v),F=(0<(F=i?1A?0:(Al&&(e+=d,a+=d,T=0),c&&++w>c&&(a=e,u=x,w=1,T=T||1);return y}BuildRandomSound(){function t(){return Math.random()}const e=this.BuildSound(1,.05,2e3*t()**2|0,.01+t()**3,t()**3,.01+t()**3,5*t()|0,.2>t()?1:2*t(),.5>t()?0:100*t()**3*(.5>t()?-1:1),.5>t()?0:100*t()**3*(.5>t()?-1:1),0,0,0,.5>t()?0:3*t()**3,.5>t()?0:1e3*t()**4,.5>t()?0:5*t()**3,.5>t()?0:.5*t()**3);.1>t()&&(e.shapeCurve=10*t()**2),2<=e.shapeCurve&&(e.shapeCurve|=0),.5>t()&&(e.modulation*=-1);const a=e.attack+e.sustain+e.release;return.5>t()&&(e.pitchJump=1e3*t()**2*(.5>t()?-1:1)|0,e.pitchJumpTime=t()*a),.5>t()&&(e.repeatTime=t()*a),e}BuildSound(t=1,e=.05,a=220,s=0,n=0,o=.1,i=0,r=1,u=0,h=0,d=0,l=0,c=0,m=0,p=0,f=0,M=0){return{volume:t,randomness:e,frequency:a,attack:s,sustain:n,release:o,shape:i,shapeCurve:r,slide:u,deltaSlide:h,pitchJump:d,pitchJumpTime:l,repeatTime:c,noise:m,modulation:p,bitCrush:f,delay:M}}GetNote(t,e){return t*2**(e/12)}SoundToArray(t){const e=this.BuildSound(),a=[];for(const s in e)a.push(t[s]);return a}CreateAudioContext(){const t=new(window.AudioContext||webkitAudioContext);return t.a=t.createBufferSource,t.createBufferSource=((e=t.a())=>(e.start=e.start||(e=>t.noteOn(e)),e.stop=e.stop||(e=>t.noteOff(e)),e)),t}}const ZZFX=new _ZZFX;function zzfx(){ZZFX.Play(...arguments)} \ No newline at end of file +class _ZZFX{constructor(){this.x=this.CreateAudioContext(),this.samples=0,this.volume=.3,this.sampleRate=44100}Play(t){if(!t||"object"!=typeof t){var e=this.BuildSound();t=this.BuildSound(...arguments);for(const a in t)void 0===t[a]&&(t[a]=e[a])}return e=this.SoundToArray(t),e=this.BuildSamples(...e,this.volume),this.PlaySamples(e)}PlaySamples(t){const e=this.x.createBuffer(1,t.length,this.sampleRate),a=this.x.createBufferSource();return e.getChannelData(0).set(t),a.buffer=e,a.connect(this.x.destination),a.start(),this.samples=t,a}BuildSamples(t,e,a,s,n,o,i,r,u,h,d,l,c,m,p,f,M,S=1){const B=2*Math.PI;var C=this.sampleRate;const x=u*=500*B/C**2,v=(0100*f&&(P=0,F=Z*a*Math.sin(b*p-v),F=(0<(F=i?1A?0:(Al&&(e+=d,a+=d,T=0),c&&++w>c&&(a=e,u=x,w=1,T=T||1);return y}BuildRandomSound(){function t(){return Math.random()}const e=this.BuildSound(1,.05,2e3*t()**2|0,.01+t()**3,t()**3,.01+t()**3,5*t()|0,.2>t()?1:2*t(),.5>t()?0:100*t()**3*(.5>t()?-1:1),.5>t()?0:100*t()**3*(.5>t()?-1:1),0,0,0,.5>t()?0:3*t()**3,.5>t()?0:1e3*t()**4,.5>t()?0:5*t()**3,.5>t()?0:.5*t()**3);.1>t()&&(e.shapeCurve=10*t()**2),2<=e.shapeCurve&&(e.shapeCurve|=0),.5>t()&&(e.modulation*=-1);const a=e.attack+e.sustain+e.release;return.5>t()&&(e.pitchJump=1e3*t()**2*(.5>t()?-1:1)|0,e.pitchJumpTime=t()*a),.5>t()&&(e.repeatTime=t()*a),e}BuildSound(t=1,e=.05,a=220,s=0,n=0,o=.1,i=0,r=1,u=0,h=0,d=0,l=0,c=0,m=0,p=0,f=0,M=0){return{volume:t,randomness:e,frequency:a,attack:s,sustain:n,release:o,shape:i,shapeCurve:r,slide:u,deltaSlide:h,pitchJump:d,pitchJumpTime:l,repeatTime:c,noise:m,modulation:p,bitCrush:f,delay:M}}GetNote(t,e){return t*2**(e/12)}SoundToArray(t){const e=this.BuildSound(),a=[];for(const s in e)a.push(t[s]);return a}CreateAudioContext(){const t=new(window.AudioContext||webkitAudioContext);return t.a=t.createBufferSource,t.createBufferSource=((e=t.a())=>(e.start=e.start||(e=>t.noteOn(e)),e.stop=e.stop||(e=>t.noteOff(e)),e)),t}}const ZZFX=new _ZZFX;function zzfx(){ZZFX.Play(...arguments)} \ No newline at end of file diff --git a/index.html b/index.html index 532f479..d2ee747 100644 --- a/index.html +++ b/index.html @@ -137,7 +137,7 @@ ZzFX © Frank Force 2019 ☮♥☻␌ - +