-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
DsfChunk.ts
137 lines (115 loc) · 2.52 KB
/
DsfChunk.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import * as Token from 'token-types';
import {FourCcToken} from '../common/FourCC';
/**
* Common interface for the common chunk DSD header
*/
export interface IChunkHeader {
/**
* Chunk ID
*/
id: string;
/**
* Chunk size
*/
size: number;
}
/**
* Common chunk DSD header: the 'chunk name (Four-CC)' & chunk size
*/
export const ChunkHeader: Token.IGetToken<IChunkHeader> = {
len: 12,
get: (buf: Buffer, off: number): IChunkHeader => {
return {id: FourCcToken.get(buf, off), size: Token.UINT64_LE.get(buf, off + 4)};
}
};
/**
* Interface to DSD payload chunk
*/
export interface IDsdChunk {
/**
* Total file size
*/
fileSize: number;
/**
* If Metadata doesn’t exist, set 0. If the file has ID3v2 tag, then set the pointer to it.
* ID3v2 tag should be located in the end of the file.
*/
metadataPointer: number;
}
/**
* Common chunk DSD header: the 'chunk name (Four-CC)' & chunk size
*/
export const DsdChunk: Token.IGetToken<IDsdChunk> = {
len: 16,
get: (buf: Buffer, off: number): IDsdChunk => {
return {
fileSize: Token.INT64_LE.get(buf, off),
metadataPointer: Token.INT64_LE.get(buf, off + 8)
}
;
}
};
export enum ChannelType {
mono = 1,
stereo = 2,
channels = 3,
quad = 4,
'4 channels' = 5,
'5 channels' = 6,
'5.1 channels' = 7
}
/**
* Interface to format chunk payload chunk
*/
export interface IFormatChunk {
/**
* Version of this file format
*/
formatVersion: number;
/**
* Format ID
*/
formatID: number;
/**
* Channel Type
*/
channelType: ChannelType;
/**
* Channel num
*/
channelNum: number;
/**
* Sampling frequency
*/
samplingFrequency: number;
/**
* Bits per sample
*/
bitsPerSample: number;
/**
* Sample count
*/
sampleCount: number;
/**
* Block size per channel
*/
blockSizePerChannel: number;
}
/**
* Common chunk DSD header: the 'chunk name (Four-CC)' & chunk size
*/
export const FormatChunk: Token.IGetToken<IFormatChunk> = {
len: 40,
get: (buf: Buffer, off: number): IFormatChunk => {
return {
formatVersion: Token.INT32_LE.get(buf, off),
formatID: Token.INT32_LE.get(buf, off + 4),
channelType: Token.INT32_LE.get(buf, off + 8),
channelNum: Token.INT32_LE.get(buf, off + 12),
samplingFrequency: Token.INT32_LE.get(buf, off + 16),
bitsPerSample: Token.INT32_LE.get(buf, off + 20),
sampleCount: Token.INT64_LE.get(buf, off + 24),
blockSizePerChannel: Token.INT32_LE.get(buf, off + 32)
};
}
};