Passed
Branch master (4064de)
by Rafael S.
02:04 queued 40s
created

test/from-scratch/8bit-from-scratch.js   A

Complexity

Total Complexity 15
Complexity/F 1

Size

Lines of Code 113
Function Count 15

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 113
rs 10
wmc 15
mnd 0
bc 15
fnc 15
bpm 1
cpm 1
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B 8bit-from-scratch.js ➔ describe(ꞌcreate 8-bit wave files from scratchꞌ) 0 111 1
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('create 8-bit wave files from scratch', function() {
13
    
14
    let wavefile = require('../../index.js');
15
    let wav = new wavefile.WaveFile();
16
    wav.fromScratch(1, 48000, '8', [0, 255, 2, 3]);
17
18
    let fs = require('fs');
19
    fs.writeFileSync("./test/files/out/8-bit-48kHz-mono-fromScratch.wav", wav.toBytes());
20
21
    it('chunkId should be "RIFF"', function() {
22
        assert.equal(wav.chunkId, "RIFF");
23
    });
24
25
    it('format should be "WAVE"', function() {
26
        assert.equal(wav.format, "WAVE");
27
    });
28
29
    it('subChunk1Id should be "fmt "', function() {
30
        assert.equal(wav.subChunk1Id, "fmt ");
31
    });
32
33
    it('subChunk1Size should be 16', function() {
34
        assert.equal(wav.subChunk1Size, 16);
35
    });
36
37
    it('audioFormat should be 1', function() {
38
        assert.equal(wav.audioFormat, 1);
39
    });
40
41
    it('numChannels should be 1', function() {
42
        assert.equal(wav.numChannels, 1);
43
    });
44
45
    it('sampleRate should be 48000', function() {
46
        assert.equal(wav.sampleRate, 48000);
47
    });
48
49
    it('byteRate should be 48000', function() {
50
        assert.equal(wav.byteRate, 48000);
51
    });
52
53
    it('blockAlign should be 1', function() {
54
        assert.equal(wav.blockAlign, 1);
55
    });
56
57
    it('bitsPerSample should be 8', function() {
58
        assert.equal(wav.bitsPerSample, 8);
59
    });
60
61
    it('subChunk2Id should be "data"', function() {
62
        assert.equal(wav.subChunk2Id, "data");
63
    });
64
65
    it('subChunk2Size should be 4', function() {
66
        assert.equal(wav.subChunk2Size, 4);
67
    });
68
69
    it('samples_ should be the same as the args', function() {
70
        assert.deepEqual(wav.samples_, [0, 255, 2, 3]);
71
    });
72
73
    it('bitDepth_ should be "8"', function() {
74
        assert.equal(wav.bitDepth_, "8");
75
    });
76
77
    /*
78
    it('should return a 8-bit wave file with an odd number of samples',
79
            function() {
80
        let wav = rw64.writeWavBytes(1, 48000, '8', [0, 255, 2]);
81
        let wavRead = rw64.readWavBytes(wav);
82
83
        assert.equal(wavRead.audioFormat, 1);
84
        assert.equal(wavRead.numChannels, 1);
85
        assert.equal(wavRead.blockAlign, 1);
86
        assert.equal(wavRead.sampleRate, 48000);
87
        assert.equal(wavRead.bitsPerSample, 8);
88
        assert.deepEqual(wavRead.samples, [0, 255, 2]);
89
    });
90
91
    it('should write a 8-bit wav file with 1 Hz sample rate',
92
            function() {
93
        let samples = [0,1];
94
        let wav = rw64.writeWavBytes(1, 1, '8', samples);
95
        let read = rw64.readWavBytes(wav);
96
        
97
        assert.equal(read.subChunk1Size, 16);
98
        assert.equal(read.audioFormat, 1);
99
        assert.equal(read.numChannels, 1);
100
        assert.equal(read.sampleRate, 1);
101
        assert.equal(read.blockAlign, 1);
102
        assert.equal(read.bitsPerSample, 8);
103
    });
104
105
    it('should write a 8-bit stereo wav file', function() {
106
        let channels = [
107
            [0,1,2],
108
            [0,1,2]
109
        ];
110
        let samples = rw64.interleave(channels);
111
        let wav = rw64.writeWavBytes(2, 44100, '8', samples);
112
        let read = rw64.readWavBytes(wav);
113
        
114
        assert.equal(read.subChunk1Size, 16);
115
        assert.equal(read.audioFormat, 1);
116
        assert.equal(read.numChannels, 2);
117
        assert.equal(read.sampleRate, 44100);
118
        assert.equal(read.blockAlign, 2);
119
        assert.equal(read.bitsPerSample, 8);
120
    });
121
    */
122
});
123