nodejs-audio-visualizer 2.0.0 → 2.1.1
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/README.md +2 -1
- package/dist/bpmEncoder.d.ts +10 -0
- package/dist/bpmEncoder.js +76 -0
- package/dist/bpmEncoder.js.map +1 -0
- package/dist/config.d.ts +7 -0
- package/dist/config.js +31 -15
- package/dist/config.js.map +1 -1
- package/dist/image.d.ts +28 -3
- package/dist/image.js +80 -21
- package/dist/image.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/bpmEncoder.ts +71 -0
- package/src/config.ts +39 -13
- package/src/image.ts +153 -30
- package/src/index.ts +21 -11
- package/src/tests/config.test.ts +60 -0
- package/src/tests/image.test.ts +91 -22
- package/src/tests/index.test.ts +2 -2
- package/src/tests/snapshots/frameSnapshotSpectrumDown.json +1 -1
- package/src/tests/snapshots/frameSnapshotSpectrumUp.json +1 -1
- package/src/tests/snapshots/frameSnapshotSpectrumUpOpacity50.json +1 -0
package/src/tests/image.test.ts
CHANGED
|
@@ -1,15 +1,59 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import {
|
|
5
|
+
drawRect,
|
|
6
|
+
Color,
|
|
7
|
+
createVisualizerFrame,
|
|
8
|
+
parseImage,
|
|
9
|
+
convertToBmp,
|
|
10
|
+
mixValues,
|
|
11
|
+
mixColors,
|
|
12
|
+
} from '../image';
|
|
13
|
+
import { createBpmEncoder } from '../bpmEncoder';
|
|
4
14
|
|
|
5
15
|
import frameSnapshotSpectrumDown from './snapshots/frameSnapshotSpectrumDown.json';
|
|
6
16
|
import frameSnapshotSpectrumUp from './snapshots/frameSnapshotSpectrumUp.json';
|
|
17
|
+
import frameSnapshotSpectrumUpOpacity50 from './snapshots/frameSnapshotSpectrumUpOpacity50.json';
|
|
7
18
|
|
|
8
19
|
describe('image', function () {
|
|
20
|
+
it('mixValues', function () {
|
|
21
|
+
expect(mixValues(420, 0.69, 96)).equal(320);
|
|
22
|
+
expect(mixValues(420, 1, 96)).equal(420);
|
|
23
|
+
expect(mixValues(420, 0, 96)).equal(96);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('mixColors', function () {
|
|
27
|
+
const result1 = mixColors({
|
|
28
|
+
color: { red: 123, green: 69, blue: 96 },
|
|
29
|
+
colorOpacity: 0.24,
|
|
30
|
+
backgroundColor: { red: 69, green: 123, blue: 42 },
|
|
31
|
+
});
|
|
32
|
+
expect(result1).deep.equal({ red: 82, green: 110, blue: 55 });
|
|
33
|
+
|
|
34
|
+
const result2 = mixColors({
|
|
35
|
+
color: { red: 123, green: 69, blue: 96 },
|
|
36
|
+
colorOpacity: 0,
|
|
37
|
+
backgroundColor: { red: 69, green: 123, blue: 42 },
|
|
38
|
+
});
|
|
39
|
+
expect(result2).deep.equal({ red: 69, green: 123, blue: 42 });
|
|
40
|
+
|
|
41
|
+
const result3 = mixColors({
|
|
42
|
+
color: { red: 123, green: 69, blue: 96 },
|
|
43
|
+
colorOpacity: 1,
|
|
44
|
+
backgroundColor: { red: 69, green: 123, blue: 42 },
|
|
45
|
+
});
|
|
46
|
+
expect(result3).deep.equal({ red: 123, green: 69, blue: 96 });
|
|
47
|
+
});
|
|
48
|
+
|
|
9
49
|
it('drawRect', function () {
|
|
10
50
|
const imageWidth = 10;
|
|
11
51
|
const imageHeight = 10;
|
|
52
|
+
const extraBytes = imageWidth % 4;
|
|
53
|
+
const rowBytes = 3 * imageWidth + extraBytes;
|
|
12
54
|
const imageDstBuffer = {
|
|
55
|
+
shiftPos: 54,
|
|
56
|
+
rowBytes,
|
|
13
57
|
width: imageWidth,
|
|
14
58
|
data: Array.from({ length: imageWidth * imageHeight * 4 }).fill(0)
|
|
15
59
|
};
|
|
@@ -20,14 +64,20 @@ describe('image', function () {
|
|
|
20
64
|
const rectColor: Color = { red: 111, green: 112, blue: 123 };
|
|
21
65
|
|
|
22
66
|
const expectedImageData = Array.from({ length: imageWidth * imageWidth * 4 }).fill(0);
|
|
23
|
-
const imagePixelIndices = [
|
|
67
|
+
const imagePixelIndices = [162, 165, 168, 171, 194, 197, 200, 203, 226, 229, 232, 235];
|
|
24
68
|
imagePixelIndices.forEach((pixelIndex) => {
|
|
25
|
-
expectedImageData[pixelIndex
|
|
26
|
-
expectedImageData[pixelIndex +
|
|
27
|
-
expectedImageData[pixelIndex +
|
|
69
|
+
expectedImageData[pixelIndex] = rectColor.blue;
|
|
70
|
+
expectedImageData[pixelIndex + 1] = rectColor.green;
|
|
71
|
+
expectedImageData[pixelIndex + 2] = rectColor.red;
|
|
28
72
|
});
|
|
29
73
|
|
|
30
|
-
drawRect(
|
|
74
|
+
drawRect({
|
|
75
|
+
imageDstBuffer: imageDstBuffer as any,
|
|
76
|
+
position: { x: rectX, y: rectY },
|
|
77
|
+
size: { width: rectWidth, height: rectHeight },
|
|
78
|
+
color: rectColor,
|
|
79
|
+
opacity: 1
|
|
80
|
+
});
|
|
31
81
|
expect(imageDstBuffer.data).deep.equal(expectedImageData);
|
|
32
82
|
});
|
|
33
83
|
|
|
@@ -35,26 +85,45 @@ describe('image', function () {
|
|
|
35
85
|
const backgroundImagePath = path.resolve('example/media/background.png');
|
|
36
86
|
const backgroundImageBmpBuffer = await convertToBmp(backgroundImagePath);
|
|
37
87
|
const backgroundImage = parseImage(backgroundImageBmpBuffer);
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
88
|
+
const bpmEncoder = createBpmEncoder({ width: backgroundImage.width, height: backgroundImage.height });
|
|
89
|
+
const backgroundImageBuffer = bpmEncoder(backgroundImage.data);
|
|
90
|
+
const frameSpectrumDown = createVisualizerFrame({
|
|
91
|
+
backgroundImageBuffer,
|
|
92
|
+
spectrum: [0.5, 0, 1],
|
|
93
|
+
size: { width: 15, height: 20 },
|
|
94
|
+
position: { x: 15, y: 0 },
|
|
95
|
+
rotation: 'down',
|
|
96
|
+
margin: 4,
|
|
97
|
+
color: { red: 1, green: 1, blue: 1 },
|
|
98
|
+
opacity: 1,
|
|
99
|
+
});
|
|
46
100
|
const resultSpectrumDown = frameSpectrumDown.data.toJSON().data;
|
|
47
101
|
expect(resultSpectrumDown).deep.equal(frameSnapshotSpectrumDown);
|
|
48
102
|
|
|
49
|
-
const frameSpectrumUp = createVisualizerFrame(
|
|
50
|
-
|
|
51
|
-
[0.1, 1, 0],
|
|
52
|
-
{ width: 25, height: 23 },
|
|
53
|
-
{ x: 10, y: 5 },
|
|
54
|
-
'up',
|
|
55
|
-
|
|
56
|
-
|
|
103
|
+
const frameSpectrumUp = createVisualizerFrame({
|
|
104
|
+
backgroundImageBuffer,
|
|
105
|
+
spectrum: [0.1, 1, 0],
|
|
106
|
+
size: { width: 25, height: 23 },
|
|
107
|
+
position: { x: 10, y: 5 },
|
|
108
|
+
rotation: 'up',
|
|
109
|
+
margin: 4,
|
|
110
|
+
color: { red: 0, green: 123, blue: 69 },
|
|
111
|
+
opacity: 1,
|
|
112
|
+
});
|
|
57
113
|
const resultSpectrumUp = frameSpectrumUp.data.toJSON().data;
|
|
58
114
|
expect(resultSpectrumUp).deep.equal(frameSnapshotSpectrumUp);
|
|
115
|
+
|
|
116
|
+
const frameSpectrumUpOpacity50 = createVisualizerFrame({
|
|
117
|
+
backgroundImageBuffer,
|
|
118
|
+
spectrum: [0.1, 1, 0],
|
|
119
|
+
size: { width: 25, height: 23 },
|
|
120
|
+
position: { x: 10, y: 5 },
|
|
121
|
+
rotation: 'up',
|
|
122
|
+
margin: 4,
|
|
123
|
+
color: { red: 0, green: 123, blue: 69 },
|
|
124
|
+
opacity: 0.5,
|
|
125
|
+
});
|
|
126
|
+
const resultSpectrumUpOpacity50 = frameSpectrumUpOpacity50.data.toJSON().data;
|
|
127
|
+
expect(resultSpectrumUpOpacity50).deep.equal(frameSnapshotSpectrumUpOpacity50);
|
|
59
128
|
});
|
|
60
129
|
});
|
package/src/tests/index.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
import { createSandbox } from 'sinon';
|
|
3
|
-
import { renderAudioVisualizer, Config
|
|
3
|
+
import { renderAudioVisualizer, Config } from '../index';
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import { Writable, Readable } from 'stream';
|
|
6
6
|
import { ChildProcessWithoutNullStreams } from 'child_process';
|
|
@@ -24,7 +24,7 @@ describe('index', function () {
|
|
|
24
24
|
let childProcessStream: unknown = {
|
|
25
25
|
stdin: new Writable(),
|
|
26
26
|
stderr: new Readable(),
|
|
27
|
-
on: function (
|
|
27
|
+
on: function (_: string, callback: Function) {
|
|
28
28
|
exitCallback = callback;
|
|
29
29
|
}
|
|
30
30
|
};
|