@audio/synth-sfx 1.1.3 → 1.1.4
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/package.json +4 -1
- package/sfx.js +8 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audio/synth-sfx",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "Game/UI sound effects generator — ZZFX / ChipTone class parameterized synthesis",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -32,6 +32,9 @@
|
|
|
32
32
|
"audio.d.ts"
|
|
33
33
|
],
|
|
34
34
|
"types": "sfx.d.ts",
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@audio/synth-osc": "^1.1.0"
|
|
37
|
+
},
|
|
35
38
|
"publishConfig": {
|
|
36
39
|
"access": "public"
|
|
37
40
|
},
|
package/sfx.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// noise/bitcrush/lowpass. Named presets cover the sfxr archetypes; every field is
|
|
4
4
|
// overridable, deterministic (seeded noise) so renders are reproducible.
|
|
5
5
|
|
|
6
|
+
import { wave } from '@audio/synth-osc'
|
|
7
|
+
|
|
6
8
|
let { sin, PI, abs, exp, sign } = Math
|
|
7
9
|
|
|
8
10
|
export const PRESETS = {
|
|
@@ -49,12 +51,14 @@ export default function sfx (preset = 'blip', opts = {}) {
|
|
|
49
51
|
if (arp && t > arpAt) f *= arp ** Math.min(2, Math.floor(t / arpAt))
|
|
50
52
|
if (vib) f *= 1 + vibDepth * sin(2 * PI * vib * t)
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
// band-limited (synth-osc): the rising saw and the triangle rising from −1 are its falling ones negated
|
|
55
|
+
let dt = f / fs
|
|
56
|
+
phase += dt
|
|
53
57
|
let ph = phase % 1
|
|
54
58
|
let s = shape === 'sine' ? sin(2 * PI * ph)
|
|
55
|
-
: shape === 'square' ? (ph
|
|
56
|
-
: shape === 'saw' ? (
|
|
57
|
-
: shape === 'triangle' ? (
|
|
59
|
+
: shape === 'square' ? wave('square', ph, dt) * 0.7
|
|
60
|
+
: shape === 'saw' ? -wave('sawtooth', ph, dt) * 0.8
|
|
61
|
+
: shape === 'triangle' ? -wave('triangle', ph, dt)
|
|
58
62
|
: noise()
|
|
59
63
|
|
|
60
64
|
// envelope: linear attack, flat sustain, exponential release
|