|
1
|
|
|
/** |
|
2
|
|
|
* @fileoverview Externs for wavefile 8.0 |
|
3
|
|
|
* |
|
4
|
|
|
* @see https://github.com/rochars/wavefile |
|
5
|
|
|
* @externs |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
var WaveFile; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Set up the WaveFile object based on the arguments passed. |
|
12
|
|
|
* @param {number} numChannels The number of channels |
|
13
|
|
|
* (Integer numbers: 1 for mono, 2 stereo and so on). |
|
14
|
|
|
* @param {number} sampleRate The sample rate. |
|
15
|
|
|
* Integer numbers like 8000, 44100, 48000, 96000, 192000. |
|
16
|
|
|
* @param {string} bitDepth The audio bit depth code. |
|
17
|
|
|
* One of "4", "8", "8a", "8m", "16", "24", "32", "32f", "64" |
|
18
|
|
|
* or any value between "8" and "32" (like "12"). |
|
19
|
|
|
* @param {!Array<number>} samples Array of samples to be written. |
|
20
|
|
|
* The samples must be in the correct range according to the |
|
21
|
|
|
* bit depth. |
|
22
|
|
|
* @param {?Object} options Optional. Used to force the container |
|
23
|
|
|
* as RIFX with {"container": "RIFX"} |
|
24
|
|
|
* @throws {Error} If any argument does not meet the criteria. |
|
25
|
|
|
*/ |
|
26
|
|
|
WaveFile.fromScratch = function(numChannels, sampleRate, bitDepth, samples, options={}) {} |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Set up the WaveFile object from a byte buffer. |
|
30
|
|
|
* @param {!Uint8Array} bytes The buffer. |
|
31
|
|
|
* @param {boolean=} samples True if the samples should be loaded. |
|
32
|
|
|
* @throws {Error} If container is not RIFF, RIFX or RF64. |
|
33
|
|
|
* @throws {Error} If no "fmt " chunk is found. |
|
34
|
|
|
* @throws {Error} If no "data" chunk is found. |
|
35
|
|
|
*/ |
|
36
|
|
|
WaveFile.fromBuffer = function(bytes, samples=true) {} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Return a byte buffer representig the WaveFile object as a .wav file. |
|
40
|
|
|
* The return value of this method can be written straight to disk. |
|
41
|
|
|
* @return {!Uint8Array} A .wav file. |
|
42
|
|
|
* @throws {Error} If any property of the object appears invalid. |
|
43
|
|
|
*/ |
|
44
|
|
|
WaveFile.toBuffer = function() {} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Use a .wav file encoded as a base64 string to load the WaveFile object. |
|
48
|
|
|
* @param {string} base64String A .wav file as a base64 string. |
|
49
|
|
|
* @throws {Error} If any property of the object appears invalid. |
|
50
|
|
|
*/ |
|
51
|
|
|
WaveFile.fromBase64 = function(base64String) {} |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Return a base64 string representig the WaveFile object as a .wav file. |
|
55
|
|
|
* @return {string} A .wav file as a base64 string. |
|
56
|
|
|
* @throws {Error} If any property of the object appears invalid. |
|
57
|
|
|
*/ |
|
58
|
|
|
WaveFile.toBase64 = function() {} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Return a DataURI string representig the WaveFile object as a .wav file. |
|
62
|
|
|
* The return of this method can be used to load the audio in browsers. |
|
63
|
|
|
* @return {string} A .wav file as a DataURI. |
|
64
|
|
|
* @throws {Error} If any property of the object appears invalid. |
|
65
|
|
|
*/ |
|
66
|
|
|
WaveFile.toDataURI = function() {} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Use a .wav file encoded as a DataURI to load the WaveFile object. |
|
70
|
|
|
* @param {string} dataURI A .wav file as DataURI. |
|
71
|
|
|
* @throws {Error} If any property of the object appears invalid. |
|
72
|
|
|
*/ |
|
73
|
|
|
WaveFile.fromDataURI = function(dataURI) {} |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Force a file as RIFF. |
|
77
|
|
|
*/ |
|
78
|
|
|
WaveFile.toRIFF = function() {} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Force a file as RIFX. |
|
82
|
|
|
*/ |
|
83
|
|
|
WaveFile.toRIFX = function() {} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Change the bit depth of the samples. |
|
87
|
|
|
* @param {string} bitDepth The new bit depth of the samples. |
|
88
|
|
|
* One of "8" ... "32" (integers), "32f" or "64" (floats) |
|
89
|
|
|
* @param {boolean} changeResolution A boolean indicating if the |
|
90
|
|
|
* resolution of samples should be actually changed or not. |
|
91
|
|
|
* @throws {Error} If the bit depth is not valid. |
|
92
|
|
|
*/ |
|
93
|
|
|
WaveFile.toBitDepth = function(bitDepth, changeResolution=true) {} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Encode a 16-bit wave file as 4-bit IMA ADPCM. |
|
97
|
|
|
* @throws {Error} If sample rate is not 8000. |
|
98
|
|
|
* @throws {Error} If number of channels is not 1. |
|
99
|
|
|
*/ |
|
100
|
|
|
WaveFile.toIMAADPCM = function() {} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Decode a 4-bit IMA ADPCM wave file as a 16-bit wave file. |
|
104
|
|
|
* @param {string} bitDepth The new bit depth of the samples. |
|
105
|
|
|
* One of "8" ... "32" (integers), "32f" or "64" (floats). |
|
106
|
|
|
* Optional. Default is 16. |
|
107
|
|
|
*/ |
|
108
|
|
|
WaveFile.fromIMAADPCM = function(bitDepth="16") {} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Encode 16-bit wave file as 8-bit A-Law. |
|
112
|
|
|
*/ |
|
113
|
|
|
WaveFile.toALaw = function() {} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Decode a 8-bit A-Law wave file into a 16-bit wave file. |
|
117
|
|
|
* @param {string} bitDepth The new bit depth of the samples. |
|
118
|
|
|
* One of "8" ... "32" (integers), "32f" or "64" (floats). |
|
119
|
|
|
* Optional. Default is 16. |
|
120
|
|
|
*/ |
|
121
|
|
|
WaveFile.fromALaw = function(bitDepth="16") {} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Encode 16-bit wave file as 8-bit mu-Law. |
|
125
|
|
|
*/ |
|
126
|
|
|
WaveFile.toMuLaw = function() {} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Decode a 8-bit mu-Law wave file into a 16-bit wave file. |
|
130
|
|
|
* @param {string} bitDepth The new bit depth of the samples. |
|
131
|
|
|
* One of "8" ... "32" (integers), "32f" or "64" (floats). |
|
132
|
|
|
* Optional. Default is 16. |
|
133
|
|
|
*/ |
|
134
|
|
|
WaveFile.fromMuLaw = function(bitDepth="16") {} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Write a RIFF tag in the INFO chunk. If the tag do not exist, |
|
138
|
|
|
* then it is created. It if exists, it is overwritten. |
|
139
|
|
|
* @param {string} tag The tag name. |
|
140
|
|
|
* @param {string} value The tag value. |
|
141
|
|
|
* @throws {Error} If the tag name is not valid. |
|
142
|
|
|
*/ |
|
143
|
|
|
WaveFile.setTag = function(tag, value) {} |
|
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Return the value of a RIFF tag in the INFO chunk. |
|
147
|
|
|
* @param {string} tag The tag name. |
|
148
|
|
|
* @return {?string} The value if the tag is found, null otherwise. |
|
149
|
|
|
*/ |
|
150
|
|
|
WaveFile.getTag = function(tag) {} |
|
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Remove a RIFF tag in the INFO chunk. |
|
154
|
|
|
* @param {string} tag The tag name. |
|
155
|
|
|
* @return {boolean} True if a tag was deleted. |
|
156
|
|
|
*/ |
|
157
|
|
|
WaveFile.deleteTag = function(tag) {} |
|
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Create a cue point in the wave file. |
|
161
|
|
|
* @param {number} position The cue point position in milliseconds. |
|
162
|
|
|
* @param {string} labl The LIST adtl labl text of the marker. Optional. |
|
163
|
|
|
*/ |
|
164
|
|
|
WaveFile.setCuePoint = function(position, labl="") {} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Remove a cue point from a wave file. |
|
168
|
|
|
* @param {number} index the index of the point. First is 1, |
|
169
|
|
|
* second is 2, and so on. |
|
170
|
|
|
*/ |
|
171
|
|
|
WaveFile.deleteCuePoint = function(index) {} |
|
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Update the label of a cue point. |
|
175
|
|
|
* @param {number} pointIndex The ID of the cue point. |
|
176
|
|
|
* @param {string} label The new text for the label. |
|
177
|
|
|
*/ |
|
178
|
|
|
WaveFile.updateLabel = function(pointIndex, label) {} |
|
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* The container identifier. |
|
182
|
|
|
* "RIFF", "RIFX" and "RF64" are supported. |
|
183
|
|
|
* @type {string} |
|
184
|
|
|
*/ |
|
185
|
|
|
WaveFile.container = ""; |
|
186
|
|
|
/** |
|
187
|
|
|
* @type {number} |
|
188
|
|
|
*/ |
|
189
|
|
|
WaveFile.chunkSize = 0; |
|
190
|
|
|
/** |
|
191
|
|
|
* The format. |
|
192
|
|
|
* Always "WAVE". |
|
193
|
|
|
* @type {string} |
|
194
|
|
|
*/ |
|
195
|
|
|
WaveFile.format = ""; |
|
196
|
|
|
/** |
|
197
|
|
|
* The data of the "fmt" chunk. |
|
198
|
|
|
* @type {!Object<string, *>} |
|
199
|
|
|
*/ |
|
200
|
|
|
WaveFile.fmt = { |
|
201
|
|
|
/** @export @type {string} */ |
|
202
|
|
|
"chunkId": "", |
|
203
|
|
|
/** @export @type {number} */ |
|
204
|
|
|
"chunkSize": 0, |
|
205
|
|
|
/** @export @type {number} */ |
|
206
|
|
|
"audioFormat": 0, |
|
207
|
|
|
/** @export @type {number} */ |
|
208
|
|
|
"numChannels": 0, |
|
209
|
|
|
/** @export @type {number} */ |
|
210
|
|
|
"sampleRate": 0, |
|
211
|
|
|
/** @export @type {number} */ |
|
212
|
|
|
"byteRate": 0, |
|
213
|
|
|
/** @export @type {number} */ |
|
214
|
|
|
"blockAlign": 0, |
|
215
|
|
|
/** @export @type {number} */ |
|
216
|
|
|
"bitsPerSample": 0, |
|
217
|
|
|
/** @export @type {number} */ |
|
218
|
|
|
"cbSize": 0, |
|
219
|
|
|
/** @export @type {number} */ |
|
220
|
|
|
"validBitsPerSample": 0, |
|
221
|
|
|
/** @export @type {number} */ |
|
222
|
|
|
"dwChannelMask": 0, |
|
223
|
|
|
/** |
|
224
|
|
|
* 4 32-bit values representing a 128-bit ID |
|
225
|
|
|
* @export @type {!Array<number>} |
|
226
|
|
|
*/ |
|
227
|
|
|
"subformat": [] |
|
228
|
|
|
}; |
|
229
|
|
|
/** |
|
230
|
|
|
* The data of the "fact" chunk. |
|
231
|
|
|
* @type {!Object<string, *>} |
|
232
|
|
|
*/ |
|
233
|
|
|
WaveFile.fact = { |
|
234
|
|
|
/** @export @type {string} */ |
|
235
|
|
|
"chunkId": "", |
|
236
|
|
|
/** @export @type {number} */ |
|
237
|
|
|
"chunkSize": 0, |
|
238
|
|
|
/** @export @type {number} */ |
|
239
|
|
|
"dwSampleLength": 0 |
|
240
|
|
|
}; |
|
241
|
|
|
/** |
|
242
|
|
|
* The data of the "cue " chunk. |
|
243
|
|
|
* @type {!Object<string, *>} |
|
244
|
|
|
*/ |
|
245
|
|
|
WaveFile.cue = { |
|
246
|
|
|
/** @export @type {string} */ |
|
247
|
|
|
"chunkId": "", |
|
248
|
|
|
/** @export @type {number} */ |
|
249
|
|
|
"chunkSize": 0, |
|
250
|
|
|
/** @export @type {number} */ |
|
251
|
|
|
"dwCuePoints": 0, |
|
252
|
|
|
/** @export @type {!Array<!Object>} */ |
|
253
|
|
|
"points": [], |
|
254
|
|
|
}; |
|
255
|
|
|
/** |
|
256
|
|
|
* The data of the "smpl" chunk. |
|
257
|
|
|
* @type {!Object<string, *>} |
|
258
|
|
|
*/ |
|
259
|
|
|
WaveFile.smpl = { |
|
260
|
|
|
/** @export @type {string} */ |
|
261
|
|
|
"chunkId": "", |
|
262
|
|
|
/** @export @type {number} */ |
|
263
|
|
|
"chunkSize": 0, |
|
264
|
|
|
/** @export @type {number} */ |
|
265
|
|
|
"dwManufacturer": 0, |
|
266
|
|
|
/** @export @type {number} */ |
|
267
|
|
|
"dwProduct": 0, |
|
268
|
|
|
/** @export @type {number} */ |
|
269
|
|
|
"dwSamplePeriod": 0, |
|
270
|
|
|
/** @export @type {number} */ |
|
271
|
|
|
"dwMIDIUnityNote": 0, |
|
272
|
|
|
/** @export @type {number} */ |
|
273
|
|
|
"dwMIDIPitchFraction": 0, |
|
274
|
|
|
/** @export @type {number} */ |
|
275
|
|
|
"dwSMPTEFormat": 0, |
|
276
|
|
|
/** @export @type {number} */ |
|
277
|
|
|
"dwSMPTEOffset": 0, |
|
278
|
|
|
/** @export @type {number} */ |
|
279
|
|
|
"dwNumSampleLoops": 0, |
|
280
|
|
|
/** @export @type {number} */ |
|
281
|
|
|
"dwSamplerData": 0, |
|
282
|
|
|
/** @export @type {!Array<!Object>} */ |
|
283
|
|
|
"loops": [], |
|
284
|
|
|
}; |
|
285
|
|
|
/** |
|
286
|
|
|
* The data of the "bext" chunk. |
|
287
|
|
|
* @type {!Object<string, *>} |
|
288
|
|
|
*/ |
|
289
|
|
|
WaveFile.bext = { |
|
290
|
|
|
/** @export @type {string} */ |
|
291
|
|
|
"chunkId": "", |
|
292
|
|
|
/** @export @type {number} */ |
|
293
|
|
|
"chunkSize": 0, |
|
294
|
|
|
/** @export @type {string} */ |
|
295
|
|
|
"description": "", //256 |
|
296
|
|
|
/** @export @type {string} */ |
|
297
|
|
|
"originator": "", //32 |
|
298
|
|
|
/** @export @type {string} */ |
|
299
|
|
|
"originatorReference": "", //32 |
|
300
|
|
|
/** @export @type {string} */ |
|
301
|
|
|
"originationDate": "", //10 |
|
302
|
|
|
/** @export @type {string} */ |
|
303
|
|
|
"originationTime": "", //8 |
|
304
|
|
|
/** |
|
305
|
|
|
* 2 32-bit values, timeReference high and low |
|
306
|
|
|
* @export @type {!Array<number>} |
|
307
|
|
|
*/ |
|
308
|
|
|
"timeReference": [0, 0], |
|
309
|
|
|
/** @export @type {number} */ |
|
310
|
|
|
"version": 0, //WORD |
|
311
|
|
|
/** @export @type {string} */ |
|
312
|
|
|
"UMID": "", // 64 chars |
|
313
|
|
|
/** @export @type {number} */ |
|
314
|
|
|
"loudnessValue": 0, //WORD |
|
315
|
|
|
/** @export @type {number} */ |
|
316
|
|
|
"loudnessRange": 0, //WORD |
|
317
|
|
|
/** @export @type {number} */ |
|
318
|
|
|
"maxTruePeakLevel": 0, //WORD |
|
319
|
|
|
/** @export @type {number} */ |
|
320
|
|
|
"maxMomentaryLoudness": 0, //WORD |
|
321
|
|
|
/** @export @type {number} */ |
|
322
|
|
|
"maxShortTermLoudness": 0, //WORD |
|
323
|
|
|
/** @export @type {string} */ |
|
324
|
|
|
"reserved": "", //180 |
|
325
|
|
|
/** @export @type {string} */ |
|
326
|
|
|
"codingHistory": "" // string, unlimited |
|
327
|
|
|
}; |
|
328
|
|
|
/** |
|
329
|
|
|
* The data of the "ds64" chunk. |
|
330
|
|
|
* Used only with RF64 files. |
|
331
|
|
|
* @type {!Object<string, *>} |
|
332
|
|
|
*/ |
|
333
|
|
|
WaveFile.ds64 = { |
|
334
|
|
|
/** @type {string} */ |
|
335
|
|
|
"chunkId": "", |
|
336
|
|
|
/** @export @type {number} */ |
|
337
|
|
|
"chunkSize": 0, |
|
338
|
|
|
/** @export @type {number} */ |
|
339
|
|
|
"riffSizeHigh": 0, // DWORD |
|
340
|
|
|
/** @export @type {number} */ |
|
341
|
|
|
"riffSizeLow": 0, // DWORD |
|
342
|
|
|
/** @export @type {number} */ |
|
343
|
|
|
"dataSizeHigh": 0, // DWORD |
|
344
|
|
|
/** @export @type {number} */ |
|
345
|
|
|
"dataSizeLow": 0, // DWORD |
|
346
|
|
|
/** @export @type {number} */ |
|
347
|
|
|
"originationTime": 0, // DWORD |
|
348
|
|
|
/** @export @type {number} */ |
|
349
|
|
|
"sampleCountHigh": 0, // DWORD |
|
350
|
|
|
/** @export @type {number} */ |
|
351
|
|
|
"sampleCountLow": 0, // DWORD |
|
352
|
|
|
/** @export @type {number} */ |
|
353
|
|
|
//"tableLength": 0, // DWORD |
|
354
|
|
|
/** @export @type {!Array<number>} */ |
|
355
|
|
|
//"table": [] |
|
356
|
|
|
}; |
|
357
|
|
|
/** |
|
358
|
|
|
* The data of the "data" chunk. |
|
359
|
|
|
* @type {!Object<string, *>} |
|
360
|
|
|
*/ |
|
361
|
|
|
WaveFile.data = { |
|
362
|
|
|
/** @export @type {string} */ |
|
363
|
|
|
"chunkId": "", |
|
364
|
|
|
/** @export @type {number} */ |
|
365
|
|
|
"chunkSize": 0, |
|
366
|
|
|
/** @export @type {!Array<number>} */ |
|
367
|
|
|
"samples": [] |
|
368
|
|
|
}; |
|
369
|
|
|
/** |
|
370
|
|
|
* The data of the "LIST" chunks. |
|
371
|
|
|
* Each item in this list must have this signature: |
|
372
|
|
|
* { |
|
373
|
|
|
* "chunkId": "", |
|
374
|
|
|
* "chunkSize": 0, |
|
375
|
|
|
* "format": "", |
|
376
|
|
|
* "subChunks": [] |
|
377
|
|
|
* } |
|
378
|
|
|
* @type {!Array<!Object>} |
|
379
|
|
|
*/ |
|
380
|
|
|
WaveFile.LIST = []; |
|
381
|
|
|
/** |
|
382
|
|
|
* The data of the "junk" chunk. |
|
383
|
|
|
* @type {!Object<string, *>} |
|
384
|
|
|
*/ |
|
385
|
|
|
WaveFile.junk = { |
|
386
|
|
|
/** @export @type {string} */ |
|
387
|
|
|
"chunkId": "", |
|
388
|
|
|
/** @export @type {number} */ |
|
389
|
|
|
"chunkSize": 0, |
|
390
|
|
|
/** @export @type {!Array<number>} */ |
|
391
|
|
|
"chunkData": [] |
|
392
|
|
|
}; |
|
393
|
|
|
/** |
|
394
|
|
|
* The bit depth code according to the samples. |
|
395
|
|
|
* @type {string} |
|
396
|
|
|
*/ |
|
397
|
|
|
WaveFile.bitDepth = ""; |
|
398
|
|
|
|