@audio/synth-drum 2.0.0 → 2.0.2

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 (4) hide show
  1. package/README.md +36 -0
  2. package/drum.d.ts +40 -0
  3. package/drum.js +1 -1
  4. package/package.json +10 -2
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @audio/synth-drum [![npm](https://img.shields.io/npm/v/@audio/synth-drum)](https://www.npmjs.com/package/@audio/synth-drum) [![MIT](https://img.shields.io/badge/MIT-%E0%A5%90-white)](https://github.com/krishnized/license)
2
+
3
+ Membrane (pitch-drop kick) / metal (inharmonic cymbal) / noiseDrum (snare/hat)
4
+
5
+ ```
6
+ npm install @audio/synth-drum
7
+ ```
8
+
9
+ ```js
10
+ import membrane, { metal, noiseDrum } from '@audio/synth-drum'
11
+ ```
12
+
13
+ Three drum-synthesis kernels, the Tone.js MembraneSynth/MetalSynth/NoiseSynth class: `membrane` is a sine whose pitch drops exponentially (kick), `metal` sums six inharmonic square-ish partials (cymbal — classic FM-bell ratio set), `noiseDrum` is decaying seeded band noise (snare/hat). `membrane` and `metal` are pitched — `(freq, opts)`; `noiseDrum` is unpitched — `(opts)`.
14
+
15
+ ```js
16
+ membrane(55, { drop: 3, duration: 0.5 }) // kick
17
+ metal(200, { duration: 0.6 }) // cymbal
18
+ noiseDrum({ duration: 0.25, seed: 9 }) // snare/hat
19
+ ```
20
+
21
+ | Param | Default | Applies to | |
22
+ |---|---|---|---|
23
+ | `freq` | `55` / `200` | membrane / metal | Hz (positional) |
24
+ | `drop` | `3` | membrane | pitch-drop multiplier |
25
+ | `duration` | `0.5` / `0.6` / `0.25` | all | seconds |
26
+ | `amp` | `0.9` / `0.5` / `0.7` | all | peak amplitude |
27
+ | `seed` | `9` | noiseDrum | PRNG seed |
28
+ | `fs` | `44100` | all | sample rate |
29
+
30
+ **Use when:** synthetic drum hits — `membrane` for kicks, `metal` for cymbals/bells, `noiseDrum` for snare/hat layers.
31
+
32
+ ---
33
+
34
+ Part of [@audio/synth](https://github.com/audiojs/synth) — the synth family umbrella.
35
+
36
+ MIT © [audiojs](https://github.com/audiojs)
package/drum.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ /** Drum synthesis — membrane (pitch-drop kick), metal (inharmonic cymbal), noiseDrum (snare/hat). */
2
+ export interface MembraneOptions {
3
+ /** pitch-drop multiplier, default 3 */
4
+ drop?: number
5
+ /** seconds, default 0.5 */
6
+ duration?: number
7
+ /** sample rate, default 44100 */
8
+ fs?: number
9
+ /** peak amplitude, default 0.9 */
10
+ amp?: number
11
+ }
12
+
13
+ export interface MetalOptions {
14
+ /** seconds, default 0.6 */
15
+ duration?: number
16
+ /** sample rate, default 44100 */
17
+ fs?: number
18
+ /** peak amplitude, default 0.5 */
19
+ amp?: number
20
+ }
21
+
22
+ export interface NoiseDrumOptions {
23
+ /** seconds, default 0.25 */
24
+ duration?: number
25
+ /** sample rate, default 44100 */
26
+ fs?: number
27
+ /** peak amplitude, default 0.7 */
28
+ amp?: number
29
+ /** PRNG seed, default 9 */
30
+ seed?: number
31
+ }
32
+
33
+ /** Sine kick with exponentially dropping pitch. */
34
+ export function membrane(freq?: number, options?: MembraneOptions): Float32Array
35
+ /** Six-partial inharmonic square-ish cymbal (classic FM-bell ratio set). */
36
+ export function metal(freq?: number, options?: MetalOptions): Float32Array
37
+ /** Decaying seeded band noise — snare/hat. */
38
+ export function noiseDrum(options?: NoiseDrumOptions): Float32Array
39
+
40
+ export default membrane
package/drum.js CHANGED
@@ -26,7 +26,7 @@ export function noiseDrum ({ duration = 0.25, fs = 44100, amp = 0.7, seed = 9 }
26
26
  let n = Math.round(duration * fs)
27
27
  let out = new Float32Array(n)
28
28
  let s = seed
29
- for (let i = 0; i < n; i++) { s = (s * 1103515245 + 12345) & 0x7fffffff; out[i] = amp * (s / 0x3fffffff - 1) * Math.exp(-i / n * 7) }
29
+ for (let i = 0; i < n; i++) { s = (Math.imul(s, 1103515245) + 12345) & 0x7fffffff; out[i] = amp * (s / 0x3fffffff - 1) * Math.exp(-i / n * 7) } // imul: exact mod 2³²
30
30
  return out
31
31
  }
32
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@audio/synth-drum",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Drum synthesis — membrane kick, metal cymbal, noise snare (Tone.js class)",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -15,9 +15,11 @@
15
15
  },
16
16
  "files": [
17
17
  "drum.js",
18
+ "drum.d.ts",
18
19
  "audio.js",
19
20
  "audio.d.ts"
20
21
  ],
22
+ "types": "drum.d.ts",
21
23
  "keywords": [
22
24
  "audio",
23
25
  "dsp",
@@ -32,5 +34,11 @@
32
34
  "publishConfig": {
33
35
  "access": "public"
34
36
  },
35
- "audio": "./audio.js"
37
+ "audio": "./audio.js",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/audiojs/synth.git",
41
+ "directory": "packages/synth-drum"
42
+ },
43
+ "funding": "https://github.com/sponsors/audiojs"
36
44
  }