vpr_audio_analyzer/frames/
types.rs

1#[derive(Debug, Clone)]
2pub struct AudioFrameHeader {
3    pub version: MpegVersion,
4    pub layer: MpegLayer,
5    pub protected: bool,
6    pub bitrate: BitRate,
7    pub sample_rate: SampleRate,
8    pub padding: u8,
9    pub private: bool,
10    pub channel_mode: ChannelMode,
11    pub mode_extension: Option<ModeExtension>,
12    pub copyrigth: bool,
13    pub original: bool,
14    pub emphasis: Emphasis,
15}
16
17#[derive(Debug, Clone)]
18pub struct AudioFrame {
19    pub header: AudioFrameHeader,
20    pub xing_header: Option<XingHeader>,
21    pub offset: u64,
22    pub data: Vec<u8>,
23}
24
25#[derive(Debug, Clone)]
26pub struct XingHeader {
27    pub flags: XingHeaderFlags,
28    pub frames: Option<u64>,
29    pub bytes: Option<u64>,
30    pub toc: Option<[u8; 100]>,
31    pub quality: Option<u32>,
32    pub sample_rate: Option<u32>,
33    pub channels: Option<u32>,
34    pub vbr_scale: Option<u32>,
35}
36
37#[derive(Debug, Clone)]
38pub struct XingHeaderFlags {
39    pub frames: bool,
40    pub bytes: bool,
41    pub toc: bool,
42    pub quality: bool,
43    pub sample_rate: bool,
44    pub channels: bool,
45    pub vbr_scale: bool,
46}
47
48#[derive(Copy, Clone, PartialEq, Eq, Debug)]
49pub enum MpegVersion {
50    Mpeg1,
51    Mpeg2,
52    Mpeg2_5,
53}
54
55#[derive(Copy, Clone, PartialEq, Eq, Debug)]
56pub enum MpegLayer {
57    NotDefined,
58    Layer1,
59    Layer2,
60    Layer3,
61}
62
63#[derive(Copy, Clone, PartialEq, Eq, Debug)]
64pub enum BitRate {
65    Kbps8,
66    Kbps16,
67    Kbps24,
68    Kbps32,
69    Kbps40,
70    Kbps48,
71    Kbps56,
72    Kbps64,
73    Kbps65,
74    Kbps80,
75    Kbps96,
76    Kbps112,
77    Kbps128,
78    Kbps144,
79    Kbps160,
80    Kbps176,
81    Kbps192,
82    Kbps224,
83    Kbps256,
84    Kbps284,
85    Kbps288,
86    Kbps320,
87    Kbps352,
88    Kbps384,
89    Kbps416,
90    Kbps448,
91}
92
93impl BitRate {
94    pub fn bps(self) -> u64 {
95        match self {
96            BitRate::Kbps8 => 8_000,
97            BitRate::Kbps16 => 16_000,
98            BitRate::Kbps24 => 24_000,
99            BitRate::Kbps32 => 32_000,
100            BitRate::Kbps40 => 40_000,
101            BitRate::Kbps48 => 48_000,
102            BitRate::Kbps56 => 56_000,
103            BitRate::Kbps64 => 64_000,
104            BitRate::Kbps65 => 65_000,
105            BitRate::Kbps80 => 80_000,
106            BitRate::Kbps96 => 96_000,
107            BitRate::Kbps112 => 112_000,
108            BitRate::Kbps128 => 128_000,
109            BitRate::Kbps144 => 144_000,
110            BitRate::Kbps160 => 160_000,
111            BitRate::Kbps176 => 176_000,
112            BitRate::Kbps192 => 192_000,
113            BitRate::Kbps224 => 224_000,
114            BitRate::Kbps256 => 256_000,
115            BitRate::Kbps284 => 284_000,
116            BitRate::Kbps288 => 288_000,
117            BitRate::Kbps320 => 320_000,
118            BitRate::Kbps352 => 352_000,
119            BitRate::Kbps384 => 384_000,
120            BitRate::Kbps416 => 416_000,
121            BitRate::Kbps448 => 448_000,
122        }
123    }
124}
125
126#[derive(Copy, Clone, PartialEq, Eq, Debug)]
127pub enum SampleRate {
128    Hz8000,
129    Hz11025,
130    Hz12000,
131    Hz16000,
132    Hz22050,
133    Hz24000,
134    Hz32000,
135    Hz44100,
136    Hz48000,
137}
138
139impl SampleRate {
140    pub fn hz(self) -> u64 {
141        match self {
142            SampleRate::Hz8000 => 8_000,
143            SampleRate::Hz11025 => 11_025,
144            SampleRate::Hz12000 => 12_000,
145            SampleRate::Hz16000 => 16_000,
146            SampleRate::Hz22050 => 22_050,
147            SampleRate::Hz24000 => 24_000,
148            SampleRate::Hz32000 => 32_000,
149            SampleRate::Hz44100 => 44_100,
150            SampleRate::Hz48000 => 48_000,
151        }
152    }
153}
154
155#[derive(Copy, Clone, PartialEq, Eq, Debug)]
156pub enum ChannelMode {
157    Stereo,
158    JointStereo,
159    DualChannel,
160    Mono,
161}
162
163#[derive(Copy, Clone, PartialEq, Eq, Debug)]
164pub enum ModeExtension {
165    Bands4To31,
166    Bands8To31,
167    Bands12To31,
168    Bands16To31,
169}
170
171#[derive(Copy, Clone, PartialEq, Eq, Debug)]
172pub enum Emphasis {
173    None,
174    FiftyFifteenMs,
175    Reserved,
176    CCITJ17,
177}