music-metadata 7.11.1 → 7.11.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +432 -432
- package/lib/ParserFactory.d.ts +49 -49
- package/lib/ParserFactory.js +251 -251
- package/lib/aiff/AiffParser.d.ts +15 -15
- package/lib/aiff/AiffParser.js +85 -85
- package/lib/aiff/AiffToken.d.ts +22 -22
- package/lib/aiff/AiffToken.js +43 -43
- package/lib/apev2/APEv2Parser.d.ts +30 -30
- package/lib/apev2/APEv2Parser.js +162 -162
- package/lib/apev2/APEv2TagMapper.d.ts +4 -4
- package/lib/apev2/APEv2TagMapper.js +87 -86
- package/lib/apev2/APEv2Token.d.ts +100 -100
- package/lib/apev2/APEv2Token.js +127 -126
- package/lib/asf/AsfObject.d.ts +319 -319
- package/lib/asf/AsfObject.js +384 -384
- package/lib/asf/AsfParser.d.ts +17 -17
- package/lib/asf/AsfParser.js +135 -135
- package/lib/asf/AsfTagMapper.d.ts +7 -7
- package/lib/asf/AsfTagMapper.js +96 -95
- package/lib/asf/AsfUtil.d.ts +13 -13
- package/lib/asf/AsfUtil.js +40 -40
- package/lib/asf/GUID.d.ts +86 -86
- package/lib/asf/GUID.js +123 -123
- package/lib/common/BasicParser.d.ts +17 -17
- package/lib/common/BasicParser.js +18 -18
- package/lib/common/CaseInsensitiveTagMap.d.ts +10 -10
- package/lib/common/CaseInsensitiveTagMap.js +22 -21
- package/lib/common/CombinedTagMapper.d.ts +19 -19
- package/lib/common/CombinedTagMapper.js +52 -51
- package/lib/common/FourCC.d.ts +6 -6
- package/lib/common/FourCC.js +29 -28
- package/lib/common/GenericTagMapper.d.ts +51 -51
- package/lib/common/GenericTagMapper.js +56 -55
- package/lib/common/GenericTagTypes.d.ts +33 -33
- package/lib/common/GenericTagTypes.js +132 -131
- package/lib/common/MetadataCollector.d.ts +76 -76
- package/lib/common/MetadataCollector.js +276 -274
- package/lib/common/RandomFileReader.d.ts +20 -20
- package/lib/common/RandomFileReader.js +37 -37
- package/lib/common/RandomUint8ArrayReader.d.ts +18 -18
- package/lib/common/RandomUint8ArrayReader.js +25 -25
- package/lib/common/Util.d.ts +57 -57
- package/lib/common/Util.js +170 -169
- package/lib/core.d.ts +48 -48
- package/lib/core.js +90 -90
- package/lib/dsdiff/DsdiffParser.d.ts +14 -14
- package/lib/dsdiff/DsdiffParser.js +143 -143
- package/lib/dsdiff/DsdiffToken.d.ts +9 -9
- package/lib/dsdiff/DsdiffToken.js +21 -21
- package/lib/dsf/DsfChunk.d.ts +86 -86
- package/lib/dsf/DsfChunk.js +54 -54
- package/lib/dsf/DsfParser.d.ts +9 -9
- package/lib/dsf/DsfParser.js +56 -56
- package/lib/flac/FlacParser.d.ts +28 -28
- package/lib/flac/FlacParser.js +175 -175
- package/lib/id3v1/ID3v1Parser.d.ts +13 -13
- package/lib/id3v1/ID3v1Parser.js +134 -134
- package/lib/id3v1/ID3v1TagMap.d.ts +4 -4
- package/lib/id3v1/ID3v1TagMap.js +23 -22
- package/lib/id3v2/AbstractID3Parser.d.ts +17 -17
- package/lib/id3v2/AbstractID3Parser.js +60 -60
- package/lib/id3v2/FrameParser.d.ts +32 -32
- package/lib/id3v2/FrameParser.js +323 -323
- package/lib/id3v2/ID3v22TagMapper.d.ts +9 -9
- package/lib/id3v2/ID3v22TagMapper.js +56 -54
- package/lib/id3v2/ID3v24TagMapper.d.ts +14 -14
- package/lib/id3v2/ID3v24TagMapper.js +194 -193
- package/lib/id3v2/ID3v2Parser.d.ts +29 -29
- package/lib/id3v2/ID3v2Parser.js +194 -194
- package/lib/id3v2/ID3v2Token.d.ts +73 -73
- package/lib/id3v2/ID3v2Token.js +106 -106
- package/lib/iff/index.d.ts +33 -33
- package/lib/iff/index.js +19 -19
- package/lib/index.d.ts +34 -34
- package/lib/index.js +64 -64
- package/lib/lyrics3/Lyrics3.d.ts +3 -3
- package/lib/lyrics3/Lyrics3.js +17 -17
- package/lib/matroska/MatroskaDtd.d.ts +8 -8
- package/lib/matroska/MatroskaDtd.js +279 -279
- package/lib/matroska/MatroskaParser.d.ts +37 -37
- package/lib/matroska/MatroskaParser.js +235 -234
- package/lib/matroska/MatroskaTagMapper.d.ts +4 -4
- package/lib/matroska/MatroskaTagMapper.js +36 -35
- package/lib/matroska/types.d.ts +175 -175
- package/lib/matroska/types.js +32 -32
- package/lib/mp4/Atom.d.ts +16 -16
- package/lib/mp4/Atom.js +70 -70
- package/lib/mp4/AtomToken.d.ts +395 -395
- package/lib/mp4/AtomToken.js +406 -406
- package/lib/mp4/MP4Parser.d.ts +30 -31
- package/lib/mp4/MP4Parser.js +511 -515
- package/lib/mp4/MP4TagMapper.d.ts +5 -5
- package/lib/mp4/MP4TagMapper.js +116 -115
- package/lib/mpeg/ExtendedLameHeader.d.ts +27 -27
- package/lib/mpeg/ExtendedLameHeader.js +31 -31
- package/lib/mpeg/MpegParser.d.ts +49 -49
- package/lib/mpeg/MpegParser.js +529 -529
- package/lib/mpeg/ReplayGainDataFormat.d.ts +55 -55
- package/lib/mpeg/ReplayGainDataFormat.js +69 -69
- package/lib/mpeg/XingTag.d.ts +45 -45
- package/lib/mpeg/XingTag.js +69 -69
- package/lib/musepack/index.d.ts +5 -5
- package/lib/musepack/index.js +32 -32
- package/lib/musepack/sv7/BitReader.d.ts +13 -13
- package/lib/musepack/sv7/BitReader.js +54 -54
- package/lib/musepack/sv7/MpcSv7Parser.d.ts +8 -8
- package/lib/musepack/sv7/MpcSv7Parser.js +46 -46
- package/lib/musepack/sv7/StreamVersion7.d.ts +28 -28
- package/lib/musepack/sv7/StreamVersion7.js +41 -41
- package/lib/musepack/sv8/MpcSv8Parser.d.ts +6 -6
- package/lib/musepack/sv8/MpcSv8Parser.js +55 -55
- package/lib/musepack/sv8/StreamVersion8.d.ts +40 -40
- package/lib/musepack/sv8/StreamVersion8.js +80 -80
- package/lib/ogg/Ogg.d.ts +72 -72
- package/lib/ogg/Ogg.js +2 -2
- package/lib/ogg/OggParser.d.ts +23 -23
- package/lib/ogg/OggParser.js +126 -126
- package/lib/ogg/opus/Opus.d.ts +48 -48
- package/lib/ogg/opus/Opus.js +28 -28
- package/lib/ogg/opus/OpusParser.d.ts +25 -25
- package/lib/ogg/opus/OpusParser.js +56 -56
- package/lib/ogg/speex/Speex.d.ts +36 -36
- package/lib/ogg/speex/Speex.js +31 -31
- package/lib/ogg/speex/SpeexParser.d.ts +22 -22
- package/lib/ogg/speex/SpeexParser.js +35 -35
- package/lib/ogg/theora/Theora.d.ts +20 -20
- package/lib/ogg/theora/Theora.js +23 -23
- package/lib/ogg/theora/TheoraParser.d.ts +28 -28
- package/lib/ogg/theora/TheoraParser.js +44 -44
- package/lib/ogg/vorbis/Vorbis.d.ts +79 -79
- package/lib/ogg/vorbis/Vorbis.js +78 -78
- package/lib/ogg/vorbis/VorbisDecoder.d.ts +12 -12
- package/lib/ogg/vorbis/VorbisDecoder.js +32 -32
- package/lib/ogg/vorbis/VorbisParser.d.ts +36 -36
- package/lib/ogg/vorbis/VorbisParser.js +128 -128
- package/lib/ogg/vorbis/VorbisTagMapper.d.ts +7 -7
- package/lib/ogg/vorbis/VorbisTagMapper.js +133 -132
- package/lib/riff/RiffChunk.d.ts +16 -16
- package/lib/riff/RiffChunk.js +32 -32
- package/lib/riff/RiffInfoTagMap.d.ts +10 -10
- package/lib/riff/RiffInfoTagMap.js +38 -37
- package/lib/type.d.ts +599 -599
- package/lib/type.js +14 -13
- package/lib/wav/WaveChunk.d.ts +64 -64
- package/lib/wav/WaveChunk.js +65 -65
- package/lib/wav/WaveParser.d.ts +24 -24
- package/lib/wav/WaveParser.js +144 -144
- package/lib/wavpack/WavPackParser.d.ts +14 -14
- package/lib/wavpack/WavPackParser.js +105 -105
- package/lib/wavpack/WavPackToken.d.ts +64 -64
- package/lib/wavpack/WavPackToken.js +76 -76
- package/package.json +142 -142
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RandomFileReader = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
/**
|
|
6
|
-
* Provides abstract file access via the IRandomRead interface
|
|
7
|
-
*/
|
|
8
|
-
class RandomFileReader {
|
|
9
|
-
constructor(filePath, fileSize) {
|
|
10
|
-
this.fileSize = fileSize;
|
|
11
|
-
this.fd = fs.openSync(filePath, 'r');
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Read from a given position of an abstracted file or buffer.
|
|
15
|
-
* @param buffer {Buffer} is the buffer that the data will be written to.
|
|
16
|
-
* @param offset {number} is the offset in the buffer to start writing at.
|
|
17
|
-
* @param length {number}is an integer specifying the number of bytes to read.
|
|
18
|
-
* @param position {number} is an argument specifying where to begin reading from in the file.
|
|
19
|
-
* @return {Promise<number>} bytes read
|
|
20
|
-
*/
|
|
21
|
-
randomRead(buffer, offset, length, position) {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
fs.read(this.fd, buffer, offset, length, position, (err, bytesRead) => {
|
|
24
|
-
if (err) {
|
|
25
|
-
reject(err);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
resolve(bytesRead);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
close() {
|
|
34
|
-
fs.closeSync(this.fd);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.RandomFileReader = RandomFileReader;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RandomFileReader = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
/**
|
|
6
|
+
* Provides abstract file access via the IRandomRead interface
|
|
7
|
+
*/
|
|
8
|
+
class RandomFileReader {
|
|
9
|
+
constructor(filePath, fileSize) {
|
|
10
|
+
this.fileSize = fileSize;
|
|
11
|
+
this.fd = fs.openSync(filePath, 'r');
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Read from a given position of an abstracted file or buffer.
|
|
15
|
+
* @param buffer {Buffer} is the buffer that the data will be written to.
|
|
16
|
+
* @param offset {number} is the offset in the buffer to start writing at.
|
|
17
|
+
* @param length {number}is an integer specifying the number of bytes to read.
|
|
18
|
+
* @param position {number} is an argument specifying where to begin reading from in the file.
|
|
19
|
+
* @return {Promise<number>} bytes read
|
|
20
|
+
*/
|
|
21
|
+
randomRead(buffer, offset, length, position) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
fs.read(this.fd, buffer, offset, length, position, (err, bytesRead) => {
|
|
24
|
+
if (err) {
|
|
25
|
+
reject(err);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
resolve(bytesRead);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
close() {
|
|
34
|
+
fs.closeSync(this.fd);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.RandomFileReader = RandomFileReader;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { IRandomReader } from '../type';
|
|
2
|
-
/**
|
|
3
|
-
* Provides abstract Uint8Array access via the IRandomRead interface
|
|
4
|
-
*/
|
|
5
|
-
export declare class RandomUint8ArrayReader implements IRandomReader {
|
|
6
|
-
private readonly uint8Array;
|
|
7
|
-
readonly fileSize: number;
|
|
8
|
-
constructor(uint8Array: Uint8Array);
|
|
9
|
-
/**
|
|
10
|
-
* Read from a given position of an abstracted file or buffer.
|
|
11
|
-
* @param uint8Array - Uint8Array that the data will be written to.
|
|
12
|
-
* @param offset - Offset in the buffer to start writing at.
|
|
13
|
-
* @param length - Integer specifying the number of bytes to read.
|
|
14
|
-
* @param position - Specifies where to begin reading from in the file.
|
|
15
|
-
* @return Promise providing bytes read
|
|
16
|
-
*/
|
|
17
|
-
randomRead(uint8Array: Uint8Array, offset: number, length: number, position: number): Promise<number>;
|
|
18
|
-
}
|
|
1
|
+
import { IRandomReader } from '../type';
|
|
2
|
+
/**
|
|
3
|
+
* Provides abstract Uint8Array access via the IRandomRead interface
|
|
4
|
+
*/
|
|
5
|
+
export declare class RandomUint8ArrayReader implements IRandomReader {
|
|
6
|
+
private readonly uint8Array;
|
|
7
|
+
readonly fileSize: number;
|
|
8
|
+
constructor(uint8Array: Uint8Array);
|
|
9
|
+
/**
|
|
10
|
+
* Read from a given position of an abstracted file or buffer.
|
|
11
|
+
* @param uint8Array - Uint8Array that the data will be written to.
|
|
12
|
+
* @param offset - Offset in the buffer to start writing at.
|
|
13
|
+
* @param length - Integer specifying the number of bytes to read.
|
|
14
|
+
* @param position - Specifies where to begin reading from in the file.
|
|
15
|
+
* @return Promise providing bytes read
|
|
16
|
+
*/
|
|
17
|
+
randomRead(uint8Array: Uint8Array, offset: number, length: number, position: number): Promise<number>;
|
|
18
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RandomUint8ArrayReader = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Provides abstract Uint8Array access via the IRandomRead interface
|
|
6
|
-
*/
|
|
7
|
-
class RandomUint8ArrayReader {
|
|
8
|
-
constructor(uint8Array) {
|
|
9
|
-
this.uint8Array = uint8Array;
|
|
10
|
-
this.fileSize = uint8Array.length;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Read from a given position of an abstracted file or buffer.
|
|
14
|
-
* @param uint8Array - Uint8Array that the data will be written to.
|
|
15
|
-
* @param offset - Offset in the buffer to start writing at.
|
|
16
|
-
* @param length - Integer specifying the number of bytes to read.
|
|
17
|
-
* @param position - Specifies where to begin reading from in the file.
|
|
18
|
-
* @return Promise providing bytes read
|
|
19
|
-
*/
|
|
20
|
-
async randomRead(uint8Array, offset, length, position) {
|
|
21
|
-
uint8Array.set(this.uint8Array.subarray(position, position + length), offset);
|
|
22
|
-
return length;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.RandomUint8ArrayReader = RandomUint8ArrayReader;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RandomUint8ArrayReader = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Provides abstract Uint8Array access via the IRandomRead interface
|
|
6
|
+
*/
|
|
7
|
+
class RandomUint8ArrayReader {
|
|
8
|
+
constructor(uint8Array) {
|
|
9
|
+
this.uint8Array = uint8Array;
|
|
10
|
+
this.fileSize = uint8Array.length;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Read from a given position of an abstracted file or buffer.
|
|
14
|
+
* @param uint8Array - Uint8Array that the data will be written to.
|
|
15
|
+
* @param offset - Offset in the buffer to start writing at.
|
|
16
|
+
* @param length - Integer specifying the number of bytes to read.
|
|
17
|
+
* @param position - Specifies where to begin reading from in the file.
|
|
18
|
+
* @return Promise providing bytes read
|
|
19
|
+
*/
|
|
20
|
+
async randomRead(uint8Array, offset, length, position) {
|
|
21
|
+
uint8Array.set(this.uint8Array.subarray(position, position + length), offset);
|
|
22
|
+
return length;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.RandomUint8ArrayReader = RandomUint8ArrayReader;
|
package/lib/common/Util.d.ts
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { IRatio } from '../type';
|
|
3
|
-
export declare type StringEncoding = 'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'base64url' | 'latin1' | 'hex';
|
|
4
|
-
export declare function getBit(buf: Uint8Array, off: number, bit: number): boolean;
|
|
5
|
-
/**
|
|
6
|
-
* Found delimiting zero in uint8Array
|
|
7
|
-
* @param uint8Array Uint8Array to find the zero delimiter in
|
|
8
|
-
* @param start Offset in uint8Array
|
|
9
|
-
* @param end Last position to parse in uint8Array
|
|
10
|
-
* @param encoding The string encoding used
|
|
11
|
-
* @return Absolute position on uint8Array where zero found
|
|
12
|
-
*/
|
|
13
|
-
export declare function findZero(uint8Array: Uint8Array, start: number, end: number, encoding?: StringEncoding): number;
|
|
14
|
-
export declare function trimRightNull(x: string): string;
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* @param buffer Decoder input data
|
|
18
|
-
* @param encoding 'utf16le' | 'utf16' | 'utf8' | 'iso-8859-1'
|
|
19
|
-
* @return {string}
|
|
20
|
-
*/
|
|
21
|
-
export declare function decodeString(buffer: Buffer, encoding: StringEncoding): string;
|
|
22
|
-
export declare function stripNulls(str: string): string;
|
|
23
|
-
/**
|
|
24
|
-
* Read bit-aligned number start from buffer
|
|
25
|
-
* Total offset in bits = byteOffset * 8 + bitOffset
|
|
26
|
-
* @param buf Byte buffer
|
|
27
|
-
* @param byteOffset Starting offset in bytes
|
|
28
|
-
* @param bitOffset Starting offset in bits: 0 = lsb
|
|
29
|
-
* @param len Length of number in bits
|
|
30
|
-
* @return {number} decoded bit aligned number
|
|
31
|
-
*/
|
|
32
|
-
export declare function getBitAllignedNumber(buf: Uint8Array, byteOffset: number, bitOffset: number, len: number): number;
|
|
33
|
-
/**
|
|
34
|
-
* Read bit-aligned number start from buffer
|
|
35
|
-
* Total offset in bits = byteOffset * 8 + bitOffset
|
|
36
|
-
* @param buf Byte buffer
|
|
37
|
-
* @param byteOffset Starting offset in bytes
|
|
38
|
-
* @param bitOffset Starting offset in bits: 0 = most significant bit, 7 is least significant bit
|
|
39
|
-
* @return {number} decoded bit aligned number
|
|
40
|
-
*/
|
|
41
|
-
export declare function isBitSet(buf: Uint8Array, byteOffset: number, bitOffset: number): boolean;
|
|
42
|
-
export declare function a2hex(str: string): string;
|
|
43
|
-
/**
|
|
44
|
-
* Convert power ratio to DB
|
|
45
|
-
* ratio: [0..1]
|
|
46
|
-
*/
|
|
47
|
-
export declare function ratioToDb(ratio: number): number;
|
|
48
|
-
/**
|
|
49
|
-
* Convert dB to ratio
|
|
50
|
-
* db Decibels
|
|
51
|
-
*/
|
|
52
|
-
export declare function dbToRatio(dB: number): number;
|
|
53
|
-
/**
|
|
54
|
-
* Convert replay gain to ratio and Decibel
|
|
55
|
-
* @param value string holding a ratio like '0.034' or '-7.54 dB'
|
|
56
|
-
*/
|
|
57
|
-
export declare function toRatio(value: string): IRatio;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IRatio } from '../type';
|
|
3
|
+
export declare type StringEncoding = 'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'base64url' | 'latin1' | 'hex';
|
|
4
|
+
export declare function getBit(buf: Uint8Array, off: number, bit: number): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Found delimiting zero in uint8Array
|
|
7
|
+
* @param uint8Array Uint8Array to find the zero delimiter in
|
|
8
|
+
* @param start Offset in uint8Array
|
|
9
|
+
* @param end Last position to parse in uint8Array
|
|
10
|
+
* @param encoding The string encoding used
|
|
11
|
+
* @return Absolute position on uint8Array where zero found
|
|
12
|
+
*/
|
|
13
|
+
export declare function findZero(uint8Array: Uint8Array, start: number, end: number, encoding?: StringEncoding): number;
|
|
14
|
+
export declare function trimRightNull(x: string): string;
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param buffer Decoder input data
|
|
18
|
+
* @param encoding 'utf16le' | 'utf16' | 'utf8' | 'iso-8859-1'
|
|
19
|
+
* @return {string}
|
|
20
|
+
*/
|
|
21
|
+
export declare function decodeString(buffer: Buffer, encoding: StringEncoding): string;
|
|
22
|
+
export declare function stripNulls(str: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Read bit-aligned number start from buffer
|
|
25
|
+
* Total offset in bits = byteOffset * 8 + bitOffset
|
|
26
|
+
* @param buf Byte buffer
|
|
27
|
+
* @param byteOffset Starting offset in bytes
|
|
28
|
+
* @param bitOffset Starting offset in bits: 0 = lsb
|
|
29
|
+
* @param len Length of number in bits
|
|
30
|
+
* @return {number} decoded bit aligned number
|
|
31
|
+
*/
|
|
32
|
+
export declare function getBitAllignedNumber(buf: Uint8Array, byteOffset: number, bitOffset: number, len: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Read bit-aligned number start from buffer
|
|
35
|
+
* Total offset in bits = byteOffset * 8 + bitOffset
|
|
36
|
+
* @param buf Byte buffer
|
|
37
|
+
* @param byteOffset Starting offset in bytes
|
|
38
|
+
* @param bitOffset Starting offset in bits: 0 = most significant bit, 7 is least significant bit
|
|
39
|
+
* @return {number} decoded bit aligned number
|
|
40
|
+
*/
|
|
41
|
+
export declare function isBitSet(buf: Uint8Array, byteOffset: number, bitOffset: number): boolean;
|
|
42
|
+
export declare function a2hex(str: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Convert power ratio to DB
|
|
45
|
+
* ratio: [0..1]
|
|
46
|
+
*/
|
|
47
|
+
export declare function ratioToDb(ratio: number): number;
|
|
48
|
+
/**
|
|
49
|
+
* Convert dB to ratio
|
|
50
|
+
* db Decibels
|
|
51
|
+
*/
|
|
52
|
+
export declare function dbToRatio(dB: number): number;
|
|
53
|
+
/**
|
|
54
|
+
* Convert replay gain to ratio and Decibel
|
|
55
|
+
* @param value string holding a ratio like '0.034' or '-7.54 dB'
|
|
56
|
+
*/
|
|
57
|
+
export declare function toRatio(value: string): IRatio;
|
package/lib/common/Util.js
CHANGED
|
@@ -1,169 +1,170 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toRatio = exports.dbToRatio = exports.ratioToDb = exports.a2hex = exports.isBitSet = exports.getBitAllignedNumber = exports.stripNulls = exports.decodeString = exports.trimRightNull = exports.findZero = exports.getBit = void 0;
|
|
4
|
-
function getBit(buf, off, bit) {
|
|
5
|
-
return (buf[off] & (1 << bit)) !== 0;
|
|
6
|
-
}
|
|
7
|
-
exports.getBit = getBit;
|
|
8
|
-
/**
|
|
9
|
-
* Found delimiting zero in uint8Array
|
|
10
|
-
* @param uint8Array Uint8Array to find the zero delimiter in
|
|
11
|
-
* @param start Offset in uint8Array
|
|
12
|
-
* @param end Last position to parse in uint8Array
|
|
13
|
-
* @param encoding The string encoding used
|
|
14
|
-
* @return Absolute position on uint8Array where zero found
|
|
15
|
-
*/
|
|
16
|
-
function findZero(uint8Array, start, end, encoding) {
|
|
17
|
-
let i = start;
|
|
18
|
-
if (encoding === 'utf16le') {
|
|
19
|
-
while (uint8Array[i] !== 0 || uint8Array[i + 1] !== 0) {
|
|
20
|
-
if (i >= end)
|
|
21
|
-
return end;
|
|
22
|
-
i += 2;
|
|
23
|
-
}
|
|
24
|
-
return i;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
while (uint8Array[i] !== 0) {
|
|
28
|
-
if (i >= end)
|
|
29
|
-
return end;
|
|
30
|
-
i++;
|
|
31
|
-
}
|
|
32
|
-
return i;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.findZero = findZero;
|
|
36
|
-
function trimRightNull(x) {
|
|
37
|
-
const pos0 = x.indexOf('\0');
|
|
38
|
-
return pos0 === -1 ? x : x.substr(0, pos0);
|
|
39
|
-
}
|
|
40
|
-
exports.trimRightNull = trimRightNull;
|
|
41
|
-
function swapBytes(uint8Array) {
|
|
42
|
-
const l = uint8Array.length;
|
|
43
|
-
if ((l & 1) !== 0)
|
|
44
|
-
throw new Error('Buffer length must be even');
|
|
45
|
-
for (let i = 0; i < l; i += 2) {
|
|
46
|
-
const a = uint8Array[i];
|
|
47
|
-
uint8Array[i] = uint8Array[i + 1];
|
|
48
|
-
uint8Array[i + 1] = a;
|
|
49
|
-
}
|
|
50
|
-
return uint8Array;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
*
|
|
54
|
-
* @param buffer Decoder input data
|
|
55
|
-
* @param encoding 'utf16le' | 'utf16' | 'utf8' | 'iso-8859-1'
|
|
56
|
-
* @return {string}
|
|
57
|
-
*/
|
|
58
|
-
function decodeString(buffer, encoding) {
|
|
59
|
-
// annoying workaround for a double BOM issue
|
|
60
|
-
// https://github.com/leetreveil/musicmetadata/issues/84
|
|
61
|
-
let offset = 0;
|
|
62
|
-
if (buffer[0] === 0xFF && buffer[1] === 0xFE) { // little endian
|
|
63
|
-
if (encoding === 'utf16le') {
|
|
64
|
-
offset = 2;
|
|
65
|
-
}
|
|
66
|
-
else if (buffer[2] === 0xFE && buffer[3] === 0xFF) {
|
|
67
|
-
offset = 2; // Clear double BOM
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else if (encoding === 'utf16le' && buffer[0] === 0xFE && buffer[1] === 0xFF) {
|
|
71
|
-
// BOM, indicating big endian decoding
|
|
72
|
-
return decodeString(swapBytes(buffer), encoding);
|
|
73
|
-
}
|
|
74
|
-
return buffer.toString(encoding, offset);
|
|
75
|
-
}
|
|
76
|
-
exports.decodeString = decodeString;
|
|
77
|
-
function stripNulls(str) {
|
|
78
|
-
str = str.replace(/^\x00+/g, '');
|
|
79
|
-
str = str.replace(/\x00+$/g, '');
|
|
80
|
-
return str;
|
|
81
|
-
}
|
|
82
|
-
exports.stripNulls = stripNulls;
|
|
83
|
-
/**
|
|
84
|
-
* Read bit-aligned number start from buffer
|
|
85
|
-
* Total offset in bits = byteOffset * 8 + bitOffset
|
|
86
|
-
* @param buf Byte buffer
|
|
87
|
-
* @param byteOffset Starting offset in bytes
|
|
88
|
-
* @param bitOffset Starting offset in bits: 0 = lsb
|
|
89
|
-
* @param len Length of number in bits
|
|
90
|
-
* @return {number} decoded bit aligned number
|
|
91
|
-
*/
|
|
92
|
-
function getBitAllignedNumber(buf, byteOffset, bitOffset, len) {
|
|
93
|
-
const byteOff = byteOffset + ~~(bitOffset / 8);
|
|
94
|
-
const bitOff = bitOffset % 8;
|
|
95
|
-
let value = buf[byteOff];
|
|
96
|
-
value &= 0xff >> bitOff;
|
|
97
|
-
const bitsRead = 8 - bitOff;
|
|
98
|
-
const bitsLeft = len - bitsRead;
|
|
99
|
-
if (bitsLeft < 0) {
|
|
100
|
-
value >>= (8 - bitOff - len);
|
|
101
|
-
}
|
|
102
|
-
else if (bitsLeft > 0) {
|
|
103
|
-
value <<= bitsLeft;
|
|
104
|
-
value |= getBitAllignedNumber(buf, byteOffset, bitOffset + bitsRead, bitsLeft);
|
|
105
|
-
}
|
|
106
|
-
return value;
|
|
107
|
-
}
|
|
108
|
-
exports.getBitAllignedNumber = getBitAllignedNumber;
|
|
109
|
-
/**
|
|
110
|
-
* Read bit-aligned number start from buffer
|
|
111
|
-
* Total offset in bits = byteOffset * 8 + bitOffset
|
|
112
|
-
* @param buf Byte buffer
|
|
113
|
-
* @param byteOffset Starting offset in bytes
|
|
114
|
-
* @param bitOffset Starting offset in bits: 0 = most significant bit, 7 is least significant bit
|
|
115
|
-
* @return {number} decoded bit aligned number
|
|
116
|
-
*/
|
|
117
|
-
function isBitSet(buf, byteOffset, bitOffset) {
|
|
118
|
-
return getBitAllignedNumber(buf, byteOffset, bitOffset, 1) === 1;
|
|
119
|
-
}
|
|
120
|
-
exports.isBitSet = isBitSet;
|
|
121
|
-
function a2hex(str) {
|
|
122
|
-
const arr = [];
|
|
123
|
-
for (let i = 0, l = str.length; i < l; i++) {
|
|
124
|
-
const hex = Number(str.charCodeAt(i)).toString(16);
|
|
125
|
-
arr.push(hex.length === 1 ? '0' + hex : hex);
|
|
126
|
-
}
|
|
127
|
-
return arr.join(' ');
|
|
128
|
-
}
|
|
129
|
-
exports.a2hex = a2hex;
|
|
130
|
-
/**
|
|
131
|
-
* Convert power ratio to DB
|
|
132
|
-
* ratio: [0..1]
|
|
133
|
-
*/
|
|
134
|
-
function ratioToDb(ratio) {
|
|
135
|
-
return 10 * Math.log10(ratio);
|
|
136
|
-
}
|
|
137
|
-
exports.ratioToDb = ratioToDb;
|
|
138
|
-
/**
|
|
139
|
-
* Convert dB to ratio
|
|
140
|
-
* db Decibels
|
|
141
|
-
*/
|
|
142
|
-
function dbToRatio(dB) {
|
|
143
|
-
return Math.pow(10, dB / 10);
|
|
144
|
-
}
|
|
145
|
-
exports.dbToRatio = dbToRatio;
|
|
146
|
-
/**
|
|
147
|
-
* Convert replay gain to ratio and Decibel
|
|
148
|
-
* @param value string holding a ratio like '0.034' or '-7.54 dB'
|
|
149
|
-
*/
|
|
150
|
-
function toRatio(value) {
|
|
151
|
-
const ps = value.split(' ').map(p => p.trim().toLowerCase());
|
|
152
|
-
// @ts-ignore
|
|
153
|
-
if (ps.length >= 1) {
|
|
154
|
-
const v = parseFloat(ps[0]);
|
|
155
|
-
if (ps.length === 2 && ps[1] === 'db') {
|
|
156
|
-
return {
|
|
157
|
-
dB: v,
|
|
158
|
-
ratio: dbToRatio(v)
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
return {
|
|
163
|
-
dB: ratioToDb(v),
|
|
164
|
-
ratio: v
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
exports.toRatio = toRatio;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toRatio = exports.dbToRatio = exports.ratioToDb = exports.a2hex = exports.isBitSet = exports.getBitAllignedNumber = exports.stripNulls = exports.decodeString = exports.trimRightNull = exports.findZero = exports.getBit = void 0;
|
|
4
|
+
function getBit(buf, off, bit) {
|
|
5
|
+
return (buf[off] & (1 << bit)) !== 0;
|
|
6
|
+
}
|
|
7
|
+
exports.getBit = getBit;
|
|
8
|
+
/**
|
|
9
|
+
* Found delimiting zero in uint8Array
|
|
10
|
+
* @param uint8Array Uint8Array to find the zero delimiter in
|
|
11
|
+
* @param start Offset in uint8Array
|
|
12
|
+
* @param end Last position to parse in uint8Array
|
|
13
|
+
* @param encoding The string encoding used
|
|
14
|
+
* @return Absolute position on uint8Array where zero found
|
|
15
|
+
*/
|
|
16
|
+
function findZero(uint8Array, start, end, encoding) {
|
|
17
|
+
let i = start;
|
|
18
|
+
if (encoding === 'utf16le') {
|
|
19
|
+
while (uint8Array[i] !== 0 || uint8Array[i + 1] !== 0) {
|
|
20
|
+
if (i >= end)
|
|
21
|
+
return end;
|
|
22
|
+
i += 2;
|
|
23
|
+
}
|
|
24
|
+
return i;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
while (uint8Array[i] !== 0) {
|
|
28
|
+
if (i >= end)
|
|
29
|
+
return end;
|
|
30
|
+
i++;
|
|
31
|
+
}
|
|
32
|
+
return i;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.findZero = findZero;
|
|
36
|
+
function trimRightNull(x) {
|
|
37
|
+
const pos0 = x.indexOf('\0');
|
|
38
|
+
return pos0 === -1 ? x : x.substr(0, pos0);
|
|
39
|
+
}
|
|
40
|
+
exports.trimRightNull = trimRightNull;
|
|
41
|
+
function swapBytes(uint8Array) {
|
|
42
|
+
const l = uint8Array.length;
|
|
43
|
+
if ((l & 1) !== 0)
|
|
44
|
+
throw new Error('Buffer length must be even');
|
|
45
|
+
for (let i = 0; i < l; i += 2) {
|
|
46
|
+
const a = uint8Array[i];
|
|
47
|
+
uint8Array[i] = uint8Array[i + 1];
|
|
48
|
+
uint8Array[i + 1] = a;
|
|
49
|
+
}
|
|
50
|
+
return uint8Array;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @param buffer Decoder input data
|
|
55
|
+
* @param encoding 'utf16le' | 'utf16' | 'utf8' | 'iso-8859-1'
|
|
56
|
+
* @return {string}
|
|
57
|
+
*/
|
|
58
|
+
function decodeString(buffer, encoding) {
|
|
59
|
+
// annoying workaround for a double BOM issue
|
|
60
|
+
// https://github.com/leetreveil/musicmetadata/issues/84
|
|
61
|
+
let offset = 0;
|
|
62
|
+
if (buffer[0] === 0xFF && buffer[1] === 0xFE) { // little endian
|
|
63
|
+
if (encoding === 'utf16le') {
|
|
64
|
+
offset = 2;
|
|
65
|
+
}
|
|
66
|
+
else if (buffer[2] === 0xFE && buffer[3] === 0xFF) {
|
|
67
|
+
offset = 2; // Clear double BOM
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (encoding === 'utf16le' && buffer[0] === 0xFE && buffer[1] === 0xFF) {
|
|
71
|
+
// BOM, indicating big endian decoding
|
|
72
|
+
return decodeString(swapBytes(buffer), encoding);
|
|
73
|
+
}
|
|
74
|
+
return buffer.toString(encoding, offset);
|
|
75
|
+
}
|
|
76
|
+
exports.decodeString = decodeString;
|
|
77
|
+
function stripNulls(str) {
|
|
78
|
+
str = str.replace(/^\x00+/g, '');
|
|
79
|
+
str = str.replace(/\x00+$/g, '');
|
|
80
|
+
return str;
|
|
81
|
+
}
|
|
82
|
+
exports.stripNulls = stripNulls;
|
|
83
|
+
/**
|
|
84
|
+
* Read bit-aligned number start from buffer
|
|
85
|
+
* Total offset in bits = byteOffset * 8 + bitOffset
|
|
86
|
+
* @param buf Byte buffer
|
|
87
|
+
* @param byteOffset Starting offset in bytes
|
|
88
|
+
* @param bitOffset Starting offset in bits: 0 = lsb
|
|
89
|
+
* @param len Length of number in bits
|
|
90
|
+
* @return {number} decoded bit aligned number
|
|
91
|
+
*/
|
|
92
|
+
function getBitAllignedNumber(buf, byteOffset, bitOffset, len) {
|
|
93
|
+
const byteOff = byteOffset + ~~(bitOffset / 8);
|
|
94
|
+
const bitOff = bitOffset % 8;
|
|
95
|
+
let value = buf[byteOff];
|
|
96
|
+
value &= 0xff >> bitOff;
|
|
97
|
+
const bitsRead = 8 - bitOff;
|
|
98
|
+
const bitsLeft = len - bitsRead;
|
|
99
|
+
if (bitsLeft < 0) {
|
|
100
|
+
value >>= (8 - bitOff - len);
|
|
101
|
+
}
|
|
102
|
+
else if (bitsLeft > 0) {
|
|
103
|
+
value <<= bitsLeft;
|
|
104
|
+
value |= getBitAllignedNumber(buf, byteOffset, bitOffset + bitsRead, bitsLeft);
|
|
105
|
+
}
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
exports.getBitAllignedNumber = getBitAllignedNumber;
|
|
109
|
+
/**
|
|
110
|
+
* Read bit-aligned number start from buffer
|
|
111
|
+
* Total offset in bits = byteOffset * 8 + bitOffset
|
|
112
|
+
* @param buf Byte buffer
|
|
113
|
+
* @param byteOffset Starting offset in bytes
|
|
114
|
+
* @param bitOffset Starting offset in bits: 0 = most significant bit, 7 is least significant bit
|
|
115
|
+
* @return {number} decoded bit aligned number
|
|
116
|
+
*/
|
|
117
|
+
function isBitSet(buf, byteOffset, bitOffset) {
|
|
118
|
+
return getBitAllignedNumber(buf, byteOffset, bitOffset, 1) === 1;
|
|
119
|
+
}
|
|
120
|
+
exports.isBitSet = isBitSet;
|
|
121
|
+
function a2hex(str) {
|
|
122
|
+
const arr = [];
|
|
123
|
+
for (let i = 0, l = str.length; i < l; i++) {
|
|
124
|
+
const hex = Number(str.charCodeAt(i)).toString(16);
|
|
125
|
+
arr.push(hex.length === 1 ? '0' + hex : hex);
|
|
126
|
+
}
|
|
127
|
+
return arr.join(' ');
|
|
128
|
+
}
|
|
129
|
+
exports.a2hex = a2hex;
|
|
130
|
+
/**
|
|
131
|
+
* Convert power ratio to DB
|
|
132
|
+
* ratio: [0..1]
|
|
133
|
+
*/
|
|
134
|
+
function ratioToDb(ratio) {
|
|
135
|
+
return 10 * Math.log10(ratio);
|
|
136
|
+
}
|
|
137
|
+
exports.ratioToDb = ratioToDb;
|
|
138
|
+
/**
|
|
139
|
+
* Convert dB to ratio
|
|
140
|
+
* db Decibels
|
|
141
|
+
*/
|
|
142
|
+
function dbToRatio(dB) {
|
|
143
|
+
return Math.pow(10, dB / 10);
|
|
144
|
+
}
|
|
145
|
+
exports.dbToRatio = dbToRatio;
|
|
146
|
+
/**
|
|
147
|
+
* Convert replay gain to ratio and Decibel
|
|
148
|
+
* @param value string holding a ratio like '0.034' or '-7.54 dB'
|
|
149
|
+
*/
|
|
150
|
+
function toRatio(value) {
|
|
151
|
+
const ps = value.split(' ').map(p => p.trim().toLowerCase());
|
|
152
|
+
// @ts-ignore
|
|
153
|
+
if (ps.length >= 1) {
|
|
154
|
+
const v = parseFloat(ps[0]);
|
|
155
|
+
if (ps.length === 2 && ps[1] === 'db') {
|
|
156
|
+
return {
|
|
157
|
+
dB: v,
|
|
158
|
+
ratio: dbToRatio(v)
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
return {
|
|
163
|
+
dB: ratioToDb(v),
|
|
164
|
+
ratio: v
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.toRatio = toRatio;
|
|
170
|
+
//# sourceMappingURL=Util.js.map
|