Completed
Push — master ( 22e2f2...1154c3 )
by Rafael S.
09:53 queued 15s
created

index.d.ts   A

Complexity

Total Complexity 26
Complexity/F 1

Size

Lines of Code 299
Function Count 26

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 87
dl 0
loc 299
rs 10
c 0
b 0
f 0
wmc 26
mnd 0
bc 0
fnc 26
bpm 0
cpm 1
noi 0

26 Functions

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