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
|
|
View Code Duplication |
var assert = require('assert'); |
|
|
|
|
11
|
|
|
|
12
|
|
|
describe('create 64-bit wave file from scratch', function() { |
13
|
|
|
|
14
|
|
|
let wavefile = require('../../index.js'); |
15
|
|
|
let wav = new wavefile.WaveFile(); |
16
|
|
|
wav.fromScratch(1, 44100, '64', [0.0, 0.04029440055111987, -0.04029440055111987, 1.0]); |
17
|
|
|
|
18
|
|
|
let fs = require('fs'); |
19
|
|
|
fs.writeFileSync("./test/files/out/64-bit-441kHz-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 3', function() { |
38
|
|
|
assert.equal(wav.audioFormat, 3); |
39
|
|
|
}); |
40
|
|
|
|
41
|
|
|
it('numChannels should be 1', function() { |
42
|
|
|
assert.equal(wav.numChannels, 1); |
43
|
|
|
}); |
44
|
|
|
|
45
|
|
|
it('sampleRate should be 44100', function() { |
46
|
|
|
assert.equal(wav.sampleRate, 44100); |
47
|
|
|
}); |
48
|
|
|
|
49
|
|
|
it('byteRate should be 176400', function() { |
50
|
|
|
assert.equal(wav.byteRate, 352800); |
51
|
|
|
}); |
52
|
|
|
|
53
|
|
|
it('blockAlign should be 4', function() { |
54
|
|
|
assert.equal(wav.blockAlign, 8); |
55
|
|
|
}); |
56
|
|
|
|
57
|
|
|
it('bitsPerSample should be 32', function() { |
58
|
|
|
assert.equal(wav.bitsPerSample, 64); |
59
|
|
|
}); |
60
|
|
|
|
61
|
|
|
it('subChunk2Id should be "data"', function() { |
62
|
|
|
assert.equal(wav.subChunk2Id, "data"); |
63
|
|
|
}); |
64
|
|
|
|
65
|
|
|
it('subChunk2Size should be 16', function() { |
66
|
|
|
assert.equal(wav.subChunk2Size, 32); |
67
|
|
|
}); |
68
|
|
|
|
69
|
|
|
it('samples_ should be the same as the args', function() { |
70
|
|
|
assert.deepEqual(wav.samples_, [0.0, 0.04029440055111987, -0.04029440055111987, 1.0]); |
71
|
|
|
}); |
72
|
|
|
|
73
|
|
|
it('bitDepth_ should be "24"', function() { |
74
|
|
|
assert.equal(wav.bitDepth_, "64"); |
75
|
|
|
}); |
76
|
|
|
|
77
|
|
|
/* |
78
|
|
|
it('should return a wave file with 64-bit audio', function() { |
79
|
|
|
let wav = rw64.writeWavBytes(1, 48000, '64', |
80
|
|
|
[0.0, 0.04029440055111987, -0.04029440055111987, 1.0]); |
81
|
|
|
let wavRead = rw64.readWavBytes(wav); |
82
|
|
|
|
83
|
|
|
assert.equal(wavRead.audioFormat, 3); |
84
|
|
|
assert.equal(wavRead.numChannels, 1); |
85
|
|
|
assert.equal(wavRead.sampleRate, 48000); |
86
|
|
|
assert.equal(wavRead.blockAlign, 8); |
87
|
|
|
assert.equal(wavRead.bitsPerSample, 64); |
88
|
|
|
assert.deepEqual(wavRead.samples, |
89
|
|
|
[0.0, 0.04029440055111987, -0.04029440055111987, 1.0]); |
90
|
|
|
}); |
91
|
|
|
|
92
|
|
|
it('should return a wave file with 64-bit ' + |
93
|
|
|
'audio and a odd number of samples', |
94
|
|
|
function() { |
95
|
|
|
let wav = rw64.writeWavBytes(1, 48000, '64', |
96
|
|
|
[0.0, 0.04029440055111987, -0.04029440055111987, 1.0, 1]); |
97
|
|
|
let wavRead = rw64.readWavBytes(wav); |
98
|
|
|
|
99
|
|
|
assert.equal(wavRead.audioFormat, 3); |
100
|
|
|
assert.equal(wavRead.numChannels, 1); |
101
|
|
|
assert.equal(wavRead.sampleRate, 48000); |
102
|
|
|
assert.equal(wavRead.blockAlign, 8); |
103
|
|
|
assert.equal(wavRead.bitsPerSample, 64); |
104
|
|
|
assert.deepEqual(wavRead.samples, |
105
|
|
|
[0.0, 0.04029440055111987, -0.04029440055111987, 1, 1]); |
106
|
|
|
}); |
107
|
|
|
|
108
|
|
|
it('check rouding for double values on read/write', |
109
|
|
|
function() { |
110
|
|
|
let wav = rw64.writeWavBytes(1, 48000, '64', |
111
|
|
|
[3.141592653589793]); |
112
|
|
|
let wavRead = rw64.readWavBytes(wav); |
113
|
|
|
|
114
|
|
|
assert.ok(wavRead.samples[0] == |
115
|
|
|
3.141592653589793); |
116
|
|
|
|
117
|
|
|
}); |
118
|
|
|
|
119
|
|
|
it('check rouding for double values on read/write (forced change)', |
120
|
|
|
function() { |
121
|
|
|
let wav = rw64.writeWavBytes(1, 48000, '64', |
122
|
|
|
[3.141592653589793]); |
123
|
|
|
let wavRead = rw64.readWavBytes(wav); |
124
|
|
|
|
125
|
|
|
assert.ok(wavRead.samples[0] != |
126
|
|
|
3.141592653589792); |
127
|
|
|
}); |
128
|
|
|
|
129
|
|
|
it('should return a wave file with 64-bit audio on max and min range', |
130
|
|
|
function() { |
131
|
|
|
let wav = rw64.writeWavBytes(1, 48000, '64', [0,1,0,-1]); |
132
|
|
|
let wavRead = rw64.readWavBytes(wav); |
133
|
|
|
|
134
|
|
|
assert.equal(wavRead.audioFormat, 3); |
135
|
|
|
assert.equal(wavRead.numChannels, 1); |
136
|
|
|
assert.equal(wavRead.sampleRate, 48000); |
137
|
|
|
assert.equal(wavRead.blockAlign, 8); |
138
|
|
|
assert.equal(wavRead.bitsPerSample, 64); |
139
|
|
|
assert.deepEqual(wavRead.samples, [0,1,0,-1]); |
140
|
|
|
}); |
141
|
|
|
|
142
|
|
|
it('should return another wave file with 64-bit audio', function() { |
143
|
|
|
let wav = rw64.writeWavBytes(1, 48000, '64', |
144
|
|
|
[0.0, 0.99999999999999999, -0.00000000000000001, 1]); |
145
|
|
|
let wavRead = rw64.readWavBytes(wav); |
146
|
|
|
|
147
|
|
|
assert.equal(wavRead.audioFormat, 3); |
148
|
|
|
assert.equal(wavRead.numChannels, 1); |
149
|
|
|
assert.equal(wavRead.sampleRate, 48000); |
150
|
|
|
assert.equal(wavRead.blockAlign, 8); |
151
|
|
|
assert.equal(wavRead.bitsPerSample, 64); |
152
|
|
|
assert.deepEqual(wavRead.samples, |
153
|
|
|
[0, 0.99999999999999999, -0.00000000000000001, 1]); |
154
|
|
|
}); |
155
|
|
|
|
156
|
|
|
it('should return one more wave file with 64-bit audio', function() { |
157
|
|
|
let wav = rw64.writeWavBytes(1, 48000, '64', |
158
|
|
|
[0, 1, 1, -1, 0, -1, 0.99999999999999999, |
159
|
|
|
-0.00000000000000001, 1]); |
160
|
|
|
let wavRead = rw64.readWavBytes(wav); |
161
|
|
|
|
162
|
|
|
assert.equal(wavRead.audioFormat, 3); |
163
|
|
|
assert.equal(wavRead.numChannels, 1); |
164
|
|
|
assert.equal(wavRead.sampleRate, 48000); |
165
|
|
|
assert.equal(wavRead.blockAlign, 8); |
166
|
|
|
assert.equal(wavRead.bitsPerSample, 64); |
167
|
|
|
assert.deepEqual(wavRead.samples, |
168
|
|
|
[0, 1, 1, -1, 0, -1, 0.99999999999999999, |
169
|
|
|
-0.00000000000000001, 1]); |
170
|
|
|
}); |
171
|
|
|
|
172
|
|
|
it('should return a 64-bit wave file encoded as a base 64 string', |
173
|
|
|
function() { |
174
|
|
|
assert.ok(rw64.writeWavBase64(1, 48000, '64', |
175
|
|
|
[0, 0.5, -0.5])); |
176
|
|
|
}); |
177
|
|
|
|
178
|
|
|
it('should return a 64-bit wave file encoded as a Data URI', |
179
|
|
|
function() { |
180
|
|
|
assert.ok(rw64.writeWavDataURI(1, 48000, '64', |
181
|
|
|
[0, 0.5, -0.5])); |
182
|
|
|
}); |
183
|
|
|
|
184
|
|
|
it('should return another 64-bit wave file encoded as a Data URI', |
185
|
|
|
function() { |
186
|
|
|
assert.ok(rw64.writeWavDataURI(1, 48000, '64', |
187
|
|
|
[0, 1, -1, 0, 1])); |
188
|
|
|
}); |
189
|
|
|
|
190
|
|
|
it('should write a 64-bit stereo wav file', function() { |
191
|
|
|
let channels = [ |
192
|
|
|
[0,1,-1], |
193
|
|
|
[0,1,-1] |
194
|
|
|
]; |
195
|
|
|
let samples = rw64.interleave(channels); |
196
|
|
|
let wav = rw64.writeWavBytes(2, 44100, '64', samples); |
197
|
|
|
let read = rw64.readWavBytes(wav); |
198
|
|
|
|
199
|
|
|
assert.equal(read.subChunk1Size, 16); |
200
|
|
|
assert.equal(read.audioFormat, 3); |
201
|
|
|
assert.equal(read.numChannels, 2); |
202
|
|
|
assert.equal(read.sampleRate, 44100); |
203
|
|
|
assert.equal(read.blockAlign, 16); |
204
|
|
|
assert.equal(read.bitsPerSample, 64); |
205
|
|
|
}); |
206
|
|
|
|
207
|
|
|
it('should return a 64-bit wave file with non-negative 0', |
208
|
|
|
function() { |
209
|
|
|
let wav = rw64.writeWavBytes(1, 48000, '64', [0, 1, -1, -0, 1]); |
210
|
|
|
let wavRead = rw64.readWavBytes(wav); |
211
|
|
|
assert.equal(wavRead.audioFormat, 3); |
212
|
|
|
assert.equal(wavRead.numChannels, 1); |
213
|
|
|
assert.equal(wavRead.sampleRate, 48000); |
214
|
|
|
assert.equal(wavRead.blockAlign, 8); |
215
|
|
|
assert.equal(wavRead.bitsPerSample, 64); |
216
|
|
|
assert.deepEqual(wavRead.samples, [0, 1, -1, 0, 1]); |
217
|
|
|
}); |
218
|
|
|
*/ |
219
|
|
|
}); |
220
|
|
|
|