nodejs-audio-visualizer 4.5.0 → 5.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.
Files changed (47) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +80 -80
  3. package/dist/audio.d.ts +12 -12
  4. package/dist/audio.js +120 -120
  5. package/dist/beats.d.ts +19 -19
  6. package/dist/beats.js +43 -43
  7. package/dist/bpmEncoder.d.ts +14 -14
  8. package/dist/bpmEncoder.js +97 -97
  9. package/dist/config.d.ts +77 -77
  10. package/dist/config.js +369 -369
  11. package/dist/dsp.d.ts +16 -16
  12. package/dist/dsp.js +76 -76
  13. package/dist/highlight.d.ts +32 -32
  14. package/dist/highlight.js +325 -325
  15. package/dist/image.d.ts +79 -79
  16. package/dist/image.js +458 -458
  17. package/dist/index.d.ts +79 -79
  18. package/dist/index.js +534 -531
  19. package/dist/index.js.map +1 -1
  20. package/dist/subtitleConvert.d.ts +3 -3
  21. package/dist/subtitleConvert.js +61 -61
  22. package/dist/video.d.ts +80 -80
  23. package/dist/video.js +434 -426
  24. package/dist/video.js.map +1 -1
  25. package/dist/waitForEventLoop.d.ts +1 -1
  26. package/dist/waitForEventLoop.js +5 -5
  27. package/package.json +61 -61
  28. package/src/audio.ts +120 -120
  29. package/src/beats.ts +68 -68
  30. package/src/bpmEncoder.ts +97 -97
  31. package/src/config.ts +476 -476
  32. package/src/dsp.ts +95 -95
  33. package/src/highlight.ts +284 -284
  34. package/src/image.ts +602 -602
  35. package/src/index.ts +718 -713
  36. package/src/subtitleConvert.ts +63 -63
  37. package/src/tests/audio.test.ts +96 -96
  38. package/src/tests/config.test.ts +496 -496
  39. package/src/tests/dsp.test.ts +24 -24
  40. package/src/tests/highlight.test.ts +178 -178
  41. package/src/tests/image.test.ts +222 -222
  42. package/src/tests/index.test.ts +180 -112
  43. package/src/tests/subtitleConvert.test.ts +23 -23
  44. package/src/tests/video.test.ts +285 -216
  45. package/src/typings.d.ts +6 -6
  46. package/src/video.ts +550 -542
  47. 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
+ };