Completed
Push — master ( 4a50f5...b7cf3e )
by Rafael S.
01:57
created

lib/wavstruct.js   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 218
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 2
eloc 77
c 1
b 0
f 0
nc 1
mnd 0
bc 1
fnc 1
dl 0
loc 218
rs 10
bpm 1
cpm 2
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B wavstruct.js ➔ constructor 0 215 1
1
/*
2
 * Copyright (c) 2017-2018 Rafael da Silva Rocha.
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining
5
 * a copy of this software and associated documentation files (the
6
 * "Software"), to deal in the Software without restriction, including
7
 * without limitation the rights to use, copy, modify, merge, publish,
8
 * distribute, sublicense, and/or sell copies of the Software, and to
9
 * permit persons to whom the Software is furnished to do so, subject to
10
 * the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be
13
 * included in all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
 *
23
 */
24
25
/**
26
 * @fileoverview A class with the data structure of a wav file.
27
 * @see https://github.com/rochars/wavefile
28
 */
29
30
/**
31
 * A class with the data structure of a wav file.
32
 */
33
export default class WavStruct {
34
35
  constructor() {
36
    /**
37
     * The container identifier.
38
     * 'RIFF', 'RIFX' and 'RF64' are supported.
39
     * @type {string}
40
     */
41
    this.container = '';
42
    /**
43
     * @type {number}
44
     */
45
    this.chunkSize = 0;
46
    /**
47
     * The format.
48
     * Always 'WAVE'.
49
     * @type {string}
50
     */
51
    this.format = '';
52
    /**
53
     * The data of the 'fmt' chunk.
54
     * @type {!Object<string, *>}
55
     */
56
    this.fmt = {
57
      /** @type {string} */
58
      chunkId: '',
59
      /** @type {number} */
60
      chunkSize: 0,
61
      /** @type {number} */
62
      audioFormat: 0,
63
      /** @type {number} */
64
      numChannels: 0,
65
      /** @type {number} */
66
      sampleRate: 0,
67
      /** @type {number} */
68
      byteRate: 0,
69
      /** @type {number} */
70
      blockAlign: 0,
71
      /** @type {number} */
72
      bitsPerSample: 0,
73
      /** @type {number} */
74
      cbSize: 0,
75
      /** @type {number} */
76
      validBitsPerSample: 0,
77
      /** @type {number} */
78
      dwChannelMask: 0,
79
      /**
80
       * 4 32-bit values representing a 128-bit ID
81
       * @type {!Array<number>}
82
       */
83
      subformat: []
84
    };
85
    /**
86
     * The data of the 'fact' chunk.
87
     * @type {!Object<string, *>}
88
     */
89
    this.fact = {
90
      /** @type {string} */
91
      chunkId: '',
92
      /** @type {number} */
93
      chunkSize: 0,
94
      /** @type {number} */
95
      dwSampleLength: 0
96
    };
97
    /**
98
     * The data of the 'cue ' chunk.
99
     * @type {!Object<string, *>}
100
     */
101
    this.cue = {
102
      /** @type {string} */
103
      chunkId: '',
104
      /** @type {number} */
105
      chunkSize: 0,
106
      /** @type {number} */
107
      dwCuePoints: 0,
108
      /** @type {!Array<!Object>} */
109
      points: [],
110
    };
111
    /**
112
     * The data of the 'smpl' chunk.
113
     * @type {!Object<string, *>}
114
     */
115
    this.smpl = {
116
      /** @type {string} */
117
      chunkId: '',
118
      /** @type {number} */
119
      chunkSize: 0,
120
      /** @type {number} */
121
      dwManufacturer: 0,
122
      /** @type {number} */
123
      dwProduct: 0,
124
      /** @type {number} */
125
      dwSamplePeriod: 0,
126
      /** @type {number} */
127
      dwMIDIUnityNote: 0,
128
      /** @type {number} */
129
      dwMIDIPitchFraction: 0,
130
      /** @type {number} */
131
      dwSMPTEFormat: 0,
132
      /** @type {number} */
133
      dwSMPTEOffset: 0,
134
      /** @type {number} */
135
      dwNumSampleLoops: 0,
136
      /** @type {number} */
137
      dwSamplerData: 0,
138
      /** @type {!Array<!Object>} */
139
      loops: []
140
    };
141
    /**
142
     * The data of the 'bext' chunk.
143
     * @type {!Object<string, *>}
144
     */
145
    this.bext = {
146
      /** @type {string} */
147
      chunkId: '',
148
      /** @type {number} */
149
      chunkSize: 0,
150
      /** @type {string} */
151
      description: '', //256
152
      /** @type {string} */
153
      originator: '', //32
154
      /** @type {string} */
155
      originatorReference: '', //32
156
      /** @type {string} */
157
      originationDate: '', //10
158
      /** @type {string} */
159
      originationTime: '', //8
160
      /**
161
       * 2 32-bit values, timeReference high and low
162
       * @type {!Array<number>}
163
       */
164
      timeReference: [0, 0],
165
      /** @type {number} */
166
      version: 0, //WORD
167
      /** @type {string} */
168
      UMID: '', // 64 chars
169
      /** @type {number} */
170
      loudnessValue: 0, //WORD
171
      /** @type {number} */
172
      loudnessRange: 0, //WORD
173
      /** @type {number} */
174
      maxTruePeakLevel: 0, //WORD
175
      /** @type {number} */
176
      maxMomentaryLoudness: 0, //WORD
177
      /** @type {number} */
178
      maxShortTermLoudness: 0, //WORD
179
      /** @type {string} */
180
      reserved: '', //180
181
      /** @type {string} */
182
      codingHistory: '' // string, unlimited
183
    };
184
    /**
185
     * The data of the 'ds64' chunk.
186
     * Used only with RF64 files.
187
     * @type {!Object<string, *>}
188
     */
189
    this.ds64 = {
190
      /** @type {string} */
191
      chunkId: '',
192
      /** @type {number} */
193
      chunkSize: 0,
194
      /** @type {number} */
195
      riffSizeHigh: 0, // DWORD
196
      /** @type {number} */
197
      riffSizeLow: 0, // DWORD
198
      /** @type {number} */
199
      dataSizeHigh: 0, // DWORD
200
      /** @type {number} */
201
      dataSizeLow: 0, // DWORD
202
      /** @type {number} */
203
      originationTime: 0, // DWORD
204
      /** @type {number} */
205
      sampleCountHigh: 0, // DWORD
206
      /** @type {number} */
207
      sampleCountLow: 0 // DWORD
208
      /** @type {number} */
209
      //'tableLength': 0, // DWORD
210
      /** @type {!Array<number>} */
211
      //'table': []
212
    };
213
    /**
214
     * The data of the 'data' chunk.
215
     * @type {!Object<string, *>}
216
     */
217
    this.data = {
218
      /** @type {string} */
219
      chunkId: '',
220
      /** @type {number} */
221
      chunkSize: 0,
222
      /** @type {!Uint8Array} */
223
      samples: new Uint8Array(0)
224
    };
225
    /**
226
     * The data of the 'LIST' chunks.
227
     * Each item in this list look like this:
228
     *  {
229
     *      chunkId: '',
230
     *      chunkSize: 0,
231
     *      format: '',
232
     *      subChunks: []
233
     *   }
234
     * @type {!Array<!Object>}
235
     */
236
    this.LIST = [];
237
    /**
238
     * The data of the 'junk' chunk.
239
     * @type {!Object<string, *>}
240
     */
241
    this.junk = {
242
      /** @type {string} */
243
      chunkId: '',
244
      /** @type {number} */
245
      chunkSize: 0,
246
      /** @type {!Array<number>} */
247
      chunkData: []
248
    };
249
  }
250
}
251