@audio/dynamics-ducker 0.1.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/ducker.js +34 -0
- package/package.json +43 -0
package/ducker.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { envelope } from '@audio/dynamics-envelope'
|
|
2
|
+
import { compressorGain } from '@audio/dynamics-compressor'
|
|
3
|
+
import { writer2, concat, db2lin, lin2db } from '@audio/dynamics-core'
|
|
4
|
+
|
|
5
|
+
// External-sidechain compressor: main signal's gain is reduced in proportion
|
|
6
|
+
// to the level of a separate side signal (e.g. voice track ducking music).
|
|
7
|
+
export default function ducker(main, side, opts) {
|
|
8
|
+
if (!(main instanceof Float32Array)) return writer2(duckerStream(main))
|
|
9
|
+
let s = duckerStream(opts)
|
|
10
|
+
return concat(s.write(main, side), s.flush())
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function duckerStream(opts = {}) {
|
|
14
|
+
let threshold = opts.threshold ?? -30
|
|
15
|
+
let ratio = opts.ratio ?? 4
|
|
16
|
+
let knee = opts.knee ?? 6
|
|
17
|
+
let range = opts.range ?? -24 // max reduction in dB
|
|
18
|
+
let env = envelope({ ...opts, attack: opts.attack ?? 20, release: opts.release ?? 300 })
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
write(main, side) {
|
|
22
|
+
let n = Math.min(main.length, side.length)
|
|
23
|
+
let out = new Float32Array(main.length)
|
|
24
|
+
for (let i = 0; i < n; i++) {
|
|
25
|
+
let rDb = compressorGain(lin2db(env(side[i])), threshold, ratio, knee)
|
|
26
|
+
if (rDb < range) rDb = range
|
|
27
|
+
out[i] = main[i] * db2lin(rDb)
|
|
28
|
+
}
|
|
29
|
+
for (let i = n; i < main.length; i++) out[i] = main[i]
|
|
30
|
+
return out
|
|
31
|
+
},
|
|
32
|
+
flush() { return new Float32Array(0) }
|
|
33
|
+
}
|
|
34
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@audio/dynamics-ducker",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "External-sidechain compressor: main signal's gain is reduced in proportion",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "ducker.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./ducker.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"ducker.js"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@audio/dynamics-core": "^0.1.0",
|
|
17
|
+
"@audio/dynamics-envelope": "^0.1.0",
|
|
18
|
+
"@audio/dynamics-compressor": "^0.1.0"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"audio",
|
|
22
|
+
"dsp",
|
|
23
|
+
"dynamics",
|
|
24
|
+
"ducker"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"author": "Dmitry Iv. <dfcreative@gmail.com>",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/audiojs/dynamics.git",
|
|
31
|
+
"directory": "packages/dynamics-ducker"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/audiojs/dynamics/tree/main/packages/dynamics-ducker",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/audiojs/dynamics/issues"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
}
|
|
43
|
+
}
|