Passed
Push — master ( 4064de...2105e3 )
by Rafael S.
01:24
created

interleave.js ➔ ... ➔ it(ꞌshould interleave the samples of a 3-channel wave fileꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 12
rs 9.4285
1
/*!
2
 * riffwave64
3
 * Read & write wave files with 8, 16, 24, 32 PCM, 32 IEEE & 64-bit data.
4
 * Copyright (c) 2017 Rafael da Silva Rocha.
5
 * https://github.com/rochars/riffwave64
6
 * https://tr2099.github.io
7
 *
8
 */
9
10
var assert = require('assert');
11
12
describe('interleave', function() {
13
    
14
    let wavefile = require('../index.js');    
15
16
    it('should interleave the samples of a 2-channel wave file',
17
            function() {
18
        let wav = new wavefile.WaveFile();
19
        let stereoSamples = [
20
            [0, -2, 4, 3],
21
            [0, -1, 4, 3]
22
        ];
23
        wav.fromScratch(2, 48000, '8', stereoSamples);
24
        wav.interleave();
25
        let expected = [0, 0, -2, -1, 4, 4, 3, 3];
26
        assert.deepEqual(wav.samples_, expected);
27
    });
28
29
    it('should de-interleave the samples of a 2-channel wave file',
30
            function() {
31
        let wav = new wavefile.WaveFile();
32
        let samples = [0, 0, -2, -1, 4, 4, 3, 3];
33
        wav.fromScratch(1, 48000, '8', samples);
34
        wav.numChannels = 2;
35
        wav.deInterleave();
36
        let expected = [
37
            [0, -2, 4, 3],
38
            [0, -1, 4, 3]
39
        ];
40
        assert.deepEqual(wav.samples_, expected);
41
    });
42
43
    it('should interleave the samples of a 3-channel wave file',
44
            function() {
45
        let wav = new wavefile.WaveFile();
46
        let stereoSamples = [
47
            [0, -2, 4, 3],
48
            [0, -1, 4, 3],
49
            [0, -1, 5, 3]
50
        ];
51
        wav.fromScratch(2, 48000, '8', stereoSamples);
52
        wav.interleave();
53
        let expected = [0, 0, 0, -2, -1, -1, 4, 4, 5, 3, 3, 3];
54
        assert.deepEqual(wav.samples_, expected);
55
    });
56
57
    it('should de-interleave the samples of a 3-channel wave file',
58
            function() {
59
        let wav = new wavefile.WaveFile();
60
        let samples = [0, 0, 0, -2, -1, -1, 4, 4, 5, 3, 3, 3];
61
        wav.fromScratch(1, 48000, '8', samples);
62
        wav.numChannels = 3;
63
        wav.deInterleave();
64
        let expected = [
65
            [0, -2, 4, 3],
66
            [0, -1, 4, 3],
67
            [0, -1, 5, 3]
68
        ];
69
        assert.deepEqual(wav.samples_, expected);
70
    });
71
72
    /*
73
    it('should de-interleave the samples of a 2-channel wave file',
74
            function() {
75
        let samples = [0, 0, -2, -1, 4, 4, 3, 3];
76
        let expected = [
77
            [0, -2, 4, 3],
78
            [0, -1, 4, 3]
79
        ];
80
        let deIntervealedSamples = rw64.deInterleave(samples, 2);
81
        assert.deepEqual(deIntervealedSamples, expected);
82
    });
83
84
    it('should interleave and de-interleave the samples ' +
85
        'of a 2-channel wave file', function() {
86
        let buffer = [
87
            [0, -2, 4, 3],
88
            [0, -1, 4, 3]
89
        ];
90
        let samples = rw64.interleave(buffer);
91
        let samples2 = rw64.deInterleave(samples, buffer.length);
92
93
        assert.deepEqual(samples2, buffer);
94
    });
95
96
    it('should interleave and de-interleave the samples ' +
97
        'of a 3-channel wave file', function() {
98
        let buffer = [
99
            [0, -2, 4, 3],
100
            [0, -1, 4, 3],
101
            [0, -1, 5, 3]
102
        ];
103
        let samples = rw64.interleave(buffer);
104
        let samples2 = rw64.deInterleave(samples, buffer.length);
105
106
        assert.deepEqual(samples2, buffer);
107
    });
108
109
    it('should write a two channel file and then read ' +
110
        'and de-interleave the samples', function() {
111
        let buffer = [
112
            [0, -2, 4, 3],
113
            [0, -1, 4, 3]
114
        ];
115
        let samples = rw64.interleave(buffer);
116
        let wav = rw64.writeWavBytes(2, 48000, '16', samples);
117
        let wavRead = rw64.readWavBytes(wav);
118
119
        assert.equal(wavRead.numChannels, 2);
120
121
        let samples2 = rw64.deInterleave(
122
            wavRead.samples, wavRead.numChannels);
123
124
        assert.deepEqual(samples2, buffer);
125
    });
126
    */
127
});
128