nodejs-audio-visualizer 4.3.6 → 4.3.8
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/LICENSE +21 -21
- package/README.md +75 -75
- package/dist/audio.d.ts +12 -12
- package/dist/audio.js +120 -120
- package/dist/beats.d.ts +19 -19
- package/dist/beats.js +43 -43
- package/dist/bpmEncoder.d.ts +14 -14
- package/dist/bpmEncoder.js +97 -97
- package/dist/config.d.ts +67 -67
- package/dist/config.js +356 -356
- package/dist/dsp.d.ts +16 -16
- package/dist/dsp.js +76 -76
- package/dist/highlight.d.ts +32 -32
- package/dist/highlight.js +325 -325
- package/dist/image.d.ts +79 -79
- package/dist/image.js +458 -458
- package/dist/index.d.ts +72 -72
- package/dist/index.js +536 -533
- package/dist/index.js.map +1 -1
- package/dist/subtitleConvert.d.ts +3 -3
- package/dist/subtitleConvert.js +61 -61
- package/dist/video.d.ts +72 -72
- package/dist/video.js +338 -338
- package/dist/waitForEventLoop.d.ts +1 -1
- package/dist/waitForEventLoop.js +5 -5
- package/package.json +61 -61
- package/src/audio.ts +120 -120
- package/src/beats.ts +68 -68
- package/src/bpmEncoder.ts +97 -97
- package/src/config.ts +462 -462
- package/src/dsp.ts +95 -95
- package/src/highlight.ts +284 -284
- package/src/image.ts +602 -602
- package/src/index.ts +678 -674
- package/src/subtitleConvert.ts +63 -63
- package/src/tests/audio.test.ts +96 -96
- package/src/tests/config.test.ts +475 -475
- package/src/tests/dsp.test.ts +24 -24
- package/src/tests/highlight.test.ts +178 -178
- package/src/tests/image.test.ts +222 -222
- package/src/tests/index.test.ts +63 -63
- package/src/tests/subtitleConvert.test.ts +23 -23
- package/src/tests/video.test.ts +138 -138
- package/src/typings.d.ts +6 -6
- package/src/video.ts +437 -437
- package/src/waitForEventLoop.ts +2 -2
package/src/bpmEncoder.ts
CHANGED
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
export interface EncodedBmp {
|
|
2
|
-
shiftPos: number;
|
|
3
|
-
rowBytes: number;
|
|
4
|
-
data: Buffer;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
const writeBmpHeader = (buffer: Buffer, width: number, height: number, rgbSize: number) => {
|
|
8
|
-
const headerInfoSize = 40;
|
|
9
|
-
const offset = 54;
|
|
10
|
-
const fileSize = rgbSize + offset;
|
|
11
|
-
|
|
12
|
-
let pos = 0;
|
|
13
|
-
buffer.write('BM', pos, 2); pos += 2;
|
|
14
|
-
buffer.writeUInt32LE(fileSize, pos); pos += 4;
|
|
15
|
-
buffer.writeUInt32LE(0, pos); pos += 4;
|
|
16
|
-
buffer.writeUInt32LE(offset, pos); pos += 4;
|
|
17
|
-
|
|
18
|
-
buffer.writeUInt32LE(headerInfoSize, pos); pos += 4;
|
|
19
|
-
buffer.writeUInt32LE(width, pos); pos += 4;
|
|
20
|
-
buffer.writeInt32LE(-height, pos); pos += 4;
|
|
21
|
-
buffer.writeUInt16LE(1, pos); pos += 2;
|
|
22
|
-
buffer.writeUInt16LE(24, pos); pos += 2;
|
|
23
|
-
buffer.writeUInt32LE(0, pos); pos += 4;
|
|
24
|
-
buffer.writeUInt32LE(rgbSize, pos); pos += 4;
|
|
25
|
-
buffer.writeUInt32LE(0, pos); pos += 4;
|
|
26
|
-
buffer.writeUInt32LE(0, pos); pos += 4;
|
|
27
|
-
buffer.writeUInt32LE(0, pos); pos += 4;
|
|
28
|
-
buffer.writeUInt32LE(0, pos); pos += 4;
|
|
29
|
-
|
|
30
|
-
return offset;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const createBpmEncoder = (imgData: { width: number; height: number; }) => {
|
|
34
|
-
const width = imgData.width;
|
|
35
|
-
const height = imgData.height;
|
|
36
|
-
const extraBytes = width % 4;
|
|
37
|
-
const rgbSize = height * (3 * width + extraBytes);
|
|
38
|
-
const offset = 54;
|
|
39
|
-
|
|
40
|
-
return (buffer: Buffer): EncodedBmp => {
|
|
41
|
-
const tempBuffer = Buffer.alloc(offset + rgbSize);
|
|
42
|
-
const pos = writeBmpHeader(tempBuffer, width, height, rgbSize);
|
|
43
|
-
|
|
44
|
-
let i = 0;
|
|
45
|
-
const rowBytes = 3 * width + extraBytes;
|
|
46
|
-
|
|
47
|
-
for (let y = 0; y < height; y++) {
|
|
48
|
-
for (let x = 0; x < width; x++) {
|
|
49
|
-
const p = pos + y * rowBytes + x * 3;
|
|
50
|
-
i++; // a
|
|
51
|
-
tempBuffer[p] = buffer[i++]; // b
|
|
52
|
-
tempBuffer[p + 1] = buffer[i++]; // g
|
|
53
|
-
tempBuffer[p + 2] = buffer[i++]; // r
|
|
54
|
-
}
|
|
55
|
-
if (extraBytes > 0) {
|
|
56
|
-
const fillOffset = pos + y * rowBytes + width * 3;
|
|
57
|
-
tempBuffer.fill(0, fillOffset, fillOffset + extraBytes);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
shiftPos: pos,
|
|
63
|
-
rowBytes,
|
|
64
|
-
data: tempBuffer
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const createBgrFrameEncoder = (imgData: { width: number; height: number }) => {
|
|
70
|
-
const width = imgData.width;
|
|
71
|
-
const height = imgData.height;
|
|
72
|
-
const extraBytes = width % 4;
|
|
73
|
-
const rowBytes = 3 * width + extraBytes;
|
|
74
|
-
const rgbSize = height * rowBytes;
|
|
75
|
-
const offset = 54;
|
|
76
|
-
|
|
77
|
-
const tempBuffer = Buffer.alloc(offset + rgbSize);
|
|
78
|
-
const pos = writeBmpHeader(tempBuffer, width, height, rgbSize);
|
|
79
|
-
|
|
80
|
-
return (bgrBuffer: Buffer): EncodedBmp => {
|
|
81
|
-
if (extraBytes === 0) {
|
|
82
|
-
bgrBuffer.copy(tempBuffer, pos, 0, width * height * 3);
|
|
83
|
-
} else {
|
|
84
|
-
for (let y = 0; y < height; y++) {
|
|
85
|
-
const srcOffset = y * width * 3;
|
|
86
|
-
const dstOffset = pos + y * rowBytes;
|
|
87
|
-
bgrBuffer.copy(tempBuffer, dstOffset, srcOffset, srcOffset + width * 3);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
shiftPos: pos,
|
|
93
|
-
rowBytes,
|
|
94
|
-
data: tempBuffer
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
};
|
|
1
|
+
export interface EncodedBmp {
|
|
2
|
+
shiftPos: number;
|
|
3
|
+
rowBytes: number;
|
|
4
|
+
data: Buffer;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const writeBmpHeader = (buffer: Buffer, width: number, height: number, rgbSize: number) => {
|
|
8
|
+
const headerInfoSize = 40;
|
|
9
|
+
const offset = 54;
|
|
10
|
+
const fileSize = rgbSize + offset;
|
|
11
|
+
|
|
12
|
+
let pos = 0;
|
|
13
|
+
buffer.write('BM', pos, 2); pos += 2;
|
|
14
|
+
buffer.writeUInt32LE(fileSize, pos); pos += 4;
|
|
15
|
+
buffer.writeUInt32LE(0, pos); pos += 4;
|
|
16
|
+
buffer.writeUInt32LE(offset, pos); pos += 4;
|
|
17
|
+
|
|
18
|
+
buffer.writeUInt32LE(headerInfoSize, pos); pos += 4;
|
|
19
|
+
buffer.writeUInt32LE(width, pos); pos += 4;
|
|
20
|
+
buffer.writeInt32LE(-height, pos); pos += 4;
|
|
21
|
+
buffer.writeUInt16LE(1, pos); pos += 2;
|
|
22
|
+
buffer.writeUInt16LE(24, pos); pos += 2;
|
|
23
|
+
buffer.writeUInt32LE(0, pos); pos += 4;
|
|
24
|
+
buffer.writeUInt32LE(rgbSize, pos); pos += 4;
|
|
25
|
+
buffer.writeUInt32LE(0, pos); pos += 4;
|
|
26
|
+
buffer.writeUInt32LE(0, pos); pos += 4;
|
|
27
|
+
buffer.writeUInt32LE(0, pos); pos += 4;
|
|
28
|
+
buffer.writeUInt32LE(0, pos); pos += 4;
|
|
29
|
+
|
|
30
|
+
return offset;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const createBpmEncoder = (imgData: { width: number; height: number; }) => {
|
|
34
|
+
const width = imgData.width;
|
|
35
|
+
const height = imgData.height;
|
|
36
|
+
const extraBytes = width % 4;
|
|
37
|
+
const rgbSize = height * (3 * width + extraBytes);
|
|
38
|
+
const offset = 54;
|
|
39
|
+
|
|
40
|
+
return (buffer: Buffer): EncodedBmp => {
|
|
41
|
+
const tempBuffer = Buffer.alloc(offset + rgbSize);
|
|
42
|
+
const pos = writeBmpHeader(tempBuffer, width, height, rgbSize);
|
|
43
|
+
|
|
44
|
+
let i = 0;
|
|
45
|
+
const rowBytes = 3 * width + extraBytes;
|
|
46
|
+
|
|
47
|
+
for (let y = 0; y < height; y++) {
|
|
48
|
+
for (let x = 0; x < width; x++) {
|
|
49
|
+
const p = pos + y * rowBytes + x * 3;
|
|
50
|
+
i++; // a
|
|
51
|
+
tempBuffer[p] = buffer[i++]; // b
|
|
52
|
+
tempBuffer[p + 1] = buffer[i++]; // g
|
|
53
|
+
tempBuffer[p + 2] = buffer[i++]; // r
|
|
54
|
+
}
|
|
55
|
+
if (extraBytes > 0) {
|
|
56
|
+
const fillOffset = pos + y * rowBytes + width * 3;
|
|
57
|
+
tempBuffer.fill(0, fillOffset, fillOffset + extraBytes);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
shiftPos: pos,
|
|
63
|
+
rowBytes,
|
|
64
|
+
data: tempBuffer
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const createBgrFrameEncoder = (imgData: { width: number; height: number }) => {
|
|
70
|
+
const width = imgData.width;
|
|
71
|
+
const height = imgData.height;
|
|
72
|
+
const extraBytes = width % 4;
|
|
73
|
+
const rowBytes = 3 * width + extraBytes;
|
|
74
|
+
const rgbSize = height * rowBytes;
|
|
75
|
+
const offset = 54;
|
|
76
|
+
|
|
77
|
+
const tempBuffer = Buffer.alloc(offset + rgbSize);
|
|
78
|
+
const pos = writeBmpHeader(tempBuffer, width, height, rgbSize);
|
|
79
|
+
|
|
80
|
+
return (bgrBuffer: Buffer): EncodedBmp => {
|
|
81
|
+
if (extraBytes === 0) {
|
|
82
|
+
bgrBuffer.copy(tempBuffer, pos, 0, width * height * 3);
|
|
83
|
+
} else {
|
|
84
|
+
for (let y = 0; y < height; y++) {
|
|
85
|
+
const srcOffset = y * width * 3;
|
|
86
|
+
const dstOffset = pos + y * rowBytes;
|
|
87
|
+
bgrBuffer.copy(tempBuffer, dstOffset, srcOffset, srcOffset + width * 3);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
shiftPos: pos,
|
|
93
|
+
rowBytes,
|
|
94
|
+
data: tempBuffer
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
};
|