Passed
Push — master ( 29aa6e...c898d2 )
by Rafael S.
02:29
created

WaveFile.getSamples   A

Complexity

Conditions 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
1
// Type definitions for wavefile 10.1
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 samples packed in a Float64Array.
107
     * @param {?boolean} interleaved True to return interleaved samples,
108
     *   false to return the samples de-interleaved. Defaults to false.
109
     * @return {!Float64Array|Array<Float64Array>} the samples.
110
     */
111
    getSamples(interleaved?:boolean): Float64Array;
112
113
    /**
114
     * Return the sample at a given index.
115
     * @param {number} index The sample index.
116
     * @return {number} The sample.
117
     * @throws {Error} If the sample index is off range.
118
     */
119
    getSample(index: number): number;
120
121
    /**
122
     * Set the sample at a given index.
123
     * @param {number} index The sample index.
124
     * @param {number} sample The sample.
125
     * @throws {Error} If the sample index is off range.
126
     */
127
    setSample(index: number, sample: number): void;
128
129
    /**
130
     * Set up the WaveFile object based on the arguments passed.
131
     * @param {number} numChannels The number of channels.
132
     * @param {number} sampleRate The sample rate.
133
     *  Integer numbers like 8000, 44100, 48000, 96000, 192000.
134
     * @param {string} bitDepthCode The audio bit depth code.
135
     *  One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64'
136
     *  or any value between '8' and '32' (like '12').
137
     * @param {!Array<number>|!Array<Array<number>>|!TypedArray|!!Array<TypedArray>} samples
138
     * @param {?Object} options Optional. Used to force the container
139
     *  as RIFX with {'container': 'RIFX'}
140
     * @throws {Error} If any argument does not meet the criteria.
141
     */
142
    fromScratch(
143
      numChannels: number,
144
      sampleRate: number,
145
      bitDepthCode: string,
146
      samples: Array<number>|Array<Array<number>>|ArrayLike<any>|Array<ArrayLike<any>>,
147
      options?: object): void;
148
149
    /**
150
     * Set up the WaveFile object from a byte buffer.
151
     * @param {!Uint8Array} bytes The buffer.
152
     * @param {boolean=} samples True if the samples should be loaded.
153
     * @throws {Error} If container is not RIFF, RIFX or RF64.
154
     * @throws {Error} If no 'fmt ' chunk is found.
155
     * @throws {Error} If no 'data' chunk is found.
156
     */
157
    fromBuffer(bytes: Uint8Array, samples?:boolean): void;
158
159
    /**
160
     * Return a byte buffer representig the WaveFile object as a .wav file.
161
     * The return value of this method can be written straight to disk.
162
     * @return {!Uint8Array} A .wav file.
163
     * @throws {Error} If any property of the object appears invalid.
164
     */
165
    toBuffer(): Uint8Array;
166
167
    /**
168
     * Use a .wav file encoded as a base64 string to load the WaveFile object.
169
     * @param {string} base64String A .wav file as a base64 string.
170
     * @throws {Error} If any property of the object appears invalid.
171
     */
172
    fromBase64(base64String: string): void;
173
174
    /**
175
     * Return a base64 string representig the WaveFile object as a .wav file.
176
     * @return {string} A .wav file as a base64 string.
177
     * @throws {Error} If any property of the object appears invalid.
178
     */
179
    toBase64(): string;
180
181
    /**
182
     * Return a DataURI string representig the WaveFile object as a .wav file.
183
     * The return of this method can be used to load the audio in browsers.
184
     * @return {string} A .wav file as a DataURI.
185
     * @throws {Error} If any property of the object appears invalid.
186
     */
187
    toDataURI(): string;
188
189
    /**
190
     * Use a .wav file encoded as a DataURI to load the WaveFile object.
191
     * @param {string} dataURI A .wav file as DataURI.
192
     * @throws {Error} If any property of the object appears invalid.
193
     */
194
    fromDataURI(dataURI: string): void;
195
196
    /**
197
     * Force a file as RIFF.
198
     */
199
    toRIFF(): void;
200
201
    /**
202
     * Force a file as RIFX.
203
     */
204
    toRIFX(): void;
205
206
    /**
207
     * Change the bit depth of the samples.
208
     * @param {string} newBitDepth The new bit depth of the samples.
209
     *  One of '8' ... '32' (integers), '32f' or '64' (floats)
210
     * @param {boolean} changeResolution A boolean indicating if the
211
     *  resolution of samples should be actually changed or not.
212
     * @throws {Error} If the bit depth is not valid.
213
     */
214
    toBitDepth(newBitDepth: string, changeResolution?: boolean): void;
215
216
    /**
217
     * Encode a 16-bit wave file as 4-bit IMA ADPCM.
218
     * @throws {Error} If sample rate is not 8000.
219
     * @throws {Error} If number of channels is not 1.
220
     */
221
    toIMAADPCM(): void;
