loudness-worklet 1.4.3 → 1.5.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/dist/index.js +58 -14
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -2,11 +2,11 @@ const i = `/**
|
|
|
2
2
|
* A lightweight and efficient AudioWorklet for real-time loudness measurement in the browser, compliant with the ITU-R BS.1770-5 standard.
|
|
3
3
|
*
|
|
4
4
|
* @file loudness.worklet.js
|
|
5
|
-
* @version 1.
|
|
5
|
+
* @version 1.5.0
|
|
6
6
|
* @author lcweden
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @see
|
|
9
|
-
* @date 2025-
|
|
8
|
+
* @see https://github.com/lcweden/loudness-audio-worklet-processor.git
|
|
9
|
+
* @date 2025-10-07T13:01:56.024Z
|
|
10
10
|
*/\r
|
|
11
11
|
\r
|
|
12
12
|
class O {
|
|
@@ -35,12 +35,14 @@ class O {
|
|
|
35
35
|
* Sets new filter coefficients.
|
|
36
36
|
* @param { number[] } a - Feedback coefficients [a1, a2]
|
|
37
37
|
* @param { number[] } b - Feedforward coefficients [b0, b1, b2]
|
|
38
|
+
* @returns { void }
|
|
38
39
|
*/
|
|
39
40
|
set(e, r) {
|
|
40
41
|
this.#t.set((e.length = 2, e)), this.#e.set((r.length = 3, r));
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
44
|
* Resets the filter state.
|
|
45
|
+
* @returns { void }
|
|
44
46
|
*/
|
|
45
47
|
reset() {
|
|
46
48
|
this.#s.fill(0), this.#r.fill(0);
|
|
@@ -52,22 +54,45 @@ class d {
|
|
|
52
54
|
#s = 0;
|
|
53
55
|
#r = 0;
|
|
54
56
|
#n = 0;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new CircularBuffer with given capacity.
|
|
59
|
+
* @param { number } capacity - The maximum number of items the buffer can hold.
|
|
60
|
+
*/
|
|
55
61
|
constructor(e) {
|
|
56
62
|
this.#e = e || 0, this.#t = new Array(e);
|
|
57
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Adds an item to the buffer.
|
|
66
|
+
* @param item - The item to add to the buffer.
|
|
67
|
+
* @returns { void }
|
|
68
|
+
*/
|
|
58
69
|
push(e) {
|
|
59
70
|
this.#t[this.#r] = e, this.isFull() ? this.#s = (this.#s + 1) % this.#e : this.#n++, this.#r = (this.#r + 1) % this.#e;
|
|
60
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Removes and returns the oldest item from the buffer.
|
|
74
|
+
* @returns { T | undefined }
|
|
75
|
+
*/
|
|
61
76
|
pop() {
|
|
62
77
|
if (this.isEmpty())
|
|
63
78
|
return;
|
|
64
79
|
const e = this.#t[this.#s];
|
|
65
80
|
return this.#s = (this.#s + 1) % this.#e, this.#n--, e;
|
|
66
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Returns the oldest item from the buffer without removing it.
|
|
84
|
+
* @returns { T | undefined }
|
|
85
|
+
*/
|
|
67
86
|
peek() {
|
|
68
87
|
if (!this.isEmpty())
|
|
69
88
|
return this.#t[this.#s];
|
|
70
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Returns a slice of the buffer contents.
|
|
92
|
+
* @param { number } start - The starting index of the slice (inclusive).
|
|
93
|
+
* @param { number } end - The ending index of the slice (exclusive).
|
|
94
|
+
* @returns { T[] }
|
|
95
|
+
*/
|
|
71
96
|
slice(e = 0, r = this.#n) {
|
|
72
97
|
if (e < 0 && (e = 0), r > this.#n && (r = this.#n), e >= r)
|
|
73
98
|
return [];
|
|
@@ -78,18 +103,29 @@ class d {
|
|
|
78
103
|
}
|
|
79
104
|
return n;
|
|
80
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Checks if the buffer is empty.
|
|
108
|
+
* @returns { boolean }
|
|
109
|
+
*/
|
|
81
110
|
isEmpty() {
|
|
82
111
|
return this.#n === 0;
|
|
83
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Checks if the buffer is full.
|
|
115
|
+
* @returns { boolean }
|
|
116
|
+
*/
|
|
84
117
|
isFull() {
|
|
85
118
|
return this.#n === this.#e;
|
|
86
119
|
}
|
|
120
|
+
/** @type { number } */
|
|
87
121
|
get length() {
|
|
88
122
|
return this.#n;
|
|
89
123
|
}
|
|
124
|
+
/** @type { number } */
|
|
90
125
|
get capacity() {
|
|
91
126
|
return this.#e;
|
|
92
127
|
}
|
|
128
|
+
/** @type { IterableIterator<T> } */
|
|
93
129
|
*[Symbol.iterator]() {
|
|
94
130
|
for (let e = 0; e < this.#n; e++) {
|
|
95
131
|
const r = (this.#s + e) % this.#e;
|
|
@@ -209,6 +245,10 @@ const L = {
|
|
|
209
245
|
class F {
|
|
210
246
|
#t;
|
|
211
247
|
#e;
|
|
248
|
+
/**
|
|
249
|
+
* Creates an instance of the filter.
|
|
250
|
+
* @param coefficients - The filter coefficients.
|
|
251
|
+
*/
|
|
212
252
|
constructor(e) {
|
|
213
253
|
this.#t = e, this.#e = Array(e.length).fill(0);
|
|
214
254
|
}
|
|
@@ -224,6 +264,10 @@ class F {
|
|
|
224
264
|
return n;
|
|
225
265
|
}
|
|
226
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Resets the filter state.
|
|
269
|
+
* @returns { void }
|
|
270
|
+
*/
|
|
227
271
|
reset() {
|
|
228
272
|
this.#e.fill(0);
|
|
229
273
|
}
|
|
@@ -373,26 +417,26 @@ class X extends AudioWorkletProcessor {
|
|
|
373
417
|
}
|
|
374
418
|
registerProcessor("loudness-processor", X);
|
|
375
419
|
`, t = "loudness-processor";
|
|
376
|
-
class
|
|
377
|
-
constructor(n,
|
|
378
|
-
super(n, t,
|
|
420
|
+
class o extends AudioWorkletNode {
|
|
421
|
+
constructor(n, s) {
|
|
422
|
+
super(n, t, s);
|
|
379
423
|
}
|
|
380
424
|
static async loadModule(n) {
|
|
381
425
|
return r(n);
|
|
382
426
|
}
|
|
383
427
|
}
|
|
384
|
-
async function
|
|
385
|
-
return await r(
|
|
428
|
+
async function h(e, n) {
|
|
429
|
+
return await r(e), new AudioWorkletNode(e, t, n);
|
|
386
430
|
}
|
|
387
|
-
async function r(
|
|
388
|
-
const n = new Blob([i], { type: "application/javascript" }),
|
|
431
|
+
async function r(e) {
|
|
432
|
+
const n = new Blob([i], { type: "application/javascript" }), s = URL.createObjectURL(n);
|
|
389
433
|
try {
|
|
390
|
-
await
|
|
434
|
+
await e.audioWorklet.addModule(s);
|
|
391
435
|
} finally {
|
|
392
|
-
URL.revokeObjectURL(
|
|
436
|
+
URL.revokeObjectURL(s);
|
|
393
437
|
}
|
|
394
438
|
}
|
|
395
439
|
export {
|
|
396
|
-
|
|
397
|
-
|
|
440
|
+
o as LoudnessWorkletNode,
|
|
441
|
+
h as createLoudnessWorklet
|
|
398
442
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "loudness-worklet",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "A lightweight and efficient AudioWorklet for real-time loudness measurement in the browser, compliant with the ITU-R BS.1770-5 standard.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-audio",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"author": "lcweden",
|
|
38
38
|
"homepage": "https://lcweden.github.io/loudness-audio-worklet-processor/",
|
|
39
39
|
"repository": {
|
|
40
|
-
"
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/lcweden/loudness-audio-worklet-processor.git"
|
|
41
42
|
},
|
|
42
43
|
"bugs": {
|
|
43
44
|
"url": "https://github.com/lcweden/loudness-audio-worklet-processor/issues"
|