@audio/loudness-truepeak 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/package.json +32 -0
- package/truepeak.js +20 -0
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@audio/loudness-truepeak",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "True peak (dBTP) \u2014 4\u00d7 sinc-oversampled inter-sample peak (BS.1770-4 Annex 2 methodology)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "truepeak.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./truepeak.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"truepeak.js"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@audio/resample-sinc": "^1.0.0"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"audio",
|
|
20
|
+
"dsp",
|
|
21
|
+
"loudness",
|
|
22
|
+
"truepeak"
|
|
23
|
+
],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": "Dmitry Iv. <dfcreative@gmail.com>",
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/truepeak.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// True peak (dBTP) — inter-sample peak via 4× windowed-sinc oversampling,
|
|
2
|
+
// per ITU-R BS.1770-4 Annex 2 methodology (generic sinc interpolator).
|
|
3
|
+
|
|
4
|
+
import resample from '@audio/resample-sinc'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {Float32Array|Float32Array[]} channels — mono buffer or channel array
|
|
8
|
+
* @param {object} opts — { fs=48000, oversample=4 }
|
|
9
|
+
* @returns {number} true peak in dBTP (−Infinity for silence)
|
|
10
|
+
*/
|
|
11
|
+
export default function truepeak (channels, { fs = 48000, oversample = 4 } = {}) {
|
|
12
|
+
if (channels[0]?.length === undefined) channels = [channels]
|
|
13
|
+
let peak = 0
|
|
14
|
+
for (let ch of channels) {
|
|
15
|
+
for (let i = 0; i < ch.length; i++) { let a = Math.abs(ch[i]); if (a > peak) peak = a }
|
|
16
|
+
let up = resample(ch, { from: fs, to: fs * oversample })
|
|
17
|
+
for (let i = 0; i < up.length; i++) { let a = Math.abs(up[i]); if (a > peak) peak = a }
|
|
18
|
+
}
|
|
19
|
+
return peak > 0 ? 20 * Math.log10(peak) : -Infinity
|
|
20
|
+
}
|