222
223
    /**
224
     * Decode a 4-bit IMA ADPCM wave file as a 16-bit wave file.
225
     * @param {string} bitDepthCode The new bit depth of the samples.
226
     *  One of '8' ... '32' (integers), '32f' or '64' (floats).
227
     *  Optional. Default is 16.
228
     */
229
    fromIMAADPCM(bitDepthCode?: string): void;
230
231
    /**
232
     * Encode a 16-bit wave file as 8-bit A-Law.
233
     */
234
    toALaw(): void;
235
236
    /**
237
     * Decode a 8-bit A-Law wave file into a 16-bit wave file.
238
     * @param {string} bitDepthCode The new bit depth of the samples.
239
     *  One of '8' ... '32' (integers), '32f' or '64' (floats).
240
     *  Optional. Default is 16.
241
     */
242
    fromALaw(bitDepthCode?: string): void;
243
244
    /**
245
     * Encode 16-bit wave file as 8-bit mu-Law.
246
     */
247
    toMuLaw(): void;
248
249
    /**
250
     * Decode a 8-bit mu-Law wave file into a 16-bit wave file.
251
     * @param {string} bitDepthCode The new bit depth of the samples.
252
     *  One of '8' ... '32' (integers), '32f' or '64' (floats).
253
     *  Optional. Default is 16.
254
     */
255
    fromMuLaw(bitDepthCode?: string): void;
256
257
    /**
258
     * Write a RIFF tag in the INFO chunk. If the tag do not exist,
259
     * then it is created. It if exists, it is overwritten.
260
     * @param {string} tag The tag name.
261
     * @param {string} value The tag value.
262
     * @throws {Error} If the tag name is not valid.
263
     */
264
    setTag(tag: string, value: string): void;
265
266
    /**
267
     * Return the value of a RIFF tag in the INFO chunk.
268
     * @param {string} tag The tag name.
269
     * @return {?string} The value if the tag is found, null otherwise.
270
     */
271
    getTag(tag: string): string|null;
272
273
    /**
274
     * Return a Object<tag, value> with the RIFF tags in the file.
275
     * @return {!Object<string, string>} The file tags.
276
     */
277
    listTags(): object;
278
279
    /**
280
     * Remove a RIFF tag in the INFO chunk.
281
     * @param {string} tag The tag name.
282
     * @return {boolean} True if a tag was deleted.
283
     */
284
    deleteTag(tag: string): boolean;
285
286
    /**
287
     * Create a cue point in the wave file.
288
     * @param {!Object<string, *>} pointData The data of the cue point.
289
     */
290
    setCuePoint(pointData: object): void;
291
292
    /**
293
     * Remove a cue point from a wave file.
294
     * @param {number} index the index of the point. First is 1,
295
     *  second is 2, and so on.
296
     */
297
    deleteCuePoint(index: number): void;
298
299
    /**
300
     * Return an array with all cue points in the file, in the order they appear
301
     * in the file.
302
     * Objects representing cue points/regions look like this:
303
     *   {
304
     *     position: 500, // the position in milliseconds
305
     *     label: 'cue marker 1',
306
     *     end: 1500, // the end position in milliseconds
307
     *     dwName: 1,
308
     *     dwPosition: 0,
309
     *     fccChunk: 'data',
310
     *     dwChunkStart: 0,
311
     *     dwBlockStart: 0,
312
     *     dwSampleOffset: 22050, // the position as a sample offset
313
     *     dwSampleLength: 3646827, // the region length as a sample count
314
     *     dwPurposeID: 544106354,
315
     *     dwCountry: 0,
316
     *     dwLanguage: 0,
317
     *     dwDialect: 0,
318
     *     dwCodePage: 0,
319
     *   }
320
     * @return {!Array<Object>}
321
     */
322
    listCuePoints(): Array<object>;
323
324
    /**
325
     * Update the label of a cue point.
326
     * @param {number} pointIndex The ID of the cue point.
327
     * @param {string} label The new text for the label.
328
     */
329
    updateLabel(pointIndex: number, label: string): void;
330
331
    /**
332
     * Set the value of the iXML chunk.
333
     * @param {string} iXMLValue The value for the iXML chunk.
334
     * @throws {TypeError} If the value is not a string.
335
     */
336
    setiXML(iXMLValue: string): void;
337
338
    /**
339
     * Return the value of the iXML chunk.
340
     * @return {string} The contents of the iXML chunk.
341
     */
342
    getiXML(): string;
343
344
    /**
345
     * Set the value of the _PMX chunk.
346
     * @param {string} _PMXValue The value for the _PMX chunk.
347
     * @throws {TypeError} If the value is not a string.
348
     */
349
    set_PMX(_PMXValue: string): void;
350
351
    /**
352
     * Get the value of the _PMX chunk.
353
     * @return {string} The contents of the _PMX chunk.
354
     */
355
    get_PMX(): string;
356
  }
357
}
358