nodejs-audio-visualizer 3.0.0 → 4.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.
- package/README.md +11 -1
- package/dist/config.d.ts +14 -0
- package/dist/config.js +92 -0
- package/dist/config.js.map +1 -1
- package/dist/image.d.ts +26 -2
- package/dist/image.js +192 -1
- package/dist/image.js.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.js +37 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +107 -0
- package/src/image.ts +295 -26
- package/src/index.ts +86 -27
- package/src/tests/image.test.ts +86 -3
package/src/tests/image.test.ts
CHANGED
|
@@ -3,7 +3,8 @@ import path from 'path';
|
|
|
3
3
|
import {
|
|
4
4
|
drawRect,
|
|
5
5
|
Color,
|
|
6
|
-
|
|
6
|
+
createSpectrumVisualizerFrameGenerator,
|
|
7
|
+
createPolarVisualizerFrameGenerator,
|
|
7
8
|
parseImage,
|
|
8
9
|
convertToBmp,
|
|
9
10
|
mixValues,
|
|
@@ -76,14 +77,14 @@ describe('image', function () {
|
|
|
76
77
|
expect(imageDstBuffer.data).deep.equal(expectedImageData);
|
|
77
78
|
});
|
|
78
79
|
|
|
79
|
-
it('
|
|
80
|
+
it('createSpectrumVisualizerFrameGenerator', async function () {
|
|
80
81
|
const expectedImageLength = 6220854;
|
|
81
82
|
const backgroundImagePath = path.resolve('example/media/horses.png');
|
|
82
83
|
const backgroundImageBmpBuffer = await convertToBmp(backgroundImagePath);
|
|
83
84
|
const backgroundImage = parseImage(backgroundImageBmpBuffer);
|
|
84
85
|
const bpmEncoder = createBpmEncoder({ width: backgroundImage.width, height: backgroundImage.height });
|
|
85
86
|
const backgroundImageBuffer = bpmEncoder(backgroundImage.data);
|
|
86
|
-
const createVisualizerFrame =
|
|
87
|
+
const createVisualizerFrame = createSpectrumVisualizerFrameGenerator();
|
|
87
88
|
const frameSpectrumDown = createVisualizerFrame({
|
|
88
89
|
backgroundImageBuffer,
|
|
89
90
|
spectrum: [0.5, 0, 1],
|
|
@@ -136,4 +137,86 @@ describe('image', function () {
|
|
|
136
137
|
const resultSpectrumUpOpacity50 = frameSpectrumUpOpacity50.data.toJSON().data;
|
|
137
138
|
expect(resultSpectrumUpOpacity50).to.have.length(expectedImageLength);
|
|
138
139
|
});
|
|
140
|
+
|
|
141
|
+
it('createPolarVisualizerFrameGenerator', async function () {
|
|
142
|
+
const expectedImageLength = 6220854;
|
|
143
|
+
const backgroundImagePath = path.resolve('example/media/horses.png');
|
|
144
|
+
const backgroundImageBmpBuffer = await convertToBmp(backgroundImagePath);
|
|
145
|
+
const backgroundImage = parseImage(backgroundImageBmpBuffer);
|
|
146
|
+
const bpmEncoder = createBpmEncoder({ width: backgroundImage.width, height: backgroundImage.height });
|
|
147
|
+
const backgroundImageBuffer = bpmEncoder(backgroundImage.data);
|
|
148
|
+
const createPolarVisualizerFrame = createPolarVisualizerFrameGenerator();
|
|
149
|
+
|
|
150
|
+
const framePolarBasic = createPolarVisualizerFrame({
|
|
151
|
+
backgroundImageBuffer,
|
|
152
|
+
spectrum: [0.5, 0.8, 0.3, 0.9, 0.6, 0.4, 0.7, 0.2],
|
|
153
|
+
centerX: 500,
|
|
154
|
+
centerY: 400,
|
|
155
|
+
innerRadius: 100,
|
|
156
|
+
maxBarLength: 150,
|
|
157
|
+
barWidth: 5,
|
|
158
|
+
color: { red: 255, green: 100, blue: 50 },
|
|
159
|
+
opacity: 1,
|
|
160
|
+
});
|
|
161
|
+
const resultPolarBasic = framePolarBasic.data.toJSON().data;
|
|
162
|
+
expect(resultPolarBasic).to.have.length(expectedImageLength);
|
|
163
|
+
|
|
164
|
+
const framePolarVolume = createPolarVisualizerFrame({
|
|
165
|
+
backgroundImageBuffer,
|
|
166
|
+
spectrum: [0.2, 0.5, 0.8, 0.3, 0.6, 0.9, 0.4, 0.7],
|
|
167
|
+
centerX: 500,
|
|
168
|
+
centerY: 400,
|
|
169
|
+
innerRadius: 80,
|
|
170
|
+
maxBarLength: 120,
|
|
171
|
+
barWidth: 4,
|
|
172
|
+
color: { red: 100, green: 200, blue: 255 },
|
|
173
|
+
opacity: 1,
|
|
174
|
+
spectrumEffect: 'volume',
|
|
175
|
+
});
|
|
176
|
+
const resultPolarVolume = framePolarVolume.data.toJSON().data;
|
|
177
|
+
expect(resultPolarVolume).to.have.length(expectedImageLength);
|
|
178
|
+
|
|
179
|
+
const framePolarSmooth = createPolarVisualizerFrame({
|
|
180
|
+
backgroundImageBuffer,
|
|
181
|
+
spectrum: [0.7, 0.4, 0.9, 0.2, 0.5, 0.8, 0.3, 0.6],
|
|
182
|
+
centerX: 500,
|
|
183
|
+
centerY: 400,
|
|
184
|
+
innerRadius: 90,
|
|
185
|
+
maxBarLength: 130,
|
|
186
|
+
barWidth: 6,
|
|
187
|
+
color: { red: 255, green: 255, blue: 0 },
|
|
188
|
+
opacity: 1,
|
|
189
|
+
spectrumEffect: 'smooth',
|
|
190
|
+
});
|
|
191
|
+
const resultPolarSmooth = framePolarSmooth.data.toJSON().data;
|
|
192
|
+
expect(resultPolarSmooth).to.have.length(expectedImageLength);
|
|
193
|
+
|
|
194
|
+
const framePolarOpacity50 = createPolarVisualizerFrame({
|
|
195
|
+
backgroundImageBuffer,
|
|
196
|
+
spectrum: [0.6, 0.3, 0.8, 0.5, 0.4, 0.7, 0.2, 0.9],
|
|
197
|
+
centerX: 500,
|
|
198
|
+
centerY: 400,
|
|
199
|
+
innerRadius: 100,
|
|
200
|
+
maxBarLength: 140,
|
|
201
|
+
barWidth: 5,
|
|
202
|
+
color: { red: 0, green: 255, blue: 128 },
|
|
203
|
+
opacity: 0.5,
|
|
204
|
+
});
|
|
205
|
+
const resultPolarOpacity50 = framePolarOpacity50.data.toJSON().data;
|
|
206
|
+
expect(resultPolarOpacity50).to.have.length(expectedImageLength);
|
|
207
|
+
|
|
208
|
+
const framePolarHexColor = createPolarVisualizerFrame({
|
|
209
|
+
backgroundImageBuffer,
|
|
210
|
+
spectrum: [0.5, 0.6, 0.7, 0.8, 0.9, 0.4, 0.3, 0.2],
|
|
211
|
+
centerX: 500,
|
|
212
|
+
centerY: 400,
|
|
213
|
+
innerRadius: 110,
|
|
214
|
+
maxBarLength: 160,
|
|
215
|
+
barWidth: 7,
|
|
216
|
+
color: '#FF5733',
|
|
217
|
+
opacity: 1,
|
|
218
|
+
});
|
|
219
|
+
const resultPolarHexColor = framePolarHexColor.data.toJSON().data;
|
|
220
|
+
expect(resultPolarHexColor).to.have.length(expectedImageLength);
|
|
221
|
+
});
|
|
139
222
|
});
|