earcons 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -1
- package/dist/earcon.min.global.js +1 -1
- package/dist/index.cjs +378 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -1
- package/dist/index.d.ts +46 -1
- package/dist/index.js +370 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# earcons
|
|
2
2
|
|
|
3
3
|
> Tiny vanilla TypeScript library for UI notification sounds — pure Web Audio API, no audio files, zero dependencies.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/earcons)
|
|
6
|
+
[](https://github.com/smolgroot/earcons/actions/workflows/ci.yml)
|
|
6
7
|
[](https://bundlephobia.com/package/earcons)
|
|
7
8
|
[](LICENSE)
|
|
8
9
|
|
|
10
|
+
**[▶ Live demo](https://smolgroot.github.io/earcons)**
|
|
11
|
+
|
|
9
12
|
## Why earcon?
|
|
10
13
|
|
|
11
14
|
| | earcon | Howler.js | Tone.js | ZzFX |
|
|
@@ -145,6 +148,8 @@ await closeAudioContext();
|
|
|
145
148
|
|
|
146
149
|
## Sound reference
|
|
147
150
|
|
|
151
|
+
### UI sounds
|
|
152
|
+
|
|
148
153
|
| Name | Waveform | Character |
|
|
149
154
|
|---|---|---|
|
|
150
155
|
| `success` | sine | Ascending major triad — bright, positive |
|
|
@@ -153,6 +158,20 @@ await closeAudioContext();
|
|
|
153
158
|
| `notification` | sine | Soft descending two-tone ding — neutral |
|
|
154
159
|
| `click` | sine | Very short transient — tactile UI feedback |
|
|
155
160
|
| `info` | sine | Single soft tone — informational, non-intrusive |
|
|
161
|
+
| `toggle` | triangle | Short tactile pop — on/off switch |
|
|
162
|
+
| `delete` | sawtooth | Rapid descending — destructive action |
|
|
163
|
+
| `message` | sine | Soft high ping — incoming chat message |
|
|
164
|
+
| `upload` | sine | Ascending sweep — file sent |
|
|
165
|
+
| `download` | sine | Descending sweep — file received |
|
|
166
|
+
|
|
167
|
+
### Fun & misc
|
|
168
|
+
|
|
169
|
+
| Name | Waveform | Character |
|
|
170
|
+
|---|---|---|
|
|
171
|
+
| `eightBit` | square | Chiptune arpeggio — retro 8-bit 🕹️ |
|
|
172
|
+
| `police` | sawtooth | Alternating wee-woo siren 🚨 |
|
|
173
|
+
| `coin` | square | Classic pickup coin 🪙 |
|
|
174
|
+
| `boing` | sine | Comedy spring drop 🎪 |
|
|
156
175
|
|
|
157
176
|
---
|
|
158
177
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Earcon=(()=>{var w=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var O=(e,n)=>{for(var o in n)w(e,o,{get:n[o],enumerable:!0})},b=(e,n,o,c)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of C(n))!R.call(e,r)&&r!==o&&w(e,r,{get:()=>n[r],enumerable:!(c=N(n,r))||c.enumerable});return e};var j=e=>b(w({},"__esModule",{value:!0}),e);var Y={};O(Y,{closeAudioContext:()=>V,earcon:()=>Q,playClick:()=>H,playError:()=>F,playInfo:()=>J,playNotification:()=>z,playSuccess:()=>D,playWarning:()=>U,registerSound:()=>X,semitonesToMultiplier:()=>q,setAudioContext:()=>P});var u=null;async function E(){return u||(u=new AudioContext),u.state==="suspended"&&await u.resume(),u}async function V(){u&&(await u.close(),u=null)}function P(e){u=e}var G={attack:.01,decay:.05,sustain:.7,release:.08,hold:0};function q(e){return Math.pow(2,e/12)}function I(e,n,o,c,r){let t={...G,...n.envelope},i=r+n.startAt,s=n.gain??1,m=n.waveShape??"sine",d=n.frequency*c,a=e.createGain();a.connect(o),a.gain.setValueAtTime(0,i),a.gain.linearRampToValueAtTime(s,i+t.attack);let x=i+t.attack+(t.hold??0);a.gain.setValueAtTime(s,x),a.gain.linearRampToValueAtTime(s*t.sustain,x+t.decay);let l=i+n.duration;a.gain.setValueAtTime(s*t.sustain,l),a.gain.linearRampToValueAtTime(0,l+t.release);let f=e.createOscillator();return f.type=m,f.frequency.setValueAtTime(d,i),f.connect(a),f.start(i),f.stop(l+t.release+.01),l+t.release}function k(e,n,o,c,r){let t=e.createGain();t.gain.setValueAtTime(Math.max(0,Math.min(1,o)),e.currentTime),t.connect(e.destination);let i=q(c),s=e.currentTime,m=s;for(let d of n.notes){let a=I(e,d,t,i,s);a>m&&(m=a)}if(r){let d=e.createOscillator(),a=e.createGain();a.gain.setValueAtTime(0,s),d.connect(a),a.connect(e.destination),d.start(s),d.stop(m),d.onended=r}}var M={short:{name:"success",duration:.25,notes:[{frequency:523.25,duration:.1,startAt:0,waveShape:"sine",gain:.8},{frequency:783.99,duration:.15,startAt:.1,waveShape:"sine",gain:.9}]},medium:{name:"success",duration:.45,notes:[{frequency:523.25,duration:.12,startAt:0,waveShape:"sine",gain:.7},{frequency:659.25,duration:.12,startAt:.12,waveShape:"sine",gain:.8},{frequency:783.99,duration:.2,startAt:.24,waveShape:"sine",gain:.9}]},long:{name:"success",duration:.7,notes:[{frequency:392,duration:.1,startAt:0,waveShape:"sine",gain:.6},{frequency:523.25,duration:.12,startAt:.1,waveShape:"sine",gain:.7},{frequency:659.25,duration:.12,startAt:.22,waveShape:"sine",gain:.8},{frequency:783.99,duration:.25,startAt:.34,waveShape:"sine",gain:.9}]}};function S(e,n){return M[e]}var B={short:{name:"error",duration:.25,notes:[{frequency:440,duration:.1,startAt:0,waveShape:"square",gain:.5,envelope:{attack:.005,decay:.04,sustain:.6,release:.06}},{frequency:311,duration:.15,startAt:.1,waveShape:"square",gain:.6,envelope:{attack:.005,decay:.04,sustain:.6,release:.06}}]},medium:{name:"error",duration:.5,notes:[{frequency:440,duration:.12,startAt:0,waveShape:"sawtooth",gain:.4,envelope:{attack:.005,decay:.06,sustain:.5,release:.08}},{frequency:392,duration:.12,startAt:.13,waveShape:"sawtooth",gain:.45,envelope:{attack:.005,decay:.06,sustain:.5,release:.08}},{frequency:311,duration:.2,startAt:.26,waveShape:"sawtooth",gain:.55,envelope:{attack:.005,decay:.06,sustain:.5,release:.12}}]},long:{name:"error",duration:.75,notes:[{frequency:440,duration:.12,startAt:0,waveShape:"sawtooth",gain:.4,envelope:{attack:.005,decay:.07,sustain:.5,release:.1}},{frequency:415,duration:.1,startAt:.14,waveShape:"sawtooth",gain:.4,envelope:{attack:.005,decay:.07,sustain:.5,release:.1}},{frequency:370,duration:.12,startAt:.26,waveShape:"sawtooth",gain:.45,envelope:{attack:.005,decay:.07,sustain:.5,release:.1}},{frequency:311,duration:.25,startAt:.4,waveShape:"sawtooth",gain:.55,envelope:{attack:.005,decay:.08,sustain:.5,release:.15}}]}};function y(e,n){return B[e]}var K={short:{name:"warning",duration:.28,notes:[{frequency:587.33,duration:.1,startAt:0,waveShape:"triangle",gain:.7},{frequency:523.25,duration:.18,startAt:.1,waveShape:"triangle",gain:.75}]},medium:{name:"warning",duration:.5,notes:[{frequency:587.33,duration:.12,startAt:0,waveShape:"triangle",gain:.65},{frequency:587.33,duration:.12,startAt:.14,waveShape:"triangle",gain:.65},{frequency:493.88,duration:.2,startAt:.28,waveShape:"triangle",gain:.75}]},long:{name:"warning",duration:.8,notes:[{frequency:587.33,duration:.12,startAt:0,waveShape:"triangle",gain:.6},{frequency:587.33,duration:.12,startAt:.15,waveShape:"triangle",gain:.6},{frequency:554.37,duration:.12,startAt:.3,waveShape:"triangle",gain:.65},{frequency:493.88,duration:.25,startAt:.45,waveShape:"triangle",gain:.75}]}};function v(e,n){return K[e]}var L={short:{name:"notification",duration:.22,notes:[{frequency:880,duration:.08,startAt:0,waveShape:"sine",gain:.6},{frequency:660,duration:.14,startAt:.08,waveShape:"sine",gain:.65}]},medium:{name:"notification",duration:.38,notes:[{frequency:880,duration:.1,startAt:0,waveShape:"sine",gain:.55},{frequency:660,duration:.28,startAt:.1,waveShape:"sine",gain:.6}]},long:{name:"notification",duration:.55,notes:[{frequency:1046.5,duration:.08,startAt:0,waveShape:"sine",gain:.5},{frequency:880,duration:.1,startAt:.1,waveShape:"sine",gain:.55},{frequency:660,duration:.3,startAt:.22,waveShape:"sine",gain:.6}]}};function g(e,n){return L[e]}var W={short:{name:"click",duration:.04,notes:[{frequency:1200,duration:.03,startAt:0,waveShape:"sine",gain:.5,envelope:{attack:.002,decay:.015,sustain:0,release:.01}}]},medium:{name:"click",duration:.07,notes:[{frequency:900,duration:.05,startAt:0,waveShape:"sine",gain:.55,envelope:{attack:.002,decay:.03,sustain:0,release:.015}}]},long:{name:"click",duration:.12,notes:[{frequency:700,duration:.08,startAt:0,waveShape:"triangle",gain:.6,envelope:{attack:.002,decay:.05,sustain:0,release:.025}}]}};function A(e,n){return W[e]}var _={short:{name:"info",duration:.2,notes:[{frequency:698.46,duration:.18,startAt:0,waveShape:"sine",gain:.55,envelope:{attack:.015,decay:.04,sustain:.5,release:.1}}]},medium:{name:"info",duration:.35,notes:[{frequency:698.46,duration:.32,startAt:0,waveShape:"sine",gain:.55,envelope:{attack:.02,decay:.05,sustain:.5,release:.12}}]},long:{name:"info",duration:.55,notes:[{frequency:587.33,duration:.18,startAt:0,waveShape:"sine",gain:.5,envelope:{attack:.02,decay:.05,sustain:.4,release:.1}},{frequency:698.46,duration:.3,startAt:.2,waveShape:"sine",gain:.55,envelope:{attack:.02,decay:.06,sustain:.5,release:.12}}]}};function h(e,n){return _[e]}async function p(e,n={}){let{volume:o=.5,pitch:c=0,audioContext:r,onEnded:t}=n,i=r??await E();k(i,e,o,c,t)}async function D(e={}){return p(S(e.variant??"medium",e.pitch??0),e)}async function F(e={}){return p(y(e.variant??"medium",e.pitch??0),e)}async function U(e={}){return p(v(e.variant??"medium",e.pitch??0),e)}async function z(e={}){return p(g(e.variant??"medium",e.pitch??0),e)}async function H(e={}){return p(A(e.variant??"short",e.pitch??0),e)}async function J(e={}){return p(h(e.variant??"medium",e.pitch??0),e)}var T={success:S,error:y,warning:v,notification:g,click:A,info:h};async function Q(e,n={}){let o=T[e];return p(o(n.variant??"medium",n.pitch??0),n)}function X(e,n){T[e]=n}return j(Y);})();
|
|
1
|
+
"use strict";var Earcon=(()=>{var G=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var J=(e,n)=>{for(var u in n)G(e,u,{get:n[u],enumerable:!0})},Q=(e,n,u,f)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of z(n))!H.call(e,s)&&s!==u&&G(e,s,{get:()=>n[s],enumerable:!(f=F(n,s))||f.enumerable});return e};var X=e=>Q(G({},"__esModule",{value:!0}),e);var Oe={};J(Oe,{closeAudioContext:()=>L,earcon:()=>Te,playBoing:()=>ke,playClick:()=>he,playCoin:()=>Re,playDelete:()=>qe,playDownload:()=>Pe,playEightBit:()=>xe,playError:()=>ye,playInfo:()=>Ae,playMessage:()=>Ve,playNotification:()=>ge,playPolice:()=>Ne,playSuccess:()=>fe,playToggle:()=>we,playUpload:()=>Ee,playWarning:()=>me,registerSound:()=>be,semitonesToMultiplier:()=>M,setAudioContext:()=>U});var v=null;async function K(){return v||(v=new AudioContext),v.state==="suspended"&&await v.resume(),v}async function L(){v&&(await v.close(),v=null)}function U(e){v=e}var Y={attack:.01,decay:.05,sustain:.7,release:.08,hold:0};function M(e){return Math.pow(2,e/12)}function Z(e,n,u,f,s){let r={...Y,...n.envelope},c=s+n.startAt,p=n.gain??1,h=n.waveShape??"sine",y=n.frequency*f,o=e.createGain();o.connect(u),o.gain.setValueAtTime(0,c),o.gain.linearRampToValueAtTime(p,c+r.attack);let D=c+r.attack+(r.hold??0);o.gain.setValueAtTime(p,D),o.gain.linearRampToValueAtTime(p*r.sustain,D+r.decay);let w=c+n.duration;o.gain.setValueAtTime(p*r.sustain,w),o.gain.linearRampToValueAtTime(0,w+r.release);let A=e.createOscillator();return A.type=h,A.frequency.setValueAtTime(y,c),A.connect(o),A.start(c),A.stop(w+r.release+.01),w+r.release}function W(e,n,u,f,s){let r=e.createGain();r.gain.setValueAtTime(Math.max(0,Math.min(1,u)),e.currentTime),r.connect(e.destination);let c=M(f),p=e.currentTime,h=p;for(let y of n.notes){let o=Z(e,y,r,c,p);o>h&&(h=o)}if(s){let y=e.createOscillator(),o=e.createGain();o.gain.setValueAtTime(0,p),y.connect(o),o.connect(e.destination),y.start(p),y.stop(h),y.onended=s}}var $={short:{name:"success",duration:.25,notes:[{frequency:523.25,duration:.1,startAt:0,waveShape:"sine",gain:.8},{frequency:783.99,duration:.15,startAt:.1,waveShape:"sine",gain:.9}]},medium:{name:"success",duration:.45,notes:[{frequency:523.25,duration:.12,startAt:0,waveShape:"sine",gain:.7},{frequency:659.25,duration:.12,startAt:.12,waveShape:"sine",gain:.8},{frequency:783.99,duration:.2,startAt:.24,waveShape:"sine",gain:.9}]},long:{name:"success",duration:.7,notes:[{frequency:392,duration:.1,startAt:0,waveShape:"sine",gain:.6},{frequency:523.25,duration:.12,startAt:.1,waveShape:"sine",gain:.7},{frequency:659.25,duration:.12,startAt:.22,waveShape:"sine",gain:.8},{frequency:783.99,duration:.25,startAt:.34,waveShape:"sine",gain:.9}]}};function q(e,n){return $[e]}var ee={short:{name:"error",duration:.25,notes:[{frequency:440,duration:.1,startAt:0,waveShape:"square",gain:.5,envelope:{attack:.005,decay:.04,sustain:.6,release:.06}},{frequency:311,duration:.15,startAt:.1,waveShape:"square",gain:.6,envelope:{attack:.005,decay:.04,sustain:.6,release:.06}}]},medium:{name:"error",duration:.5,notes:[{frequency:440,duration:.12,startAt:0,waveShape:"sawtooth",gain:.4,envelope:{attack:.005,decay:.06,sustain:.5,release:.08}},{frequency:392,duration:.12,startAt:.13,waveShape:"sawtooth",gain:.45,envelope:{attack:.005,decay:.06,sustain:.5,release:.08}},{frequency:311,duration:.2,startAt:.26,waveShape:"sawtooth",gain:.55,envelope:{attack:.005,decay:.06,sustain:.5,release:.12}}]},long:{name:"error",duration:.75,notes:[{frequency:440,duration:.12,startAt:0,waveShape:"sawtooth",gain:.4,envelope:{attack:.005,decay:.07,sustain:.5,release:.1}},{frequency:415,duration:.1,startAt:.14,waveShape:"sawtooth",gain:.4,envelope:{attack:.005,decay:.07,sustain:.5,release:.1}},{frequency:370,duration:.12,startAt:.26,waveShape:"sawtooth",gain:.45,envelope:{attack:.005,decay:.07,sustain:.5,release:.1}},{frequency:311,duration:.25,startAt:.4,waveShape:"sawtooth",gain:.55,envelope:{attack:.005,decay:.08,sustain:.5,release:.15}}]}};function V(e,n){return ee[e]}var ne={short:{name:"warning",duration:.28,notes:[{frequency:587.33,duration:.1,startAt:0,waveShape:"triangle",gain:.7},{frequency:523.25,duration:.18,startAt:.1,waveShape:"triangle",gain:.75}]},medium:{name:"warning",duration:.5,notes:[{frequency:587.33,duration:.12,startAt:0,waveShape:"triangle",gain:.65},{frequency:587.33,duration:.12,startAt:.14,waveShape:"triangle",gain:.65},{frequency:493.88,duration:.2,startAt:.28,waveShape:"triangle",gain:.75}]},long:{name:"warning",duration:.8,notes:[{frequency:587.33,duration:.12,startAt:0,waveShape:"triangle",gain:.6},{frequency:587.33,duration:.12,startAt:.15,waveShape:"triangle",gain:.6},{frequency:554.37,duration:.12,startAt:.3,waveShape:"triangle",gain:.65},{frequency:493.88,duration:.25,startAt:.45,waveShape:"triangle",gain:.75}]}};function E(e,n){return ne[e]}var te={short:{name:"notification",duration:.22,notes:[{frequency:880,duration:.08,startAt:0,waveShape:"sine",gain:.6},{frequency:660,duration:.14,startAt:.08,waveShape:"sine",gain:.65}]},medium:{name:"notification",duration:.38,notes:[{frequency:880,duration:.1,startAt:0,waveShape:"sine",gain:.55},{frequency:660,duration:.28,startAt:.1,waveShape:"sine",gain:.6}]},long:{name:"notification",duration:.55,notes:[{frequency:1046.5,duration:.08,startAt:0,waveShape:"sine",gain:.5},{frequency:880,duration:.1,startAt:.1,waveShape:"sine",gain:.55},{frequency:660,duration:.3,startAt:.22,waveShape:"sine",gain:.6}]}};function P(e,n){return te[e]}var ae={short:{name:"click",duration:.04,notes:[{frequency:1200,duration:.03,startAt:0,waveShape:"sine",gain:.5,envelope:{attack:.002,decay:.015,sustain:0,release:.01}}]},medium:{name:"click",duration:.07,notes:[{frequency:900,duration:.05,startAt:0,waveShape:"sine",gain:.55,envelope:{attack:.002,decay:.03,sustain:0,release:.015}}]},long:{name:"click",duration:.12,notes:[{frequency:700,duration:.08,startAt:0,waveShape:"triangle",gain:.6,envelope:{attack:.002,decay:.05,sustain:0,release:.025}}]}};function x(e,n){return ae[e]}var re={short:{name:"info",duration:.2,notes:[{frequency:698.46,duration:.18,startAt:0,waveShape:"sine",gain:.55,envelope:{attack:.015,decay:.04,sustain:.5,release:.1}}]},medium:{name:"info",duration:.35,notes:[{frequency:698.46,duration:.32,startAt:0,waveShape:"sine",gain:.55,envelope:{attack:.02,decay:.05,sustain:.5,release:.12}}]},long:{name:"info",duration:.55,notes:[{frequency:587.33,duration:.18,startAt:0,waveShape:"sine",gain:.5,envelope:{attack:.02,decay:.05,sustain:.4,release:.1}},{frequency:698.46,duration:.3,startAt:.2,waveShape:"sine",gain:.55,envelope:{attack:.02,decay:.06,sustain:.5,release:.12}}]}};function N(e,n){return re[e]}var m={attack:.003,decay:.022,sustain:0,release:.018},oe={short:{name:"toggle",duration:.08,notes:[{frequency:880,duration:.06,startAt:0,waveShape:"triangle",gain:.6,envelope:m}]},medium:{name:"toggle",duration:.18,notes:[{frequency:660,duration:.05,startAt:0,waveShape:"triangle",gain:.5,envelope:m},{frequency:880,duration:.07,startAt:.08,waveShape:"triangle",gain:.65,envelope:m}]},long:{name:"toggle",duration:.3,notes:[{frequency:440,duration:.05,startAt:0,waveShape:"triangle",gain:.45,envelope:m},{frequency:660,duration:.05,startAt:.08,waveShape:"triangle",gain:.55,envelope:m},{frequency:880,duration:.08,startAt:.16,waveShape:"triangle",gain:.65,envelope:m}]}};function R(e,n){return oe[e]}var S={attack:.003,decay:.04,sustain:.3,release:.07},ie={short:{name:"delete",duration:.22,notes:[{frequency:440,duration:.07,startAt:0,waveShape:"sawtooth",gain:.5,envelope:S},{frequency:293,duration:.12,startAt:.08,waveShape:"sawtooth",gain:.55,envelope:S}]},medium:{name:"delete",duration:.38,notes:[{frequency:523,duration:.07,startAt:0,waveShape:"sawtooth",gain:.45,envelope:S},{frequency:415,duration:.07,startAt:.09,waveShape:"sawtooth",gain:.5,envelope:S},{frequency:277,duration:.15,startAt:.18,waveShape:"sawtooth",gain:.55,envelope:S}]},long:{name:"delete",duration:.55,notes:[{frequency:587,duration:.07,startAt:0,waveShape:"sawtooth",gain:.4,envelope:S},{frequency:494,duration:.07,startAt:.09,waveShape:"sawtooth",gain:.45,envelope:S},{frequency:392,duration:.07,startAt:.18,waveShape:"sawtooth",gain:.5,envelope:S},{frequency:277,duration:.2,startAt:.27,waveShape:"sawtooth",gain:.55,envelope:S}]}};function k(e,n){return ie[e]}var g={attack:.01,decay:.04,sustain:.3,release:.08},ue={short:{name:"message",duration:.15,notes:[{frequency:1318,duration:.12,startAt:0,waveShape:"sine",gain:.35,envelope:g}]},medium:{name:"message",duration:.26,notes:[{frequency:1318,duration:.07,startAt:0,waveShape:"sine",gain:.35,envelope:g},{frequency:1047,duration:.15,startAt:.08,waveShape:"sine",gain:.4,envelope:g}]},long:{name:"message",duration:.4,notes:[{frequency:1568,duration:.06,startAt:0,waveShape:"sine",gain:.3,envelope:g},{frequency:1318,duration:.07,startAt:.07,waveShape:"sine",gain:.35,envelope:g},{frequency:1047,duration:.22,startAt:.15,waveShape:"sine",gain:.4,envelope:g}]}};function T(e,n){return ue[e]}var se={short:{name:"upload",duration:.24,notes:[{frequency:523,duration:.08,startAt:0,waveShape:"sine",gain:.6},{frequency:784,duration:.13,startAt:.09,waveShape:"sine",gain:.7}]},medium:{name:"upload",duration:.4,notes:[{frequency:392,duration:.08,startAt:0,waveShape:"sine",gain:.55},{frequency:523,duration:.08,startAt:.1,waveShape:"sine",gain:.65},{frequency:784,duration:.18,startAt:.2,waveShape:"sine",gain:.75}]},long:{name:"upload",duration:.58,notes:[{frequency:330,duration:.08,startAt:0,waveShape:"sine",gain:.5},{frequency:392,duration:.08,startAt:.1,waveShape:"sine",gain:.6},{frequency:523,duration:.08,startAt:.2,waveShape:"sine",gain:.65},{frequency:784,duration:.24,startAt:.3,waveShape:"sine",gain:.75}]}};function b(e,n){return se[e]}var de={short:{name:"download",duration:.24,notes:[{frequency:784,duration:.08,startAt:0,waveShape:"sine",gain:.7},{frequency:523,duration:.13,startAt:.09,waveShape:"sine",gain:.6}]},medium:{name:"download",duration:.4,notes:[{frequency:784,duration:.08,startAt:0,waveShape:"sine",gain:.75},{frequency:523,duration:.08,startAt:.1,waveShape:"sine",gain:.65},{frequency:392,duration:.18,startAt:.2,waveShape:"sine",gain:.55}]},long:{name:"download",duration:.58,notes:[{frequency:784,duration:.08,startAt:0,waveShape:"sine",gain:.75},{frequency:523,duration:.08,startAt:.1,waveShape:"sine",gain:.65},{frequency:392,duration:.08,startAt:.2,waveShape:"sine",gain:.6},{frequency:330,duration:.24,startAt:.3,waveShape:"sine",gain:.5}]}};function O(e,n){return de[e]}var i={attack:.003,decay:.015,sustain:.4,release:.015},ce={short:{name:"eightBit",duration:.2,notes:[{frequency:523.25,duration:.04,startAt:0,waveShape:"square",gain:.38,envelope:i},{frequency:659.26,duration:.04,startAt:.05,waveShape:"square",gain:.38,envelope:i},{frequency:783.99,duration:.08,startAt:.1,waveShape:"square",gain:.42,envelope:i}]},medium:{name:"eightBit",duration:.33,notes:[{frequency:523.25,duration:.04,startAt:0,waveShape:"square",gain:.35,envelope:i},{frequency:659.26,duration:.04,startAt:.06,waveShape:"square",gain:.38,envelope:i},{frequency:783.99,duration:.04,startAt:.12,waveShape:"square",gain:.4,envelope:i},{frequency:1046.5,duration:.12,startAt:.18,waveShape:"square",gain:.45,envelope:i}]},long:{name:"eightBit",duration:.5,notes:[{frequency:523.25,duration:.04,startAt:0,waveShape:"square",gain:.32,envelope:i},{frequency:659.26,duration:.04,startAt:.06,waveShape:"square",gain:.35,envelope:i},{frequency:783.99,duration:.04,startAt:.12,waveShape:"square",gain:.38,envelope:i},{frequency:659.26,duration:.04,startAt:.18,waveShape:"square",gain:.35,envelope:i},{frequency:783.99,duration:.04,startAt:.24,waveShape:"square",gain:.38,envelope:i},{frequency:1046.5,duration:.15,startAt:.3,waveShape:"square",gain:.45,envelope:i}]}};function j(e,n){return ce[e]}var pe={attack:.02,decay:0,sustain:1,release:.04};function d(e,n){return{frequency:e,duration:.22,startAt:n,waveShape:"sawtooth",gain:.45,envelope:pe}}var ve={short:{name:"police",duration:.52,notes:[d(770,0),d(577,.26)]},medium:{name:"police",duration:1.04,notes:[d(770,0),d(577,.26),d(770,.52),d(577,.78)]},long:{name:"police",duration:1.56,notes:[d(770,0),d(577,.26),d(770,.52),d(577,.78),d(770,1.04),d(577,1.3)]}};function C(e,n){return ve[e]}var l={attack:.003,decay:.025,sustain:.45,release:.04},Se={short:{name:"coin",duration:.16,notes:[{frequency:987.77,duration:.04,startAt:0,waveShape:"square",gain:.45,envelope:l},{frequency:1318.51,duration:.1,startAt:.045,waveShape:"square",gain:.5,envelope:l}]},medium:{name:"coin",duration:.28,notes:[{frequency:987.77,duration:.05,startAt:0,waveShape:"square",gain:.42,envelope:l},{frequency:1174.66,duration:.05,startAt:.06,waveShape:"square",gain:.45,envelope:l},{frequency:1318.51,duration:.14,startAt:.12,waveShape:"square",gain:.5,envelope:l}]},long:{name:"coin",duration:.42,notes:[{frequency:987.77,duration:.05,startAt:0,waveShape:"square",gain:.4,envelope:l},{frequency:1174.66,duration:.05,startAt:.06,waveShape:"square",gain:.43,envelope:l},{frequency:1318.51,duration:.05,startAt:.12,waveShape:"square",gain:.47,envelope:l},{frequency:1568,duration:.2,startAt:.18,waveShape:"square",gain:.52,envelope:l}]}};function I(e,n){return Se[e]}var t={attack:.004,decay:0,sustain:1,release:.025},le={short:{name:"boing",duration:.38,notes:[{frequency:1200,duration:.03,startAt:0,waveShape:"sine",gain:.6,envelope:t},{frequency:900,duration:.03,startAt:.04,waveShape:"sine",gain:.58,envelope:t},{frequency:680,duration:.04,startAt:.08,waveShape:"sine",gain:.55,envelope:t},{frequency:500,duration:.05,startAt:.13,waveShape:"sine",gain:.52,envelope:t},{frequency:350,duration:.07,startAt:.19,waveShape:"sine",gain:.48,envelope:t},{frequency:220,duration:.1,startAt:.27,waveShape:"sine",gain:.42,envelope:t}]},medium:{name:"boing",duration:.6,notes:[{frequency:1400,duration:.04,startAt:0,waveShape:"sine",gain:.62,envelope:t},{frequency:1050,duration:.04,startAt:.05,waveShape:"sine",gain:.6,envelope:t},{frequency:800,duration:.05,startAt:.1,waveShape:"sine",gain:.57,envelope:t},{frequency:600,duration:.06,startAt:.16,waveShape:"sine",gain:.54,envelope:t},{frequency:450,duration:.07,startAt:.23,waveShape:"sine",gain:.51,envelope:t},{frequency:330,duration:.09,startAt:.31,waveShape:"sine",gain:.47,envelope:t},{frequency:240,duration:.13,startAt:.41,waveShape:"sine",gain:.42,envelope:t}]},long:{name:"boing",duration:.9,notes:[{frequency:1600,duration:.04,startAt:0,waveShape:"sine",gain:.62,envelope:t},{frequency:1200,duration:.04,startAt:.05,waveShape:"sine",gain:.6,envelope:t},{frequency:950,duration:.05,startAt:.1,waveShape:"sine",gain:.58,envelope:t},{frequency:720,duration:.06,startAt:.16,waveShape:"sine",gain:.55,envelope:t},{frequency:540,duration:.07,startAt:.23,waveShape:"sine",gain:.52,envelope:t},{frequency:400,duration:.09,startAt:.31,waveShape:"sine",gain:.49,envelope:t},{frequency:290,duration:.12,startAt:.41,waveShape:"sine",gain:.45,envelope:t},{frequency:210,duration:.16,startAt:.54,waveShape:"sine",gain:.41,envelope:t},{frequency:160,duration:.18,startAt:.71,waveShape:"sine",gain:.36,envelope:t}]}};function B(e,n){return le[e]}async function a(e,n={}){let{volume:u=.5,pitch:f=0,audioContext:s,onEnded:r}=n,c=s??await K();W(c,e,u,f,r)}async function fe(e={}){return a(q(e.variant??"medium",e.pitch??0),e)}async function ye(e={}){return a(V(e.variant??"medium",e.pitch??0),e)}async function me(e={}){return a(E(e.variant??"medium",e.pitch??0),e)}async function ge(e={}){return a(P(e.variant??"medium",e.pitch??0),e)}async function he(e={}){return a(x(e.variant??"short",e.pitch??0),e)}async function Ae(e={}){return a(N(e.variant??"medium",e.pitch??0),e)}async function we(e={}){return a(R(e.variant??"short",e.pitch??0),e)}async function qe(e={}){return a(k(e.variant??"medium",e.pitch??0),e)}async function Ve(e={}){return a(T(e.variant??"medium",e.pitch??0),e)}async function Ee(e={}){return a(b(e.variant??"medium",e.pitch??0),e)}async function Pe(e={}){return a(O(e.variant??"medium",e.pitch??0),e)}async function xe(e={}){return a(j(e.variant??"medium",e.pitch??0),e)}async function Ne(e={}){return a(C(e.variant??"short",e.pitch??0),e)}async function Re(e={}){return a(I(e.variant??"short",e.pitch??0),e)}async function ke(e={}){return a(B(e.variant??"medium",e.pitch??0),e)}var _={success:q,error:V,warning:E,notification:P,click:x,info:N,toggle:R,delete:k,message:T,upload:b,download:O,eightBit:j,police:C,coin:I,boing:B};async function Te(e,n={}){let u=_[e];return a(u(n.variant??"medium",n.pitch??0),n)}function be(e,n){_[e]=n}return X(Oe);})();
|
package/dist/index.cjs
CHANGED
|
@@ -391,6 +391,336 @@ function infoPreset(variant, pitchSemitones) {
|
|
|
391
391
|
return VARIANTS6[variant];
|
|
392
392
|
}
|
|
393
393
|
|
|
394
|
+
// src/sounds/toggle.ts
|
|
395
|
+
var ENV = { attack: 3e-3, decay: 0.022, sustain: 0, release: 0.018 };
|
|
396
|
+
var VARIANTS7 = {
|
|
397
|
+
short: {
|
|
398
|
+
name: "toggle",
|
|
399
|
+
duration: 0.08,
|
|
400
|
+
notes: [
|
|
401
|
+
{ frequency: 880, duration: 0.06, startAt: 0, waveShape: "triangle", gain: 0.6, envelope: ENV }
|
|
402
|
+
]
|
|
403
|
+
},
|
|
404
|
+
medium: {
|
|
405
|
+
name: "toggle",
|
|
406
|
+
duration: 0.18,
|
|
407
|
+
notes: [
|
|
408
|
+
{ frequency: 660, duration: 0.05, startAt: 0, waveShape: "triangle", gain: 0.5, envelope: ENV },
|
|
409
|
+
{ frequency: 880, duration: 0.07, startAt: 0.08, waveShape: "triangle", gain: 0.65, envelope: ENV }
|
|
410
|
+
]
|
|
411
|
+
},
|
|
412
|
+
long: {
|
|
413
|
+
name: "toggle",
|
|
414
|
+
duration: 0.3,
|
|
415
|
+
notes: [
|
|
416
|
+
{ frequency: 440, duration: 0.05, startAt: 0, waveShape: "triangle", gain: 0.45, envelope: ENV },
|
|
417
|
+
{ frequency: 660, duration: 0.05, startAt: 0.08, waveShape: "triangle", gain: 0.55, envelope: ENV },
|
|
418
|
+
{ frequency: 880, duration: 0.08, startAt: 0.16, waveShape: "triangle", gain: 0.65, envelope: ENV }
|
|
419
|
+
]
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
function togglePreset(variant, pitchSemitones) {
|
|
423
|
+
return VARIANTS7[variant];
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// src/sounds/delete.ts
|
|
427
|
+
var ENV2 = { attack: 3e-3, decay: 0.04, sustain: 0.3, release: 0.07 };
|
|
428
|
+
var VARIANTS8 = {
|
|
429
|
+
short: {
|
|
430
|
+
name: "delete",
|
|
431
|
+
duration: 0.22,
|
|
432
|
+
notes: [
|
|
433
|
+
{ frequency: 440, duration: 0.07, startAt: 0, waveShape: "sawtooth", gain: 0.5, envelope: ENV2 },
|
|
434
|
+
{ frequency: 293, duration: 0.12, startAt: 0.08, waveShape: "sawtooth", gain: 0.55, envelope: ENV2 }
|
|
435
|
+
]
|
|
436
|
+
},
|
|
437
|
+
medium: {
|
|
438
|
+
name: "delete",
|
|
439
|
+
duration: 0.38,
|
|
440
|
+
notes: [
|
|
441
|
+
{ frequency: 523, duration: 0.07, startAt: 0, waveShape: "sawtooth", gain: 0.45, envelope: ENV2 },
|
|
442
|
+
{ frequency: 415, duration: 0.07, startAt: 0.09, waveShape: "sawtooth", gain: 0.5, envelope: ENV2 },
|
|
443
|
+
{ frequency: 277, duration: 0.15, startAt: 0.18, waveShape: "sawtooth", gain: 0.55, envelope: ENV2 }
|
|
444
|
+
]
|
|
445
|
+
},
|
|
446
|
+
long: {
|
|
447
|
+
name: "delete",
|
|
448
|
+
duration: 0.55,
|
|
449
|
+
notes: [
|
|
450
|
+
{ frequency: 587, duration: 0.07, startAt: 0, waveShape: "sawtooth", gain: 0.4, envelope: ENV2 },
|
|
451
|
+
{ frequency: 494, duration: 0.07, startAt: 0.09, waveShape: "sawtooth", gain: 0.45, envelope: ENV2 },
|
|
452
|
+
{ frequency: 392, duration: 0.07, startAt: 0.18, waveShape: "sawtooth", gain: 0.5, envelope: ENV2 },
|
|
453
|
+
{ frequency: 277, duration: 0.2, startAt: 0.27, waveShape: "sawtooth", gain: 0.55, envelope: ENV2 }
|
|
454
|
+
]
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
function deletePreset(variant, pitchSemitones) {
|
|
458
|
+
return VARIANTS8[variant];
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// src/sounds/message.ts
|
|
462
|
+
var ENV3 = { attack: 0.01, decay: 0.04, sustain: 0.3, release: 0.08 };
|
|
463
|
+
var VARIANTS9 = {
|
|
464
|
+
short: {
|
|
465
|
+
name: "message",
|
|
466
|
+
duration: 0.15,
|
|
467
|
+
notes: [
|
|
468
|
+
{ frequency: 1318, duration: 0.12, startAt: 0, waveShape: "sine", gain: 0.35, envelope: ENV3 }
|
|
469
|
+
]
|
|
470
|
+
},
|
|
471
|
+
medium: {
|
|
472
|
+
name: "message",
|
|
473
|
+
duration: 0.26,
|
|
474
|
+
notes: [
|
|
475
|
+
{ frequency: 1318, duration: 0.07, startAt: 0, waveShape: "sine", gain: 0.35, envelope: ENV3 },
|
|
476
|
+
{ frequency: 1047, duration: 0.15, startAt: 0.08, waveShape: "sine", gain: 0.4, envelope: ENV3 }
|
|
477
|
+
]
|
|
478
|
+
},
|
|
479
|
+
long: {
|
|
480
|
+
name: "message",
|
|
481
|
+
duration: 0.4,
|
|
482
|
+
notes: [
|
|
483
|
+
{ frequency: 1568, duration: 0.06, startAt: 0, waveShape: "sine", gain: 0.3, envelope: ENV3 },
|
|
484
|
+
{ frequency: 1318, duration: 0.07, startAt: 0.07, waveShape: "sine", gain: 0.35, envelope: ENV3 },
|
|
485
|
+
{ frequency: 1047, duration: 0.22, startAt: 0.15, waveShape: "sine", gain: 0.4, envelope: ENV3 }
|
|
486
|
+
]
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
function messagePreset(variant, pitchSemitones) {
|
|
490
|
+
return VARIANTS9[variant];
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// src/sounds/upload.ts
|
|
494
|
+
var VARIANTS10 = {
|
|
495
|
+
short: {
|
|
496
|
+
name: "upload",
|
|
497
|
+
duration: 0.24,
|
|
498
|
+
notes: [
|
|
499
|
+
{ frequency: 523, duration: 0.08, startAt: 0, waveShape: "sine", gain: 0.6 },
|
|
500
|
+
{ frequency: 784, duration: 0.13, startAt: 0.09, waveShape: "sine", gain: 0.7 }
|
|
501
|
+
]
|
|
502
|
+
},
|
|
503
|
+
medium: {
|
|
504
|
+
name: "upload",
|
|
505
|
+
duration: 0.4,
|
|
506
|
+
notes: [
|
|
507
|
+
{ frequency: 392, duration: 0.08, startAt: 0, waveShape: "sine", gain: 0.55 },
|
|
508
|
+
{ frequency: 523, duration: 0.08, startAt: 0.1, waveShape: "sine", gain: 0.65 },
|
|
509
|
+
{ frequency: 784, duration: 0.18, startAt: 0.2, waveShape: "sine", gain: 0.75 }
|
|
510
|
+
]
|
|
511
|
+
},
|
|
512
|
+
long: {
|
|
513
|
+
name: "upload",
|
|
514
|
+
duration: 0.58,
|
|
515
|
+
notes: [
|
|
516
|
+
{ frequency: 330, duration: 0.08, startAt: 0, waveShape: "sine", gain: 0.5 },
|
|
517
|
+
{ frequency: 392, duration: 0.08, startAt: 0.1, waveShape: "sine", gain: 0.6 },
|
|
518
|
+
{ frequency: 523, duration: 0.08, startAt: 0.2, waveShape: "sine", gain: 0.65 },
|
|
519
|
+
{ frequency: 784, duration: 0.24, startAt: 0.3, waveShape: "sine", gain: 0.75 }
|
|
520
|
+
]
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
function uploadPreset(variant, pitchSemitones) {
|
|
524
|
+
return VARIANTS10[variant];
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// src/sounds/download.ts
|
|
528
|
+
var VARIANTS11 = {
|
|
529
|
+
short: {
|
|
530
|
+
name: "download",
|
|
531
|
+
duration: 0.24,
|
|
532
|
+
notes: [
|
|
533
|
+
{ frequency: 784, duration: 0.08, startAt: 0, waveShape: "sine", gain: 0.7 },
|
|
534
|
+
{ frequency: 523, duration: 0.13, startAt: 0.09, waveShape: "sine", gain: 0.6 }
|
|
535
|
+
]
|
|
536
|
+
},
|
|
537
|
+
medium: {
|
|
538
|
+
name: "download",
|
|
539
|
+
duration: 0.4,
|
|
540
|
+
notes: [
|
|
541
|
+
{ frequency: 784, duration: 0.08, startAt: 0, waveShape: "sine", gain: 0.75 },
|
|
542
|
+
{ frequency: 523, duration: 0.08, startAt: 0.1, waveShape: "sine", gain: 0.65 },
|
|
543
|
+
{ frequency: 392, duration: 0.18, startAt: 0.2, waveShape: "sine", gain: 0.55 }
|
|
544
|
+
]
|
|
545
|
+
},
|
|
546
|
+
long: {
|
|
547
|
+
name: "download",
|
|
548
|
+
duration: 0.58,
|
|
549
|
+
notes: [
|
|
550
|
+
{ frequency: 784, duration: 0.08, startAt: 0, waveShape: "sine", gain: 0.75 },
|
|
551
|
+
{ frequency: 523, duration: 0.08, startAt: 0.1, waveShape: "sine", gain: 0.65 },
|
|
552
|
+
{ frequency: 392, duration: 0.08, startAt: 0.2, waveShape: "sine", gain: 0.6 },
|
|
553
|
+
{ frequency: 330, duration: 0.24, startAt: 0.3, waveShape: "sine", gain: 0.5 }
|
|
554
|
+
]
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
function downloadPreset(variant, pitchSemitones) {
|
|
558
|
+
return VARIANTS11[variant];
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// src/sounds/eightBit.ts
|
|
562
|
+
var ENV4 = { attack: 3e-3, decay: 0.015, sustain: 0.4, release: 0.015 };
|
|
563
|
+
var VARIANTS12 = {
|
|
564
|
+
short: {
|
|
565
|
+
name: "eightBit",
|
|
566
|
+
duration: 0.2,
|
|
567
|
+
notes: [
|
|
568
|
+
{ frequency: 523.25, duration: 0.04, startAt: 0, waveShape: "square", gain: 0.38, envelope: ENV4 },
|
|
569
|
+
{ frequency: 659.26, duration: 0.04, startAt: 0.05, waveShape: "square", gain: 0.38, envelope: ENV4 },
|
|
570
|
+
{ frequency: 783.99, duration: 0.08, startAt: 0.1, waveShape: "square", gain: 0.42, envelope: ENV4 }
|
|
571
|
+
]
|
|
572
|
+
},
|
|
573
|
+
medium: {
|
|
574
|
+
name: "eightBit",
|
|
575
|
+
duration: 0.33,
|
|
576
|
+
notes: [
|
|
577
|
+
{ frequency: 523.25, duration: 0.04, startAt: 0, waveShape: "square", gain: 0.35, envelope: ENV4 },
|
|
578
|
+
{ frequency: 659.26, duration: 0.04, startAt: 0.06, waveShape: "square", gain: 0.38, envelope: ENV4 },
|
|
579
|
+
{ frequency: 783.99, duration: 0.04, startAt: 0.12, waveShape: "square", gain: 0.4, envelope: ENV4 },
|
|
580
|
+
{ frequency: 1046.5, duration: 0.12, startAt: 0.18, waveShape: "square", gain: 0.45, envelope: ENV4 }
|
|
581
|
+
]
|
|
582
|
+
},
|
|
583
|
+
long: {
|
|
584
|
+
name: "eightBit",
|
|
585
|
+
duration: 0.5,
|
|
586
|
+
notes: [
|
|
587
|
+
{ frequency: 523.25, duration: 0.04, startAt: 0, waveShape: "square", gain: 0.32, envelope: ENV4 },
|
|
588
|
+
{ frequency: 659.26, duration: 0.04, startAt: 0.06, waveShape: "square", gain: 0.35, envelope: ENV4 },
|
|
589
|
+
{ frequency: 783.99, duration: 0.04, startAt: 0.12, waveShape: "square", gain: 0.38, envelope: ENV4 },
|
|
590
|
+
{ frequency: 659.26, duration: 0.04, startAt: 0.18, waveShape: "square", gain: 0.35, envelope: ENV4 },
|
|
591
|
+
{ frequency: 783.99, duration: 0.04, startAt: 0.24, waveShape: "square", gain: 0.38, envelope: ENV4 },
|
|
592
|
+
{ frequency: 1046.5, duration: 0.15, startAt: 0.3, waveShape: "square", gain: 0.45, envelope: ENV4 }
|
|
593
|
+
]
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
function eightBitPreset(variant, pitchSemitones) {
|
|
597
|
+
return VARIANTS12[variant];
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// src/sounds/police.ts
|
|
601
|
+
var ENV5 = { attack: 0.02, decay: 0, sustain: 1, release: 0.04 };
|
|
602
|
+
function sirenNote(freq, startAt) {
|
|
603
|
+
return { frequency: freq, duration: 0.22, startAt, waveShape: "sawtooth", gain: 0.45, envelope: ENV5 };
|
|
604
|
+
}
|
|
605
|
+
var VARIANTS13 = {
|
|
606
|
+
short: {
|
|
607
|
+
name: "police",
|
|
608
|
+
duration: 0.52,
|
|
609
|
+
notes: [
|
|
610
|
+
sirenNote(770, 0),
|
|
611
|
+
sirenNote(577, 0.26)
|
|
612
|
+
]
|
|
613
|
+
},
|
|
614
|
+
medium: {
|
|
615
|
+
name: "police",
|
|
616
|
+
duration: 1.04,
|
|
617
|
+
notes: [
|
|
618
|
+
sirenNote(770, 0),
|
|
619
|
+
sirenNote(577, 0.26),
|
|
620
|
+
sirenNote(770, 0.52),
|
|
621
|
+
sirenNote(577, 0.78)
|
|
622
|
+
]
|
|
623
|
+
},
|
|
624
|
+
long: {
|
|
625
|
+
name: "police",
|
|
626
|
+
duration: 1.56,
|
|
627
|
+
notes: [
|
|
628
|
+
sirenNote(770, 0),
|
|
629
|
+
sirenNote(577, 0.26),
|
|
630
|
+
sirenNote(770, 0.52),
|
|
631
|
+
sirenNote(577, 0.78),
|
|
632
|
+
sirenNote(770, 1.04),
|
|
633
|
+
sirenNote(577, 1.3)
|
|
634
|
+
]
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
function policePreset(variant, pitchSemitones) {
|
|
638
|
+
return VARIANTS13[variant];
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// src/sounds/coin.ts
|
|
642
|
+
var ENV6 = { attack: 3e-3, decay: 0.025, sustain: 0.45, release: 0.04 };
|
|
643
|
+
var VARIANTS14 = {
|
|
644
|
+
short: {
|
|
645
|
+
name: "coin",
|
|
646
|
+
duration: 0.16,
|
|
647
|
+
notes: [
|
|
648
|
+
{ frequency: 987.77, duration: 0.04, startAt: 0, waveShape: "square", gain: 0.45, envelope: ENV6 },
|
|
649
|
+
{ frequency: 1318.51, duration: 0.1, startAt: 0.045, waveShape: "square", gain: 0.5, envelope: ENV6 }
|
|
650
|
+
]
|
|
651
|
+
},
|
|
652
|
+
medium: {
|
|
653
|
+
name: "coin",
|
|
654
|
+
duration: 0.28,
|
|
655
|
+
notes: [
|
|
656
|
+
{ frequency: 987.77, duration: 0.05, startAt: 0, waveShape: "square", gain: 0.42, envelope: ENV6 },
|
|
657
|
+
{ frequency: 1174.66, duration: 0.05, startAt: 0.06, waveShape: "square", gain: 0.45, envelope: ENV6 },
|
|
658
|
+
{ frequency: 1318.51, duration: 0.14, startAt: 0.12, waveShape: "square", gain: 0.5, envelope: ENV6 }
|
|
659
|
+
]
|
|
660
|
+
},
|
|
661
|
+
long: {
|
|
662
|
+
name: "coin",
|
|
663
|
+
duration: 0.42,
|
|
664
|
+
notes: [
|
|
665
|
+
{ frequency: 987.77, duration: 0.05, startAt: 0, waveShape: "square", gain: 0.4, envelope: ENV6 },
|
|
666
|
+
{ frequency: 1174.66, duration: 0.05, startAt: 0.06, waveShape: "square", gain: 0.43, envelope: ENV6 },
|
|
667
|
+
{ frequency: 1318.51, duration: 0.05, startAt: 0.12, waveShape: "square", gain: 0.47, envelope: ENV6 },
|
|
668
|
+
{ frequency: 1568, duration: 0.2, startAt: 0.18, waveShape: "square", gain: 0.52, envelope: ENV6 }
|
|
669
|
+
]
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
function coinPreset(variant, pitchSemitones) {
|
|
673
|
+
return VARIANTS14[variant];
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// src/sounds/boing.ts
|
|
677
|
+
var ENV7 = { attack: 4e-3, decay: 0, sustain: 1, release: 0.025 };
|
|
678
|
+
var VARIANTS15 = {
|
|
679
|
+
short: {
|
|
680
|
+
name: "boing",
|
|
681
|
+
duration: 0.38,
|
|
682
|
+
notes: [
|
|
683
|
+
{ frequency: 1200, duration: 0.03, startAt: 0, waveShape: "sine", gain: 0.6, envelope: ENV7 },
|
|
684
|
+
{ frequency: 900, duration: 0.03, startAt: 0.04, waveShape: "sine", gain: 0.58, envelope: ENV7 },
|
|
685
|
+
{ frequency: 680, duration: 0.04, startAt: 0.08, waveShape: "sine", gain: 0.55, envelope: ENV7 },
|
|
686
|
+
{ frequency: 500, duration: 0.05, startAt: 0.13, waveShape: "sine", gain: 0.52, envelope: ENV7 },
|
|
687
|
+
{ frequency: 350, duration: 0.07, startAt: 0.19, waveShape: "sine", gain: 0.48, envelope: ENV7 },
|
|
688
|
+
{ frequency: 220, duration: 0.1, startAt: 0.27, waveShape: "sine", gain: 0.42, envelope: ENV7 }
|
|
689
|
+
]
|
|
690
|
+
},
|
|
691
|
+
medium: {
|
|
692
|
+
name: "boing",
|
|
693
|
+
duration: 0.6,
|
|
694
|
+
notes: [
|
|
695
|
+
{ frequency: 1400, duration: 0.04, startAt: 0, waveShape: "sine", gain: 0.62, envelope: ENV7 },
|
|
696
|
+
{ frequency: 1050, duration: 0.04, startAt: 0.05, waveShape: "sine", gain: 0.6, envelope: ENV7 },
|
|
697
|
+
{ frequency: 800, duration: 0.05, startAt: 0.1, waveShape: "sine", gain: 0.57, envelope: ENV7 },
|
|
698
|
+
{ frequency: 600, duration: 0.06, startAt: 0.16, waveShape: "sine", gain: 0.54, envelope: ENV7 },
|
|
699
|
+
{ frequency: 450, duration: 0.07, startAt: 0.23, waveShape: "sine", gain: 0.51, envelope: ENV7 },
|
|
700
|
+
{ frequency: 330, duration: 0.09, startAt: 0.31, waveShape: "sine", gain: 0.47, envelope: ENV7 },
|
|
701
|
+
{ frequency: 240, duration: 0.13, startAt: 0.41, waveShape: "sine", gain: 0.42, envelope: ENV7 }
|
|
702
|
+
]
|
|
703
|
+
},
|
|
704
|
+
long: {
|
|
705
|
+
name: "boing",
|
|
706
|
+
duration: 0.9,
|
|
707
|
+
notes: [
|
|
708
|
+
{ frequency: 1600, duration: 0.04, startAt: 0, waveShape: "sine", gain: 0.62, envelope: ENV7 },
|
|
709
|
+
{ frequency: 1200, duration: 0.04, startAt: 0.05, waveShape: "sine", gain: 0.6, envelope: ENV7 },
|
|
710
|
+
{ frequency: 950, duration: 0.05, startAt: 0.1, waveShape: "sine", gain: 0.58, envelope: ENV7 },
|
|
711
|
+
{ frequency: 720, duration: 0.06, startAt: 0.16, waveShape: "sine", gain: 0.55, envelope: ENV7 },
|
|
712
|
+
{ frequency: 540, duration: 0.07, startAt: 0.23, waveShape: "sine", gain: 0.52, envelope: ENV7 },
|
|
713
|
+
{ frequency: 400, duration: 0.09, startAt: 0.31, waveShape: "sine", gain: 0.49, envelope: ENV7 },
|
|
714
|
+
{ frequency: 290, duration: 0.12, startAt: 0.41, waveShape: "sine", gain: 0.45, envelope: ENV7 },
|
|
715
|
+
{ frequency: 210, duration: 0.16, startAt: 0.54, waveShape: "sine", gain: 0.41, envelope: ENV7 },
|
|
716
|
+
{ frequency: 160, duration: 0.18, startAt: 0.71, waveShape: "sine", gain: 0.36, envelope: ENV7 }
|
|
717
|
+
]
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
function boingPreset(variant, pitchSemitones) {
|
|
721
|
+
return VARIANTS15[variant];
|
|
722
|
+
}
|
|
723
|
+
|
|
394
724
|
// src/index.ts
|
|
395
725
|
async function play(preset, opts = {}) {
|
|
396
726
|
const { volume = 0.5, pitch = 0, audioContext, onEnded } = opts;
|
|
@@ -418,13 +748,51 @@ async function playClick(opts = {}) {
|
|
|
418
748
|
async function playInfo(opts = {}) {
|
|
419
749
|
return play(infoPreset(opts.variant ?? "medium", opts.pitch ?? 0), opts);
|
|
420
750
|
}
|
|
751
|
+
async function playToggle(opts = {}) {
|
|
752
|
+
return play(togglePreset(opts.variant ?? "short", opts.pitch ?? 0), opts);
|
|
753
|
+
}
|
|
754
|
+
async function playDelete(opts = {}) {
|
|
755
|
+
return play(deletePreset(opts.variant ?? "medium", opts.pitch ?? 0), opts);
|
|
756
|
+
}
|
|
757
|
+
async function playMessage(opts = {}) {
|
|
758
|
+
return play(messagePreset(opts.variant ?? "medium", opts.pitch ?? 0), opts);
|
|
759
|
+
}
|
|
760
|
+
async function playUpload(opts = {}) {
|
|
761
|
+
return play(uploadPreset(opts.variant ?? "medium", opts.pitch ?? 0), opts);
|
|
762
|
+
}
|
|
763
|
+
async function playDownload(opts = {}) {
|
|
764
|
+
return play(downloadPreset(opts.variant ?? "medium", opts.pitch ?? 0), opts);
|
|
765
|
+
}
|
|
766
|
+
async function playEightBit(opts = {}) {
|
|
767
|
+
return play(eightBitPreset(opts.variant ?? "medium", opts.pitch ?? 0), opts);
|
|
768
|
+
}
|
|
769
|
+
async function playPolice(opts = {}) {
|
|
770
|
+
return play(policePreset(opts.variant ?? "short", opts.pitch ?? 0), opts);
|
|
771
|
+
}
|
|
772
|
+
async function playCoin(opts = {}) {
|
|
773
|
+
return play(coinPreset(opts.variant ?? "short", opts.pitch ?? 0), opts);
|
|
774
|
+
}
|
|
775
|
+
async function playBoing(opts = {}) {
|
|
776
|
+
return play(boingPreset(opts.variant ?? "medium", opts.pitch ?? 0), opts);
|
|
777
|
+
}
|
|
421
778
|
var BANK = {
|
|
779
|
+
// UI sounds
|
|
422
780
|
success: successPreset,
|
|
423
781
|
error: errorPreset,
|
|
424
782
|
warning: warningPreset,
|
|
425
783
|
notification: notificationPreset,
|
|
426
784
|
click: clickPreset,
|
|
427
|
-
info: infoPreset
|
|
785
|
+
info: infoPreset,
|
|
786
|
+
toggle: togglePreset,
|
|
787
|
+
delete: deletePreset,
|
|
788
|
+
message: messagePreset,
|
|
789
|
+
upload: uploadPreset,
|
|
790
|
+
download: downloadPreset,
|
|
791
|
+
// fun & misc
|
|
792
|
+
eightBit: eightBitPreset,
|
|
793
|
+
police: policePreset,
|
|
794
|
+
coin: coinPreset,
|
|
795
|
+
boing: boingPreset
|
|
428
796
|
};
|
|
429
797
|
async function earcon(name, opts = {}) {
|
|
430
798
|
const preset = BANK[name];
|
|
@@ -436,11 +804,20 @@ function registerSound(name, preset) {
|
|
|
436
804
|
|
|
437
805
|
exports.closeAudioContext = closeAudioContext;
|
|
438
806
|
exports.earcon = earcon;
|
|
807
|
+
exports.playBoing = playBoing;
|
|
439
808
|
exports.playClick = playClick;
|
|
809
|
+
exports.playCoin = playCoin;
|
|
810
|
+
exports.playDelete = playDelete;
|
|
811
|
+
exports.playDownload = playDownload;
|
|
812
|
+
exports.playEightBit = playEightBit;
|
|
440
813
|
exports.playError = playError;
|
|
441
814
|
exports.playInfo = playInfo;
|
|
815
|
+
exports.playMessage = playMessage;
|
|
442
816
|
exports.playNotification = playNotification;
|
|
817
|
+
exports.playPolice = playPolice;
|
|
443
818
|
exports.playSuccess = playSuccess;
|
|
819
|
+
exports.playToggle = playToggle;
|
|
820
|
+
exports.playUpload = playUpload;
|
|
444
821
|
exports.playWarning = playWarning;
|
|
445
822
|
exports.registerSound = registerSound;
|
|
446
823
|
exports.semitonesToMultiplier = semitonesToMultiplier;
|