@audio/synth-envelope 1.0.0 → 1.1.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.
Files changed (2) hide show
  1. package/atom.js +34 -0
  2. package/package.json +6 -3
package/atom.js ADDED
@@ -0,0 +1,34 @@
1
+ // atom manifest — ADSR applied as a gain envelope over the whole take (attack/decay
2
+ // at the start, release ending at the end — Tone.js "envelope applicable to gain").
3
+ // whole-render: the envelope spans the full duration, so release placement needs the
4
+ // total length up front.
5
+
6
+ import adsrFn from './envelope.js'
7
+
8
+ export const adsr = (ctx) => {
9
+ return (inputs, outputs, params) => {
10
+ const inp = inputs[0], out = outputs[0]
11
+ if (!inp || !inp.length) return
12
+ const n = inp[0].length
13
+ const env = adsrFn({
14
+ attack: params.attack[0], decay: params.decay[0],
15
+ sustain: params.sustain[0], release: params.release[0],
16
+ // kernel total = duration + release — place the release so it ends at the take's end
17
+ duration: Math.max(0, n / ctx.sampleRate - params.release[0]), fs: ctx.sampleRate,
18
+ })
19
+ const m = Math.min(n, env.length)
20
+ for (let c = 0; c < inp.length; c++) {
21
+ const x = inp[c], y = out[c]
22
+ for (let i = 0; i < m; i++) y[i] = x[i] * env[i]
23
+ for (let i = m; i < n; i++) y[i] = 0
24
+ }
25
+ }
26
+ }
27
+ adsr.channels = 'any'
28
+ adsr.streaming = false
29
+ adsr.params = {
30
+ attack: { type: 'number', min: 0.001, max: 2, default: 0.01, unit: 's', curve: 'log' },
31
+ decay: { type: 'number', min: 0.001, max: 2, default: 0.1, unit: 's', curve: 'log' },
32
+ sustain: { type: 'number', min: 0, max: 1, default: 0.7 },
33
+ release: { type: 'number', min: 0.001, max: 4, default: 0.3, unit: 's', curve: 'log' },
34
+ }
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "name": "@audio/synth-envelope",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "ADSR envelope generator — gain contour for amplitude/filter modulation",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "main": "envelope.js",
8
8
  "exports": {
9
9
  ".": "./envelope.js",
10
+ "./atom": "./atom.js",
10
11
  "./package.json": "./package.json"
11
12
  },
12
13
  "files": [
13
- "envelope.js"
14
+ "envelope.js",
15
+ "atom.js"
14
16
  ],
15
17
  "keywords": [
16
18
  "audio",
@@ -25,5 +27,6 @@
25
27
  },
26
28
  "publishConfig": {
27
29
  "access": "public"
28
- }
30
+ },
31
+ "atom": "./atom.js"
29
32
  }