@audio/effect-subbass 1.1.5 → 1.2.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/README.md +3 -3
- package/audio.d.ts +3 -1
- package/audio.js +2 -2
- package/package.json +1 -1
- package/subbass.d.ts +4 -2
- package/subbass.js +5 -5
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Psychoacoustic bass enhancer — harmonic synthesis below cutoff (MaxxBass/RBass class)
|
|
4
4
|
|
|
5
|
-
Extracts the band below `
|
|
5
|
+
Extracts the band below `fc`, generates its harmonic series with an even/odd waveshaper, band-limits the harmonics to the audible low-mids, and mixes against dry. Small speakers reproduce the harmonics; the ear reconstructs the missing fundamental.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -15,13 +15,13 @@ npm install @audio/effect-subbass
|
|
|
15
15
|
```js
|
|
16
16
|
import subbass from '@audio/effect-subbass'
|
|
17
17
|
|
|
18
|
-
let p = {
|
|
18
|
+
let p = { fc: 80, amount: 0.5, drive: 0.5, keep: 1, fs: 44100 }
|
|
19
19
|
for (let buf of stream) subbass(buf, p)
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
`subbass(data, params)` mutates `data` (`Float32Array`/`Float64Array`) in place and returns it. Pass the same `params` object across calls — the sub-extraction and harmonic-band filter state persists on it (`_sub`, `_out`, `_dc`).
|
|
23
23
|
|
|
24
|
-
**`
|
|
24
|
+
**`fc`** sub cutoff, Hz — harmonics built from below this (default 80; `freq` still accepted) · **`amount`** harmonic level 0–1 (default 0.5) · **`drive`** waveshaper intensity 0–1 (default 0.5) · **`keep`** how much original sub to keep, 0–1, 0 = replace entirely (default 1) · **`fs`** sample rate
|
|
25
25
|
|
|
26
26
|
**Use when**: small-speaker/phone playback, bass on systems that can't reproduce true sub<br>
|
|
27
27
|
**Not for**: sources already reproduced on full-range monitors, general saturation (use `@audio/effect-distortion`)
|
package/audio.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ type Process = (inputs: Float32Array[][], outputs: Float32Array[][], params: Liv
|
|
|
11
11
|
/** Chainable-host options for 'subbass' */
|
|
12
12
|
export interface SubbassOptions {
|
|
13
13
|
/** 30..200 Hz (default 80) */
|
|
14
|
+
"fc"?: Auto
|
|
15
|
+
/** @deprecated former name of "fc" */
|
|
14
16
|
"freq"?: Auto
|
|
15
17
|
/** 0..1 (default 0.5) */
|
|
16
18
|
"amount"?: Auto
|
|
@@ -27,7 +29,7 @@ export declare const subbass: {
|
|
|
27
29
|
channels: "any"
|
|
28
30
|
params: {
|
|
29
31
|
/** 30..200 Hz (default 80) */
|
|
30
|
-
"
|
|
32
|
+
"fc": { type: "number", default: 80, alias: "freq" }
|
|
31
33
|
/** 0..1 (default 0.5) */
|
|
32
34
|
"amount": { type: "number", default: 0.5 }
|
|
33
35
|
/** 0..1 (default 0.5) */
|
package/audio.js
CHANGED
|
@@ -11,7 +11,7 @@ export const subbass = (ctx) => {
|
|
|
11
11
|
if (!inp || !inp.length) return
|
|
12
12
|
for (let c = 0; c < inp.length; c++) {
|
|
13
13
|
const p = chP[c]
|
|
14
|
-
p.
|
|
14
|
+
p.fc = params.fc[0]
|
|
15
15
|
p.amount = params.amount[0]
|
|
16
16
|
p.drive = params.drive[0]
|
|
17
17
|
p.keep = params.keep[0]
|
|
@@ -22,7 +22,7 @@ export const subbass = (ctx) => {
|
|
|
22
22
|
}
|
|
23
23
|
subbass.channels = 'any'
|
|
24
24
|
subbass.params = {
|
|
25
|
-
|
|
25
|
+
fc: { type: 'number', min: 30, max: 200, default: 80, unit: 'Hz', curve: 'log', alias: 'freq' },
|
|
26
26
|
amount: { type: 'number', min: 0, max: 1, default: 0.5 },
|
|
27
27
|
drive: { type: 'number', min: 0, max: 1, default: 0.5 },
|
|
28
28
|
keep: { type: 'number', min: 0, max: 1, default: 1 },
|
package/package.json
CHANGED
package/subbass.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Psychoacoustic bass enhancer (MaxxBass/RBass class) — extracts the band below
|
|
3
|
-
* `
|
|
3
|
+
* `fc`, generates its harmonic series with an even/odd waveshaper, band-limits
|
|
4
4
|
* the harmonics to the audible low-mids, and mixes against dry. Small speakers
|
|
5
5
|
* reproduce the harmonics; the ear reconstructs the missing fundamental.
|
|
6
6
|
*/
|
|
7
7
|
export interface SubbassOptions {
|
|
8
8
|
/** sub cutoff, Hz — harmonics built from below this, default 80 */
|
|
9
|
+
fc?: number
|
|
10
|
+
/** @deprecated former name of `fc` */
|
|
9
11
|
freq?: number
|
|
10
12
|
/** harmonic level, 0–1, default 0.5 */
|
|
11
13
|
amount?: number
|
|
@@ -22,4 +24,4 @@ export interface SubbassOptions {
|
|
|
22
24
|
* object across calls — the sub-extraction and harmonic-band filter state persist
|
|
23
25
|
* on it (`_sub`, `_out`, `_dc`).
|
|
24
26
|
*/
|
|
25
|
-
export default function subbass(data:
|
|
27
|
+
export default function subbass<T extends Float32Array | Float64Array>(data: T, params?: SubbassOptions): T
|
package/subbass.js
CHANGED
|
@@ -15,8 +15,8 @@ function svf (s, x, f, q) {
|
|
|
15
15
|
return [s.l, s.b, h]
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export default function subbass (data, params) {
|
|
19
|
-
let
|
|
18
|
+
export default function subbass (data, params = {}) {
|
|
19
|
+
let fc = params.fc ?? params.freq ?? 80 // sub cutoff, Hz — harmonics built from below here (`freq`: former name)
|
|
20
20
|
let amount = params.amount ?? 0.5 // harmonic level 0..1
|
|
21
21
|
let drive = params.drive ?? 0.5 // waveshaper intensity 0..1
|
|
22
22
|
let keep = params.keep ?? 1 // how much original sub to keep (0 = replace)
|
|
@@ -27,8 +27,8 @@ export default function subbass (data, params) {
|
|
|
27
27
|
params._out = { l: 0, b: 0 } // harmonic band BP
|
|
28
28
|
params._dc = 0
|
|
29
29
|
}
|
|
30
|
-
let f1 = 2 * sin(PI * Math.min(
|
|
31
|
-
let f2 = 2 * sin(PI * Math.min(
|
|
30
|
+
let f1 = 2 * sin(PI * Math.min(fc, fs / 4) / fs)
|
|
31
|
+
let f2 = 2 * sin(PI * Math.min(fc * 2.5, fs / 4) / fs)
|
|
32
32
|
let g = 1 + drive * 6
|
|
33
33
|
let aDc = 1 - Math.exp(-2 * PI * 10 / fs)
|
|
34
34
|
|
|
@@ -39,7 +39,7 @@ export default function subbass (data, params) {
|
|
|
39
39
|
let h = tanh(sub * g) * 0.6 + Math.abs(sub) * g * 0.4
|
|
40
40
|
params._dc += aDc * (h - params._dc) // DC-block the rectifier output
|
|
41
41
|
h -= params._dc
|
|
42
|
-
// keep harmonics in the speaker-friendly band around 2–5×
|
|
42
|
+
// keep harmonics in the speaker-friendly band around 2–5× fc
|
|
43
43
|
svf(params._out, h, f2, 0.8)
|
|
44
44
|
let harm = params._out.b // bandpass output
|
|
45
45
|
data[i] = x - (1 - keep) * sub + amount * 2 * harm
|