• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

benrr101 / node-taglib-sharp / 46462135

pending completion
46462135

push

appveyor

Benjamin Russell
Merge branch 'release/v5.1.0'

3096 of 3788 branches covered (81.73%)

Branch coverage included in aggregate %.

2171 of 2171 new or added lines in 47 files covered. (100.0%)

25320 of 26463 relevant lines covered (95.68%)

437.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.77
/src/riff/riffWaveFormatEx.ts
1
import {ByteVector} from "../byteVector";
2
import {CorruptFileError} from "../errors";
1✔
3
import {ILosslessAudioCodec, MediaTypes} from "../properties";
1✔
4
import {Guards} from "../utils";
1✔
5

6
/**
7
 * Defines the format of waveform-audio data. Only format information common to all waveform-audio
8
 * data formats is included in this structure.
9
 * https://docs.microsoft.com/en-us/previous-versions/dd757713(v=vs.85)
10
 */
11
export default class RiffWaveFormatEx implements ILosslessAudioCodec {
1✔
12
    /**
13
     * FOURCC code that indicates the chunk is a RiffWaveFormatEx object.
14
     */
15
    public static readonly CHUNK_FOURCC = "fmt ";
1✔
16

17
    /**
18
     * List of well-known wave format tags. This is similar to FOURCC codes but for audio codecs.
19
     * @remarks
20
     *     This list was put together from the Windows 10 SDK mmreg.h header file
21
     *     If any of these descriptions are wrong or out of date, please open a PR.
22
     */
23
    public static readonly WAVE_FORMAT_TAGS: Map<number, string> = new Map<number, string>([
1✔
24
        [0x0000, "Unknown Wave Format"],
25
        [0x0001, "PCM Audio"],
26
        [0x0002, "Microsoft ADPCM"],
27
        [0x0003, "PCM Audio in IEEE Floating-Point Format"],
28
        [0x0004, "Compaq VSELP Audio"],
29
        [0x0005, "IBM CVSD Audio"],
30
        [0x0006, "Microsoft ALAW Audio"],
31
        [0x0007, "Microsoft MULAW Audio"],
32
        [0x0008, "Microsoft DTS Audio"],
33
        [0x0009, "Microsoft DRM Encrypted Audio"],
34
        [0x000A, "Microsoft Speech Audio"],
35
        [0x000B, "Microsoft Windows Media RT Voice Audio"],
36
        [0x0010, "OKI ADPCM Audio"],
37
        [0x0011, "Intel ADPCM Audio"],
38
        [0x0012, "Videologic MediaSpace ADPCM Audio"],
39
        [0x0013, "Sierra ADPCM Audio"],
40
        [0x0014, "Antex G723 ADPCM Audio"],
41
        [0x0015, "DSP Solutions DIGISTD Audio"],
42
        [0x0016, "DSP Solutions DIGIFIX Audio"],
43
        [0x0017, "Dialogic OKI ADPCM Audio"],
44
        [0x0018, "Media Vision ADPCM Audio for Jazz 16"],
45
        [0x0019, "HP CU Audio"],
46
        [0x001A, "HP Dynamic Voice Audio"],
47
        [0x0020, "Yamaha ADPCM Audio"],
48
        [0x0021, "Speech Compression Sonarc Audio"],
49
        [0x0022, "DSP Group True Speech Audio "],
50
        [0x0023, "Echo Speech Audio"],
51
        [0x0024, "Virtual Music Audiofile AF36 Audio"],
52
        [0x0025, "Audio Processing Technology APTX Audio"],
53
        [0x0026, "Virtual Music Audiofile AF10 Audio"],
54
        [0x0027, "Aculab Prosody 1612 Speech Card Audio"],
55
        [0x0028, "Merging Technologies LRC Audio"],
56
        [0x0030, "Dolby AC2 Audio"],
57
        [0x0031, "Microsoft Corporation GSM6.10 Audio"],
58
        [0x0032, "Microsoft Corporation MSN Audio"],
59
        [0x0033, "Antex ADPCME Audio"],
60
        [0x0034, "Control Resources VQLPC Audio"],
61
        [0x0035, "DSP Solutions Digireal Audio"],
62
        [0x0036, "DSP Solutions DigiADPCM Audio"],
63
        [0x0037, "Control Resources CR10 Audio"],
64
        [0x0038, "Natural MicroSystems  VBXADPCM Audio"],
65
        [0x0039, "Crystal Semiconductor IMA ADPCM Audio"],
66
        [0x003A, "Echo Speech Corporation Proprietary Audio Compression Format"],
67
        [0x003B, "Rockwell ADPCM Audio"],
68
        [0x003C, "Rockwell DIGITALK Audio"],
69
        [0x003D, "Xebec Multimedia Solutions Proprietary Audio Compression Format"],
70
        [0x0040, "Antex G721 ADPCM Audio"],
71
        [0x0041, "Antex G728 CELP Audio"],
72
        [0x0042, "Microsoft MSG723 Audio"],
73
        [0x0043, "Intel G.723.1 Audio"],
74
        [0x0044, "Intel G.729 Audio"],
75
        [0x0045, "Sharp G.726 Audio"],
76
        [0x0050, "Microsoft Corporation MPEG Audio"],
77
        [0x0052, "InSoft RT24 Audio"],
78
        [0x0053, "InSoft PAC Audio"],
79
        [0x0055, "ISO/MPEG Layer 3 Audio"],
80
        [0x0059, "Lucent G.723"],
81
        [0x0060, "Cirrus Logic Audio"],
82
        [0x0061, "ESS Technology PCM Audio"],
83
        [0x0062, "Voxware Audio"],
84
        [0x0063, "Canopus ATRAC Audio"],
85
        [0x0064, "APICOM G.726 Audio"],
86
        [0x0065, "APICOM G.722 Audio"],
87
        [0x0066, "Microsoft DSAT Audio"],
88
        [0x0067, "Microsoft DSAT Display Audio"],
89
        [0x0069, "Voxware Byte Aligned Audio"],
90
        [0x0070, "Voxware AC8 Audio"],
91
        [0x0071, "Voxware AC10 Audio"],
92
        [0x0072, "Voxware AC16 Audio"],
93
        [0x0073, "Voxware AC20 Audio"],
94
        [0x0074, "Voxware RT24 Audio"],
95
        [0x0075, "Voxware RT29 Audio"],
96
        [0x0076, "Voxware RT29HW Audio"],
97
        [0x0077, "Voxware VR12 Audio"],
98
        [0x0078, "Voxware VR18 Audio"],
99
        [0x0079, "Voxware TQ40 Audio"],
100
        [0x007A, "Voxware SC3 Audio"],
101
        [0x007B, "Voxware SC3.1 Audio"],
102
        [0x0080, "Softsound Audio"],
103
        [0x0081, "Voxware TQ60 Audio"],
104
        [0x0082, "Microsoft RT24"],
105
        [0x0083, "AT&T G.729A Audio"],
106
        [0x0084, "Motion Pixels MVI2 Audio"],
107
        [0x0085, "DataFusion Systems G.726 Audio"],
108
        [0x0086, "DataFusion Systems GSM610 Audio"],
109
        [0x0088, "Iterated Systems Audio"],
110
        [0x0089, "OnLive! Audio"],
111
        [0x008A, "Multitude FT SX20 Audio"],
112
        [0x008B, "Infocom ITS G.721 Audio"],
113
        [0x008C, "Convedia G.729 Audio"],
114
        [0x008D, "Congruency Audio"],
115
        [0x0091, "Siemens Business Communications 24 Audio"],
116
        [0x0092, "Sonic Foundry Dolby AC3 Audio"],
117
        [0x0093, "MediaSonic G.723 Audio"],
118
        [0x0094, "Aculab Prosody CTI Speech Card Audio"],
119
        [0x0097, "ZyXEL ADPCM Audio"],
120
        [0x0098, "Philips Speech Processing LPCBB Audio"],
121
        [0x0099, "Studer Professional PACKED Audio"],
122
        [0x00A0, "Malden Electronics Phony Talk Audio"],
123
        [0x00A1, "Racal Recorders GSM Audio"],
124
        [0x00A2, "Racal Recorders G.720.a Audio"],
125
        [0x00A3, "Racal Recorders G.723.1  Audio"],
126
        [0x00A4, "Racal Recorders Tetra ACELP Audio"],
127
        [0x00B0, "NEC AAC Audio"],
128
        [0x00FF, "AAC1 Audio"],
129
        [0x0100, "Rhetorex ADPCM Audio"],
130
        [0x0101, "BeCubed IRAT Audio"],
131
        [0x0111, "Vivo G.723 Audio"],
132
        [0x0112, "Vivo Siren Audio"],
133
        [0x0120, "Philips Speech Processing CELP Audio"],
134
        [0x0121, "Philips Speech Processing Grundig Audio"],
135
        [0x0123, "DEC G.723 Audio"],
136
        [0x0125, "Sanyo LD-ADPCM Audio"],
137
        [0x0130, "Sipro Lab ACEPLNET Audio"],
138
        [0x0131, "Sipro Lab ACELP4800 Audio"],
139
        [0x0132, "Sipro Lab ACELP8v3 Audio"],
140
        [0x0133, "Sipro Lab G.729 Audio"],
141
        [0x0134, "Sipro Lab G.729.a Audio"],
142
        [0x0135, "Sipro Lab Kelvin Audio"],
143
        [0x0136, "VoiceAge AMR Audio"],
144
        [0x0140, "Dictaphone G.726 Audio"],
145
        [0x0141, "Dictaphone CELP68 Audio"],
146
        [0x0142, "Dictaphone CELP54 Audio"],
147
        [0x0150, "Qualcomm PureVoice Audio"],
148
        [0x0151, "Qualcomm Half Rate Audio"],
149
        [0x0155, "Ring Zero Systems TUBGSM Audio"],
150
        [0x0160, "Microsoft WMA1 Audio"],
151
        [0x0161, "Microsoft WMA2 Audio"],
152
        [0x0162, "Microsoft Multichannel WMA Audio"],
153
        [0x0163, "Microsoft Lossless WMA Audio"],
154
        [0x0164, "Microsoft WMA SPDIF Audio"],
155
        [0x0170, "Unisys NAP ADPCM Audio"],
156
        [0x0171, "Unisys NAP ULAW Audio"],
157
        [0x0172, "Unisys NAP ALAW Audio"],
158
        [0x0173, "Unisys NAP 16K Audio"],
159
        [0x0174, "SyCom ACM SYC008 Audio"],
160
        [0x0175, "SyCom ACM SYC701 G.726L Audio"],
161
        [0x0176, "SyCom ACM SYC701 CELP54 Audio"],
162
        [0x0177, "SyCom ACM SYC701 CELP68 Audio"],
163
        [0x0178, "Knowledge Adventure ADPCM Audio"],
164
        [0x0180, "Fraunhofer IIS MPEG-2/AAC Audio"],
165
        [0x0190, "Digital Theatre Systems DTS DS Audio"],
166
        [0x0200, "Creative Labs ADPCM Audio"],
167
        [0x0202, "Creative Labs FastSpeech8 Audio"],
168
        [0x0203, "Creative Labs FastSpeech10 Audio"],
169
        [0x0210, "UHER Informatic ADPCM Audio"],
170
        [0x0215, "Ulead Systems DV Audio"],
171
        [0x0216, "Ulead Systems DV Audio 1"],
172
        [0x0220, "Quarterdeck Audio"],
173
        [0x0230, "I-Link Worldwide VC Audio"],
174
        [0x0240, "Aureal Semiconductor Raw Sport Audio"],
175
        [0x0241, "ESS Technology AC3 Audio"],
176
        [0x0249, "Generic Passthru Audio"],
177
        [0x0250, "Interactive Products HSX Audio"],
178
        [0x0251, "Interactive Products RPELP Audio"],
179
        [0x0260, "Consistent Software CS2 Audio"],
180
        [0x0270, "Sony SCX Audio"],
181
        [0x0271, "Sony SCY Audio"],
182
        [0x0272, "Sony ATRAC3 Audio"],
183
        [0x0273, "Sony SPC Audio"],
184
        [0x0280, "Telum Audio"],
185
        [0x0281, "Telum IA Audio"],
186
        [0x0285, "Norcom Electronics ADPCM Audio"],
187
        [0x0300, "Fujitsu FM Towns Sound"],
188
        [0x0350, "Micronas Semiconductors Audio"],
189
        [0x0351, "Micronas Semiconductors CELP833 Audio"],
190
        [0x0400, "Brooktree BTV Digital Audio"],
191
        [0x0401, "Intel Music Coder"],
192
        [0x0402, "Ligos Indeo Audio"],
193
        [0x0450, "QDesign Music"],
194
        [0x0500, "On2 VP7 Audio"],
195
        [0x0501, "On2 VP6 Audio"],
196
        [0x0680, "AT&T Labs VMPCM Audio"],
197
        [0x0681, "AT&T TPC Audio"],
198
        [0x08AE, "Clearjump LightWave Lossless Audio"],
199
        [0x1000, "Ing. C. Olivetti & C. GSM Audio"],
200
        [0x1001, "Ing. C. Olivetti & C. PCM Audio"],
201
        [0x1002, "Ing. C. Olivetti & C. CELP Audio"],
202
        [0x1003, "Ing. C. Olivetti & C. SBC Audio"],
203
        [0x1004, "Ing. C. Olivetti & C. OPR Audio"],
204
        [0x1100, "Lernout & Hauspie Audio"],
205
        [0x1101, "Lernout & Hauspie CELP Audio"],
206
        [0x1102, "Lernout & Hauspie SBC8 Audio"],
207
        [0x1103, "Lernout & Hauspie SBC12 Audio"],
208
        [0x1104, "Lernout & Hauspie SBC16 Audio"],
209
        [0x1400, "Norris Audio"],
210
        [0x1401, "ISIAudio Audio 2"],
211
        [0x1500, "AT&T Soundspace Musiccompress Audio"],
212
        [0x1600, "Microsoft MPEG-2 ADTS AAC Audio"],
213
        [0x1601, "Microsoft MPEG-2 RAW AAC Audio"],
214
        [0x1602, "Microsoft MPEG-4 Transport Streams (LOAS/LATM) Audio"],
215
        [0x1608, "Microsoft Nokia MPEG-2 ADTS AAC Audio"],
216
        [0x1609, "Microsoft Nokia MPEG-2 Raw AAC Audio"],
217
        [0x160A, "Microsoft Vodafone MPEG-2 ADTS AAC Audio"],
218
        [0x160B, "Microsoft Vodafone MPEG-2 Raw AAC Audio"],
219
        [0x1610, "Microsoft MPEG-2 AAC or MPEG-4 HE-AAC"],
220
        [0x181C, "Voxware RT24 Speech Audio"],
221
        [0x1971, "Sonic Foundry Lossless Audio"],
222
        [0x1979, "Innings Telecom ADPCM Audio"],
223
        [0x1C07, "Lucent SX8300P Audio"],
224
        [0x1C0C, "Lucent SX5363S Audio"],
225
        [0x1F03, "CUSeeMe Audio"],
226
        [0x1FC4, "NTCSoft ALF2CM ACM Audio"],
227
        [0x2000, "FAST Multimedia DVM Audio"],
228
        [0x2001, "DTS2 Audio"],
229
        [0x3313, "MakeAVIs Audio"],
230
        [0x4143, "Divio MPEG-4 AAC Audio"],
231
        [0x4201, "Nokia Adaptive Multirate Audio"],
232
        [0x4243, "Divio G.726 Audio"],
233
        [0x434C, "LEAD Technologies Speech Audio"],
234
        [0x564C, "LEAD Technologies Vorbis Audio"],
235
        [0x5756, "xiph.org Wavpack Audio"],
236
        [0x6C61, "Apple Lossless Audio Codec"],
237
        [0x674F, "Ogg Vorbis Mode 1 Audio"],
238
        [0x6750, "Ogg Vorbis Mode 2 Audio"],
239
        [0x6751, "Ogg Vorbis Mode 3 Audio"],
240
        [0x676F, "Ogg Vorbis Mode 1+ Audio"],
241
        [0x6770, "Ogg Vorbis Mode 2+ Audio"],
242
        [0x6771, "Ogg Vorbis Mode 3+ Audio"],
243
        [0x7000, "3COM NBX Audio"],
244
        [0x704F, "Ogg Opus Audio"],
245
        [0x706D, "FAAD AAC Audio"],
246
        [0x7361, "AMR Narrowband Audio"],
247
        [0x7362, "AMR Wideband Audio"],
248
        [0x7363, "AMR Wideband Plus Audio"],
249
        [0x7A21, "GSMA/3GPP CBR Audio"],
250
        [0x7A22, "GSMA/3GPP VBR Audio"],
251
        [0xA100, "Comverse Infosys G.723.1 Audio"],
252
        [0xA101, "Comverse Infosys AVQSBC Audio"],
253
        [0xA102, "Comverse Infosys SBC Audio"],
254
        [0xA103, "Symbol Technologies G.729.a Audio"],
255
        [0xA104, "VoiceAge AMR Wideband Audio"],
256
        [0xA105, "Ingenient Technologies G.726 Audio"],
257
        [0xA106, "ISO/MPEG-4 AAC Audio"],
258
        [0xA107, "Encore Software G.726 Audio"],
259
        [0xA108, "ZOLL Medical ASAO Audio"],
260
        [0xA109, "xiph.org Speex Audio"],
261
        [0xA10A, "Vianix MASC Audio"],
262
        [0xA10B, "Microsoft Windows Media 9 Spectrum Analyzer Audio"],
263
        [0xA10C, "Microsoft Windows Media Foundation Spectrum Analyzer Audio"],
264
        [0xA10D, "GSM 610 Audio"],
265
        [0xA10E, "GSM 620 Audio"],
266
        [0xA10F, "GSM 660 Audio"],
267
        [0xA110, "GSM 690 Audio"],
268
        [0xA111, "GSM Adaptive Multirate Wideband Audio"],
269
        [0xA112, "Polycom G.722 Audio"],
270
        [0xA113, "Polycom G.728 Audio"],
271
        [0xA114, "Polycom G.729.a Audio"],
272
        [0xA115, "Polycom Siren Audio"],
273
        [0xA116, "Global IP ILBC Audio"],
274
        [0xA117, "RadioTime Time Shift Radio Audio"],
275
        [0xA118, "Nice Systems ACA Audio"],
276
        [0xA119, "Nice Systems ADPCM Audio"],
277
        [0xA11A, "Vocord Telecom G.721 Audio"],
278
        [0xA11B, "Vocord Telecom G.726 Audio"],
279
        [0xA11C, "Vocord Telecom G.722.1 Audio"],
280
        [0xA11D, "Vocord Telecom G.728 Audio"],
281
        [0xA11E, "Vocord Telecom G.729 Audio"],
282
        [0xA11F, "Vocord Telecom G.729.a Audio"],
283
        [0xA120, "Vocord Telecom G.723.1 Audio"],
284
        [0xA121, "Vocord Telecom LBC Audio"],
285
        [0xA122, "Nice Systems G.728 Audio"],
286
        [0xA123, "France Telecom G.729 Audio"],
287
        [0xA124, "CODIAN Audio"],
288
        [0xF1AC, "FLAC Audio"],
289
    ]);
290

291
    private readonly _averageBytesPerSecond: number;
292
    private readonly _bitsPerSample: number;
293
    private readonly _blockAlign: number;
294
    private readonly _channels: number;
295
    private readonly _formatTag: number;
296
    private readonly _samplesPerSecond: number;
297

298
    /**
299
     * Constructs and initializes a new instance of a RIFF wave format header from the provided
300
     * data.
301
     * @param data Byte vector that contains the raw header
302
     */
303
    public constructor(data: ByteVector) {
304
        // @TODO: Pass in data size so we can calculate duration
305
        Guards.truthy(data, "data");
30✔
306
        if (data.length < 16) {
28✔
307
            throw new CorruptFileError("WAVE format data is too short");
1✔
308
        }
309

310
        this._formatTag = data.subarray(0, 2).toUshort(false);
27✔
311
        this._channels = data.subarray(2, 2).toUshort(false);
27✔
312
        this._samplesPerSecond = data.subarray(4, 4).toUint(false);
27✔
313
        this._averageBytesPerSecond = data.subarray(8, 4).toUint(false);
27✔
314
        this._blockAlign = data.subarray(12, 2).toUshort(false);
27✔
315
        this._bitsPerSample = data.subarray(14, 2).toUshort(false);
27✔
316
    }
317

318
    // #region Properties
319

320
    /** @inheritDoc */
321
    public get audioBitrate(): number { return this.averageBytesPerSecond * 8 / 1000; }
2✔
322

323
    /** @inheritDoc */
324
    public get audioChannels(): number { return this._channels; }
2✔
325

326
    /** @inheritDoc */
327
    public get audioSampleRate(): number { return this._samplesPerSecond; }
14✔
328

329
    /**
330
     * Gets the average data-transfer rate, in bytes per second, of audio described by the current
331
     * instance.
332
     */
333
    public get averageBytesPerSecond(): number { return this._averageBytesPerSecond; }
4✔
334

335
    /**
336
     * @inheritDoc
337
     * @remarks
338
     *     Some compression schemes cannot define a value for this field, so it may be `0`.
339
     *     This is especially common for MP3 audio embedded in an AVI.
340
     */
341
    public get bitsPerSample(): number { return this._bitsPerSample; }
14✔
342

343
    /**
344
     * Gets the block alignment, in bytes. Block alignment is the minimum atomic unit of data for
345
     * {@link formatTag} format type.
346
     */
347
    public get blockAlign(): number { return this._blockAlign; }
×
348

349
    /** @inheritDoc */
350
    public get description(): string {
351
        const fourccString = this._formatTag.toString(16).padStart(4, "0").toUpperCase();
5✔
352
        const formatString = RiffWaveFormatEx.WAVE_FORMAT_TAGS.get(this._formatTag) || "Unknown Audio Format";
5✔
353
        return `${formatString} [0x${fourccString}]`;
5✔
354
    }
355

356
    /**
357
     * @inheritDoc
358
     * @remarks Duration cannot be found from this object
359
     */
360
    public get durationMilliseconds(): number { return 0; }
2✔
361

362
    /**
363
     * Gets the format tag of the audio described by the current instance.
364
     * @remarks
365
     *     Format tags indicate the codec of the audio contained in the file and are
366
     *     contained in a Microsoft registry. For a description of the format, use
367
     *     {@link description}. The complete list can be found in the Win32 mmreg.h SDK header file
368
     */
369
    public get formatTag(): number { return this._formatTag; }
2✔
370

371
    /**
372
     * @inheritDoc
373
     * @remarks
374
     *     Technically any audio format can be encapsulated with a RIFF header since RIFF is
375
     *     simply a "Resource Interchange File Format". It is entirely possible to encapsulate a
376
     *     lossy format (and indeed, lossy WMA must be encapsulated) with a RIFF header. Therefore,
377
     *     this designation as lossless is somewhat misleading and checking {@link description} is
378
     *     necessary to verify the codec being used is lossless or not.
379
     */
380
    public get mediaTypes(): MediaTypes {
381
        // @TODO: This isn't guaranteed. Consider determining the description and mediatype as part
382
        //    of construction.
383
        return MediaTypes.LosslessAudio;
3✔
384
    }
385

386
    // #endregion
387
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc