Completed
Push — master ( 4763f6...044ca6 )
by Rafael S.
02:13
created

WaveFile.toRIFF   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
/**
2
 * @fileoverview Externs for wavefile 8.1
3
 *
4
 * @see https://github.com/rochars/wavefile
5
 * @externs
6
 */
7
8
// WaveFile class
9
const WaveFile = {};
10
11
/**
12
 * The container identifier.
13
 * RIFF, RIFX and RF64 are supported.
14
 * @type {string}
15
 */
16
WaveFile.container = '';
17
/**
18
 * @type {number}
19
 */
20
WaveFile.chunkSize = 0;
21
/**
22
 * The format.
23
 * Always WAVE.
24
 * @type {string}
25
 */
26
WaveFile.format = '';
27
/**
28
 * The data of the fmt chunk.
29
 * @type {!Object<string, *>}
30
 */
31
WaveFile.fmt = {
32
  /** @type {string} */
33
  chunkId: '',
34
  /** @type {number} */
35
  chunkSize: 0,
36
  /** @type {number} */
37
  audioFormat: 0,
38
  /** @type {number} */
39
  numChannels: 0,
40
  /** @type {number} */
41
  sampleRate: 0,
42
  /** @type {number} */
43
  byteRate: 0,
44
  /** @type {number} */
45
  blockAlign: 0,
46
  /** @type {number} */
47
  bitsPerSample: 0,
48
  /** @type {number} */
49
  cbSize: 0,
50
  /** @type {number} */
51
  validBitsPerSample: 0,
52
  /** @type {number} */
53
  dwChannelMask: 0,
54
  /**
55
   * 4 32-bit values representing a 128-bit ID
56
   * @type {!Array<number>}
57
   */
58
  subformat: []
59
};
60
/**
61
 * The data of the fact chunk.
62
 * @type {!Object<string, *>}
63
 */
64
WaveFile.fact = {
65
  /** @type {string} */
66
  chunkId: '',
67
  /** @type {number} */
68
  chunkSize: 0,
69
  /** @type {number} */
70
  dwSampleLength: 0
71
};
72
/**
73
 * The data of the cue  chunk.
74
 * @type {!Object<string, *>}
75
 */
76
WaveFile.cue = {
77
  /** @type {string} */
78
  chunkId: '',
79
  /** @type {number} */
80
  chunkSize: 0,
81
  /** @type {number} */
82
  dwCuePoints: 0,
83
  /** @type {!Array<!Object>} */
84
  points: [{
85
    dwName: 0, // a cue point ID
86
    dwPosition: 0,
87
    fccChunk: 0,
88
    dwChunkStart: 0,
89
    dwBlockStart: 0,
90
    dwSampleOffset: 0
91
  }],
92
};
93
/**
94
 * The data of the smpl chunk.
95
 * @type {!Object<string, *>}
96
 */
97
WaveFile.smpl = {
98
  /** @type {string} */
99
  chunkId: '',
100
  /** @type {number} */
101
  chunkSize: 0,
102
  /** @type {number} */
103
  dwManufacturer: 0,
104
  /** @type {number} */
105
  dwProduct: 0,
106
  /** @type {number} */
107
  dwSamplePeriod: 0,
108
  /** @type {number} */
109
  dwMIDIUnityNote: 0,
110
  /** @type {number} */
111
  dwMIDIPitchFraction: 0,
112
  /** @type {number} */
113
  dwSMPTEFormat: 0,
114
  /** @type {number} */
115
  dwSMPTEOffset: 0,
116
  /** @type {number} */
117
  dwNumSampleLoops: 0,
118
  /** @type {number} */
119
  dwSamplerData: 0,
120
  /** @type {!Array<!Object>} */
121
  loops: [
122
    {
123
      dwName: '', // a cue point ID
124
      dwType: 0,
125
      dwStart: 0,
126
      dwEnd: 0,
127
      dwFraction: 0,
128
      dwPlayCount: 0
129
    }
130
  ],
131
};
132
/**
133
 * The data of the bext chunk.
134
 * @type {!Object<string, *>}
135
 */
136
WaveFile.bext = {
137
  /** @type {string} */
138
  chunkId: '',
139
  /** @type {number} */
140
  chunkSize: 0,
141
  /** @type {string} */
142
  description: '',
143
  /** @type {string} */
144
  originator: '',
145
  /** @type {string} */
146
  originatorReference: '',
147
  /** @type {string} */
148
  originationDate: '',
149
  /** @type {string} */
150
  originationTime: '',
151
  /**
152
   * 2 32-bit values, timeReference high and low
153
   * @type {!Array<number>}
154
   */
155
  timeReference: [0, 0],
156
  /** @type {number} */
157
  version: 0,
158
  /** @type {string} */
159
  UMID: '',
160
  /** @type {number} */
161
  loudnessValue: 0,
162
  /** @type {number} */
163
  loudnessRange: 0,
164
  /** @type {number} */
165
  maxTruePeakLevel: 0,
166
  /** @type {number} */
167
  maxMomentaryLoudness: 0,
168
  /** @type {number} */
169
  maxShortTermLoudness: 0,
170
  /** @type {string} */
171
  reserved: '',
172
  /** @type {string} */
173
  codingHistory: ''
174
};
175
/**
176
 * The data of the ds64 chunk.
177
 * Used only with RF64 files.
178
 * @type {!Object<string, *>}
179
 */
