nodejs-audio-visualizer 4.2.4 → 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.
@@ -1,96 +1,96 @@
1
- import { expect } from 'chai';
2
- import { Readable, Writable, Pipe } from 'stream';
3
- import child_process, { ChildProcessWithoutNullStreams } from 'child_process';
4
- import {
5
- bufferToUInt8,
6
- normalizeAudioData,
7
- spawnFfmpegAudioReader,
8
- skipEvery,
9
- getPeaks,
10
- correctPeaks,
11
- createSpectrumsProcessor,
12
- } from '../audio';
13
- import { createSandbox } from 'sinon';
14
-
15
- let childProcessStream = {
16
- stdin: new Writable(),
17
- stderr: new Readable(),
18
- };
19
-
20
- const videoSandbox = createSandbox();
21
-
22
- describe('audio', function () {
23
-
24
- this.beforeAll(function () {
25
- videoSandbox.stub(child_process, 'spawn').returns(childProcessStream as ChildProcessWithoutNullStreams);
26
- });
27
-
28
- this.afterAll(function () {
29
- videoSandbox.restore();
30
- });
31
-
32
- it('bufferToUInt8', function () {
33
- const expected = [1, 2, 3, 4, 5];
34
- const buffer = Buffer.from(new Uint8Array(expected));
35
- const result = bufferToUInt8(buffer, 0, 5);
36
- expect(result).deep.equal(expected);
37
- });
38
-
39
- it('normalizeAudioData', function () {
40
- const result = normalizeAudioData([4, 5, 23, 78, 2]);
41
- const expected = [-0.96875, -0.9609375, -0.8203125, -0.390625, -0.984375];
42
- expect(result).deep.equal(expected);
43
- });
44
-
45
- it('spawnFfmpegAudioReader', function (done) {
46
- const childProcessReadableStream = new Readable();
47
- const childProcessWritableStream = new Writable();
48
- childProcessReadableStream._read = () => { done(); };
49
- (<Pipe>childProcessWritableStream.pipe) = () => childProcessWritableStream;
50
-
51
- childProcessStream.stdin = childProcessWritableStream;
52
- childProcessStream.stderr = childProcessReadableStream;
53
-
54
- const ffmpegProcess = spawnFfmpegAudioReader('filename', 'format');
55
- ffmpegProcess.stderr.on('data', (data) => {
56
- expect(data).equal('some data');
57
- });
58
-
59
- childProcessStream.stderr.emit('data', 'some data');
60
- });
61
-
62
- it('skipEvery', () => {
63
- const sampleData = [1, 2, 3, 4];
64
- const result = sampleData.filter(skipEvery(2));
65
- const expected = [1, 3];
66
- expect(result).deep.equal(expected);
67
- });
68
-
69
- it('getPeaks', () => {
70
- const sampleData = [1, 2, 3, 4];
71
- const prevPeaks = [2, 2, 2, 5];
72
- const resultNoPrevPeaks = getPeaks(sampleData);
73
- expect(resultNoPrevPeaks).deep.equal(sampleData);
74
- const resultWithPrevPeaks = getPeaks(sampleData, prevPeaks);
75
- const expectedWithPrevPeaks = [2, 2, 3, 5];
76
- expect(resultWithPrevPeaks).deep.equal(expectedWithPrevPeaks);
77
- });
78
-
79
- it('correctPeaks', () => {
80
- const spectrums = [1, 2, 3, 4];
81
- const peaks = [2, 2, 3, 5];
82
- const result = correctPeaks(spectrums, peaks);
83
- const expected = [1 / 3, 2 / 3, 1, 0.8];
84
- expect(result).deep.equal(expected);
85
- });
86
-
87
-
88
- it('createSpectrumsProcessor', () => {
89
- const spectrumsProcessor = createSpectrumsProcessor(44100);
90
-
91
- const frame0 = spectrumsProcessor(() => ([1, 2, 3, 4]));
92
- expect(frame0).to.have.length(24);
93
- const frame1 = spectrumsProcessor(() => ([2, 2, 6, 2]));
94
- expect(frame1).to.have.length(24);
95
- });
96
- });
1
+ import { expect } from 'chai';
2
+ import { Readable, Writable, Pipe } from 'stream';
3
+ import child_process, { ChildProcessWithoutNullStreams } from 'child_process';
4
+ import {
5
+ bufferToUInt8,
6
+ normalizeAudioData,
7
+ spawnFfmpegAudioReader,
8
+ skipEvery,
9
+ getPeaks,
10
+ correctPeaks,
11
+ createSpectrumsProcessor,
12
+ } from '../audio';
13
+ import { createSandbox } from 'sinon';
14
+
15
+ let childProcessStream = {
16
+ stdin: new Writable(),
17
+ stderr: new Readable(),
18
+ };
19
+
20
+ const videoSandbox = createSandbox();
21
+
22
+ describe('audio', function () {
23
+
24
+ this.beforeAll(function () {
25
+ videoSandbox.stub(child_process, 'spawn').returns(childProcessStream as ChildProcessWithoutNullStreams);
26
+ });
27
+
28
+ this.afterAll(function () {
29
+ videoSandbox.restore();
30
+ });
31
+
32
+ it('bufferToUInt8', function () {
33
+ const expected = [1, 2, 3, 4, 5];
34
+ const buffer = Buffer.from(new Uint8Array(expected));
35
+ const result = bufferToUInt8(buffer, 0, 5);
36
+ expect(result).deep.equal(expected);
37
+ });
38
+
39
+ it('normalizeAudioData', function () {
40
+ const result = normalizeAudioData([4, 5, 23, 78, 2]);
41
+ const expected = [-0.96875, -0.9609375, -0.8203125, -0.390625, -0.984375];
42
+ expect(result).deep.equal(expected);
43
+ });
44
+
45
+ it('spawnFfmpegAudioReader', function (done) {
46
+ const childProcessReadableStream = new Readable();
47
+ const childProcessWritableStream = new Writable();
48
+ childProcessReadableStream._read = () => { done(); };
49
+ (<Pipe>childProcessWritableStream.pipe) = () => childProcessWritableStream;
50
+
51
+ childProcessStream.stdin = childProcessWritableStream;
52
+ childProcessStream.stderr = childProcessReadableStream;
53
+
54
+ const ffmpegProcess = spawnFfmpegAudioReader('filename', 'format');
55
+ ffmpegProcess.stderr.on('data', (data) => {
56
+ expect(data).equal('some data');
57
+ });
58
+
59
+ childProcessStream.stderr.emit('data', 'some data');
60
+ });
61
+
62
+ it('skipEvery', () => {
63
+ const sampleData = [1, 2, 3, 4];
64
+ const result = sampleData.filter(skipEvery(2));
65
+ const expected = [1, 3];
66
+ expect(result).deep.equal(expected);
67
+ });
68
+
69
+ it('getPeaks', () => {
70
+ const sampleData = [1, 2, 3, 4];
71
+ const prevPeaks = [2, 2, 2, 5];
72
+ const resultNoPrevPeaks = getPeaks(sampleData);
73
+ expect(resultNoPrevPeaks).deep.equal(sampleData);
74
+ const resultWithPrevPeaks = getPeaks(sampleData, prevPeaks);
75
+ const expectedWithPrevPeaks = [2, 2, 3, 5];
76
+ expect(resultWithPrevPeaks).deep.equal(expectedWithPrevPeaks);
77
+ });
78
+
79
+ it('correctPeaks', () => {
80
+ const spectrums = [1, 2, 3, 4];
81
+ const peaks = [2, 2, 3, 5];
82
+ const result = correctPeaks(spectrums, peaks);
83
+ const expected = [1 / 3, 2 / 3, 1, 0.8];
84
+ expect(result).deep.equal(expected);
85
+ });
86
+
87
+
88
+ it('createSpectrumsProcessor', () => {
89
+ const spectrumsProcessor = createSpectrumsProcessor(44100);
90
+
91
+ const frame0 = spectrumsProcessor(() => ([1, 2, 3, 4]));
92
+ expect(frame0).to.have.length(24);
93
+ const frame1 = spectrumsProcessor(() => ([2, 2, 6, 2]));
94
+ expect(frame1).to.have.length(24);
95
+ });
96
+ });