nodejs-audio-visualizer 5.1.0 → 5.3.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.
Files changed (51) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +81 -80
  3. package/dist/audio.d.ts +13 -13
  4. package/dist/audio.js +128 -128
  5. package/dist/beats.d.ts +39 -39
  6. package/dist/beats.js +220 -220
  7. package/dist/bpmEncoder.d.ts +14 -14
  8. package/dist/bpmEncoder.js +97 -97
  9. package/dist/config.d.ts +78 -77
  10. package/dist/config.js +377 -369
  11. package/dist/config.js.map +1 -1
  12. package/dist/dsp.d.ts +16 -16
  13. package/dist/dsp.js +76 -76
  14. package/dist/highlight.d.ts +66 -34
  15. package/dist/highlight.js +471 -334
  16. package/dist/highlight.js.map +1 -1
  17. package/dist/image.d.ts +97 -92
  18. package/dist/image.js +545 -538
  19. package/dist/image.js.map +1 -1
  20. package/dist/index.d.ts +87 -79
  21. package/dist/index.js +598 -566
  22. package/dist/index.js.map +1 -1
  23. package/dist/subtitleConvert.d.ts +3 -3
  24. package/dist/subtitleConvert.js +61 -61
  25. package/dist/video.d.ts +150 -120
  26. package/dist/video.js +677 -582
  27. package/dist/video.js.map +1 -1
  28. package/dist/waitForEventLoop.d.ts +1 -1
  29. package/dist/waitForEventLoop.js +5 -5
  30. package/package.json +62 -62
  31. package/src/audio.ts +129 -129
  32. package/src/beats.ts +279 -279
  33. package/src/bpmEncoder.ts +97 -97
  34. package/src/config.ts +487 -476
  35. package/src/dsp.ts +95 -95
  36. package/src/highlight.ts +451 -291
  37. package/src/image.ts +707 -700
  38. package/src/index.ts +813 -769
  39. package/src/subtitleConvert.ts +63 -63
  40. package/src/tests/audio.test.ts +102 -102
  41. package/src/tests/beats.test.ts +134 -134
  42. package/src/tests/config.test.ts +534 -496
  43. package/src/tests/dsp.test.ts +24 -24
  44. package/src/tests/highlight.test.ts +261 -178
  45. package/src/tests/image.test.ts +319 -308
  46. package/src/tests/index.test.ts +180 -180
  47. package/src/tests/subtitleConvert.test.ts +23 -23
  48. package/src/tests/video.test.ts +535 -447
  49. package/src/typings.d.ts +28 -28
  50. package/src/video.ts +856 -722
  51. 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
+ };