180
WaveFile.ds64 = {
181
  /** @type {string} */
182
  chunkId: '',
183
  /** @type {number} */
184
  chunkSize: 0,
185
  /** @type {number} */
186
  riffSizeHigh: 0,
187
  /** @type {number} */
188
  riffSizeLow: 0,
189
  /** @type {number} */
190
  dataSizeHigh: 0,
191
  /** @type {number} */
192
  dataSizeLow: 0,
193
  /** @type {number} */
194
  originationTime: 0,
195
  /** @type {number} */
196
  sampleCountHigh: 0,
197
  /** @type {number} */
198
  sampleCountLow: 0
199
};
200
/**
201
 * The data of the data chunk.
202
 * @type {!Object<string, *>}
203
 */
204
WaveFile.data = {
205
  /** @type {string} */
206
  chunkId: '',
207
  /** @type {number} */
208
  chunkSize: 0,
209
  /** @type {!Uint8Array} */
210
  samples: null //
211
};
212
/**
213
 * The data of the LIST chunks.
214
 * @type {!Array<!Object>}
215
 */
216
WaveFile.LIST = [
217
  {
218
    chunkId: '',
219
    chunkSize: 0,
220
    format: '',
221
    subChunks: [
222
      // For format 'INFO'
223
      {
224
        chunkId: '',
225
        chunkSize: 0,
226
        value: ''
227
      },
228
      // For format 'adtl' types 'labl' or 'note'
229
      {
230
        chunkId: '',
231
        chunkSize: 0,
232
        dwName: 0,
233
        value: ''
234
      },
235
      // For format 'adtl' type 'ltxt'
236
      {
237
        chunkId: '',
238
        value: 0,
239
        dwName: 0,
240
        dwSampleLength: 0,
241
        dwPurposeID: 0,
242
        dwCountry: 0,
243
        dwLanguage: 0,
244
        dwDialect: 0,
245
        dwCodePage: 0
246
      }
247
    ]
248
  }
249
];
250
/**
251
 * The data of the junk chunk.
252
 * @type {!Object<string, *>}
253
 */
254
WaveFile.junk = {
255
  /** @type {string} */
256
  chunkId: '',
257
  /** @type {number} */
258
  chunkSize: 0,
259
  /** @type {!Array<number>} */
260
  chunkData: []
261
};
262
/**
263
 * The bit depth code according to the samples.
264
 * @type {string}
265
 */
266
WaveFile.bitDepth = '';
267
268
/**
269
 * Set up the WaveFile object based on the arguments passed.
270
 * @param {number} numChannels The number of channels
271
 *      (Integer numbers: 1 for mono, 2 stereo and so on).
272
 * @param {number} sampleRate The sample rate.
273
 *      Integer numbers like 8000, 44100, 48000, 96000, 192000.
274
 * @param {string} bitDepthCode The audio bit depth code.
275
 *      One of 4, 8, 8a, 8m, 16, 24, 32, 32f, 64
276
 *      or any value between 8 and 32 (like 12).
277
 * @param {!Array<number>} samples Array of samples to be written.
278
 *      The samples must be in the correct range according to the
279
 *      bit depth.
280
 * @param {?Object} options Optional. Used to force the container
281
 *      as RIFX with {container: RIFX}
282
 * @throws {Error} If any argument does not meet the criteria.
283
 */
284
WaveFile.fromScratch = function(
285
  numChannels, sampleRate, bitDepthCode, samples, options={container:'RIFF'}) {};
286
287
/**
288
 * Set up the WaveFile object from a byte buffer.
289
 * @param {!Uint8Array} bytes The buffer.
290
 * @param {boolean=} samples True if the samples should be loaded.
291
 * @throws {Error} If container is not RIFF, RIFX or RF64.
292
 * @throws {Error} If no fmt  chunk is found.
293
 * @throws {Error} If no data chunk is found.
294
 */
295
WaveFile.fromBuffer = function(bytes, samples=true) {};
296
297
/**
298
 * Return a byte buffer representig the WaveFile object as a .wav file.
299
 * The return value of this method can be written straight to disk.
300
 * @return {!Uint8Array} A .wav file.
301
 * @throws {Error} If any property of the object appears invalid.
302
 */
303
WaveFile.toBuffer = function() {};
304
305
/**
306
 * Use a .wav file encoded as a base64 string to load the WaveFile object.
307
 * @param {string} base64String A .wav file as a base64 string.
308
 * @throws {Error} If any property of the object appears invalid.
309
 */
310
WaveFile.fromBase64 = function(base64String) {};
0 ignored issues
show
Unused Code introduced by
The parameter base64String is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
311
312
/**
313
 * Return a base64 string representig the WaveFile object as a .wav file.
314
 * @return {string} A .wav file as a base64 string.
315
 * @throws {Error} If any property of the object appears invalid.
316
 */
