@audio/synth-drum 1.1.1 → 2.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.
- package/audio.d.ts +79 -0
- package/audio.js +2 -2
- package/drum.js +2 -2
- package/package.json +7 -3
package/audio.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Generated from the audio.js manifest (params metadata is the source of truth).
|
|
2
|
+
// Regenerate: node tools/dts.js in @audio/compile. Do not edit by hand.
|
|
3
|
+
|
|
4
|
+
/** Automatable number — scalar, `t => value` fn, or breakpoint curve {t, v} */
|
|
5
|
+
type Auto = number | ((t: number) => number) | { t: number[], v: number[] }
|
|
6
|
+
/** Per-block param values as delivered by hosts (numbers arrive as 1-length Float32Array) */
|
|
7
|
+
type Live = Record<string, Float32Array | string | boolean>
|
|
8
|
+
type Ctx = { sampleRate: number, maxBlockSize: number, maxChannels: number, currentTime: number, duration?: number, events?: readonly any[], emit?: (name: string, ...args: any[]) => void, [k: string]: unknown }
|
|
9
|
+
type Process = (inputs: Float32Array[][], outputs: Float32Array[][], params: Live) => void
|
|
10
|
+
|
|
11
|
+
/** Chainable-host options for 'cymbal' */
|
|
12
|
+
export interface CymbalOptions {
|
|
13
|
+
/** 100..800 Hz (default 200) */
|
|
14
|
+
"freq"?: Auto
|
|
15
|
+
/** 0..1 (default 0.5) */
|
|
16
|
+
"amp"?: Auto
|
|
17
|
+
at?: number | string
|
|
18
|
+
duration?: number | string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export declare const cymbal: {
|
|
22
|
+
(ctx: Ctx): Process
|
|
23
|
+
channels: {"inputs":[],"outputs":"any"}
|
|
24
|
+
streaming: false
|
|
25
|
+
params: {
|
|
26
|
+
/** 100..800 Hz (default 200) */
|
|
27
|
+
"freq": { type: "number", default: 200 }
|
|
28
|
+
/** 0..1 (default 0.5) */
|
|
29
|
+
"amp": { type: "number", default: 0.5 }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Chainable-host options for 'kick' */
|
|
34
|
+
export interface KickOptions {
|
|
35
|
+
/** 30..120 Hz (default 55) */
|
|
36
|
+
"freq"?: Auto
|
|
37
|
+
/** 1..8 (default 3) */
|
|
38
|
+
"drop"?: Auto
|
|
39
|
+
/** 0..1 (default 0.9) */
|
|
40
|
+
"amp"?: Auto
|
|
41
|
+
at?: number | string
|
|
42
|
+
duration?: number | string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export declare const kick: {
|
|
46
|
+
(ctx: Ctx): Process
|
|
47
|
+
channels: {"inputs":[],"outputs":"any"}
|
|
48
|
+
streaming: false
|
|
49
|
+
params: {
|
|
50
|
+
/** 30..120 Hz (default 55) */
|
|
51
|
+
"freq": { type: "number", default: 55 }
|
|
52
|
+
/** 1..8 (default 3) */
|
|
53
|
+
"drop": { type: "number", default: 3 }
|
|
54
|
+
/** 0..1 (default 0.9) */
|
|
55
|
+
"amp": { type: "number", default: 0.9 }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Chainable-host options for 'snare' */
|
|
60
|
+
export interface SnareOptions {
|
|
61
|
+
/** 0..1 (default 0.7) */
|
|
62
|
+
"amp"?: Auto
|
|
63
|
+
/** 1..65536 (default 9) */
|
|
64
|
+
"seed"?: Auto
|
|
65
|
+
at?: number | string
|
|
66
|
+
duration?: number | string
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export declare const snare: {
|
|
70
|
+
(ctx: Ctx): Process
|
|
71
|
+
channels: {"inputs":[],"outputs":"any"}
|
|
72
|
+
streaming: false
|
|
73
|
+
params: {
|
|
74
|
+
/** 0..1 (default 0.7) */
|
|
75
|
+
"amp": { type: "number", default: 0.7 }
|
|
76
|
+
/** 1..65536 (default 9) */
|
|
77
|
+
"seed": { type: "number", default: 9 }
|
|
78
|
+
}
|
|
79
|
+
}
|
package/audio.js
CHANGED
|
@@ -13,7 +13,7 @@ const place = (out, d) => {
|
|
|
13
13
|
export const kick = (ctx) => (inputs, outputs, params) => {
|
|
14
14
|
const out = outputs[0]
|
|
15
15
|
if (!out || !out.length) return
|
|
16
|
-
place(out, membrane(
|
|
16
|
+
place(out, membrane(params.freq[0], { drop: params.drop[0], duration: Math.min(out[0].length / ctx.sampleRate, 2), fs: ctx.sampleRate, amp: params.amp[0] }))
|
|
17
17
|
}
|
|
18
18
|
kick.channels = { inputs: [], outputs: 'any' }
|
|
19
19
|
kick.streaming = false
|
|
@@ -26,7 +26,7 @@ kick.params = {
|
|
|
26
26
|
export const cymbal = (ctx) => (inputs, outputs, params) => {
|
|
27
27
|
const out = outputs[0]
|
|
28
28
|
if (!out || !out.length) return
|
|
29
|
-
place(out, metal(
|
|
29
|
+
place(out, metal(params.freq[0], { duration: Math.min(out[0].length / ctx.sampleRate, 2), fs: ctx.sampleRate, amp: params.amp[0] }))
|
|
30
30
|
}
|
|
31
31
|
cymbal.channels = { inputs: [], outputs: 'any' }
|
|
32
32
|
cymbal.streaming = false
|
package/drum.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Drum synthesis — membrane (pitch-dropping sine kick), metal (inharmonic square-ish
|
|
2
2
|
// cymbal), noise (snare/hat band noise), Tone.js MembraneSynth/MetalSynth/NoiseSynth class.
|
|
3
3
|
|
|
4
|
-
export function membrane (
|
|
4
|
+
export function membrane (freq = 55, { drop = 3, duration = 0.5, fs = 44100, amp = 0.9 } = {}) {
|
|
5
5
|
let n = Math.round(duration * fs)
|
|
6
6
|
let out = new Float32Array(n)
|
|
7
7
|
let phase = 0
|
|
@@ -14,7 +14,7 @@ export function membrane ({ freq = 55, drop = 3, duration = 0.5, fs = 44100, amp
|
|
|
14
14
|
return out
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export function metal (
|
|
17
|
+
export function metal (freq = 200, { duration = 0.6, fs = 44100, amp = 0.5 } = {}) {
|
|
18
18
|
const RATIOS = [1, 1.483, 1.932, 2.546, 2.63, 3.897] // classic FM-bell inharmonic set
|
|
19
19
|
let n = Math.round(duration * fs)
|
|
20
20
|
let out = new Float32Array(n)
|
package/package.json
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audio/synth-drum",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Drum synthesis — membrane kick, metal cymbal, noise snare (Tone.js class)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "drum.js",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./drum.js",
|
|
10
|
-
"./audio":
|
|
10
|
+
"./audio": {
|
|
11
|
+
"types": "./audio.d.ts",
|
|
12
|
+
"default": "./audio.js"
|
|
13
|
+
},
|
|
11
14
|
"./package.json": "./package.json"
|
|
12
15
|
},
|
|
13
16
|
"files": [
|
|
14
17
|
"drum.js",
|
|
15
|
-
"audio.js"
|
|
18
|
+
"audio.js",
|
|
19
|
+
"audio.d.ts"
|
|
16
20
|
],
|
|
17
21
|
"keywords": [
|
|
18
22
|
"audio",
|