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/dist/dsp.js CHANGED
@@ -1,77 +1,77 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var fft_js_1 = require("fft-js");
4
- // Common frequency bands (in Hz)
5
- exports.FREQUENCY_BANDS = [
6
- { name: 'Sub Bass 1', start: 20, end: 30 },
7
- { name: 'Sub Bass 2', start: 30, end: 40 },
8
- { name: 'Sub Bass 3', start: 50, end: 60 },
9
- { name: 'Sub Bass 4', start: 20, end: 60 },
10
- { name: 'Bass 1', start: 60, end: 107.5 },
11
- { name: 'Bass 2', start: 107.5, end: 155 },
12
- { name: 'Bass 3', start: 155, end: 202.5 },
13
- { name: 'Bass 4', start: 202.5, end: 250 },
14
- { name: 'Low Mids 1', start: 250, end: 312.5 },
15
- { name: 'Low Mids 2', start: 312.5, end: 375 },
16
- { name: 'Low Mids 3', start: 375, end: 437.5 },
17
- { name: 'Low Mids 4', start: 437.5, end: 500 },
18
- { name: 'Mids 1', start: 500, end: 875 },
19
- { name: 'Mids 2', start: 875, end: 1250 },
20
- { name: 'Mids 3', start: 1250, end: 1625 },
21
- { name: 'Mids 4', start: 1625, end: 2000 },
22
- { name: 'High Mids 1', start: 2000, end: 2500 },
23
- { name: 'High Mids 2', start: 2500, end: 3000 },
24
- { name: 'High Mids 3', start: 3000, end: 3500 },
25
- { name: 'High Mids 4', start: 3500, end: 4000 },
26
- { name: 'Presence 1', start: 4000, end: 5000 },
27
- { name: 'Presence 2', start: 5000, end: 6000 },
28
- { name: 'Brilliance 1', start: 6000, end: 13000 },
29
- { name: 'Brilliance 2', start: 13000, end: 20000 },
30
- ];
31
- var combineToBuses = function (spectrum) {
32
- return exports.FREQUENCY_BANDS.map(function (band) {
33
- var pointsInBand = spectrum.filter(function (point) {
34
- return point.frequency >= band.start && point.frequency < band.end;
35
- });
36
- // If no points found in this band, return zero magnitude
37
- if (pointsInBand.length === 0) {
38
- return 0;
39
- }
40
- // Average the magnitudes in this frequency band
41
- var avgMagnitude = pointsInBand.reduce(function (sum, point) {
42
- return sum + point.magnitude;
43
- }, 0) / pointsInBand.length;
44
- return avgMagnitude;
45
- });
46
- };
47
- exports.brutForceFFTSignalLength = function (PCMDataLength) {
48
- var exponent = 1;
49
- while (true) {
50
- var pow = Math.pow(2, exponent);
51
- if ((pow * 2) > PCMDataLength) {
52
- return Math.pow(2, exponent - 1) * 2;
53
- }
54
- exponent++;
55
- }
56
- };
57
- exports.getSpectrum = function (PCMData, sampleRate) {
58
- var signalLength = exports.brutForceFFTSignalLength(PCMData.length);
59
- var signalStartIndex = Math.trunc(PCMData.length / 2 - signalLength / 2);
60
- var signal = PCMData.slice(signalStartIndex, signalStartIndex + signalLength);
61
- // Use fft-js to compute the FFT
62
- var phasors = fft_js_1.fft(signal);
63
- var frequencies = fft_js_1.util.fftFreq(phasors, sampleRate);
64
- var magnitudes = fft_js_1.util.fftMag(phasors);
65
- // Create combined spectrum array with both frequency and magnitude
66
- var spectrum = frequencies.map(function (freq, i) { return ({
67
- frequency: freq,
68
- magnitude: magnitudes[i]
69
- }); });
70
- // Apply frequency-dependent scaling
71
- for (var i = 0; i < spectrum.length; i++) {
72
- spectrum[i].magnitude *= -1 * Math.log((signalLength / 2 - i) * (0.5 / signalLength / 2)) * signalLength;
73
- }
74
- // Combine frequencies into buses
75
- return combineToBuses(spectrum);
76
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var fft_js_1 = require("fft-js");
4
+ // Common frequency bands (in Hz)
5
+ exports.FREQUENCY_BANDS = [
6
+ { name: 'Sub Bass 1', start: 20, end: 30 },
7
+ { name: 'Sub Bass 2', start: 30, end: 40 },
8
+ { name: 'Sub Bass 3', start: 50, end: 60 },
9
+ { name: 'Sub Bass 4', start: 20, end: 60 },
10
+ { name: 'Bass 1', start: 60, end: 107.5 },
11
+ { name: 'Bass 2', start: 107.5, end: 155 },
12
+ { name: 'Bass 3', start: 155, end: 202.5 },
13
+ { name: 'Bass 4', start: 202.5, end: 250 },
14
+ { name: 'Low Mids 1', start: 250, end: 312.5 },
15
+ { name: 'Low Mids 2', start: 312.5, end: 375 },
16
+ { name: 'Low Mids 3', start: 375, end: 437.5 },
17
+ { name: 'Low Mids 4', start: 437.5, end: 500 },
18
+ { name: 'Mids 1', start: 500, end: 875 },
19
+ { name: 'Mids 2', start: 875, end: 1250 },
20
+ { name: 'Mids 3', start: 1250, end: 1625 },
21
+ { name: 'Mids 4', start: 1625, end: 2000 },
22
+ { name: 'High Mids 1', start: 2000, end: 2500 },
23
+ { name: 'High Mids 2', start: 2500, end: 3000 },
24
+ { name: 'High Mids 3', start: 3000, end: 3500 },
25
+ { name: 'High Mids 4', start: 3500, end: 4000 },
26
+ { name: 'Presence 1', start: 4000, end: 5000 },
27
+ { name: 'Presence 2', start: 5000, end: 6000 },
28
+ { name: 'Brilliance 1', start: 6000, end: 13000 },
29
+ { name: 'Brilliance 2', start: 13000, end: 20000 },
30
+ ];
31
+ var combineToBuses = function (spectrum) {
32
+ return exports.FREQUENCY_BANDS.map(function (band) {
33
+ var pointsInBand = spectrum.filter(function (point) {
34
+ return point.frequency >= band.start && point.frequency < band.end;
35
+ });
36
+ // If no points found in this band, return zero magnitude
37
+ if (pointsInBand.length === 0) {
38
+ return 0;
39
+ }
40
+ // Average the magnitudes in this frequency band
41
+ var avgMagnitude = pointsInBand.reduce(function (sum, point) {
42
+ return sum + point.magnitude;
43
+ }, 0) / pointsInBand.length;
44
+ return avgMagnitude;
45
+ });
46
+ };
47
+ exports.brutForceFFTSignalLength = function (PCMDataLength) {
48
+ var exponent = 1;
49
+ while (true) {
50
+ var pow = Math.pow(2, exponent);
51
+ if ((pow * 2) > PCMDataLength) {
52
+ return Math.pow(2, exponent - 1) * 2;
53
+ }
54
+ exponent++;
55
+ }
56
+ };
57
+ exports.getSpectrum = function (PCMData, sampleRate) {
58
+ var signalLength = exports.brutForceFFTSignalLength(PCMData.length);
59
+ var signalStartIndex = Math.trunc(PCMData.length / 2 - signalLength / 2);
60
+ var signal = PCMData.slice(signalStartIndex, signalStartIndex + signalLength);
61
+ // Use fft-js to compute the FFT
62
+ var phasors = fft_js_1.fft(signal);
63
+ var frequencies = fft_js_1.util.fftFreq(phasors, sampleRate);
64
+ var magnitudes = fft_js_1.util.fftMag(phasors);
65
+ // Create combined spectrum array with both frequency and magnitude
66
+ var spectrum = frequencies.map(function (freq, i) { return ({
67
+ frequency: freq,
68
+ magnitude: magnitudes[i]
69
+ }); });
70
+ // Apply frequency-dependent scaling
71
+ for (var i = 0; i < spectrum.length; i++) {
72
+ spectrum[i].magnitude *= -1 * Math.log((signalLength / 2 - i) * (0.5 / signalLength / 2)) * signalLength;
73
+ }
74
+ // Combine frequencies into buses
75
+ return combineToBuses(spectrum);
76
+ };
77
77
  //# sourceMappingURL=dsp.js.map
@@ -1,32 +1,32 @@
1
- /** Output length per segment when `audio.autoHighlight` is true (seconds). */
2
- export declare const HIGHLIGHT_DURATION_SEC = 15;
3
- export interface BeatFrameEvent {
4
- frameIndex: number;
5
- intensity: number;
6
- }
7
- export interface HighlightAudioSegment {
8
- seekSeconds: number;
9
- durationSeconds: number;
10
- }
11
- /** One auto-highlight segment before concatenation (for separate output files). */
12
- export interface HighlightRun {
13
- startFrame: number;
14
- highlightFrames: number;
15
- spectrums: number[][];
16
- beatFrameIndices: number[];
17
- audioSegment: HighlightAudioSegment;
18
- }
19
- /**
20
- * Picks up to `segmentCount` non-overlapping 15s windows with highest summed spectral energy each,
21
- * sorts them chronologically, concatenates spectrums, and remaps beat indices.
22
- */
23
- export declare function computeHighlightSlice(fps: number, totalFrames: number, spectrums: number[][], beatEvents: BeatFrameEvent[], segmentCount?: number): Promise<{
24
- startFrame: number;
25
- highlightFrames: number;
26
- spectrums: number[][];
27
- beatFrameIndices: number[];
28
- audioSeekSeconds: number;
29
- audioDurationSeconds: number;
30
- audioSegments: HighlightAudioSegment[];
31
- runs: HighlightRun[];
32
- }>;
1
+ /** Output length per segment when `audio.autoHighlight` is true (seconds). */
2
+ export declare const HIGHLIGHT_DURATION_SEC = 15;
3
+ export interface BeatFrameEvent {
4
+ frameIndex: number;
5
+ intensity: number;
6
+ }
7
+ export interface HighlightAudioSegment {
8
+ seekSeconds: number;
9
+ durationSeconds: number;
10
+ }
11
+ /** One auto-highlight segment before concatenation (for separate output files). */
12
+ export interface HighlightRun {
13
+ startFrame: number;
14
+ highlightFrames: number;
15
+ spectrums: number[][];
16
+ beatFrameIndices: number[];
17
+ audioSegment: HighlightAudioSegment;
18
+ }
19
+ /**
20
+ * Picks up to `segmentCount` non-overlapping 15s windows with highest summed spectral energy each,
21
+ * sorts them chronologically, concatenates spectrums, and remaps beat indices.
22
+ */
23
+ export declare function computeHighlightSlice(fps: number, totalFrames: number, spectrums: number[][], beatEvents: BeatFrameEvent[], segmentCount?: number): Promise<{
24
+ startFrame: number;
25
+ highlightFrames: number;
26
+ spectrums: number[][];
27
+ beatFrameIndices: number[];
28
+ audioSeekSeconds: number;
29
+ audioDurationSeconds: number;
30
+ audioSegments: HighlightAudioSegment[];
31
+ runs: HighlightRun[];
32
+ }>;