symphonia_bundle_mp3/layer3/
common.rs

1// Symphonia
2// Copyright (c) 2019-2022 The Project Symphonia Developers.
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at https://mozilla.org/MPL/2.0/.
7
8/// Startng indicies of each scale factor band at various sampling rates for long blocks.
9pub const SFB_LONG_BANDS: [[usize; 23]; 9] = [
10    // 44.1 kHz, MPEG version 1, derived from ISO/IEC 11172-3 Table B.8
11    [
12        0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 52, 62, 74, 90, 110, 134, 162, 196, 238, 288, 342,
13        418, 576,
14    ],
15    // 48 kHz
16    [
17        0, 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 60, 72, 88, 106, 128, 156, 190, 230, 276, 330,
18        384, 576,
19    ],
20    // 32 kHz
21    [
22        0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 54, 66, 82, 102, 126, 156, 194, 240, 296, 364, 448,
23        550, 576,
24    ],
25    // 22.050 kHz, MPEG version 2, derived from ISO/IEC 13818-3 Table B.2
26    [
27        0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464,
28        522, 576,
29    ],
30    // 24 kHz (the band starting at 332 starts at 330 in some decoders, but 332 is correct)
31    [
32        0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 114, 136, 162, 194, 232, 278, 332, 394, 464,
33        540, 576,
34    ],
35    // 16 kHz
36    [
37        0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464,
38        522, 576,
39    ],
40    // 11.025 kHz, MPEG version 2.5
41    [
42        0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464,
43        522, 576,
44    ],
45    // 12 kHz
46    [
47        0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464,
48        522, 576,
49    ],
50    // 8 kHz
51    [
52        0, 12, 24, 36, 48, 60, 72, 88, 108, 132, 160, 192, 232, 280, 336, 400, 476, 566, 568, 570,
53        572, 574, 576,
54    ],
55];
56
57/// Starting indicies of each scale factor band at various sampling rates for short blocks. Each
58/// value must be multiplied by 3 since there are three equal length windows per short scale factor
59/// band.
60pub const SFB_SHORT_BANDS: [[usize; 40]; 9] = [
61    // 44.1 kHz, MPEG version 1, derived from ISO/IEC 11172-3 Table B.8
62    [
63        0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 54, 60, 66, 74, 82, 90, 100, 110, 120,
64        132, 144, 156, 170, 184, 198, 216, 234, 252, 274, 296, 318, 348, 378, 408, 464, 520, 576,
65    ],
66    // 48 kHz
67    [
68        0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 54, 60, 66, 72, 78, 84, 94, 104, 114, 126,
69        138, 150, 164, 178, 192, 208, 224, 240, 260, 280, 300, 326, 352, 378, 444, 510, 576,
70    ],
71    // 32 kHz
72    [
73        0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 54, 60, 66, 74, 82, 90, 102, 114, 126,
74        142, 158, 174, 194, 214, 234, 260, 286, 312, 346, 380, 414, 456, 498, 540, 552, 564, 576,
75    ],
76    // 22.050 kHz, MPEG version 2, derived from ISO/IEC 13818-3 Table B.2
77    [
78        0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 42, 48, 54, 60, 66, 72, 80, 88, 96, 106, 116, 126,
79        140, 154, 168, 186, 204, 222, 248, 274, 300, 332, 364, 396, 438, 480, 522, 540, 558, 576,
80    ],
81    // 24 kHz
82    [
83        0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 42, 48, 54, 62, 70, 78, 88, 98, 108, 120, 132, 144,
84        158, 172, 186, 204, 222, 240, 264, 288, 312, 344, 376, 408, 452, 496, 540, 552, 564, 576,
85    ],
86    // 16 kHz
87    [
88        0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 42, 48, 54, 62, 70, 78, 88, 98, 108, 120, 132, 144,
89        158, 172, 186, 204, 222, 240, 264, 288, 312, 342, 372, 402, 442, 482, 522, 540, 558, 576,
90    ],
91    // 11.025 kHz, MPEG version 2.5
92    [
93        0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 42, 48, 54, 62, 70, 78, 88, 98, 108, 120, 132, 144,
94        158, 172, 186, 204, 222, 240, 264, 288, 312, 342, 372, 402, 442, 482, 522, 540, 558, 576,
95    ],
96    // 12 kHz
97    [
98        0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 42, 48, 54, 62, 70, 78, 88, 98, 108, 120, 132, 144,
99        158, 172, 186, 204, 222, 240, 264, 288, 312, 342, 372, 402, 442, 482, 522, 540, 558, 576,
100    ],
101    // 8 kHz
102    [
103        0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 84, 96, 108, 124, 140, 156, 176, 196, 216, 240, 264,
104        288, 316, 344, 372, 408, 444, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498, 524, 550,
105        576,
106    ],
107];
108
109pub const SFB_MIXED_BANDS: [&[usize]; 9] = [
110    // 44.1 kHz, MPEG version 1, derived from ISO/IEC 11172-3 Table B.8
111    &[
112        0, 4, 8, 12, 16, 20, 24, 30, // Split-point
113        36, 40, 44, 48, 54, 60, 66, 74, 82, 90, 100, 110, 120, 132, 144, 156, 170, 184, 198, 216,
114        234, 252, 274, 296, 318, 348, 378, 408, 464, 520, 576,
115    ],
116    // 48 kHz
117    &[
118        0, 4, 8, 12, 16, 20, 24, 30, // Split-point
119        36, 40, 44, 48, 54, 60, 66, 72, 78, 84, 94, 104, 114, 126, 138, 150, 164, 178, 192, 208,
120        224, 240, 260, 280, 300, 326, 352, 378, 444, 510, 576,
121    ],
122    // 32 kHz
123    &[
124        0, 4, 8, 12, 16, 20, 24, 30, // Split-point
125        36, 40, 44, 48, 54, 60, 66, 74, 82, 90, 102, 114, 126, 142, 158, 174, 194, 214, 234, 260,
126        286, 312, 346, 380, 414, 456, 498, 540, 552, 564, 576,
127    ],
128    // 22.050 kHz, MPEG version 2, derived from ISO/IEC 13818-3 Table B.2
129    &[
130        0, 6, 12, 18, 24, 30, // Split-point
131        36, 42, 48, 54, 60, 66, 72, 80, 88, 96, 106, 116, 126, 140, 154, 168, 186, 204, 222, 248,
132        274, 300, 332, 364, 396, 438, 480, 522, 540, 558, 576,
133    ],
134    // 24 kHz
135    &[
136        0, 6, 12, 18, 24, 30, // Split-point
137        36, 42, 48, 54, 62, 70, 78, 88, 98, 108, 120, 132, 144, 158, 172, 186, 204, 222, 240, 264,
138        288, 312, 344, 376, 408, 452, 496, 540, 552, 564, 576,
139    ],
140    // 16 kHz
141    &[
142        0, 6, 12, 18, 24, 30, // Split-point
143        36, 42, 48, 54, 62, 70, 78, 88, 98, 108, 120, 132, 144, 158, 172, 186, 204, 222, 240, 264,
144        288, 312, 342, 372, 402, 442, 482, 522, 540, 558, 576,
145    ],
146    // 11.025 kHz, MPEG version 2.5
147    &[
148        0, 6, 12, 18, 24, 30, // Split-point
149        36, 42, 48, 54, 62, 70, 78, 88, 98, 108, 120, 132, 144, 158, 172, 186, 204, 222, 240, 264,
150        288, 312, 342, 372, 402, 442, 482, 522, 540, 558, 576,
151    ],
152    // 12 kHz
153    &[
154        0, 6, 12, 18, 24, 30, // Split-point
155        36, 42, 48, 54, 62, 70, 78, 88, 98, 108, 120, 132, 144, 158, 172, 186, 204, 222, 240, 264,
156        288, 312, 342, 372, 402, 442, 482, 522, 540, 558, 576,
157    ],
158    // 8 kHz
159    //
160    // Note: The mixed bands for 8kHz do not follow the same pattern as the other sample rates.
161    // There does not appear to be a consensus among other MP3 implementations either, so this is
162    // at best an educated guess.
163    &[
164        0, 12, 24, 36, 40, 44, 48, 56, 64, 72, 84, 96, 108, 124, 140, 156, 176, 196, 216, 240, 264,
165        288, 316, 344, 372, 408, 444, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498, 524, 550,
166        576,
167    ],
168];
169
170/// The index of the first window in the first short band of a mixed block. All bands preceeding
171/// the switch point are long bands.
172pub const SFB_MIXED_SWITCH_POINT: [usize; 9] = [8, 8, 8, 6, 6, 6, 6, 6, 3];
173
174#[derive(Debug, PartialEq)]
175pub enum BlockType {
176    // Default case when window switching is off. Also the normal case when window switching is
177    // on. Granule contains one long block.
178    Long,
179    Start,
180    Short { is_mixed: bool },
181    End,
182}