nodejs-audio-visualizer 4.2.3 → 4.2.5
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 +70 -70
- package/dist/audio.d.ts +12 -12
- package/dist/audio.js +120 -120
- package/dist/beats.d.ts +19 -19
- package/dist/beats.js +43 -43
- package/dist/bpmEncoder.d.ts +14 -14
- package/dist/bpmEncoder.js +97 -97
- package/dist/config.d.ts +54 -54
- package/dist/config.js +299 -299
- package/dist/dsp.d.ts +16 -16
- package/dist/dsp.js +76 -76
- package/dist/highlight.d.ts +32 -32
- package/dist/highlight.js +325 -325
- package/dist/image.d.ts +79 -79
- package/dist/image.js +458 -458
- package/dist/index.d.ts +67 -67
- package/dist/index.js +470 -466
- package/dist/index.js.map +1 -1
- package/dist/video.d.ts +67 -64
- package/dist/video.js +317 -293
- package/dist/video.js.map +1 -1
- package/dist/waitForEventLoop.d.ts +1 -1
- package/dist/waitForEventLoop.js +5 -5
- package/package.json +61 -61
- package/src/audio.ts +120 -120
- package/src/beats.ts +68 -68
- package/src/bpmEncoder.ts +97 -97
- package/src/config.ts +382 -382
- package/src/dsp.ts +95 -95
- package/src/highlight.ts +284 -284
- package/src/image.ts +602 -602
- package/src/index.ts +610 -606
- package/src/tests/audio.test.ts +96 -96
- package/src/tests/config.test.ts +406 -406
- package/src/tests/dsp.test.ts +24 -24
- package/src/tests/highlight.test.ts +178 -178
- package/src/tests/image.test.ts +222 -222
- package/src/tests/index.test.ts +63 -63
- package/src/tests/video.test.ts +71 -71
- package/src/typings.d.ts +6 -6
- package/src/video.ts +403 -375
- package/src/waitForEventLoop.ts +2 -2
package/dist/config.js
CHANGED
|
@@ -1,300 +1,300 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var path_1 = __importDefault(require("path"));
|
|
7
|
-
var dsp_1 = require("./dsp");
|
|
8
|
-
exports.defaults = {
|
|
9
|
-
fps: 30,
|
|
10
|
-
spectrumWidth: '33%',
|
|
11
|
-
spectrumHeight: 160,
|
|
12
|
-
spectrumX: 'center',
|
|
13
|
-
spectrumY: 'middle',
|
|
14
|
-
spectrumRotation: 'mirror',
|
|
15
|
-
spectrumBusMargin: 12,
|
|
16
|
-
spectrumOpacity: '80%',
|
|
17
|
-
polarX: 'center',
|
|
18
|
-
polarY: 'middle',
|
|
19
|
-
polarInnerRadius: 100,
|
|
20
|
-
polarMaxBarLength: 160,
|
|
21
|
-
polarBarWidth: 15,
|
|
22
|
-
};
|
|
23
|
-
var postitionAliases = [
|
|
24
|
-
{ name: 'left', value: 0 },
|
|
25
|
-
{ name: 'center', value: 0.5 },
|
|
26
|
-
{ name: 'right', value: 1 },
|
|
27
|
-
{ name: 'top', value: 0 },
|
|
28
|
-
{ name: 'middle', value: 0.5 },
|
|
29
|
-
{ name: 'bottom', value: 1 },
|
|
30
|
-
];
|
|
31
|
-
exports.rotationAliasValues = ['up', 'down', 'mirror'];
|
|
32
|
-
exports.checkIsPercentValue = function (value) {
|
|
33
|
-
return RegExp(/\d+%/).test(value);
|
|
34
|
-
};
|
|
35
|
-
exports.getAudioFilePath = function (config) {
|
|
36
|
-
return path_1.default.resolve(config.audio.path);
|
|
37
|
-
};
|
|
38
|
-
exports.getAudioAutoHighlight = function (config) {
|
|
39
|
-
return config.audio.autoHighlight === true;
|
|
40
|
-
};
|
|
41
|
-
exports.getAudioAutoHighlightCount = function (config) {
|
|
42
|
-
var raw = config.audio.autoHighlightCount;
|
|
43
|
-
if (raw === undefined) {
|
|
44
|
-
return 1;
|
|
45
|
-
}
|
|
46
|
-
if (typeof raw !== 'number' ||
|
|
47
|
-
!Number.isFinite(raw) ||
|
|
48
|
-
!Number.isInteger(raw) ||
|
|
49
|
-
raw < 1) {
|
|
50
|
-
throw new Error("Invalid audio.autoHighlightCount: expected a finite integer >= 1, got '" + String(raw) + "'.");
|
|
51
|
-
}
|
|
52
|
-
return raw;
|
|
53
|
-
};
|
|
54
|
-
exports.getBackgroundImagePath = function (config) {
|
|
55
|
-
return config.image ? path_1.default.resolve(config.image.path) : undefined;
|
|
56
|
-
};
|
|
57
|
-
exports.getBackgroundVideoPath = function (config) {
|
|
58
|
-
return config.video ? path_1.default.resolve(config.video.path) : undefined;
|
|
59
|
-
};
|
|
60
|
-
exports.getAutoEditVideo = function (config) { var _a; return ((_a = config.video) === null || _a === void 0 ? void 0 : _a.autoEdit) === true; };
|
|
61
|
-
exports.getOutVideoPath = function (config) {
|
|
62
|
-
return path_1.default.resolve(config.outVideo.path);
|
|
63
|
-
};
|
|
64
|
-
exports.getFPS = function (config) {
|
|
65
|
-
return config.outVideo.fps || exports.defaults.fps;
|
|
66
|
-
};
|
|
67
|
-
exports.getOutputResolution = function (config) {
|
|
68
|
-
return config.outVideo.resolution;
|
|
69
|
-
};
|
|
70
|
-
exports.getSpectrumBusMargin = function () { return exports.defaults.spectrumBusMargin; };
|
|
71
|
-
var getSpectrumWidth = function (config) {
|
|
72
|
-
return (config.outVideo.spectrum && config.outVideo.spectrum.width) ||
|
|
73
|
-
exports.defaults.spectrumWidth;
|
|
74
|
-
};
|
|
75
|
-
exports.getSpectrumEffect = function (config) { var _a; return (_a = config.outVideo.spectrum) === null || _a === void 0 ? void 0 : _a.effect; };
|
|
76
|
-
var getSpectrumSizeAbsolute = function (spectrumSize, backgroundImageSize, fieldName) {
|
|
77
|
-
if (typeof spectrumSize === 'number') {
|
|
78
|
-
return spectrumSize;
|
|
79
|
-
}
|
|
80
|
-
var isPercentValue = exports.checkIsPercentValue(spectrumSize);
|
|
81
|
-
if (!isPercentValue) {
|
|
82
|
-
throw new Error(getSpectrumSizeValueErrorMessage(fieldName, spectrumSize));
|
|
83
|
-
}
|
|
84
|
-
var percentValue = parseInt(spectrumSize) / 100;
|
|
85
|
-
return backgroundImageSize * percentValue;
|
|
86
|
-
};
|
|
87
|
-
var getSpectrumSizeValueErrorMessage = function (fieldName, value) {
|
|
88
|
-
return "Invalid spectrum " + fieldName + " value: '" + value + "'. Use number value or percent value in string, for example: '30%'.";
|
|
89
|
-
};
|
|
90
|
-
exports.getSpectrumWidthAbsolute = function (config, backgroundImageWidth) {
|
|
91
|
-
var spectrumWidth = getSpectrumWidth(config);
|
|
92
|
-
var spectrumWidthAbsolute = getSpectrumSizeAbsolute(spectrumWidth, backgroundImageWidth, 'width');
|
|
93
|
-
var spectrumWidthWithoutMargin = Math.trunc(spectrumWidthAbsolute / dsp_1.FREQUENCY_BANDS.length) - exports.defaults.spectrumBusMargin / 2;
|
|
94
|
-
if (spectrumWidthWithoutMargin <= 0) {
|
|
95
|
-
throw new Error("Spectrum width '" + spectrumWidth + "' is too small.");
|
|
96
|
-
}
|
|
97
|
-
return spectrumWidthAbsolute;
|
|
98
|
-
};
|
|
99
|
-
var getSpectrumHeight = function (config) {
|
|
100
|
-
return (config.outVideo.spectrum && config.outVideo.spectrum.height) ||
|
|
101
|
-
exports.defaults.spectrumHeight;
|
|
102
|
-
};
|
|
103
|
-
exports.getSpectrumHeightAbsolute = function (config, backgroundImageHeight) {
|
|
104
|
-
var spectrumHeight = getSpectrumHeight(config);
|
|
105
|
-
return getSpectrumSizeAbsolute(spectrumHeight, backgroundImageHeight, 'height');
|
|
106
|
-
};
|
|
107
|
-
var getSpectrumX = function (config) {
|
|
108
|
-
return parseNumberIfPossible((config.outVideo.spectrum && config.outVideo.spectrum.x) ||
|
|
109
|
-
exports.defaults.spectrumX);
|
|
110
|
-
};
|
|
111
|
-
var getSpectrumY = function (config) {
|
|
112
|
-
return parseNumberIfPossible((config.outVideo.spectrum && config.outVideo.spectrum.y) ||
|
|
113
|
-
exports.defaults.spectrumY);
|
|
114
|
-
};
|
|
115
|
-
var parseNumberIfPossible = function (value) {
|
|
116
|
-
var parsed = Number(value);
|
|
117
|
-
if (isNaN(parsed)) {
|
|
118
|
-
return value;
|
|
119
|
-
}
|
|
120
|
-
return parsed;
|
|
121
|
-
};
|
|
122
|
-
var parsePositionAlias = function (aliasName) {
|
|
123
|
-
var nameNormalized = aliasName.trim().toLowerCase();
|
|
124
|
-
var alias = postitionAliases.find(function (als) { return als.name === nameNormalized; });
|
|
125
|
-
if (!alias) {
|
|
126
|
-
throw new Error();
|
|
127
|
-
}
|
|
128
|
-
return alias;
|
|
129
|
-
};
|
|
130
|
-
var getValidPositionAliasValues = function () {
|
|
131
|
-
return postitionAliases.map(function (aliasEl) { return aliasEl.name; }).join(', ');
|
|
132
|
-
};
|
|
133
|
-
var getSpectrumAbsolutePosition = function (relativePosition, spectrumSize, backgroundImageSize) {
|
|
134
|
-
switch (relativePosition) {
|
|
135
|
-
case 0:
|
|
136
|
-
return 0;
|
|
137
|
-
case 0.5:
|
|
138
|
-
return relativePosition * backgroundImageSize - spectrumSize / 2;
|
|
139
|
-
case 1:
|
|
140
|
-
return relativePosition * backgroundImageSize - spectrumSize;
|
|
141
|
-
default:
|
|
142
|
-
throw new Error();
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
exports.getSpectrumXAbsolute = function (config, spectrumWidth, backgroundImageWidth) {
|
|
146
|
-
var spectrumX = getSpectrumX(config);
|
|
147
|
-
if (typeof spectrumX !== 'string') {
|
|
148
|
-
return spectrumX;
|
|
149
|
-
}
|
|
150
|
-
try {
|
|
151
|
-
var spectrumXParsed = parsePositionAlias(spectrumX);
|
|
152
|
-
return getSpectrumAbsolutePosition(spectrumXParsed.value, spectrumWidth, backgroundImageWidth);
|
|
153
|
-
}
|
|
154
|
-
catch (_a) {
|
|
155
|
-
throw new Error("Invalid spectrum x value: " + spectrumX + ". Valid values: " + getValidPositionAliasValues() + ".");
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
exports.getSpectrumYAbsolute = function (config, spectrumHeight, backgroundImageHeight) {
|
|
159
|
-
var spectrumY = getSpectrumY(config);
|
|
160
|
-
if (typeof spectrumY !== 'string') {
|
|
161
|
-
return spectrumY;
|
|
162
|
-
}
|
|
163
|
-
try {
|
|
164
|
-
var spectrumXParsed = parsePositionAlias(spectrumY);
|
|
165
|
-
return getSpectrumAbsolutePosition(spectrumXParsed.value, spectrumHeight, backgroundImageHeight);
|
|
166
|
-
}
|
|
167
|
-
catch (_a) {
|
|
168
|
-
throw new Error("Invalid spectrum y value: " + spectrumY + ". Valid values: " + getValidPositionAliasValues() + ".");
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
var getValidRotationAliasValues = function () {
|
|
172
|
-
return exports.rotationAliasValues.join(', ');
|
|
173
|
-
};
|
|
174
|
-
exports.checkIsValidRotationAlias = function (aliasName) {
|
|
175
|
-
return !!exports.rotationAliasValues.find(function (al) { return al === aliasName; });
|
|
176
|
-
};
|
|
177
|
-
exports.getSpectrumRotation = function (config) {
|
|
178
|
-
var rotationValue = (config.outVideo.spectrum && config.outVideo.spectrum.rotation) ||
|
|
179
|
-
exports.defaults.spectrumRotation;
|
|
180
|
-
if (!exports.checkIsValidRotationAlias(rotationValue)) {
|
|
181
|
-
throw new Error("Invalid spectrum rotation value: " + rotationValue + ". Valid values: " + getValidRotationAliasValues + ".");
|
|
182
|
-
}
|
|
183
|
-
return rotationValue;
|
|
184
|
-
};
|
|
185
|
-
exports.getSpectrumColor = function (config) {
|
|
186
|
-
return config.outVideo.spectrum && config.outVideo.spectrum.color;
|
|
187
|
-
};
|
|
188
|
-
exports.getSpectrumOpacity = function (config) {
|
|
189
|
-
return (config.outVideo.spectrum && config.outVideo.spectrum.opacity) ||
|
|
190
|
-
exports.defaults.spectrumOpacity;
|
|
191
|
-
};
|
|
192
|
-
exports.getSpectrumOpacityParsed = function (config) {
|
|
193
|
-
var spectrumOpacity = exports.getSpectrumOpacity(config);
|
|
194
|
-
if (!exports.checkIsPercentValue(spectrumOpacity)) {
|
|
195
|
-
throw new Error("Invalid spectrum opacity value: '" + spectrumOpacity + "'. Use string percent value, for example '80%'.");
|
|
196
|
-
}
|
|
197
|
-
var percentValue = parseInt(spectrumOpacity);
|
|
198
|
-
if ((percentValue < 0) ||
|
|
199
|
-
(percentValue > 100)) {
|
|
200
|
-
throw new Error("Invalid spectrum opacity value: '" + spectrumOpacity + "'. Percent values must be in range from '0%' to '100%'.");
|
|
201
|
-
}
|
|
202
|
-
return percentValue / 100;
|
|
203
|
-
};
|
|
204
|
-
exports.getFfmpeg_cfr = function (config) {
|
|
205
|
-
return config.tweaks && config.tweaks.ffmpeg_cfr;
|
|
206
|
-
};
|
|
207
|
-
exports.getFfmpeg_preset = function (config) {
|
|
208
|
-
return config.tweaks && config.tweaks.ffmpeg_preset;
|
|
209
|
-
};
|
|
210
|
-
exports.getFrame_processing_delay = function (config) {
|
|
211
|
-
return config.tweaks && config.tweaks.frame_processing_delay;
|
|
212
|
-
};
|
|
213
|
-
// Polar visualizer config getters
|
|
214
|
-
var getPolarX = function (config) {
|
|
215
|
-
return parseNumberIfPossible((config.outVideo.polar && config.outVideo.polar.x) ||
|
|
216
|
-
exports.defaults.polarX);
|
|
217
|
-
};
|
|
218
|
-
var getPolarY = function (config) {
|
|
219
|
-
return parseNumberIfPossible((config.outVideo.polar && config.outVideo.polar.y) ||
|
|
220
|
-
exports.defaults.polarY);
|
|
221
|
-
};
|
|
222
|
-
exports.getPolarXAbsolute = function (config, backgroundImageWidth) {
|
|
223
|
-
var polarX = getPolarX(config);
|
|
224
|
-
if (typeof polarX !== 'string') {
|
|
225
|
-
return polarX;
|
|
226
|
-
}
|
|
227
|
-
try {
|
|
228
|
-
var polarXParsed = parsePositionAlias(polarX);
|
|
229
|
-
if (polarXParsed.value === 0) {
|
|
230
|
-
var polarLength = exports.getPolarMaxBarLength(config);
|
|
231
|
-
var polarRadius = exports.getPolarInnerRadius(config);
|
|
232
|
-
return polarRadius + polarLength;
|
|
233
|
-
}
|
|
234
|
-
if (polarXParsed.value === 1) {
|
|
235
|
-
var polarLength = exports.getPolarMaxBarLength(config);
|
|
236
|
-
var polarRadius = exports.getPolarInnerRadius(config);
|
|
237
|
-
return backgroundImageWidth - polarRadius - polarLength;
|
|
238
|
-
}
|
|
239
|
-
return polarXParsed.value * backgroundImageWidth;
|
|
240
|
-
}
|
|
241
|
-
catch (_a) {
|
|
242
|
-
throw new Error("Invalid polar x value: " + polarX + ". Valid values: " + getValidPositionAliasValues() + ".");
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
exports.getPolarYAbsolute = function (config, backgroundImageHeight) {
|
|
246
|
-
var polarY = getPolarY(config);
|
|
247
|
-
if (typeof polarY !== 'string') {
|
|
248
|
-
return polarY;
|
|
249
|
-
}
|
|
250
|
-
try {
|
|
251
|
-
var polarYParsed = parsePositionAlias(polarY);
|
|
252
|
-
if (polarYParsed.value === 0) {
|
|
253
|
-
var polarLength = exports.getPolarMaxBarLength(config);
|
|
254
|
-
var polarRadius = exports.getPolarInnerRadius(config);
|
|
255
|
-
return polarRadius + polarLength;
|
|
256
|
-
}
|
|
257
|
-
if (polarYParsed.value === 1) {
|
|
258
|
-
var polarLength = exports.getPolarMaxBarLength(config);
|
|
259
|
-
var polarRadius = exports.getPolarInnerRadius(config);
|
|
260
|
-
return backgroundImageHeight - polarRadius - polarLength;
|
|
261
|
-
}
|
|
262
|
-
return polarYParsed.value * backgroundImageHeight;
|
|
263
|
-
}
|
|
264
|
-
catch (_a) {
|
|
265
|
-
throw new Error("Invalid polar y value: " + polarY + ". Valid values: " + getValidPositionAliasValues() + ".");
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
exports.getPolarInnerRadius = function (config) {
|
|
269
|
-
return (config.outVideo.polar && config.outVideo.polar.innerRadius) ||
|
|
270
|
-
exports.defaults.polarInnerRadius;
|
|
271
|
-
};
|
|
272
|
-
exports.getPolarMaxBarLength = function (config) {
|
|
273
|
-
return (config.outVideo.polar && config.outVideo.polar.maxBarLength) ||
|
|
274
|
-
exports.defaults.polarMaxBarLength;
|
|
275
|
-
};
|
|
276
|
-
exports.getPolarBarWidth = function (config) {
|
|
277
|
-
return (config.outVideo.polar && config.outVideo.polar.barWidth) ||
|
|
278
|
-
exports.defaults.polarBarWidth;
|
|
279
|
-
};
|
|
280
|
-
exports.getPolarEffect = function (config) { var _a; return (_a = config.outVideo.polar) === null || _a === void 0 ? void 0 : _a.effect; };
|
|
281
|
-
exports.getPolarColor = function (config) {
|
|
282
|
-
return config.outVideo.polar && config.outVideo.polar.color;
|
|
283
|
-
};
|
|
284
|
-
exports.getPolarOpacity = function (config) {
|
|
285
|
-
return (config.outVideo.polar && config.outVideo.polar.opacity) ||
|
|
286
|
-
exports.defaults.spectrumOpacity;
|
|
287
|
-
};
|
|
288
|
-
exports.getPolarOpacityParsed = function (config) {
|
|
289
|
-
var polarOpacity = exports.getPolarOpacity(config);
|
|
290
|
-
if (!exports.checkIsPercentValue(polarOpacity)) {
|
|
291
|
-
throw new Error("Invalid polar opacity value: '" + polarOpacity + "'. Use string percent value, for example '80%'.");
|
|
292
|
-
}
|
|
293
|
-
var percentValue = parseInt(polarOpacity);
|
|
294
|
-
if ((percentValue < 0) ||
|
|
295
|
-
(percentValue > 100)) {
|
|
296
|
-
throw new Error("Invalid polar opacity value: '" + polarOpacity + "'. Percent values must be in range from '0%' to '100%'.");
|
|
297
|
-
}
|
|
298
|
-
return percentValue / 100;
|
|
299
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var path_1 = __importDefault(require("path"));
|
|
7
|
+
var dsp_1 = require("./dsp");
|
|
8
|
+
exports.defaults = {
|
|
9
|
+
fps: 30,
|
|
10
|
+
spectrumWidth: '33%',
|
|
11
|
+
spectrumHeight: 160,
|
|
12
|
+
spectrumX: 'center',
|
|
13
|
+
spectrumY: 'middle',
|
|
14
|
+
spectrumRotation: 'mirror',
|
|
15
|
+
spectrumBusMargin: 12,
|
|
16
|
+
spectrumOpacity: '80%',
|
|
17
|
+
polarX: 'center',
|
|
18
|
+
polarY: 'middle',
|
|
19
|
+
polarInnerRadius: 100,
|
|
20
|
+
polarMaxBarLength: 160,
|
|
21
|
+
polarBarWidth: 15,
|
|
22
|
+
};
|
|
23
|
+
var postitionAliases = [
|
|
24
|
+
{ name: 'left', value: 0 },
|
|
25
|
+
{ name: 'center', value: 0.5 },
|
|
26
|
+
{ name: 'right', value: 1 },
|
|
27
|
+
{ name: 'top', value: 0 },
|
|
28
|
+
{ name: 'middle', value: 0.5 },
|
|
29
|
+
{ name: 'bottom', value: 1 },
|
|
30
|
+
];
|
|
31
|
+
exports.rotationAliasValues = ['up', 'down', 'mirror'];
|
|
32
|
+
exports.checkIsPercentValue = function (value) {
|
|
33
|
+
return RegExp(/\d+%/).test(value);
|
|
34
|
+
};
|
|
35
|
+
exports.getAudioFilePath = function (config) {
|
|
36
|
+
return path_1.default.resolve(config.audio.path);
|
|
37
|
+
};
|
|
38
|
+
exports.getAudioAutoHighlight = function (config) {
|
|
39
|
+
return config.audio.autoHighlight === true;
|
|
40
|
+
};
|
|
41
|
+
exports.getAudioAutoHighlightCount = function (config) {
|
|
42
|
+
var raw = config.audio.autoHighlightCount;
|
|
43
|
+
if (raw === undefined) {
|
|
44
|
+
return 1;
|
|
45
|
+
}
|
|
46
|
+
if (typeof raw !== 'number' ||
|
|
47
|
+
!Number.isFinite(raw) ||
|
|
48
|
+
!Number.isInteger(raw) ||
|
|
49
|
+
raw < 1) {
|
|
50
|
+
throw new Error("Invalid audio.autoHighlightCount: expected a finite integer >= 1, got '" + String(raw) + "'.");
|
|
51
|
+
}
|
|
52
|
+
return raw;
|
|
53
|
+
};
|
|
54
|
+
exports.getBackgroundImagePath = function (config) {
|
|
55
|
+
return config.image ? path_1.default.resolve(config.image.path) : undefined;
|
|
56
|
+
};
|
|
57
|
+
exports.getBackgroundVideoPath = function (config) {
|
|
58
|
+
return config.video ? path_1.default.resolve(config.video.path) : undefined;
|
|
59
|
+
};
|
|
60
|
+
exports.getAutoEditVideo = function (config) { var _a; return ((_a = config.video) === null || _a === void 0 ? void 0 : _a.autoEdit) === true; };
|
|
61
|
+
exports.getOutVideoPath = function (config) {
|
|
62
|
+
return path_1.default.resolve(config.outVideo.path);
|
|
63
|
+
};
|
|
64
|
+
exports.getFPS = function (config) {
|
|
65
|
+
return config.outVideo.fps || exports.defaults.fps;
|
|
66
|
+
};
|
|
67
|
+
exports.getOutputResolution = function (config) {
|
|
68
|
+
return config.outVideo.resolution;
|
|
69
|
+
};
|
|
70
|
+
exports.getSpectrumBusMargin = function () { return exports.defaults.spectrumBusMargin; };
|
|
71
|
+
var getSpectrumWidth = function (config) {
|
|
72
|
+
return (config.outVideo.spectrum && config.outVideo.spectrum.width) ||
|
|
73
|
+
exports.defaults.spectrumWidth;
|
|
74
|
+
};
|
|
75
|
+
exports.getSpectrumEffect = function (config) { var _a; return (_a = config.outVideo.spectrum) === null || _a === void 0 ? void 0 : _a.effect; };
|
|
76
|
+
var getSpectrumSizeAbsolute = function (spectrumSize, backgroundImageSize, fieldName) {
|
|
77
|
+
if (typeof spectrumSize === 'number') {
|
|
78
|
+
return spectrumSize;
|
|
79
|
+
}
|
|
80
|
+
var isPercentValue = exports.checkIsPercentValue(spectrumSize);
|
|
81
|
+
if (!isPercentValue) {
|
|
82
|
+
throw new Error(getSpectrumSizeValueErrorMessage(fieldName, spectrumSize));
|
|
83
|
+
}
|
|
84
|
+
var percentValue = parseInt(spectrumSize) / 100;
|
|
85
|
+
return backgroundImageSize * percentValue;
|
|
86
|
+
};
|
|
87
|
+
var getSpectrumSizeValueErrorMessage = function (fieldName, value) {
|
|
88
|
+
return "Invalid spectrum " + fieldName + " value: '" + value + "'. Use number value or percent value in string, for example: '30%'.";
|
|
89
|
+
};
|
|
90
|
+
exports.getSpectrumWidthAbsolute = function (config, backgroundImageWidth) {
|
|
91
|
+
var spectrumWidth = getSpectrumWidth(config);
|
|
92
|
+
var spectrumWidthAbsolute = getSpectrumSizeAbsolute(spectrumWidth, backgroundImageWidth, 'width');
|
|
93
|
+
var spectrumWidthWithoutMargin = Math.trunc(spectrumWidthAbsolute / dsp_1.FREQUENCY_BANDS.length) - exports.defaults.spectrumBusMargin / 2;
|
|
94
|
+
if (spectrumWidthWithoutMargin <= 0) {
|
|
95
|
+
throw new Error("Spectrum width '" + spectrumWidth + "' is too small.");
|
|
96
|
+
}
|
|
97
|
+
return spectrumWidthAbsolute;
|
|
98
|
+
};
|
|
99
|
+
var getSpectrumHeight = function (config) {
|
|
100
|
+
return (config.outVideo.spectrum && config.outVideo.spectrum.height) ||
|
|
101
|
+
exports.defaults.spectrumHeight;
|
|
102
|
+
};
|
|
103
|
+
exports.getSpectrumHeightAbsolute = function (config, backgroundImageHeight) {
|
|
104
|
+
var spectrumHeight = getSpectrumHeight(config);
|
|
105
|
+
return getSpectrumSizeAbsolute(spectrumHeight, backgroundImageHeight, 'height');
|
|
106
|
+
};
|
|
107
|
+
var getSpectrumX = function (config) {
|
|
108
|
+
return parseNumberIfPossible((config.outVideo.spectrum && config.outVideo.spectrum.x) ||
|
|
109
|
+
exports.defaults.spectrumX);
|
|
110
|
+
};
|
|
111
|
+
var getSpectrumY = function (config) {
|
|
112
|
+
return parseNumberIfPossible((config.outVideo.spectrum && config.outVideo.spectrum.y) ||
|
|
113
|
+
exports.defaults.spectrumY);
|
|
114
|
+
};
|
|
115
|
+
var parseNumberIfPossible = function (value) {
|
|
116
|
+
var parsed = Number(value);
|
|
117
|
+
if (isNaN(parsed)) {
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
return parsed;
|
|
121
|
+
};
|
|
122
|
+
var parsePositionAlias = function (aliasName) {
|
|
123
|
+
var nameNormalized = aliasName.trim().toLowerCase();
|
|
124
|
+
var alias = postitionAliases.find(function (als) { return als.name === nameNormalized; });
|
|
125
|
+
if (!alias) {
|
|
126
|
+
throw new Error();
|
|
127
|
+
}
|
|
128
|
+
return alias;
|
|
129
|
+
};
|
|
130
|
+
var getValidPositionAliasValues = function () {
|
|
131
|
+
return postitionAliases.map(function (aliasEl) { return aliasEl.name; }).join(', ');
|
|
132
|
+
};
|
|
133
|
+
var getSpectrumAbsolutePosition = function (relativePosition, spectrumSize, backgroundImageSize) {
|
|
134
|
+
switch (relativePosition) {
|
|
135
|
+
case 0:
|
|
136
|
+
return 0;
|
|
137
|
+
case 0.5:
|
|
138
|
+
return relativePosition * backgroundImageSize - spectrumSize / 2;
|
|
139
|
+
case 1:
|
|
140
|
+
return relativePosition * backgroundImageSize - spectrumSize;
|
|
141
|
+
default:
|
|
142
|
+
throw new Error();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
exports.getSpectrumXAbsolute = function (config, spectrumWidth, backgroundImageWidth) {
|
|
146
|
+
var spectrumX = getSpectrumX(config);
|
|
147
|
+
if (typeof spectrumX !== 'string') {
|
|
148
|
+
return spectrumX;
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
var spectrumXParsed = parsePositionAlias(spectrumX);
|
|
152
|
+
return getSpectrumAbsolutePosition(spectrumXParsed.value, spectrumWidth, backgroundImageWidth);
|
|
153
|
+
}
|
|
154
|
+
catch (_a) {
|
|
155
|
+
throw new Error("Invalid spectrum x value: " + spectrumX + ". Valid values: " + getValidPositionAliasValues() + ".");
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
exports.getSpectrumYAbsolute = function (config, spectrumHeight, backgroundImageHeight) {
|
|
159
|
+
var spectrumY = getSpectrumY(config);
|
|
160
|
+
if (typeof spectrumY !== 'string') {
|
|
161
|
+
return spectrumY;
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
var spectrumXParsed = parsePositionAlias(spectrumY);
|
|
165
|
+
return getSpectrumAbsolutePosition(spectrumXParsed.value, spectrumHeight, backgroundImageHeight);
|
|
166
|
+
}
|
|
167
|
+
catch (_a) {
|
|
168
|
+
throw new Error("Invalid spectrum y value: " + spectrumY + ". Valid values: " + getValidPositionAliasValues() + ".");
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
var getValidRotationAliasValues = function () {
|
|
172
|
+
return exports.rotationAliasValues.join(', ');
|
|
173
|
+
};
|
|
174
|
+
exports.checkIsValidRotationAlias = function (aliasName) {
|
|
175
|
+
return !!exports.rotationAliasValues.find(function (al) { return al === aliasName; });
|
|
176
|
+
};
|
|
177
|
+
exports.getSpectrumRotation = function (config) {
|
|
178
|
+
var rotationValue = (config.outVideo.spectrum && config.outVideo.spectrum.rotation) ||
|
|
179
|
+
exports.defaults.spectrumRotation;
|
|
180
|
+
if (!exports.checkIsValidRotationAlias(rotationValue)) {
|
|
181
|
+
throw new Error("Invalid spectrum rotation value: " + rotationValue + ". Valid values: " + getValidRotationAliasValues + ".");
|
|
182
|
+
}
|
|
183
|
+
return rotationValue;
|
|
184
|
+
};
|
|
185
|
+
exports.getSpectrumColor = function (config) {
|
|
186
|
+
return config.outVideo.spectrum && config.outVideo.spectrum.color;
|
|
187
|
+
};
|
|
188
|
+
exports.getSpectrumOpacity = function (config) {
|
|
189
|
+
return (config.outVideo.spectrum && config.outVideo.spectrum.opacity) ||
|
|
190
|
+
exports.defaults.spectrumOpacity;
|
|
191
|
+
};
|
|
192
|
+
exports.getSpectrumOpacityParsed = function (config) {
|
|
193
|
+
var spectrumOpacity = exports.getSpectrumOpacity(config);
|
|
194
|
+
if (!exports.checkIsPercentValue(spectrumOpacity)) {
|
|
195
|
+
throw new Error("Invalid spectrum opacity value: '" + spectrumOpacity + "'. Use string percent value, for example '80%'.");
|
|
196
|
+
}
|
|
197
|
+
var percentValue = parseInt(spectrumOpacity);
|
|
198
|
+
if ((percentValue < 0) ||
|
|
199
|
+
(percentValue > 100)) {
|
|
200
|
+
throw new Error("Invalid spectrum opacity value: '" + spectrumOpacity + "'. Percent values must be in range from '0%' to '100%'.");
|
|
201
|
+
}
|
|
202
|
+
return percentValue / 100;
|
|
203
|
+
};
|
|
204
|
+
exports.getFfmpeg_cfr = function (config) {
|
|
205
|
+
return config.tweaks && config.tweaks.ffmpeg_cfr;
|
|
206
|
+
};
|
|
207
|
+
exports.getFfmpeg_preset = function (config) {
|
|
208
|
+
return config.tweaks && config.tweaks.ffmpeg_preset;
|
|
209
|
+
};
|
|
210
|
+
exports.getFrame_processing_delay = function (config) {
|
|
211
|
+
return config.tweaks && config.tweaks.frame_processing_delay;
|
|
212
|
+
};
|
|
213
|
+
// Polar visualizer config getters
|
|
214
|
+
var getPolarX = function (config) {
|
|
215
|
+
return parseNumberIfPossible((config.outVideo.polar && config.outVideo.polar.x) ||
|
|
216
|
+
exports.defaults.polarX);
|
|
217
|
+
};
|
|
218
|
+
var getPolarY = function (config) {
|
|
219
|
+
return parseNumberIfPossible((config.outVideo.polar && config.outVideo.polar.y) ||
|
|
220
|
+
exports.defaults.polarY);
|
|
221
|
+
};
|
|
222
|
+
exports.getPolarXAbsolute = function (config, backgroundImageWidth) {
|
|
223
|
+
var polarX = getPolarX(config);
|
|
224
|
+
if (typeof polarX !== 'string') {
|
|
225
|
+
return polarX;
|
|
226
|
+
}
|
|
227
|
+
try {
|
|
228
|
+
var polarXParsed = parsePositionAlias(polarX);
|
|
229
|
+
if (polarXParsed.value === 0) {
|
|
230
|
+
var polarLength = exports.getPolarMaxBarLength(config);
|
|
231
|
+
var polarRadius = exports.getPolarInnerRadius(config);
|
|
232
|
+
return polarRadius + polarLength;
|
|
233
|
+
}
|
|
234
|
+
if (polarXParsed.value === 1) {
|
|
235
|
+
var polarLength = exports.getPolarMaxBarLength(config);
|
|
236
|
+
var polarRadius = exports.getPolarInnerRadius(config);
|
|
237
|
+
return backgroundImageWidth - polarRadius - polarLength;
|
|
238
|
+
}
|
|
239
|
+
return polarXParsed.value * backgroundImageWidth;
|
|
240
|
+
}
|
|
241
|
+
catch (_a) {
|
|
242
|
+
throw new Error("Invalid polar x value: " + polarX + ". Valid values: " + getValidPositionAliasValues() + ".");
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
exports.getPolarYAbsolute = function (config, backgroundImageHeight) {
|
|
246
|
+
var polarY = getPolarY(config);
|
|
247
|
+
if (typeof polarY !== 'string') {
|
|
248
|
+
return polarY;
|
|
249
|
+
}
|
|
250
|
+
try {
|
|
251
|
+
var polarYParsed = parsePositionAlias(polarY);
|
|
252
|
+
if (polarYParsed.value === 0) {
|
|
253
|
+
var polarLength = exports.getPolarMaxBarLength(config);
|
|
254
|
+
var polarRadius = exports.getPolarInnerRadius(config);
|
|
255
|
+
return polarRadius + polarLength;
|
|
256
|
+
}
|
|
257
|
+
if (polarYParsed.value === 1) {
|
|
258
|
+
var polarLength = exports.getPolarMaxBarLength(config);
|
|
259
|
+
var polarRadius = exports.getPolarInnerRadius(config);
|
|
260
|
+
return backgroundImageHeight - polarRadius - polarLength;
|
|
261
|
+
}
|
|
262
|
+
return polarYParsed.value * backgroundImageHeight;
|
|
263
|
+
}
|
|
264
|
+
catch (_a) {
|
|
265
|
+
throw new Error("Invalid polar y value: " + polarY + ". Valid values: " + getValidPositionAliasValues() + ".");
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
exports.getPolarInnerRadius = function (config) {
|
|
269
|
+
return (config.outVideo.polar && config.outVideo.polar.innerRadius) ||
|
|
270
|
+
exports.defaults.polarInnerRadius;
|
|
271
|
+
};
|
|
272
|
+
exports.getPolarMaxBarLength = function (config) {
|
|
273
|
+
return (config.outVideo.polar && config.outVideo.polar.maxBarLength) ||
|
|
274
|
+
exports.defaults.polarMaxBarLength;
|
|
275
|
+
};
|
|
276
|
+
exports.getPolarBarWidth = function (config) {
|
|
277
|
+
return (config.outVideo.polar && config.outVideo.polar.barWidth) ||
|
|
278
|
+
exports.defaults.polarBarWidth;
|
|
279
|
+
};
|
|
280
|
+
exports.getPolarEffect = function (config) { var _a; return (_a = config.outVideo.polar) === null || _a === void 0 ? void 0 : _a.effect; };
|
|
281
|
+
exports.getPolarColor = function (config) {
|
|
282
|
+
return config.outVideo.polar && config.outVideo.polar.color;
|
|
283
|
+
};
|
|
284
|
+
exports.getPolarOpacity = function (config) {
|
|
285
|
+
return (config.outVideo.polar && config.outVideo.polar.opacity) ||
|
|
286
|
+
exports.defaults.spectrumOpacity;
|
|
287
|
+
};
|
|
288
|
+
exports.getPolarOpacityParsed = function (config) {
|
|
289
|
+
var polarOpacity = exports.getPolarOpacity(config);
|
|
290
|
+
if (!exports.checkIsPercentValue(polarOpacity)) {
|
|
291
|
+
throw new Error("Invalid polar opacity value: '" + polarOpacity + "'. Use string percent value, for example '80%'.");
|
|
292
|
+
}
|
|
293
|
+
var percentValue = parseInt(polarOpacity);
|
|
294
|
+
if ((percentValue < 0) ||
|
|
295
|
+
(percentValue > 100)) {
|
|
296
|
+
throw new Error("Invalid polar opacity value: '" + polarOpacity + "'. Percent values must be in range from '0%' to '100%'.");
|
|
297
|
+
}
|
|
298
|
+
return percentValue / 100;
|
|
299
|
+
};
|
|
300
300
|
//# sourceMappingURL=config.js.map
|
package/dist/dsp.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export interface SpectrumPoint {
|
|
2
|
-
frequency: number;
|
|
3
|
-
magnitude: number;
|
|
4
|
-
}
|
|
5
|
-
export interface FrequencyBus {
|
|
6
|
-
startFreq: number;
|
|
7
|
-
endFreq: number;
|
|
8
|
-
magnitude: number;
|
|
9
|
-
}
|
|
10
|
-
export declare const FREQUENCY_BANDS: {
|
|
11
|
-
name: string;
|
|
12
|
-
start: number;
|
|
13
|
-
end: number;
|
|
14
|
-
}[];
|
|
15
|
-
export declare const brutForceFFTSignalLength: (PCMDataLength: number) => number;
|
|
16
|
-
export declare const getSpectrum: (PCMData: number[], sampleRate: number) => number[];
|
|
1
|
+
export interface SpectrumPoint {
|
|
2
|
+
frequency: number;
|
|
3
|
+
magnitude: number;
|
|
4
|
+
}
|
|
5
|
+
export interface FrequencyBus {
|
|
6
|
+
startFreq: number;
|
|
7
|
+
endFreq: number;
|
|
8
|
+
magnitude: number;
|
|
9
|
+
}
|
|
10
|
+
export declare const FREQUENCY_BANDS: {
|
|
11
|
+
name: string;
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
}[];
|
|
15
|
+
export declare const brutForceFFTSignalLength: (PCMDataLength: number) => number;
|
|
16
|
+
export declare const getSpectrum: (PCMData: number[], sampleRate: number) => number[];
|