@audio/synth-lfo 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.
- package/lfo.js +15 -0
- package/package.json +29 -0
package/lfo.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// LFO — low-frequency control signal (sine/triangle/square/saw), bipolar or unipolar.
|
|
2
|
+
|
|
3
|
+
export default function lfo (freq = 2, { duration = 1, fs = 44100, type = 'sine', unipolar = false, phase = 0 } = {}) {
|
|
4
|
+
let n = Math.round(duration * fs)
|
|
5
|
+
let out = new Float32Array(n)
|
|
6
|
+
for (let i = 0; i < n; i++) {
|
|
7
|
+
let t = (phase + freq * i / fs) % 1
|
|
8
|
+
let v = type === 'triangle' ? 1 - 4 * Math.abs(t - 0.5) :
|
|
9
|
+
type === 'square' ? (t < 0.5 ? 1 : -1) :
|
|
10
|
+
type === 'saw' ? 2 * t - 1 :
|
|
11
|
+
Math.sin(2 * Math.PI * t)
|
|
12
|
+
out[i] = unipolar ? (v + 1) / 2 : v
|
|
13
|
+
}
|
|
14
|
+
return out
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@audio/synth-lfo",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "LFO — low-frequency control signal, bipolar/unipolar",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "lfo.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./lfo.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"lfo.js"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"audio",
|
|
17
|
+
"dsp",
|
|
18
|
+
"synth",
|
|
19
|
+
"lfo"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "Dmitry Iv. <dfcreative@gmail.com>",
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
}
|
|
29
|
+
}
|