@audio/amp-cabinet 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/cabinet.js +29 -0
- package/package.json +34 -0
package/cabinet.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Cabinet simulation — convolve with a speaker impulse response (capture your own with
|
|
2
|
+
// @audio/measure-ir). Without an IR, a classical speaker-sim biquad chain approximates a
|
|
3
|
+
// closed-back 12" cab: 70 Hz highpass, low bump, presence peak, steep rolloff above ~4.5 kHz.
|
|
4
|
+
|
|
5
|
+
import convolve from '@audio/reverb-convolution'
|
|
6
|
+
import { lowpass, highpass, peaking } from 'digital-filter/iir/biquad.js'
|
|
7
|
+
|
|
8
|
+
function biquadRun (data, c) {
|
|
9
|
+
let x1 = 0, x2 = 0, y1 = 0, y2 = 0
|
|
10
|
+
for (let i = 0; i < data.length; i++) {
|
|
11
|
+
let x = data[i]
|
|
12
|
+
let y = c.b0 * x + c.b1 * x1 + c.b2 * x2 - c.a1 * y1 - c.a2 * y2
|
|
13
|
+
x2 = x1; x1 = x; y2 = y1; y1 = data[i] = y
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {Float32Array} data — mono PCM, processed in place
|
|
19
|
+
* @param {object} opts — { fs=44100, ir (Float32Array — measured cab IR), mix=1 }
|
|
20
|
+
*/
|
|
21
|
+
export default function cabinet (data, { fs = 44100, ir, mix = 1 } = {}) {
|
|
22
|
+
if (ir) return convolve(data, { ir, mix, normalize: true })
|
|
23
|
+
biquadRun(data, highpass(70, 0.707, fs))
|
|
24
|
+
biquadRun(data, peaking(110, 1, fs, 2))
|
|
25
|
+
biquadRun(data, peaking(2400, 1.2, fs, 3))
|
|
26
|
+
biquadRun(data, lowpass(4500, 0.707, fs))
|
|
27
|
+
biquadRun(data, lowpass(5200, 0.707, fs))
|
|
28
|
+
return data
|
|
29
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@audio/amp-cabinet",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Cabinet simulation \u2014 measured-IR convolution (pair with @audio/measure-ir) or classical speaker-sim biquads",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "cabinet.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./cabinet.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"cabinet.js"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@audio/reverb-convolution": "^1.0.0",
|
|
17
|
+
"digital-filter": "^2.0.0"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"audio",
|
|
21
|
+
"dsp",
|
|
22
|
+
"amp",
|
|
23
|
+
"cabinet",
|
|
24
|
+
"impulse-response"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"author": "Dmitry Iv. <dfcreative@gmail.com>",
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
}
|
|
34
|
+
}
|