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.
- package/LICENSE +21 -21
- package/README.md +81 -80
- package/dist/audio.d.ts +13 -13
- package/dist/audio.js +128 -128
- package/dist/beats.d.ts +39 -39
- package/dist/beats.js +220 -220
- package/dist/bpmEncoder.d.ts +14 -14
- package/dist/bpmEncoder.js +97 -97
- package/dist/config.d.ts +78 -77
- package/dist/config.js +377 -369
- package/dist/config.js.map +1 -1
- package/dist/dsp.d.ts +16 -16
- package/dist/dsp.js +76 -76
- package/dist/highlight.d.ts +66 -34
- package/dist/highlight.js +471 -334
- package/dist/highlight.js.map +1 -1
- package/dist/image.d.ts +97 -92
- package/dist/image.js +545 -538
- package/dist/image.js.map +1 -1
- package/dist/index.d.ts +87 -79
- package/dist/index.js +598 -566
- 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 +150 -120
- package/dist/video.js +677 -582
- package/dist/video.js.map +1 -1
- package/dist/waitForEventLoop.d.ts +1 -1
- package/dist/waitForEventLoop.js +5 -5
- package/package.json +62 -62
- package/src/audio.ts +129 -129
- package/src/beats.ts +279 -279
- package/src/bpmEncoder.ts +97 -97
- package/src/config.ts +487 -476
- package/src/dsp.ts +95 -95
- package/src/highlight.ts +451 -291
- package/src/image.ts +707 -700
- package/src/index.ts +813 -769
- package/src/subtitleConvert.ts +63 -63
- package/src/tests/audio.test.ts +102 -102
- package/src/tests/beats.test.ts +134 -134
- package/src/tests/config.test.ts +534 -496
- package/src/tests/dsp.test.ts +24 -24
- package/src/tests/highlight.test.ts +261 -178
- package/src/tests/image.test.ts +319 -308
- package/src/tests/index.test.ts +180 -180
- package/src/tests/subtitleConvert.test.ts +23 -23
- package/src/tests/video.test.ts +535 -447
- package/src/typings.d.ts +28 -28
- package/src/video.ts +856 -722
- package/src/waitForEventLoop.ts +2 -2
package/src/tests/image.test.ts
CHANGED
|
@@ -1,308 +1,319 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import {
|
|
4
|
-
drawRect,
|
|
5
|
-
Color,
|
|
6
|
-
createSpectrumVisualizerFrameGenerator,
|
|
7
|
-
createPolarVisualizerFrameGenerator,
|
|
8
|
-
parseImage,
|
|
9
|
-
convertToBmp,
|
|
10
|
-
mixValues,
|
|
11
|
-
mixColors,
|
|
12
|
-
applyCameraShake,
|
|
13
|
-
getCutShakeOffset,
|
|
14
|
-
buildCutShakeAmplitudes,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
expect(mixValues(420,
|
|
22
|
-
expect(mixValues(420,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
imagePixelIndices
|
|
68
|
-
|
|
69
|
-
expectedImageData[pixelIndex
|
|
70
|
-
expectedImageData[pixelIndex +
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
expect(
|
|
88
|
-
expect(magnitude(getCutShakeOffset(
|
|
89
|
-
expect(magnitude(getCutShakeOffset(
|
|
90
|
-
expect(getCutShakeOffset(
|
|
91
|
-
expect(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
expect(at128
|
|
103
|
-
expect(at128[
|
|
104
|
-
expect(
|
|
105
|
-
expect(buildCutShakeAmplitudes(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
expect(
|
|
114
|
-
expect(getCutShakeOffset(
|
|
115
|
-
expect(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
expect(
|
|
156
|
-
expect(
|
|
157
|
-
expect(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
expect(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import {
|
|
4
|
+
drawRect,
|
|
5
|
+
Color,
|
|
6
|
+
createSpectrumVisualizerFrameGenerator,
|
|
7
|
+
createPolarVisualizerFrameGenerator,
|
|
8
|
+
parseImage,
|
|
9
|
+
convertToBmp,
|
|
10
|
+
mixValues,
|
|
11
|
+
mixColors,
|
|
12
|
+
applyCameraShake,
|
|
13
|
+
getCutShakeOffset,
|
|
14
|
+
buildCutShakeAmplitudes,
|
|
15
|
+
CUT_SHAKE_AMPLITUDE_BY_OFFSET,
|
|
16
|
+
} from '../image';
|
|
17
|
+
import { createBpmEncoder } from '../bpmEncoder';
|
|
18
|
+
|
|
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
|
+
|
|
49
|
+
it('drawRect', function () {
|
|
50
|
+
const imageWidth = 10;
|
|
51
|
+
const imageHeight = 10;
|
|
52
|
+
const extraBytes = imageWidth % 4;
|
|
53
|
+
const rowBytes = 3 * imageWidth + extraBytes;
|
|
54
|
+
const imageDstBuffer = {
|
|
55
|
+
shiftPos: 54,
|
|
56
|
+
rowBytes,
|
|
57
|
+
width: imageWidth,
|
|
58
|
+
data: Array.from({ length: imageWidth * imageHeight * 4 }).fill(0)
|
|
59
|
+
};
|
|
60
|
+
const rectX = 4;
|
|
61
|
+
const rectY = 3;
|
|
62
|
+
const rectWidth = 4;
|
|
63
|
+
const rectHeight = 3;
|
|
64
|
+
const rectColor: Color = { red: 111, green: 112, blue: 123 };
|
|
65
|
+
|
|
66
|
+
const expectedImageData = Array.from({ length: imageWidth * imageWidth * 4 }).fill(0);
|
|
67
|
+
const imagePixelIndices = [162, 165, 168, 171, 194, 197, 200, 203, 226, 229, 232, 235];
|
|
68
|
+
imagePixelIndices.forEach((pixelIndex) => {
|
|
69
|
+
expectedImageData[pixelIndex] = rectColor.blue;
|
|
70
|
+
expectedImageData[pixelIndex + 1] = rectColor.green;
|
|
71
|
+
expectedImageData[pixelIndex + 2] = rectColor.red;
|
|
72
|
+
});
|
|
73
|
+
|
|
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
|
+
});
|
|
81
|
+
expect(imageDstBuffer.data).deep.equal(expectedImageData);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('getCutShakeOffset peaks on the cut and decays on the next frames', function () {
|
|
85
|
+
const cutFrames = new Set([10, 20]);
|
|
86
|
+
const magnitude = (offset: { x: number; y: number }) => Math.hypot(offset.x, offset.y);
|
|
87
|
+
expect(getCutShakeOffset(9, cutFrames)).deep.equal({ x: 0, y: 0 });
|
|
88
|
+
expect(magnitude(getCutShakeOffset(10, cutFrames))).greaterThan(magnitude(getCutShakeOffset(11, cutFrames)));
|
|
89
|
+
expect(magnitude(getCutShakeOffset(11, cutFrames))).greaterThan(magnitude(getCutShakeOffset(12, cutFrames)));
|
|
90
|
+
expect(magnitude(getCutShakeOffset(12, cutFrames))).greaterThan(magnitude(getCutShakeOffset(13, cutFrames)));
|
|
91
|
+
expect(getCutShakeOffset(15, cutFrames)).deep.equal({ x: 0, y: 0 });
|
|
92
|
+
expect(magnitude(getCutShakeOffset(20, cutFrames))).greaterThan(0);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('getCutShakeOffset uses the closer overlapping cut', function () {
|
|
96
|
+
const cutFrames = new Set([10, 11]);
|
|
97
|
+
expect(getCutShakeOffset(11, cutFrames)).deep.equal(getCutShakeOffset(11, new Set([11])));
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('buildCutShakeAmplitudes lasts about one-third of a beat', function () {
|
|
101
|
+
const at128 = buildCutShakeAmplitudes(14);
|
|
102
|
+
expect(at128.length).equal(5);
|
|
103
|
+
expect(at128[0]).equal(14);
|
|
104
|
+
expect(at128[at128.length - 1]).equal(1);
|
|
105
|
+
expect(buildCutShakeAmplitudes(30).length).equal(10);
|
|
106
|
+
expect(buildCutShakeAmplitudes(6).length).equal(3);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('getCutShakeOffset uses a longer envelope when amplitudes are passed', function () {
|
|
110
|
+
const cutFrames = new Set([10]);
|
|
111
|
+
const longAmp = buildCutShakeAmplitudes(30);
|
|
112
|
+
const magnitude = (offset: { x: number; y: number }) => Math.hypot(offset.x, offset.y);
|
|
113
|
+
expect(getCutShakeOffset(15, cutFrames)).deep.equal({ x: 0, y: 0 });
|
|
114
|
+
expect(magnitude(getCutShakeOffset(15, cutFrames, longAmp))).greaterThan(0);
|
|
115
|
+
expect(getCutShakeOffset(10 + longAmp.length, cutFrames, longAmp)).deep.equal({ x: 0, y: 0 });
|
|
116
|
+
expect(magnitude(getCutShakeOffset(10, cutFrames, longAmp))).greaterThan(
|
|
117
|
+
magnitude(getCutShakeOffset(12, cutFrames, longAmp)),
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('getCutShakeOffset delays the shake start by delayFrames', function () {
|
|
122
|
+
const cutFrames = new Set([10]);
|
|
123
|
+
const magnitude = (offset: { x: number; y: number }) => Math.hypot(offset.x, offset.y);
|
|
124
|
+
expect(getCutShakeOffset(10, cutFrames, CUT_SHAKE_AMPLITUDE_BY_OFFSET, 9)).deep.equal({ x: 0, y: 0 });
|
|
125
|
+
expect(magnitude(getCutShakeOffset(19, cutFrames, CUT_SHAKE_AMPLITUDE_BY_OFFSET, 9))).greaterThan(0);
|
|
126
|
+
expect(getCutShakeOffset(19, cutFrames, CUT_SHAKE_AMPLITUDE_BY_OFFSET, 9)).deep.equal(
|
|
127
|
+
getCutShakeOffset(10, cutFrames, CUT_SHAKE_AMPLITUDE_BY_OFFSET),
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('applyCameraShake shifts pixels and clamps edges', function () {
|
|
132
|
+
const width = 3;
|
|
133
|
+
const height = 2;
|
|
134
|
+
const extraBytes = width % 4;
|
|
135
|
+
const rowBytes = 3 * width + extraBytes;
|
|
136
|
+
const shiftPos = 4;
|
|
137
|
+
const data = Buffer.alloc(shiftPos + height * rowBytes, 0);
|
|
138
|
+
data[0] = 9;
|
|
139
|
+
data[1] = 8;
|
|
140
|
+
data[2] = 7;
|
|
141
|
+
data[3] = 6;
|
|
142
|
+
let value = 1;
|
|
143
|
+
for (let y = 0; y < height; y++) {
|
|
144
|
+
for (let x = 0; x < width; x++) {
|
|
145
|
+
const pixelIndex = shiftPos + y * rowBytes + x * 3;
|
|
146
|
+
data[pixelIndex] = value;
|
|
147
|
+
data[pixelIndex + 1] = value + 1;
|
|
148
|
+
data[pixelIndex + 2] = value + 2;
|
|
149
|
+
value += 3;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
applyCameraShake({ shiftPos, rowBytes, data }, width, height, 1, 0);
|
|
154
|
+
|
|
155
|
+
expect(data[0]).equal(9);
|
|
156
|
+
expect(data[1]).equal(8);
|
|
157
|
+
expect(data[2]).equal(7);
|
|
158
|
+
expect(data[3]).equal(6);
|
|
159
|
+
const pixelAt = (x: number, y: number) => {
|
|
160
|
+
const pixelIndex = shiftPos + y * rowBytes + x * 3;
|
|
161
|
+
return [data[pixelIndex], data[pixelIndex + 1], data[pixelIndex + 2]];
|
|
162
|
+
};
|
|
163
|
+
expect(pixelAt(0, 0)).deep.equal([1, 2, 3]);
|
|
164
|
+
expect(pixelAt(1, 0)).deep.equal([1, 2, 3]);
|
|
165
|
+
expect(pixelAt(2, 0)).deep.equal([4, 5, 6]);
|
|
166
|
+
expect(pixelAt(0, 1)).deep.equal([10, 11, 12]);
|
|
167
|
+
expect(pixelAt(1, 1)).deep.equal([10, 11, 12]);
|
|
168
|
+
expect(pixelAt(2, 1)).deep.equal([13, 14, 15]);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('applyCameraShake is a no-op at zero offset', function () {
|
|
172
|
+
const data = Buffer.from([1, 2, 3, 10, 20, 30]);
|
|
173
|
+
applyCameraShake({ shiftPos: 3, rowBytes: 3, data }, 1, 1, 0, 0);
|
|
174
|
+
expect(Array.from(data)).deep.equal([1, 2, 3, 10, 20, 30]);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('createSpectrumVisualizerFrameGenerator', async function () {
|
|
178
|
+
const expectedImageLength = 6220854;
|
|
179
|
+
const backgroundImagePath = path.resolve('example/media/horses.png');
|
|
180
|
+
const backgroundImageBmpBuffer = await convertToBmp(backgroundImagePath);
|
|
181
|
+
const backgroundImage = parseImage(backgroundImageBmpBuffer);
|
|
182
|
+
const bpmEncoder = createBpmEncoder({ width: backgroundImage.width, height: backgroundImage.height });
|
|
183
|
+
const backgroundImageBuffer = bpmEncoder(backgroundImage.data);
|
|
184
|
+
const createVisualizerFrame = createSpectrumVisualizerFrameGenerator();
|
|
185
|
+
const frameSpectrumDown = createVisualizerFrame({
|
|
186
|
+
backgroundImageBuffer,
|
|
187
|
+
spectrum: [0.5, 0, 1],
|
|
188
|
+
size: { width: 15, height: 20 },
|
|
189
|
+
position: { x: 15, y: 0 },
|
|
190
|
+
rotation: 'down',
|
|
191
|
+
margin: 4,
|
|
192
|
+
color: { red: 1, green: 1, blue: 1 },
|
|
193
|
+
opacity: 1,
|
|
194
|
+
});
|
|
195
|
+
const resultSpectrumDown = frameSpectrumDown.data.toJSON().data;
|
|
196
|
+
expect(resultSpectrumDown).to.have.length(expectedImageLength);
|
|
197
|
+
|
|
198
|
+
const frameSpectrumUp = createVisualizerFrame({
|
|
199
|
+
backgroundImageBuffer,
|
|
200
|
+
spectrum: [0.1, 1, 0],
|
|
201
|
+
size: { width: 25, height: 23 },
|
|
202
|
+
position: { x: 10, y: 5 },
|
|
203
|
+
rotation: 'up',
|
|
204
|
+
margin: 4,
|
|
205
|
+
color: { red: 0, green: 123, blue: 69 },
|
|
206
|
+
opacity: 1,
|
|
207
|
+
});
|
|
208
|
+
const resultSpectrumUp = frameSpectrumUp.data.toJSON().data;
|
|
209
|
+
expect(resultSpectrumUp).to.have.length(expectedImageLength);
|
|
210
|
+
|
|
211
|
+
const frameSpectrumMirror = createVisualizerFrame({
|
|
212
|
+
backgroundImageBuffer,
|
|
213
|
+
spectrum: [0.1, 1, 0],
|
|
214
|
+
size: { width: 25, height: 23 },
|
|
215
|
+
position: { x: 10, y: 5 },
|
|
216
|
+
rotation: 'mirror',
|
|
217
|
+
margin: 4,
|
|
218
|
+
color: { red: 0, green: 123, blue: 69 },
|
|
219
|
+
opacity: 1,
|
|
220
|
+
});
|
|
221
|
+
const resultSpectrumMirror = frameSpectrumMirror.data.toJSON().data;
|
|
222
|
+
expect(resultSpectrumMirror).to.have.length(expectedImageLength);
|
|
223
|
+
|
|
224
|
+
const frameSpectrumUpOpacity50 = createVisualizerFrame({
|
|
225
|
+
backgroundImageBuffer,
|
|
226
|
+
spectrum: [0.1, 1, 0],
|
|
227
|
+
size: { width: 25, height: 23 },
|
|
228
|
+
position: { x: 10, y: 5 },
|
|
229
|
+
rotation: 'up',
|
|
230
|
+
margin: 4,
|
|
231
|
+
color: { red: 0, green: 123, blue: 69 },
|
|
232
|
+
opacity: 0.5,
|
|
233
|
+
});
|
|
234
|
+
const resultSpectrumUpOpacity50 = frameSpectrumUpOpacity50.data.toJSON().data;
|
|
235
|
+
expect(resultSpectrumUpOpacity50).to.have.length(expectedImageLength);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('createPolarVisualizerFrameGenerator', async function () {
|
|
239
|
+
const expectedImageLength = 6220854;
|
|
240
|
+
const backgroundImagePath = path.resolve('example/media/horses.png');
|
|
241
|
+
const backgroundImageBmpBuffer = await convertToBmp(backgroundImagePath);
|
|
242
|
+
const backgroundImage = parseImage(backgroundImageBmpBuffer);
|
|
243
|
+
const bpmEncoder = createBpmEncoder({ width: backgroundImage.width, height: backgroundImage.height });
|
|
244
|
+
const backgroundImageBuffer = bpmEncoder(backgroundImage.data);
|
|
245
|
+
const createPolarVisualizerFrame = createPolarVisualizerFrameGenerator();
|
|
246
|
+
|
|
247
|
+
const framePolarBasic = createPolarVisualizerFrame({
|
|
248
|
+
backgroundImageBuffer,
|
|
249
|
+
spectrum: [0.5, 0.8, 0.3, 0.9, 0.6, 0.4, 0.7, 0.2],
|
|
250
|
+
centerX: 500,
|
|
251
|
+
centerY: 400,
|
|
252
|
+
innerRadius: 100,
|
|
253
|
+
maxBarLength: 150,
|
|
254
|
+
barWidth: 5,
|
|
255
|
+
color: { red: 255, green: 100, blue: 50 },
|
|
256
|
+
opacity: 1,
|
|
257
|
+
});
|
|
258
|
+
const resultPolarBasic = framePolarBasic.data.toJSON().data;
|
|
259
|
+
expect(resultPolarBasic).to.have.length(expectedImageLength);
|
|
260
|
+
|
|
261
|
+
const framePolarVolume = createPolarVisualizerFrame({
|
|
262
|
+
backgroundImageBuffer,
|
|
263
|
+
spectrum: [0.2, 0.5, 0.8, 0.3, 0.6, 0.9, 0.4, 0.7],
|
|
264
|
+
centerX: 500,
|
|
265
|
+
centerY: 400,
|
|
266
|
+
innerRadius: 80,
|
|
267
|
+
maxBarLength: 120,
|
|
268
|
+
barWidth: 4,
|
|
269
|
+
color: { red: 100, green: 200, blue: 255 },
|
|
270
|
+
opacity: 1,
|
|
271
|
+
spectrumEffect: 'volume',
|
|
272
|
+
});
|
|
273
|
+
const resultPolarVolume = framePolarVolume.data.toJSON().data;
|
|
274
|
+
expect(resultPolarVolume).to.have.length(expectedImageLength);
|
|
275
|
+
|
|
276
|
+
const framePolarSmooth = createPolarVisualizerFrame({
|
|
277
|
+
backgroundImageBuffer,
|
|
278
|
+
spectrum: [0.7, 0.4, 0.9, 0.2, 0.5, 0.8, 0.3, 0.6],
|
|
279
|
+
centerX: 500,
|
|
280
|
+
centerY: 400,
|
|
281
|
+
innerRadius: 90,
|
|
282
|
+
maxBarLength: 130,
|
|
283
|
+
barWidth: 6,
|
|
284
|
+
color: { red: 255, green: 255, blue: 0 },
|
|
285
|
+
opacity: 1,
|
|
286
|
+
spectrumEffect: 'smooth',
|
|
287
|
+
});
|
|
288
|
+
const resultPolarSmooth = framePolarSmooth.data.toJSON().data;
|
|
289
|
+
expect(resultPolarSmooth).to.have.length(expectedImageLength);
|
|
290
|
+
|
|
291
|
+
const framePolarOpacity50 = createPolarVisualizerFrame({
|
|
292
|
+
backgroundImageBuffer,
|
|
293
|
+
spectrum: [0.6, 0.3, 0.8, 0.5, 0.4, 0.7, 0.2, 0.9],
|
|
294
|
+
centerX: 500,
|
|
295
|
+
centerY: 400,
|
|
296
|
+
innerRadius: 100,
|
|
297
|
+
maxBarLength: 140,
|
|
298
|
+
barWidth: 5,
|
|
299
|
+
color: { red: 0, green: 255, blue: 128 },
|
|
300
|
+
opacity: 0.5,
|
|
301
|
+
});
|
|
302
|
+
const resultPolarOpacity50 = framePolarOpacity50.data.toJSON().data;
|
|
303
|
+
expect(resultPolarOpacity50).to.have.length(expectedImageLength);
|
|
304
|
+
|
|
305
|
+
const framePolarHexColor = createPolarVisualizerFrame({
|
|
306
|
+
backgroundImageBuffer,
|
|
307
|
+
spectrum: [0.5, 0.6, 0.7, 0.8, 0.9, 0.4, 0.3, 0.2],
|
|
308
|
+
centerX: 500,
|
|
309
|
+
centerY: 400,
|
|
310
|
+
innerRadius: 110,
|
|
311
|
+
maxBarLength: 160,
|
|
312
|
+
barWidth: 7,
|
|
313
|
+
color: '#FF5733',
|
|
314
|
+
opacity: 1,
|
|
315
|
+
});
|
|
316
|
+
const resultPolarHexColor = framePolarHexColor.data.toJSON().data;
|
|
317
|
+
expect(resultPolarHexColor).to.have.length(expectedImageLength);
|
|
318
|
+
});
|
|
319
|
+
});
|