@audio/synth-risset 1.0.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/package.json +29 -0
  2. package/risset.js +21 -0
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@audio/synth-risset",
3
+ "version": "1.0.0",
4
+ "description": "Risset drum — inharmonic partial set with exponential decay",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "risset.js",
8
+ "exports": {
9
+ ".": "./risset.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "risset.js"
14
+ ],
15
+ "keywords": [
16
+ "audio",
17
+ "dsp",
18
+ "synth",
19
+ "risset"
20
+ ],
21
+ "license": "MIT",
22
+ "author": "Dmitry Iv. <dfcreative@gmail.com>",
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
29
+ }
package/risset.js ADDED
@@ -0,0 +1,21 @@
1
+ // Risset drum — inharmonic partials + sine at ~an octave below + pitch-gliding noise band
2
+ // character, per Risset's classic catalogue (simplified: inharmonic partial set + decay).
3
+
4
+ const PARTIALS = [[1, 1], [1.6, 0.67], [2.2, 0.53], [2.3, 0.5], [2.9, 0.4]]
5
+
6
+ export default function risset (freq = 100, { fs = 44100, duration = 1.2, amp = 0.6 } = {}) {
7
+ let n = Math.round(duration * fs)
8
+ let out = new Float32Array(n)
9
+ for (let [ratio, a] of PARTIALS) {
10
+ for (let i = 0; i < n; i++) {
11
+ let t = i / fs
12
+ out[i] += amp * a * Math.exp(-t * 4 / duration) * Math.sin(2 * Math.PI * freq * ratio * t)
13
+ }
14
+ }
15
+ // sub sine an octave down, slower decay
16
+ for (let i = 0; i < n; i++) out[i] += amp * 0.6 * Math.exp(-i / fs * 2.5 / duration) * Math.sin(Math.PI * freq * i / fs)
17
+ let max = 0
18
+ for (let v of out) max = Math.max(max, Math.abs(v))
19
+ if (max > 0) for (let i = 0; i < n; i++) out[i] *= amp / max
20
+ return out
21
+ }