1
|
|
|
// Type definitions for wavefile 9.0 |
2
|
|
|
// Project: https://github.com/rochars/wavefile |
3
|
|
|
// Definitions by: Rafael da Silva Rocha <https://github.com/rochars> |
4
|
|
|
// Definitions: https://github.com/rochars/wavefile |
5
|
|
|
|
6
|
|
|
export = wavefile; |
7
|
|
|
|
8
|
|
|
declare module wavefile { |
9
|
|
|
|
10
|
|
|
class WaveFile { |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @param {?Uint8Array=} bytes A wave file buffer. |
14
|
|
|
* @throws {Error} If no 'RIFF' chunk is found. |
15
|
|
|
* @throws {Error} If no 'fmt ' chunk is found. |
16
|
|
|
* @throws {Error} If no 'data' chunk is found. |
17
|
|
|
*/ |
18
|
|
|
constructor(bytes?: Uint8Array); |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The bit depth code according to the samples. |
22
|
|
|
* @type {string} |
23
|
|
|
*/ |
24
|
|
|
bitDepth: string; |
25
|
|
|
/** |
26
|
|
|
* The container identifier. |
27
|
|
|
* 'RIFF', 'RIFX' and 'RF64' are supported. |
28
|
|
|
* @type {string} |
29
|
|
|
*/ |
30
|
|
|
container: string; |
31
|
|
|
/** |
32
|
|
|
* @type {number} |
33
|
|
|
*/ |
34
|
|
|
chunkSize: number; |
35
|
|
|
/** |
36
|
|
|
* The format. |
37
|
|
|
* Always 'WAVE'. |
38
|
|
|
* @type {string} |
39
|
|
|
*/ |
40
|
|
|
format: string; |
41
|
|
|
/** |
42
|
|
|
* The data of the 'fmt' chunk. |
43
|
|
|
* @type {!Object<string, *>} |
44
|
|
|
*/ |
45
|
|
|
fmt: object; |
46
|
|
|
/** |
47
|
|
|
* The data of the 'fact' chunk. |
48
|
|
|
* @type {!Object<string, *>} |
49
|
|
|
*/ |
50
|
|
|
fact: object; |
51
|
|
|
/** |
52
|
|
|
* The data of the 'cue ' chunk. |
53
|
|
|
* @type {!Object<string, *>} |
54
|
|
|
*/ |
55
|
|
|
cue: object; |
56
|
|
|
/** |
57
|
|
|
* The data of the 'smpl' chunk. |
58
|
|
|
* @type {!Object<string, *>} |
59
|
|
|
*/ |
60
|
|
|
smpl: object; |
61
|
|
|
/** |
62
|
|
|
* The data of the 'bext' chunk. |
63
|
|
|
* @type {!Object<string, *>} |
64
|
|
|
*/ |
65
|
|
|
bext: object; |
66
|
|
|
/** |
67
|
|
|
* The data of the 'iXML' chunk. |
68
|
|
|
* @type {!Object<string, *>} |
69
|
|
|
*/ |
70
|
|
|
iXML: object; |
71
|
|
|
/** |
72
|
|
|
* The data of the 'ds64' chunk. |
73
|
|
|
* Used only with RF64 files. |
74
|
|
|
* @type {!Object<string, *>} |
75
|
|
|
*/ |
76
|
|
|
ds64: object; |
77
|
|
|
/** |
78
|
|
|
* The data of the 'data' chunk. |
79
|
|
|
* @type {!Object<string, *>} |
80
|
|
|
*/ |
81
|
|
|
data: object; |
82
|
|
|
/** |
83
|
|
|
* The data of the 'LIST' chunks. |
84
|
|
|
* Each item in this list look like this: |
85
|
|
|
* { |
86
|
|
|
* chunkId: '', |
87
|
|
|
* chunkSize: 0, |
88
|
|
|
* format: '', |
89
|
|
|
* subChunks: [] |
90
|
|
|
* } |
91
|
|
|
* @type {!Array<!Object>} |
92
|
|
|
*/ |
93
|
|
|
LIST: object[]; |
94
|
|
|
/** |
95
|
|
|
* The data of the 'junk' chunk. |
96
|
|
|
* @type {!Object<string, *>} |
97
|
|
|
*/ |
98
|
|
|
junk: object; |
99
|
|
|
/** |
100
|
|
|
* The data of the '_PMX' chunk. |
101
|
|
|
* @type {!Object<string, *>} |
102
|
|
|
*/ |
103
|
|
|
_PMX: object; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Return the sample at a given index. |
107
|
|
|
* @param {number} index The sample index. |
108
|
|
|
* @return {number} The sample. |
109
|
|
|
* @throws {Error} If the sample index is off range. |
110
|
|
|
*/ |
111
|
|
|
getSample(index: number): number; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Set the sample at a given index. |
115
|
|
|
* @param {number} index The sample index. |
116
|
|
|
* @param {number} sample The sample. |
117
|
|
|
* @throws {Error} If the sample index is off range. |
118
|
|
|
*/ |
119
|
|
|
setSample(index: number, sample: number): void; |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Set up the WaveFile object based on the arguments passed. |
123
|
|
|
* @param {number} numChannels The number of channels |
124
|
|
|
* (Integer numbers: 1 for mono, 2 stereo and so on). |
125
|
|
|
* @param {number} sampleRate The sample rate. |
126
|
|
|
* Integer numbers like 8000, 44100, 48000, 96000, 192000. |
127
|
|
|
* @param {string} bitDepthCode The audio bit depth code. |
128
|
|
|
* One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64' |
129
|
|
|
* or any value between '8' and '32' (like '12'). |
130
|
|
|
* @param {!Array<number>|!Array<!Array<number>>|!ArrayBufferView} samples |
131
|
|
|
* The samples. Must be in the correct range according to the bit depth. |
132
|
|
|
* @param {?Object} options Optional. Used to force the container |
133
|
|
|
* as RIFX with {'container': 'RIFX'} |
134
|
|
|
* @throws {Error} If any argument does not meet the criteria. |
135
|
|
|
*/ |
136
|
|
|
fromScratch( |
137
|
|
|
numChannels: number, |
138
|
|
|
sampleRate: number, |
139
|
|
|
bitDepthCode: string, |
140
|
|
|
samples: Array<number>|Array<Array<number>>|ArrayBufferView, |
141
|
|
|
options?: object): void; |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Set up the WaveFile object from a byte buffer. |
145
|
|
|
* @param {!Uint8Array} bytes The buffer. |
146
|
|
|
* @param {boolean=} samples True if the samples should be loaded. |
147
|
|
|
* @throws {Error} If container is not RIFF, RIFX or RF64. |
148
|
|
|
* @throws {Error} If no 'fmt ' chunk is found. |
149
|
|
|
* @throws {Error} If no 'data' chunk is found. |
150
|
|
|
*/ |
151
|
|
|
fromBuffer(bytes: Uint8Array, samples?:boolean): void; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Return a byte buffer representig the WaveFile object as a .wav file. |
155
|
|
|
* The return value of this method can be written straight to disk. |
156
|
|
|
* @return {!Uint8Array} A .wav file. |
157
|
|
|
* @throws {Error} If any property of the object appears invalid. |
158
|
|
|
*/ |
159
|
|
|
toBuffer(): Uint8Array; |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Use a .wav file encoded as a base64 string to load the WaveFile object. |
163
|
|
|
* @param {string} base64String A .wav file as a base64 string. |
164
|
|
|
* @throws {Error} If any property of the object appears invalid. |
165
|
|
|
*/ |
166
|
|
|
fromBase64(base64String: string): void; |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Return a base64 string representig the WaveFile object as a .wav file. |
170
|
|
|
* @return {string} A .wav file as a base64 string. |
171
|
|
|
* @throws {Error} If any property of the object appears invalid. |
172
|
|
|
*/ |
173
|
|
|
toBase64(): string; |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Return a DataURI string representig the WaveFile object as a .wav file. |
177
|
|
|
* The return of this method can be used to load the audio in browsers. |
178
|
|
|
* @return {string} A .wav file as a DataURI. |
179
|
|
|
* @throws {Error} If any property of the object appears invalid. |
180
|
|
|
*/ |
181
|
|
|
toDataURI(): string; |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Use a .wav file encoded as a DataURI to load the WaveFile object. |
185
|
|
|
* @param {string} dataURI A .wav file as DataURI. |
186
|
|
|
* @throws {Error} If any property of the object appears invalid. |
187
|
|
|
*/ |
188
|
|
|
fromDataURI(dataURI: string): void; |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Force a file as RIFF. |
192
|
|
|
*/ |
193
|
|
|
toRIFF(): void; |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Force a file as RIFX. |
197
|
|
|
*/ |
198
|
|
|
toRIFX(): void; |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Change the bit depth of the samples. |
202
|
|
|
* @param {string} newBitDepth The new bit depth of the samples. |
203
|
|
|
* One of '8' ... '32' (integers), '32f' or '64' (floats) |
204
|
|
|
* @param {boolean} changeResolution A boolean indicating if the |
205
|
|
|
* resolution of samples should be actually changed or not. |
206
|
|
|
* @throws {Error} If the bit depth is not valid. |
207
|
|
|
*/ |
208
|
|
|
toBitDepth(newBitDepth: string, changeResolution?: boolean): void; |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Encode a 16-bit wave file as 4-bit IMA ADPCM. |
212
|
|
|
* @throws {Error} If sample rate is not 8000. |
213
|
|
|
* @throws {Error} If number of channels is not 1. |
214
|
|
|
*/ |
215
|
|
|
toIMAADPCM(): void; |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Decode a 4-bit IMA ADPCM wave file as a 16-bit wave file. |
219
|
|
|
* @param {string} bitDepthCode The new bit depth of the samples. |
220
|
|
|
* One of '8' ... '32' (integers), '32f' or '64' (floats). |
221
|
|
|
* Optional. Default is 16. |
222
|
|
|
*/ |
223
|
|
|
fromIMAADPCM(bitDepthCode?: string): void; |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Encode a 16-bit wave file as 8-bit A-Law. |
227
|
|
|
*/ |
228
|
|
|
toALaw(): void; |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Decode a 8-bit A-Law wave file into a 16-bit wave file. |
232
|
|
|
* @param {string} bitDepthCode The new bit depth of the samples. |
233
|
|
|
* One of '8' ... '32' (integers), '32f' or '64' (floats). |
234
|
|
|
* Optional. Default is 16. |
235
|
|
|
*/ |
236
|
|
|
fromALaw(bitDepthCode?: string): void; |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Encode 16-bit wave file as 8-bit mu-Law. |
240
|
|
|
*/ |
241
|
|
|
toMuLaw(): void; |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Decode a 8-bit mu-Law wave file into a 16-bit wave file. |
245
|
|
|
* @param {string} bitDepthCode The new bit depth of the samples. |
246
|
|
|
* One of '8' ... '32' (integers), '32f' or '64' (floats). |
247
|
|
|
* Optional. Default is 16. |
248
|
|
|
*/ |
249
|
|
|
fromMuLaw(bitDepthCode?: string): void; |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Write a RIFF tag in the INFO chunk. If the tag do not exist, |
253
|
|
|
* then it is created. It if exists, it is overwritten. |
254
|
|
|
* @param {string} tag The tag name. |
255
|
|
|
* @param {string} value The tag value. |
256
|
|
|
* @throws {Error} If the tag name is not valid. |
257
|
|
|
*/ |
258
|
|
|
setTag(tag: string, value: string): void; |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Return the value of a RIFF tag in the INFO chunk. |
262
|
|
|
* @param {string} tag The tag name. |
263
|
|
|
* @return {?string} The value if the tag is found, null otherwise. |
264
|
|
|
*/ |
265
|
|
|
getTag(tag: string): string|null; |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* Return a Object<tag, value> with the RIFF tags in the file. |
269
|
|
|
* @return {!Object<string, string>} The file tags. |
270
|
|
|
*/ |
271
|
|
|
listTags(): object; |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Remove a RIFF tag in the INFO chunk. |
275
|
|
|
* @param {string} tag The tag name. |
276
|
|
|
* @return {boolean} True if a tag was deleted. |
277
|
|
|
*/ |
278
|
|
|
deleteTag(tag: string): boolean; |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Create a cue point in the wave file. |
282
|
|
|
* @param {number} position The cue point position in milliseconds. |
283
|
|
|
* @param {string} labl The LIST adtl labl text of the marker. Optional. |
284
|
|
|
*/ |
285
|
|
|
setCuePoint(position: number, labl?: string): void; |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Remove a cue point from a wave file. |
289
|
|
|
* @param {number} index the index of the point. First is 1, |
290
|
|
|
* second is 2, and so on. |
291
|
|
|
*/ |
292
|
|
|
deleteCuePoint(index: number): void; |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Return an array with all cue points in the file, in the order they appear |
296
|
|
|
* in the file. |
297
|
|
|
* The difference between this method and using the list in WaveFile.cue |
298
|
|
|
* is that the return value of this method includes the position in |
299
|
|
|
* milliseconds of each cue point (WaveFile.cue only have the sample offset) |
300
|
|
|
* @return {!Array<!Object>} |
301
|
|
|
*/ |
302
|
|
|
listCuePoints(): Array<object>; |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Update the label of a cue point. |
306
|
|
|
* @param {number} pointIndex The ID of the cue point. |
307
|
|
|
* @param {string} label The new text for the label. |
308
|
|
|
*/ |
309
|
|
|
updateLabel(pointIndex: number, label: string): void; |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Set the value of the iXML chunk. |
313
|
|
|
* @param {string} iXMLValue The value for the iXML chunk. |
314
|
|
|
* @throws {TypeError} If the value is not a string. |
315
|
|
|
*/ |
316
|
|
|
setiXML(iXMLValue: string): void; |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* Return the value of the iXML chunk. |
320
|
|
|
* @return {string} The contents of the iXML chunk. |
321
|
|
|
*/ |
322
|
|
|
getiXML(): string; |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Set the value of the _PMX chunk. |
326
|
|
|
* @param {string} _PMXValue The value for the _PMX chunk. |
327
|
|
|
* @throws {TypeError} If the value is not a string. |
328
|
|
|
*/ |
329
|
|
|
set_PMX(_PMXValue: string): void; |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* Get the value of the _PMX chunk. |
333
|
|
|
* @return {string} The contents of the _PMX chunk. |
334
|
|
|
*/ |
335
|
|
|
get_PMX(): string; |
336
|
|
|
} |
337
|
|
|
} |
338
|
|
|
|