0
|
1 /*
|
|
2 * mpeg audio layer 2 tables. Most of them come from the mpeg audio
|
|
3 * specification.
|
|
4 *
|
|
5 * Copyright (c) 2000 Gerard Lantau.
|
|
6 *
|
|
7 * The licence of this code is contained in file LICENCE found in the
|
|
8 * same archive
|
|
9 */
|
|
10
|
|
11 static const unsigned short bitrate_tab[2][15] = {
|
|
12 {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160}, /* mpeg2 lsf */
|
|
13 {0,32,48,56,64,80,96,112,128,160,192,224,256,320,384}, /* mpeg1 */
|
|
14 };
|
|
15
|
|
16 static const unsigned short freq_tab[3] = { 44100, 48000, 32000 };
|
|
17
|
|
18 #define SQRT2 1.41421356237309514547
|
|
19
|
|
20 static const int costab32[30] = {
|
|
21 FIX(0.54119610014619701222),
|
|
22 FIX(1.3065629648763763537),
|
|
23
|
|
24 FIX(0.50979557910415917998),
|
|
25 FIX(2.5629154477415054814),
|
|
26 FIX(0.89997622313641556513),
|
|
27 FIX(0.60134488693504528634),
|
|
28
|
|
29 FIX(0.5024192861881556782),
|
|
30 FIX(5.1011486186891552563),
|
|
31 FIX(0.78815462345125020249),
|
|
32 FIX(0.64682178335999007679),
|
|
33 FIX(0.56694403481635768927),
|
|
34 FIX(1.0606776859903470633),
|
|
35 FIX(1.7224470982383341955),
|
|
36 FIX(0.52249861493968885462),
|
|
37
|
|
38 FIX(10.19000812354803287),
|
|
39 FIX(0.674808341455005678),
|
|
40 FIX(1.1694399334328846596),
|
|
41 FIX(0.53104259108978413284),
|
|
42 FIX(2.0577810099534108446),
|
|
43 FIX(0.58293496820613388554),
|
|
44 FIX(0.83934964541552681272),
|
|
45 FIX(0.50547095989754364798),
|
|
46 FIX(3.4076084184687189804),
|
|
47 FIX(0.62250412303566482475),
|
|
48 FIX(0.97256823786196078263),
|
|
49 FIX(0.51544730992262455249),
|
|
50 FIX(1.4841646163141661852),
|
|
51 FIX(0.5531038960344445421),
|
|
52 FIX(0.74453627100229857749),
|
|
53 FIX(0.5006029982351962726),
|
|
54 };
|
|
55
|
|
56 static const int bitinv32[32] = {
|
|
57 0, 16, 8, 24, 4, 20, 12, 28,
|
|
58 2, 18, 10, 26, 6, 22, 14, 30,
|
|
59 1, 17, 9, 25, 5, 21, 13, 29,
|
|
60 3, 19, 11, 27, 7, 23, 15, 31
|
|
61 };
|
|
62
|
|
63
|
|
64 static short filter_bank[512];
|
|
65
|
|
66 static const double enwindow[512] = {0.000000000,
|
|
67 -0.000000477, -0.000000477, -0.000000477, -0.000000477, -0.000000477, -0.000000477, -0.000000954, -0.000000954,
|
|
68 -0.000000954, -0.000000954, -0.000001431, -0.000001431, -0.000001907, -0.000001907, -0.000002384, -0.000002384,
|
|
69 -0.000002861, -0.000003338, -0.000003338, -0.000003815, -0.000004292, -0.000004768, -0.000005245, -0.000006199,
|
|
70 -0.000006676, -0.000007629, -0.000008106, -0.000009060, -0.000010014, -0.000011444, -0.000012398, -0.000013828,
|
|
71 -0.000014782, -0.000016689, -0.000018120, -0.000019550, -0.000021458, -0.000023365, -0.000025272, -0.000027657,
|
|
72 -0.000030041, -0.000032425, -0.000034809, -0.000037670, -0.000040531, -0.000043392, -0.000046253, -0.000049591,
|
|
73 -0.000052929, -0.000055790, -0.000059605, -0.000062943, -0.000066280, -0.000070095, -0.000073433, -0.000076771,
|
|
74 -0.000080585, -0.000083923, -0.000087261, -0.000090599, -0.000093460, -0.000096321, -0.000099182, 0.000101566,
|
|
75 0.000103951, 0.000105858, 0.000107288, 0.000108242, 0.000108719, 0.000108719, 0.000108242, 0.000106812,
|
|
76 0.000105381, 0.000102520, 0.000099182, 0.000095367, 0.000090122, 0.000084400, 0.000077724, 0.000069618,
|
|
77 0.000060558, 0.000050545, 0.000039577, 0.000027180, 0.000013828, -0.000000954, -0.000017166, -0.000034332,
|
|
78 -0.000052929, -0.000072956, -0.000093937, -0.000116348, -0.000140190, -0.000165462, -0.000191212, -0.000218868,
|
|
79 -0.000247478, -0.000277042, -0.000307560, -0.000339031, -0.000371456, -0.000404358, -0.000438213, -0.000472546,
|
|
80 -0.000507355, -0.000542164, -0.000576973, -0.000611782, -0.000646591, -0.000680923, -0.000714302, -0.000747204,
|
|
81 -0.000779152, -0.000809669, -0.000838757, -0.000866413, -0.000891685, -0.000915051, -0.000935555, -0.000954151,
|
|
82 -0.000968933, -0.000980854, -0.000989437, -0.000994205, -0.000995159, -0.000991821, -0.000983715, 0.000971317,
|
|
83 0.000953674, 0.000930786, 0.000902653, 0.000868797, 0.000829220, 0.000783920, 0.000731945, 0.000674248,
|
|
84 0.000610352, 0.000539303, 0.000462532, 0.000378609, 0.000288486, 0.000191689, 0.000088215, -0.000021458,
|
|
85 -0.000137329, -0.000259876, -0.000388145, -0.000522137, -0.000661850, -0.000806808, -0.000956535, -0.001111031,
|
|
86 -0.001269817, -0.001432419, -0.001597881, -0.001766682, -0.001937389, -0.002110004, -0.002283096, -0.002457142,
|
|
87 -0.002630711, -0.002803326, -0.002974033, -0.003141880, -0.003306866, -0.003467083, -0.003622532, -0.003771782,
|
|
88 -0.003914356, -0.004048824, -0.004174709, -0.004290581, -0.004395962, -0.004489899, -0.004570484, -0.004638195,
|
|
89 -0.004691124, -0.004728317, -0.004748821, -0.004752159, -0.004737377, -0.004703045, -0.004649162, -0.004573822,
|
|
90 -0.004477024, -0.004357815, -0.004215240, -0.004049301, -0.003858566, -0.003643036, -0.003401756, 0.003134727,
|
|
91 0.002841473, 0.002521515, 0.002174854, 0.001800537, 0.001399517, 0.000971317, 0.000515938, 0.000033379,
|
|
92 -0.000475883, -0.001011848, -0.001573563, -0.002161503, -0.002774239, -0.003411293, -0.004072189, -0.004756451,
|
|
93 -0.005462170, -0.006189346, -0.006937027, -0.007703304, -0.008487225, -0.009287834, -0.010103703, -0.010933399,
|
|
94 -0.011775017, -0.012627602, -0.013489246, -0.014358521, -0.015233517, -0.016112804, -0.016994476, -0.017876148,
|
|
95 -0.018756866, -0.019634247, -0.020506859, -0.021372318, -0.022228718, -0.023074150, -0.023907185, -0.024725437,
|
|
96 -0.025527000, -0.026310921, -0.027073860, -0.027815342, -0.028532982, -0.029224873, -0.029890060, -0.030526638,
|
|
97 -0.031132698, -0.031706810, -0.032248020, -0.032754898, -0.033225536, -0.033659935, -0.034055710, -0.034412861,
|
|
98 -0.034730434, -0.035007000, -0.035242081, -0.035435200, -0.035586357, -0.035694122, -0.035758972, 0.035780907,
|
|
99 0.035758972, 0.035694122, 0.035586357, 0.035435200, 0.035242081, 0.035007000, 0.034730434, 0.034412861,
|
|
100 0.034055710, 0.033659935, 0.033225536, 0.032754898, 0.032248020, 0.031706810, 0.031132698, 0.030526638,
|
|
101 0.029890060, 0.029224873, 0.028532982, 0.027815342, 0.027073860, 0.026310921, 0.025527000, 0.024725437,
|
|
102 0.023907185, 0.023074150, 0.022228718, 0.021372318, 0.020506859, 0.019634247, 0.018756866, 0.017876148,
|
|
103 0.016994476, 0.016112804, 0.015233517, 0.014358521, 0.013489246, 0.012627602, 0.011775017, 0.010933399,
|
|
104 0.010103703, 0.009287834, 0.008487225, 0.007703304, 0.006937027, 0.006189346, 0.005462170, 0.004756451,
|
|
105 0.004072189, 0.003411293, 0.002774239, 0.002161503, 0.001573563, 0.001011848, 0.000475883, -0.000033379,
|
|
106 -0.000515938, -0.000971317, -0.001399517, -0.001800537, -0.002174854, -0.002521515, -0.002841473, 0.003134727,
|
|
107 0.003401756, 0.003643036, 0.003858566, 0.004049301, 0.004215240, 0.004357815, 0.004477024, 0.004573822,
|
|
108 0.004649162, 0.004703045, 0.004737377, 0.004752159, 0.004748821, 0.004728317, 0.004691124, 0.004638195,
|
|
109 0.004570484, 0.004489899, 0.004395962, 0.004290581, 0.004174709, 0.004048824, 0.003914356, 0.003771782,
|
|
110 0.003622532, 0.003467083, 0.003306866, 0.003141880, 0.002974033, 0.002803326, 0.002630711, 0.002457142,
|
|
111 0.002283096, 0.002110004, 0.001937389, 0.001766682, 0.001597881, 0.001432419, 0.001269817, 0.001111031,
|
|
112 0.000956535, 0.000806808, 0.000661850, 0.000522137, 0.000388145, 0.000259876, 0.000137329, 0.000021458,
|
|
113 -0.000088215, -0.000191689, -0.000288486, -0.000378609, -0.000462532, -0.000539303, -0.000610352, -0.000674248,
|
|
114 -0.000731945, -0.000783920, -0.000829220, -0.000868797, -0.000902653, -0.000930786, -0.000953674, 0.000971317,
|
|
115 0.000983715, 0.000991821, 0.000995159, 0.000994205, 0.000989437, 0.000980854, 0.000968933, 0.000954151,
|
|
116 0.000935555, 0.000915051, 0.000891685, 0.000866413, 0.000838757, 0.000809669, 0.000779152, 0.000747204,
|
|
117 0.000714302, 0.000680923, 0.000646591, 0.000611782, 0.000576973, 0.000542164, 0.000507355, 0.000472546,
|
|
118 0.000438213, 0.000404358, 0.000371456, 0.000339031, 0.000307560, 0.000277042, 0.000247478, 0.000218868,
|
|
119 0.000191212, 0.000165462, 0.000140190, 0.000116348, 0.000093937, 0.000072956, 0.000052929, 0.000034332,
|
|
120 0.000017166, 0.000000954, -0.000013828, -0.000027180, -0.000039577, -0.000050545, -0.000060558, -0.000069618,
|
|
121 -0.000077724, -0.000084400, -0.000090122, -0.000095367, -0.000099182, -0.000102520, -0.000105381, -0.000106812,
|
|
122 -0.000108242, -0.000108719, -0.000108719, -0.000108242, -0.000107288, -0.000105858, -0.000103951, 0.000101566,
|
|
123 0.000099182, 0.000096321, 0.000093460, 0.000090599, 0.000087261, 0.000083923, 0.000080585, 0.000076771,
|
|
124 0.000073433, 0.000070095, 0.000066280, 0.000062943, 0.000059605, 0.000055790, 0.000052929, 0.000049591,
|
|
125 0.000046253, 0.000043392, 0.000040531, 0.000037670, 0.000034809, 0.000032425, 0.000030041, 0.000027657,
|
|
126 0.000025272, 0.000023365, 0.000021458, 0.000019550, 0.000018120, 0.000016689, 0.000014782, 0.000013828,
|
|
127 0.000012398, 0.000011444, 0.000010014, 0.000009060, 0.000008106, 0.000007629, 0.000006676, 0.000006199,
|
|
128 0.000005245, 0.000004768, 0.000004292, 0.000003815, 0.000003338, 0.000003338, 0.000002861, 0.000002384,
|
|
129 0.000002384, 0.000001907, 0.000001907, 0.000001431, 0.000001431, 0.000000954, 0.000000954, 0.000000954,
|
|
130 0.000000954, 0.000000477, 0.000000477, 0.000000477, 0.000000477, 0.000000477, 0.000000477
|
|
131 };
|
|
132
|
|
133 static int scale_factor_table[64];
|
|
134 #ifdef USE_FLOATS
|
|
135 static float scale_factor_inv_table[64];
|
|
136 #else
|
|
137 static INT8 scale_factor_shift[64];
|
|
138 static unsigned short scale_factor_mult[64];
|
|
139 #endif
|
|
140 static unsigned char scale_diff_table[128];
|
|
141
|
|
142 static const int sblimit_table[5] = { 27 , 30 , 8, 12 , 30 };
|
|
143
|
|
144 static const int quant_steps[17] = {
|
|
145 3, 5, 7, 9, 15,
|
|
146 31, 63, 127, 255, 511,
|
|
147 1023, 2047, 4095, 8191, 16383,
|
|
148 32767, 65535
|
|
149 };
|
|
150
|
|
151 /* we use a negative value if grouped */
|
|
152 static const int quant_bits[17] = {
|
|
153 -5, -7, 3, -10, 4,
|
|
154 5, 6, 7, 8, 9,
|
|
155 10, 11, 12, 13, 14,
|
|
156 15, 16
|
|
157 };
|
|
158
|
|
159 /* signal to noise ratio of each quantification step (could be
|
|
160 computed from quant_steps[]). The values are dB multiplied by 10
|
|
161 */
|
|
162 static unsigned short quant_snr[17] = {
|
|
163 70, 110, 160, 208,
|
|
164 253, 316, 378, 439,
|
|
165 499, 559, 620, 680,
|
|
166 740, 800, 861, 920,
|
|
167 980
|
|
168 };
|
|
169
|
|
170
|
|
171 /* total number of bits per allocation group */
|
|
172 static unsigned short total_quant_bits[17];
|
|
173
|
|
174 /* encoding tables which give the quantization index. Note how it is
|
|
175 possible to store them efficiently ! */
|
|
176 static const unsigned char alloc_table_0[] = {
|
|
177 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
|
178 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
|
179 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
|
180 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
181 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
182 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
183 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
184 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
185 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
186 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
187 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
188 3, 0, 1, 2, 3, 4, 5, 16,
|
|
189 3, 0, 1, 2, 3, 4, 5, 16,
|
|
190 3, 0, 1, 2, 3, 4, 5, 16,
|
|
191 3, 0, 1, 2, 3, 4, 5, 16,
|
|
192 3, 0, 1, 2, 3, 4, 5, 16,
|
|
193 3, 0, 1, 2, 3, 4, 5, 16,
|
|
194 3, 0, 1, 2, 3, 4, 5, 16,
|
|
195 3, 0, 1, 2, 3, 4, 5, 16,
|
|
196 3, 0, 1, 2, 3, 4, 5, 16,
|
|
197 3, 0, 1, 2, 3, 4, 5, 16,
|
|
198 3, 0, 1, 2, 3, 4, 5, 16,
|
|
199 3, 0, 1, 2, 3, 4, 5, 16,
|
|
200 2, 0, 1, 16,
|
|
201 2, 0, 1, 16,
|
|
202 2, 0, 1, 16,
|
|
203 2, 0, 1, 16,
|
|
204 };
|
|
205
|
|
206 static const unsigned char alloc_table_1[] = {
|
|
207 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
|
208 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
|
209 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
|
210 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
211 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
212 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
213 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
214 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
215 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
216 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
217 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
|
218 3, 0, 1, 2, 3, 4, 5, 16,
|
|
219 3, 0, 1, 2, 3, 4, 5, 16,
|
|
220 3, 0, 1, 2, 3, 4, 5, 16,
|
|
221 3, 0, 1, 2, 3, 4, 5, 16,
|
|
222 3, 0, 1, 2, 3, 4, 5, 16,
|
|
223 3, 0, 1, 2, 3, 4, 5, 16,
|
|
224 3, 0, 1, 2, 3, 4, 5, 16,
|
|
225 3, 0, 1, 2, 3, 4, 5, 16,
|
|
226 3, 0, 1, 2, 3, 4, 5, 16,
|
|
227 3, 0, 1, 2, 3, 4, 5, 16,
|
|
228 3, 0, 1, 2, 3, 4, 5, 16,
|
|
229 3, 0, 1, 2, 3, 4, 5, 16,
|
|
230 2, 0, 1, 16,
|
|
231 2, 0, 1, 16,
|
|
232 2, 0, 1, 16,
|
|
233 2, 0, 1, 16,
|
|
234 2, 0, 1, 16,
|
|
235 2, 0, 1, 16,
|
|
236 2, 0, 1, 16,
|
|
237 };
|
|
238
|
|
239 static const unsigned char alloc_table_2[] = {
|
|
240 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
241 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
242 3, 0, 1, 3, 4, 5, 6, 7,
|
|
243 3, 0, 1, 3, 4, 5, 6, 7,
|
|
244 3, 0, 1, 3, 4, 5, 6, 7,
|
|
245 3, 0, 1, 3, 4, 5, 6, 7,
|
|
246 3, 0, 1, 3, 4, 5, 6, 7,
|
|
247 3, 0, 1, 3, 4, 5, 6, 7,
|
|
248 };
|
|
249
|
|
250 static const unsigned char alloc_table_3[] = {
|
|
251 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
252 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
253 3, 0, 1, 3, 4, 5, 6, 7,
|
|
254 3, 0, 1, 3, 4, 5, 6, 7,
|
|
255 3, 0, 1, 3, 4, 5, 6, 7,
|
|
256 3, 0, 1, 3, 4, 5, 6, 7,
|
|
257 3, 0, 1, 3, 4, 5, 6, 7,
|
|
258 3, 0, 1, 3, 4, 5, 6, 7,
|
|
259 3, 0, 1, 3, 4, 5, 6, 7,
|
|
260 3, 0, 1, 3, 4, 5, 6, 7,
|
|
261 3, 0, 1, 3, 4, 5, 6, 7,
|
|
262 3, 0, 1, 3, 4, 5, 6, 7,
|
|
263 };
|
|
264
|
|
265 static const unsigned char alloc_table_4[] = {
|
|
266 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
|
267 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
|
268 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
|
269 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
|
270 3, 0, 1, 3, 4, 5, 6, 7,
|
|
271 3, 0, 1, 3, 4, 5, 6, 7,
|
|
272 3, 0, 1, 3, 4, 5, 6, 7,
|
|
273 3, 0, 1, 3, 4, 5, 6, 7,
|
|
274 3, 0, 1, 3, 4, 5, 6, 7,
|
|
275 3, 0, 1, 3, 4, 5, 6, 7,
|
|
276 3, 0, 1, 3, 4, 5, 6, 7,
|
|
277 2, 0, 1, 3,
|
|
278 2, 0, 1, 3,
|
|
279 2, 0, 1, 3,
|
|
280 2, 0, 1, 3,
|
|
281 2, 0, 1, 3,
|
|
282 2, 0, 1, 3,
|
|
283 2, 0, 1, 3,
|
|
284 2, 0, 1, 3,
|
|
285 2, 0, 1, 3,
|
|
286 2, 0, 1, 3,
|
|
287 2, 0, 1, 3,
|
|
288 2, 0, 1, 3,
|
|
289 2, 0, 1, 3,
|
|
290 2, 0, 1, 3,
|
|
291 2, 0, 1, 3,
|
|
292 2, 0, 1, 3,
|
|
293 2, 0, 1, 3,
|
|
294 2, 0, 1, 3,
|
|
295 2, 0, 1, 3,
|
|
296 };
|
|
297
|
|
298 const unsigned char *alloc_tables[5] =
|
|
299 { alloc_table_0, alloc_table_1, alloc_table_2, alloc_table_3, alloc_table_4, };
|
|
300
|
|
301 /* fixed psycho acoustic model. Values of SNR taken from the 'toolame'
|
|
302 project */
|
|
303 const float fixed_smr[SBLIMIT] = {
|
|
304 30, 17, 16, 10, 3, 12, 8, 2.5,
|
|
305 5, 5, 6, 6, 5, 6, 10, 6,
|
|
306 -4, -10, -21, -30, -42, -55, -68, -75,
|
|
307 -75, -75, -75, -75, -91, -107, -110, -108
|
|
308 };
|
|
309
|
|
310 const unsigned char nb_scale_factors[4] = { 3, 2, 1, 2 };
|