Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public get(buf: Buffer, off: number): ITrackHeaderAtom {
return {
version: Token.UINT8.get(buf, off),
flags: Token.UINT24_BE.get(buf, off + 1),
creationTime: Token.UINT32_BE.get(buf, off + 4),
modificationTime: Token.UINT32_BE.get(buf, off + 8),
trackId: Token.UINT32_BE.get(buf, off + 12),
// reserved 4 bytes
duration: Token.UINT32_BE.get(buf, off + 20),
layer: Token.UINT16_BE.get(buf, off + 24),
alternateGroup: Token.UINT16_BE.get(buf, off + 26),
volume: Token.UINT16_BE.get(buf, off + 28) // ToDo: fixed point
// ToDo: add remaining fields
};
}
}
get: (buf: Buffer, off: number): IBlockStreamInfo => {
return {
// The minimum block size (in samples) used in the stream.
minimumBlockSize: Token.UINT16_BE.get(buf, off),
// The maximum block size (in samples) used in the stream.
// (Minimum blocksize == maximum blocksize) implies a fixed-blocksize stream.
maximumBlockSize: Token.UINT16_BE.get(buf, off + 2) / 1000,
// The minimum frame size (in bytes) used in the stream.
// May be 0 to imply the value is not known.
minimumFrameSize: Token.UINT24_BE.get(buf, off + 4),
// The maximum frame size (in bytes) used in the stream.
// May be 0 to imply the value is not known.
maximumFrameSize: Token.UINT24_BE.get(buf, off + 7),
// Sample rate in Hz. Though 20 bits are available,
// the maximum sample rate is limited by the structure of frame headers to 655350Hz.
// Also, a value of 0 is invalid.
sampleRate: Token.UINT24_BE.get(buf, off + 10) >> 4,
// probably slower: sampleRate: common.getBitAllignedNumber(buf, off + 10, 0, 20),
// (number of channels)-1. FLAC supports from 1 to 8 channels
channels: common.getBitAllignedNumber(buf, off + 12, 4, 3) + 1,
this.metadata.setFormat('lossless', true);
this.metadata.setFormat('bitsPerSample', 1);
}
this.metadata.setFormat('codec', `${compressionIdCode} (${compressionName})`);
break;
case 'ABSS': // 3.2.4 Absolute Start Time Chunk
const hours = await this.tokenizer.readToken(Token.UINT16_BE);
const minutes = await this.tokenizer.readToken(Token.UINT8);
const seconds = await this.tokenizer.readToken(Token.UINT8);
const samples = await this.tokenizer.readToken(Token.UINT32_BE);
debug(`ABSS ${hours}:${minutes}:${seconds}.${samples}`);
break;
case 'LSCO': // 3.2.5 Loudspeaker Configuration Chunk
const lsConfig = await this.tokenizer.readToken(Token.UINT16_BE);
debug(`LSCO lsConfig=${lsConfig}`);
break;
case 'COMT':
default:
debug(`Unknown sound-property-chunk[ID=${sndPropHeader.chunkID}, size=${sndPropHeader.chunkSize}]`);
await this.tokenizer.ignore(sndPropHeader.chunkSize);
}
const remaining = sndPropHeader.chunkSize - (this.tokenizer.position - p0);
if (remaining > 0) {
debug(`After Parsing sound-property-chunk ${sndPropHeader.chunkSize}, remaining ${remaining} bytes`);
await this.tokenizer.ignore(remaining);
}
remainingSize -= ChunkHeader.len + sndPropHeader.chunkSize;
debug(`Parsing sound-property-chunks, remainingSize=${remainingSize}`);
}
get: (buf: Buffer, off: number): IBlockStreamInfo => {
return {
// The minimum block size (in samples) used in the stream.
minimumBlockSize: Token.UINT16_BE.get(buf, off),
// The maximum block size (in samples) used in the stream.
// (Minimum blocksize == maximum blocksize) implies a fixed-blocksize stream.
maximumBlockSize: Token.UINT16_BE.get(buf, off + 2) / 1000,
// The minimum frame size (in bytes) used in the stream.
// May be 0 to imply the value is not known.
minimumFrameSize: Token.UINT24_BE.get(buf, off + 4),
// The maximum frame size (in bytes) used in the stream.
// May be 0 to imply the value is not known.
maximumFrameSize: Token.UINT24_BE.get(buf, off + 7),
// Sample rate in Hz. Though 20 bits are available,
// the maximum sample rate is limited by the structure of frame headers to 655350Hz.
// Also, a value of 0 is invalid.
sampleRate: Token.UINT24_BE.get(buf, off + 10) >> 4,
// probably slower: sampleRate: common.getBitAllignedNumber(buf, off + 10, 0, 20),
// (number of channels)-1. FLAC supports from 1 to 8 channels
channels: common.getBitAllignedNumber(buf, off + 12, 4, 3) + 1,
// bits per sample)-1.
// FLAC supports from 4 to 32 bits per sample. Currently the reference encoder and decoders only support up to 24 bits per sample.
bitsPerSample: common.getBitAllignedNumber(buf, off + 12, 7, 5) + 1,
debug(`Parsing sound-property-chunks, remainingSize=${remainingSize}`);
while (remainingSize > 0) {
const sndPropHeader = await this.tokenizer.readToken(ChunkHeader);
debug(`Sound-property-chunk[ID=${sndPropHeader.chunkID}, size=${sndPropHeader.chunkSize}]`);
const p0 = this.tokenizer.position;
switch (sndPropHeader.chunkID.trim()) {
case 'FS': // 3.2.1 Sample Rate Chunk
const sampleRate = await this.tokenizer.readToken(Token.UINT32_BE);
this.metadata.setFormat('sampleRate', sampleRate);
break;
case 'CHNL': // 3.2.2 Channels Chunk
const numChannels = await this.tokenizer.readToken(Token.UINT16_BE);
this.metadata.setFormat('numberOfChannels', numChannels);
await this.handleChannelChunks(sndPropHeader.chunkSize - Token.UINT16_BE.len);
break;
case 'CMPR': // 3.2.3 Compression Type Chunk
const compressionIdCode = (await this.tokenizer.readToken(FourCcToken)).trim();
const count = await this.tokenizer.readToken(Token.UINT8);
const compressionName = await this.tokenizer.readToken(new Token.StringType(count, 'ascii'));
if (compressionIdCode === 'DSD') {
this.metadata.setFormat('lossless', true);
this.metadata.setFormat('bitsPerSample', 1);
}
this.metadata.setFormat('codec', `${compressionIdCode} (${compressionName})`);
break;
case 'ABSS': // 3.2.4 Absolute Start Time Chunk
const hours = await this.tokenizer.readToken(Token.UINT16_BE);
const minutes = await this.tokenizer.readToken(Token.UINT8);
get: (buf, off): IExtendedHeader => {
return {
// Extended header size
size: Token.UINT32_BE.get(buf, off),
// Extended Flags
extendedFlags: Token.UINT16_BE.get(buf, off + 4),
// Size of padding
sizeOfPadding: Token.UINT32_BE.get(buf, off + 6),
// CRC data present
crcDataPresent: common.strtokBITSET.get(buf, off + 4, 31)
};
}
};
get: (buf: Buffer, off: number): IBlockStreamInfo => {
return {
// The minimum block size (in samples) used in the stream.
minimumBlockSize: Token.UINT16_BE.get(buf, off),
// The maximum block size (in samples) used in the stream.
// (Minimum blocksize == maximum blocksize) implies a fixed-blocksize stream.
maximumBlockSize: Token.UINT16_BE.get(buf, off + 2) / 1000,
// The minimum frame size (in bytes) used in the stream.
// May be 0 to imply the value is not known.
minimumFrameSize: Token.UINT24_BE.get(buf, off + 4),
// The maximum frame size (in bytes) used in the stream.
// May be 0 to imply the value is not known.
maximumFrameSize: Token.UINT24_BE.get(buf, off + 7),
// Sample rate in Hz. Though 20 bits are available,
// the maximum sample rate is limited by the structure of frame headers to 655350Hz.
// Also, a value of 0 is invalid.
sampleRate: Token.UINT24_BE.get(buf, off + 10) >> 4,
// probably slower: sampleRate: common.getBitAllignedNumber(buf, off + 10, 0, 20),
// (number of channels)-1. FLAC supports from 1 to 8 channels
channels: common.getBitAllignedNumber(buf, off + 12, 4, 3) + 1,
// bits per sample)-1.
// FLAC supports from 4 to 32 bits per sample. Currently the reference encoder and decoders only support up to 24 bits per sample.
bitsPerSample: common.getBitAllignedNumber(buf, off + 12, 7, 5) + 1,
public get(buf: Buffer, off: number): ISampleDescription {
return {
dataFormat: FourCcToken.get(buf, off),
dataReferenceIndex: Token.UINT16_BE.get(buf, off + 10),
description: new Token.BufferType(this.len - 12).get(buf, off + 12)
};
}
}