@audio/synth-rhythm 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/rhythm.js +14 -0
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@audio/synth-rhythm",
3
+ "version": "1.0.0",
4
+ "description": "Rhythm / click track — BPM grid with accented downbeats",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "rhythm.js",
8
+ "exports": {
9
+ ".": "./rhythm.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "rhythm.js"
14
+ ],
15
+ "keywords": [
16
+ "audio",
17
+ "dsp",
18
+ "synth",
19
+ "rhythm"
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/rhythm.js ADDED
@@ -0,0 +1,14 @@
1
+ // Rhythm / click track — decaying tone bursts on a BPM grid, accented downbeats.
2
+
3
+ export default function rhythm ({ bpm = 120, bars = 4, beats = 4, fs = 44100, freq = 1000, accentFreq = 1500, amp = 0.7 } = {}) {
4
+ let spb = 60 / bpm
5
+ let n = Math.round(bars * beats * spb * fs)
6
+ let out = new Float32Array(n)
7
+ for (let b = 0; b < bars * beats; b++) {
8
+ let at = Math.round(b * spb * fs)
9
+ let f = b % beats === 0 ? accentFreq : freq
10
+ let a = b % beats === 0 ? amp : amp * 0.7
11
+ for (let i = 0; i < 900 && at + i < n; i++) out[at + i] += a * Math.sin(2 * Math.PI * f * i / fs) * Math.exp(-i / 250)
12
+ }
13
+ return out
14
+ }