317
WaveFile.toBase64 = function() {};
318
319
/**
320
 * Return a DataURI string representig the WaveFile object as a .wav file.
321
 * The return of this method can be used to load the audio in browsers.
322
 * @return {string} A .wav file as a DataURI.
323
 * @throws {Error} If any property of the object appears invalid.
324
 */
325
WaveFile.toDataURI = function() {};
326
327
/**
328
 * Use a .wav file encoded as a DataURI to load the WaveFile object.
329
 * @param {string} dataURI A .wav file as DataURI.
330
 * @throws {Error} If any property of the object appears invalid.
331
 */
332
WaveFile.fromDataURI = function(dataURI) {};
0 ignored issues
show
Unused Code introduced by
The parameter dataURI is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
333
334
/**
335
 * Force a file as RIFF.
336
 */
337
WaveFile.toRIFF = function() {};
338
339
/**
340
 * Force a file as RIFX.
341
 */
342
WaveFile.toRIFX = function() {};
343
344
/**
345
 * Change the bit depth of the samples.
346
 * @param {string} newBitDepth The new bit depth of the samples.
347
 *      One of 8 ... 32 (integers), 32f or 64 (floats)
348
 * @param {boolean} changeResolution A boolean indicating if the
349
 *      resolution of samples should be actually changed or not.
350
 * @throws {Error} If the bit depth is not valid.
351
 */
352
WaveFile.toBitDepth = function(newBitDepth, changeResolution=true) {};
353
354
/**
355
 * Encode a 16-bit wave file as 4-bit IMA ADPCM.
356
 * @throws {Error} If sample rate is not 8000.
357
 * @throws {Error} If number of channels is not 1.
358
 */
359
WaveFile.toIMAADPCM = function() {};
360
361
/**
362
 * Decode a 4-bit IMA ADPCM wave file as a 16-bit wave file.
363
 * @param {string} bitDepthCode The new bit depth of the samples.
364
 *      One of 8 ... 32 (integers), 32f or 64 (floats).
365
 *      Optional. Default is 16.
366
 */
367
WaveFile.fromIMAADPCM = function(bitDepthCode='16') {};
368
369
/**
370
 * Encode 16-bit wave file as 8-bit A-Law.
371
 */
372
WaveFile.toALaw = function() {};
373
374
/**
375
 * Decode a 8-bit A-Law wave file into a 16-bit wave file.
376
 * @param {string} bitDepthCode The new bit depth of the samples.
377
 *      One of 8 ... 32 (integers), 32f or 64 (floats).
378
 *      Optional. Default is 16.
379
 */
380
WaveFile.fromALaw = function(bitDepthCode='16') {};
381
382
/**
383
 * Encode 16-bit wave file as 8-bit mu-Law.
384
 */
385
WaveFile.toMuLaw = function() {};
386
387
/**
388
 * Decode a 8-bit mu-Law wave file into a 16-bit wave file.
389
 * @param {string} bitDepthCode The new bit depth of the samples.
390
 *      One of 8 ... 32 (integers), 32f or 64 (floats).
391
 *      Optional. Default is 16.
392
 */
393
WaveFile.fromMuLaw = function(bitDepthCode='16') {};
394
395
/**
396
 * Write a RIFF tag in the INFO chunk. If the tag do not exist,
397
 * then it is created. It if exists, it is overwritten.
398
 * @param {string} tag The tag name.
399
 * @param {string} value The tag value.
400
 * @throws {Error} If the tag name is not valid.
401
 */
402
WaveFile.setTag = function(tag, value) {};
0 ignored issues
show
Unused Code introduced by
The parameter value is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter tag is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
403
404
/**
405
 * Return the value of a RIFF tag in the INFO chunk.
406
 * @param {string} tag The tag name.
407
 * @return {?string} The value if the tag is found, null otherwise.
408
 */
409
WaveFile.getTag = function(tag) {};
0 ignored issues
show
Unused Code introduced by
The parameter tag is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
410
411
/**
412
 * Remove a RIFF tag in the INFO chunk.
413
 * @param {string} tag The tag name.
414
 * @return {boolean} True if a tag was deleted.
415
 */
416
WaveFile.deleteTag = function(tag) {};
0 ignored issues
show
Unused Code introduced by
The parameter tag is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
417
418
/**
419
 * Create a cue point in the wave file.
420
 * @param {number} position The cue point position in milliseconds.
421
 * @param {string} labl The LIST adtl labl text of the marker. Optional.
422
 */
423
WaveFile.setCuePoint = function(position, labl='') {};
424
425
/**
426
 * Remove a cue point from a wave file.
427
 * @param {number} index the index of the point. First is 1,
428
 *      second is 2, and so on.
429
 */
430
WaveFile.deleteCuePoint = function(index) {};
0 ignored issues
show
Unused Code introduced by
The parameter index is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
431
432
/**
433
 * Update the label of a cue point.
434
 * @param {number} pointIndex The ID of the cue point.
435
 * @param {string} label The new text for the label.
436
 */
437
WaveFile.updateLabel = function(pointIndex, label) {};
0 ignored issues
show
Unused Code introduced by
The parameter label is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter pointIndex is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
438