FFmpeg
mpegaudiodec_common.c
Go to the documentation of this file.
1 /*
2  * MPEG Audio decoder
3  * copyright (c) 2002 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * mpeg audio layer decoder tables.
25  */
26 
27 #include <stddef.h>
28 #include <stdint.h>
29 
30 #include "libavutil/avassert.h"
31 #include "libavutil/libm.h"
32 #include "libavutil/thread.h"
33 
34 #include "mpegaudiodata.h"
35 
37 
39 
40 static int16_t division_tab3[1 << 6 ];
41 static int16_t division_tab5[1 << 8 ];
42 static int16_t division_tab9[1 << 11];
43 
44 int16_t *const ff_division_tabs[4] = {
46 };
47 
48 
49 /*******************************************************/
50 /* layer 3 tables */
51 
52 const uint8_t ff_slen_table[2][16] = {
53  { 0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 },
54  { 0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3 },
55 };
56 
57 const uint8_t ff_lsf_nsf_table[6][3][4] = {
58  { { 6, 5, 5, 5 }, { 9, 9, 9, 9 }, { 6, 9, 9, 9 } },
59  { { 6, 5, 7, 3 }, { 9, 9, 12, 6 }, { 6, 9, 12, 6 } },
60  { { 11, 10, 0, 0 }, { 18, 18, 0, 0 }, { 15, 18, 0, 0 } },
61  { { 7, 7, 7, 0 }, { 12, 12, 12, 0 }, { 6, 15, 12, 0 } },
62  { { 6, 6, 6, 3 }, { 12, 9, 9, 6 }, { 6, 12, 9, 6 } },
63  { { 8, 8, 5, 0 }, { 15, 12, 9, 0 }, { 6, 18, 9, 0 } },
64 };
65 
66 /* mpegaudio layer 3 huffman tables */
67 const VLCElem *ff_huff_vlc[16];
68 static VLCElem huff_vlc_tables[128 + 128 + 128 + 130 + 128 + 154 + 166 + 142 +
69  204 + 190 + 170 + 542 + 460 + 662 + 414];
71 static VLCElem huff_quad_vlc_tables[64 + 16];
72 
73 static const uint8_t mpa_hufflens[] = {
74  /* Huffman table 1 - 4 entries */
75  3, 3, 2, 1,
76  /* Huffman table 2 - 9 entries */
77  6, 6, 5, 5, 5, 3, 3, 3, 1,
78  /* Huffman table 3 - 9 entries */
79  6, 6, 5, 5, 5, 3, 2, 2, 2,
80  /* Huffman table 5 - 16 entries */
81  8, 8, 7, 6, 7, 7, 7, 7, 6, 6, 6, 6, 3, 3, 3, 1,
82  /* Huffman table 6 - 16 entries */
83  7, 7, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4, 3, 2, 3, 3,
84  /* Huffman table 7 - 36 entries */
85  10, 10, 10, 10, 9, 9, 9, 9, 8, 8, 9, 9, 8, 9, 9, 8, 8, 7, 7,
86  7, 8, 8, 8, 8, 7, 7, 7, 7, 6, 5, 6, 6, 4, 3, 3, 1,
87  /* Huffman table 8 - 36 entries */
88  11, 11, 10, 9, 10, 10, 9, 9, 9, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
89  8, 8, 8, 8, 8, 8, 8, 8, 6, 6, 6, 4, 4, 2, 3, 3, 2,
90  /* Huffman table 9 - 36 entries */
91  9, 9, 8, 8, 9, 9, 8, 8, 8, 8, 7, 7, 7, 8, 8, 7, 7, 7, 7,
92  6, 6, 6, 6, 5, 5, 6, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3,
93  /* Huffman table 10 - 64 entries */
94  11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 11, 11, 10, 9, 9, 10,
95  10, 9, 9, 10, 10, 9, 10, 10, 8, 8, 9, 9, 10, 10, 9, 9, 10, 10, 8,
96  8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 6,
97  6, 6, 6, 4, 3, 3, 1,
98  /* Huffman table 11 - 64 entries */
99  10, 10, 10, 10, 10, 10, 10, 11, 11, 10, 10, 9, 9, 9, 10, 10, 10, 10, 8,
100  8, 9, 9, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 7, 8, 8, 7, 7,
101  8, 8, 8, 9, 9, 8, 8, 8, 8, 8, 8, 7, 7, 6, 6, 7, 7, 6, 5,
102  4, 5, 5, 3, 3, 3, 2,
103  /* Huffman table 12 - 64 entries */
104  10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 9, 9, 8, 8, 8, 8, 8, 8,
105  9, 9, 8, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7,
106  7, 7, 7, 8, 8, 7, 7, 7, 6, 6, 6, 6, 7, 7, 6, 5, 5, 5, 4,
107  4, 5, 5, 4, 3, 3, 3,
108  /* Huffman table 13 - 256 entries */
109  19, 19, 18, 17, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 15, 15, 16,
110  16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 15, 16, 16, 14, 14, 15,
111  15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 14, 13, 14,
112  14, 13, 13, 14, 14, 13, 14, 14, 13, 14, 14, 13, 14, 14, 13, 13, 14, 14, 12,
113  12, 12, 13, 13, 13, 13, 13, 13, 12, 13, 13, 12, 12, 13, 13, 13, 13, 13, 13,
114  13, 13, 13, 13, 13, 13, 12, 12, 13, 13, 12, 12, 12, 12, 13, 13, 13, 13, 12,
115  13, 13, 12, 11, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 12, 12, 11,
116  11, 12, 12, 11, 12, 12, 12, 12, 11, 11, 12, 12, 11, 12, 12, 11, 12, 12, 11,
117  12, 12, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 11, 11,
118  10, 11, 11, 10, 11, 11, 11, 11, 10, 10, 11, 11, 10, 10, 11, 11, 11, 11, 11,
119  11, 9, 9, 10, 10, 10, 10, 10, 11, 11, 9, 9, 9, 10, 10, 9, 9, 10, 10,
120  10, 10, 10, 10, 10, 10, 10, 10, 8, 9, 9, 9, 9, 9, 9, 10, 10, 9, 9,
121  9, 8, 8, 9, 9, 9, 9, 9, 9, 8, 7, 8, 8, 8, 8, 7, 7, 7, 7,
122  7, 6, 6, 6, 6, 4, 4, 3, 1,
123  /* Huffman table 15 - 256 entries */
124  13, 13, 13, 13, 12, 13, 13, 13, 13, 13, 13, 12, 13, 13, 12, 12, 12, 12, 12,
125  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
126  13, 11, 11, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 12, 12, 11, 11, 11, 11,
127  11, 11, 11, 11, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
128  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 11, 11, 11, 11, 11,
129  11, 10, 11, 11, 11, 11, 11, 11, 10, 10, 11, 11, 10, 10, 10, 10, 11, 11, 10,
130  10, 10, 10, 10, 10, 10, 11, 11, 10, 10, 10, 10, 10, 11, 11, 9, 10, 10, 10,
131  10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 10, 10, 10, 10, 9, 10, 10, 9, 10,
132  10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 10, 10, 9, 9, 9,
133  9, 9, 9, 10, 10, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9, 9,
134  9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8,
135  8, 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 7, 8, 8, 7, 7,
136  7, 7, 8, 8, 7, 7, 7, 7, 7, 6, 7, 7, 6, 6, 7, 7, 6, 6, 6,
137  5, 5, 5, 5, 5, 3, 4, 4, 3,
138  /* Huffman table 16 - 256 entries */
139  11, 11, 11, 11, 11, 11, 11, 11, 10, 11, 11, 11, 11, 10, 10, 10, 10, 10, 8,
140  10, 10, 9, 9, 9, 9, 10, 16, 17, 17, 15, 15, 16, 16, 14, 15, 15, 14, 14,
141  15, 15, 14, 14, 15, 15, 15, 15, 14, 15, 15, 14, 13, 8, 9, 9, 8, 8, 13,
142  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 14, 14, 14, 14, 13, 14, 14,
143  13, 13, 13, 14, 14, 14, 14, 13, 13, 14, 14, 13, 14, 14, 12, 13, 13, 13, 13,
144  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 13, 13, 13, 13, 13, 13, 12, 13,
145  13, 12, 12, 13, 13, 11, 12, 12, 12, 12, 12, 12, 12, 13, 13, 11, 12, 12, 12,
146  12, 11, 12, 12, 12, 12, 12, 12, 12, 12, 11, 12, 12, 11, 11, 11, 11, 12, 12,
147  12, 12, 12, 12, 12, 12, 11, 12, 12, 11, 12, 12, 11, 12, 12, 11, 12, 12, 11,
148  10, 10, 11, 11, 11, 11, 11, 11, 10, 10, 11, 11, 10, 10, 11, 11, 11, 11, 11,
149  11, 11, 11, 10, 11, 11, 10, 10, 10, 11, 11, 10, 10, 11, 11, 10, 10, 11, 11,
150  10, 9, 9, 10, 10, 10, 10, 10, 10, 9, 9, 9, 10, 10, 9, 10, 10, 9, 9,
151  8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 9, 9, 8, 8, 7, 7, 8, 8,
152  7, 6, 6, 6, 6, 4, 4, 3, 1,
153  /* Huffman table 24 - 256 entries */
154  8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 7, 7, 8, 8, 7, 7, 7, 7,
155  7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 9, 11, 11, 11, 11, 11, 11, 11, 11,
156  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
157  11, 4, 11, 11, 11, 11, 12, 12, 11, 10, 11, 11, 10, 10, 10, 10, 11, 11, 10,
158  10, 10, 10, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
159  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
160  10, 10, 10, 10, 10, 10, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
161  10, 10, 11, 11, 10, 11, 11, 10, 9, 10, 10, 10, 10, 11, 11, 10, 9, 9, 10,
162  10, 9, 10, 10, 10, 10, 9, 9, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
163  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
164  9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 9, 9, 9, 10, 10, 8, 9, 9, 8,
165  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8, 8, 8, 8,
166  8, 9, 9, 7, 8, 8, 7, 7, 7, 7, 7, 8, 8, 7, 7, 6, 6, 7, 7,
167  6, 5, 5, 6, 6, 4, 4, 4, 4,
168 };
169 
170 static const uint8_t mpa_huffsymbols[] = {
171  /* Huffman table 1 - 4 entries */
172  0x11, 0x01, 0x10, 0x00,
173  /* Huffman table 2 - 9 entries */
174  0x22, 0x02, 0x12, 0x21, 0x20, 0x11, 0x01, 0x10, 0x00,
175  /* Huffman table 3 - 9 entries */
176  0x22, 0x02, 0x12, 0x21, 0x20, 0x10, 0x11, 0x01, 0x00,
177  /* Huffman table 5 - 16 entries */
178  0x33, 0x23, 0x32, 0x31, 0x13, 0x03, 0x30, 0x22, 0x12, 0x21, 0x02, 0x20,
179  0x11, 0x01, 0x10, 0x00,
180  /* Huffman table 6 - 16 entries */
181  0x33, 0x03, 0x23, 0x32, 0x30, 0x13, 0x31, 0x22, 0x02, 0x12, 0x21, 0x20,
182  0x01, 0x11, 0x10, 0x00,
183  /* Huffman table 7 - 36 entries */
184  0x55, 0x45, 0x54, 0x53, 0x35, 0x44, 0x25, 0x52, 0x15, 0x51, 0x05, 0x34,
185  0x50, 0x43, 0x33, 0x24, 0x42, 0x14, 0x41, 0x40, 0x04, 0x23, 0x32, 0x03,
186  0x13, 0x31, 0x30, 0x22, 0x12, 0x21, 0x02, 0x20, 0x11, 0x01, 0x10, 0x00,
187  /* Huffman table 8 - 36 entries */
188  0x55, 0x54, 0x45, 0x53, 0x35, 0x44, 0x25, 0x52, 0x05, 0x15, 0x51, 0x34,
189  0x43, 0x50, 0x33, 0x24, 0x42, 0x14, 0x41, 0x04, 0x40, 0x23, 0x32, 0x13,
190  0x31, 0x03, 0x30, 0x22, 0x02, 0x20, 0x12, 0x21, 0x11, 0x01, 0x10, 0x00,
191  /* Huffman table 9 - 36 entries */
192  0x55, 0x45, 0x35, 0x53, 0x54, 0x05, 0x44, 0x25, 0x52, 0x15, 0x51, 0x34,
193  0x43, 0x50, 0x04, 0x24, 0x42, 0x33, 0x40, 0x14, 0x41, 0x23, 0x32, 0x13,
194  0x31, 0x03, 0x30, 0x22, 0x02, 0x12, 0x21, 0x20, 0x11, 0x01, 0x10, 0x00,
195  /* Huffman table 10 - 64 entries */
196  0x77, 0x67, 0x76, 0x57, 0x75, 0x66, 0x47, 0x74, 0x56, 0x65, 0x37, 0x73,
197  0x46, 0x55, 0x54, 0x63, 0x27, 0x72, 0x64, 0x07, 0x70, 0x62, 0x45, 0x35,
198  0x06, 0x53, 0x44, 0x17, 0x71, 0x36, 0x26, 0x25, 0x52, 0x15, 0x51, 0x34,
199  0x43, 0x16, 0x61, 0x60, 0x05, 0x50, 0x24, 0x42, 0x33, 0x04, 0x14, 0x41,
200  0x40, 0x23, 0x32, 0x03, 0x13, 0x31, 0x30, 0x22, 0x12, 0x21, 0x02, 0x20,
201  0x11, 0x01, 0x10, 0x00,
202  /* Huffman table 11 - 64 entries */
203  0x77, 0x67, 0x76, 0x75, 0x66, 0x47, 0x74, 0x57, 0x55, 0x56, 0x65, 0x37,
204  0x73, 0x46, 0x45, 0x54, 0x35, 0x53, 0x27, 0x72, 0x64, 0x07, 0x71, 0x17,
205  0x70, 0x36, 0x63, 0x60, 0x44, 0x25, 0x52, 0x05, 0x15, 0x62, 0x26, 0x06,
206  0x16, 0x61, 0x51, 0x34, 0x50, 0x43, 0x33, 0x24, 0x42, 0x14, 0x41, 0x04,
207  0x40, 0x23, 0x32, 0x13, 0x31, 0x03, 0x30, 0x22, 0x21, 0x12, 0x02, 0x20,
208  0x11, 0x01, 0x10, 0x00,
209  /* Huffman table 12 - 64 entries */
210  0x77, 0x67, 0x76, 0x57, 0x75, 0x66, 0x47, 0x74, 0x65, 0x56, 0x37, 0x73,
211  0x55, 0x27, 0x72, 0x46, 0x64, 0x17, 0x71, 0x07, 0x70, 0x36, 0x63, 0x45,
212  0x54, 0x44, 0x06, 0x05, 0x26, 0x62, 0x61, 0x16, 0x60, 0x35, 0x53, 0x25,
213  0x52, 0x15, 0x51, 0x34, 0x43, 0x50, 0x04, 0x24, 0x42, 0x14, 0x33, 0x41,
214  0x23, 0x32, 0x40, 0x03, 0x30, 0x13, 0x31, 0x22, 0x12, 0x21, 0x02, 0x20,
215  0x00, 0x11, 0x01, 0x10,
216  /* Huffman table 13 - 256 entries */
217  0xFE, 0xFC, 0xFD, 0xED, 0xFF, 0xEF, 0xDF, 0xEE, 0xCF, 0xDE, 0xBF, 0xFB,
218  0xCE, 0xDC, 0xAF, 0xE9, 0xEC, 0xDD, 0xFA, 0xCD, 0xBE, 0xEB, 0x9F, 0xF9,
219  0xEA, 0xBD, 0xDB, 0x8F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x82, 0x18, 0x37,
234  0x27, 0x17, 0x71, 0x55, 0x07, 0x70, 0x36, 0x63, 0x45, 0x54, 0x26, 0x62,
235  0x35, 0x81, 0x08, 0x80, 0x16, 0x61, 0x06, 0x60, 0x53, 0x44, 0x25, 0x52,
236  0x05, 0x15, 0x51, 0x34, 0x43, 0x50, 0x24, 0x42, 0x33, 0x14, 0x41, 0x04,
237  0x40, 0x23, 0x32, 0x13, 0x31, 0x03, 0x30, 0x22, 0x12, 0x21, 0x02, 0x20,
238  0x11, 0x01, 0x10, 0x00,
239  /* Huffman table 15 - 256 entries */
240  0xFF, 0xEF, 0xFE, 0xDF, 0xEE, 0xFD, 0xCF, 0xFC, 0xDE, 0xED, 0xBF, 0xFB,
241  0xCE, 0xEC, 0xDD, 0xAF, 0xFA, 0xBE, 0xEB, 0xCD, 0xDC, 0x9F, 0xF9, 0xEA,
242  0xBD, 0xDB, 0x8F, 0xF8, 0xCC, 0x9E, 0xE9, 0x7F, 0xF7, 0xAD, 0xDA, 0xBC,
243  0x6F, 0xAE, 0x0F, 0xCB, 0xF6, 0x8E, 0xE8, 0x5F, 0x9D, 0xF5, 0x7E, 0xE7,
244  0xAC, 0xCA, 0xBB, 0xD9, 0x8D, 0x4F, 0xF4, 0x3F, 0xF3, 0xD8, 0xE6, 0x2F,
245  0xF2, 0x6E, 0xF0, 0x1F, 0xF1, 0x9C, 0xC9, 0x5E, 0xAB, 0xBA, 0xE5, 0x7D,
246  0xD7, 0x4E, 0xE4, 0x8C, 0xC8, 0x3E, 0x6D, 0xD6, 0xE3, 0x9B, 0xB9, 0x2E,
247  0xAA, 0xE2, 0x1E, 0xE1, 0x0E, 0xE0, 0x5D, 0xD5, 0x7C, 0xC7, 0x4D, 0x8B,
248  0xD4, 0xB8, 0x9A, 0xA9, 0x6C, 0xC6, 0x3D, 0xD3, 0xD2, 0x2D, 0x0D, 0x1D,
249  0x7B, 0xB7, 0xD1, 0x5C, 0xD0, 0xC5, 0x8A, 0xA8, 0x4C, 0xC4, 0x6B, 0xB6,
250  0x99, 0x0C, 0x3C, 0xC3, 0x7A, 0xA7, 0xA6, 0xC0, 0x0B, 0xC2, 0x2C, 0x5B,
251  0xB5, 0x1C, 0x89, 0x98, 0xC1, 0x4B, 0xB4, 0x6A, 0x3B, 0x79, 0xB3, 0x97,
252  0x88, 0x2B, 0x5A, 0xB2, 0xA5, 0x1B, 0xB1, 0xB0, 0x69, 0x96, 0x4A, 0xA4,
253  0x78, 0x87, 0x3A, 0xA3, 0x59, 0x95, 0x2A, 0xA2, 0x1A, 0xA1, 0x0A, 0xA0,
254  0x68, 0x86, 0x49, 0x94, 0x39, 0x93, 0x77, 0x09, 0x58, 0x85, 0x29, 0x67,
255  0x76, 0x92, 0x91, 0x19, 0x90, 0x48, 0x84, 0x57, 0x75, 0x38, 0x83, 0x66,
256  0x47, 0x28, 0x82, 0x18, 0x81, 0x74, 0x08, 0x80, 0x56, 0x65, 0x37, 0x73,
257  0x46, 0x27, 0x72, 0x64, 0x17, 0x55, 0x71, 0x07, 0x70, 0x36, 0x63, 0x45,
258  0x54, 0x26, 0x62, 0x16, 0x06, 0x60, 0x35, 0x61, 0x53, 0x44, 0x25, 0x52,
259  0x15, 0x51, 0x05, 0x50, 0x34, 0x43, 0x24, 0x42, 0x33, 0x41, 0x14, 0x04,
260  0x23, 0x32, 0x40, 0x03, 0x13, 0x31, 0x30, 0x22, 0x12, 0x21, 0x02, 0x20,
261  0x11, 0x01, 0x10, 0x00,
262  /* Huffman table 16 - 256 entries */
263  0xEF, 0xFE, 0xDF, 0xFD, 0xCF, 0xFC, 0xBF, 0xFB, 0xAF, 0xFA, 0x9F, 0xF9,
264  0xF8, 0x8F, 0x7F, 0xF7, 0x6F, 0xF6, 0xFF, 0x5F, 0xF5, 0x4F, 0xF4, 0xF3,
265  0xF0, 0x3F, 0xCE, 0xEC, 0xDD, 0xDE, 0xE9, 0xEA, 0xD9, 0xEE, 0xED, 0xEB,
266  0xBE, 0xCD, 0xDC, 0xDB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,
281  0x54, 0x26, 0x62, 0x16, 0x61, 0x06, 0x60, 0x53, 0x35, 0x44, 0x25, 0x52,
282  0x51, 0x15, 0x05, 0x34, 0x43, 0x50, 0x24, 0x42, 0x33, 0x14, 0x41, 0x04,
283  0x40, 0x23, 0x32, 0x13, 0x31, 0x03, 0x30, 0x22, 0x12, 0x21, 0x02, 0x20,
284  0x11, 0x01, 0x10, 0x00,
285  /* Huffman table 24 - 256 entries */
286  0xEF, 0xFE, 0xDF, 0xFD, 0xCF, 0xFC, 0xBF, 0xFB, 0xFA, 0xAF, 0x9F, 0xF9,
287  0xF8, 0x8F, 0x7F, 0xF7, 0x6F, 0xF6, 0x5F, 0xF5, 0x4F, 0xF4, 0x3F, 0xF3,
288  0x2F, 0xF2, 0xF1, 0x1F, 0xF0, 0x0F, 0xEE, 0xDE, 0xED, 0xCE, 0xEC, 0xDD,
289  0xBE, 0xEB, 0xCD, 0xDC, 0xAE, 0xEA, 0xBD, 0xDB, 0xCC, 0x9E, 0xE9, 0xAD,
290  0xDA, 0xBC, 0xCB, 0x8E, 0xE8, 0x9D, 0xD9, 0x7E, 0xE7, 0xAC, 0xFF, 0xCA,
291  0xBB, 0x8D, 0xD8, 0x0E, 0xE0, 0x0D, 0xE6, 0x6E, 0x9C, 0xC9, 0x5E, 0xBA,
292  0xE5, 0xAB, 0x7D, 0xD7, 0xE4, 0x8C, 0xC8, 0x4E, 0x2E, 0x3E, 0x6D, 0xD6,
293  0xE3, 0x9B, 0xB9, 0xAA, 0xE2, 0x1E, 0xE1, 0x5D, 0xD5, 0x7C, 0xC7, 0x4D,
294  0x8B, 0xB8, 0xD4, 0x9A, 0xA9, 0x6C, 0xC6, 0x3D, 0xD3, 0x2D, 0xD2, 0x1D,
295  0x7B, 0xB7, 0xD1, 0x5C, 0xC5, 0x8A, 0xA8, 0x99, 0x4C, 0xC4, 0x6B, 0xB6,
296  0xD0, 0x0C, 0x3C, 0xC3, 0x7A, 0xA7, 0x2C, 0xC2, 0x5B, 0xB5, 0x1C, 0x89,
297  0x98, 0xC1, 0x4B, 0xC0, 0x0B, 0x3B, 0xB0, 0x0A, 0x1A, 0xB4, 0x6A, 0xA6,
298  0x79, 0x97, 0xA0, 0x09, 0x90, 0xB3, 0x88, 0x2B, 0x5A, 0xB2, 0xA5, 0x1B,
299  0xB1, 0x69, 0x96, 0xA4, 0x4A, 0x78, 0x87, 0x3A, 0xA3, 0x59, 0x95, 0x2A,
300  0xA2, 0xA1, 0x68, 0x86, 0x77, 0x49, 0x94, 0x39, 0x93, 0x58, 0x85, 0x29,
301  0x67, 0x76, 0x92, 0x19, 0x91, 0x48, 0x84, 0x57, 0x75, 0x38, 0x83, 0x66,
302  0x28, 0x82, 0x18, 0x47, 0x74, 0x81, 0x08, 0x80, 0x56, 0x65, 0x17, 0x07,
303  0x70, 0x73, 0x37, 0x27, 0x72, 0x46, 0x64, 0x55, 0x71, 0x36, 0x63, 0x45,
304  0x54, 0x26, 0x62, 0x16, 0x61, 0x06, 0x60, 0x35, 0x53, 0x44, 0x25, 0x52,
305  0x15, 0x05, 0x50, 0x51, 0x34, 0x43, 0x24, 0x42, 0x33, 0x14, 0x41, 0x04,
306  0x40, 0x23, 0x32, 0x13, 0x31, 0x03, 0x30, 0x22, 0x12, 0x21, 0x02, 0x20,
307  0x11, 0x01, 0x10, 0x00,
308 };
309 
310 static const uint8_t mpa_huff_sizes_minus_one[] =
311 {
312  3, 8, 8, 15, 15, 35, 35, 35, 63, 63, 63, 255, 255, 255, 255
313 };
314 
315 const uint8_t ff_mpa_huff_data[32][2] = {
316 { 0, 0 },
317 { 1, 0 },
318 { 2, 0 },
319 { 3, 0 },
320 { 0, 0 },
321 { 4, 0 },
322 { 5, 0 },
323 { 6, 0 },
324 { 7, 0 },
325 { 8, 0 },
326 { 9, 0 },
327 { 10, 0 },
328 { 11, 0 },
329 { 12, 0 },
330 { 0, 0 },
331 { 13, 0 },
332 { 14, 1 },
333 { 14, 2 },
334 { 14, 3 },
335 { 14, 4 },
336 { 14, 6 },
337 { 14, 8 },
338 { 14, 10 },
339 { 14, 13 },
340 { 15, 4 },
341 { 15, 5 },
342 { 15, 6 },
343 { 15, 7 },
344 { 15, 8 },
345 { 15, 9 },
346 { 15, 11 },
347 { 15, 13 },
348 };
349 
350 
351 /* huffman tables for quadrules */
352 static const uint8_t mpa_quad_codes[2][16] = {
353  { 1, 5, 4, 5, 6, 5, 4, 4, 7, 3, 6, 0, 7, 2, 3, 1, },
354  { 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, },
355 };
356 
357 static const uint8_t mpa_quad_bits[2][16] = {
358  { 1, 4, 4, 5, 4, 6, 5, 6, 4, 5, 5, 6, 5, 6, 6, 6, },
359  { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, },
360 };
361 
362 const uint8_t ff_band_size_long[9][22] = {
363 { 4, 4, 4, 4, 4, 4, 6, 6, 8, 8, 10,
364  12, 16, 20, 24, 28, 34, 42, 50, 54, 76, 158, }, /* 44100 */
365 { 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 10,
366  12, 16, 18, 22, 28, 34, 40, 46, 54, 54, 192, }, /* 48000 */
367 { 4, 4, 4, 4, 4, 4, 6, 6, 8, 10, 12,
368  16, 20, 24, 30, 38, 46, 56, 68, 84, 102, 26, }, /* 32000 */
369 { 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
370  20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, }, /* 22050 */
371 { 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
372  18, 22, 26, 32, 38, 46, 54, 62, 70, 76, 36, }, /* 24000 */
373 { 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
374  20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, }, /* 16000 */
375 { 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
376  20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, }, /* 11025 */
377 { 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
378  20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, }, /* 12000 */
379 { 12, 12, 12, 12, 12, 12, 16, 20, 24, 28, 32,
380  40, 48, 56, 64, 76, 90, 2, 2, 2, 2, 2, }, /* 8000 */
381 };
382 
383 const uint8_t ff_band_size_short[9][13] = {
384 { 4, 4, 4, 4, 6, 8, 10, 12, 14, 18, 22, 30, 56, }, /* 44100 */
385 { 4, 4, 4, 4, 6, 6, 10, 12, 14, 16, 20, 26, 66, }, /* 48000 */
386 { 4, 4, 4, 4, 6, 8, 12, 16, 20, 26, 34, 42, 12, }, /* 32000 */
387 { 4, 4, 4, 6, 6, 8, 10, 14, 18, 26, 32, 42, 18, }, /* 22050 */
388 { 4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 32, 44, 12, }, /* 24000 */
389 { 4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 30, 40, 18, }, /* 16000 */
390 { 4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 30, 40, 18, }, /* 11025 */
391 { 4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 30, 40, 18, }, /* 12000 */
392 { 8, 8, 8, 12, 16, 20, 24, 28, 36, 2, 2, 2, 26, }, /* 8000 */
393 };
394 
395 uint16_t ff_band_index_long[9][23];
396 
397 const uint8_t ff_mpa_pretab[2][22] = {
398  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
399  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0 },
400 };
401 
403 {
405  const uint8_t *huff_sym = mpa_huffsymbols, *huff_lens = mpa_hufflens;
406  int offset;
407 
408  /* scale factors table for layer 1/2 */
409  for (int i = 0; i < 64; i++) {
410  int shift, mod;
411  /* 1.0 (i = 3) is normalized to 2 ^ FRAC_BITS */
412  shift = i / 3;
413  mod = i % 3;
414  ff_scale_factor_modshift[i] = mod | (shift << 2);
415  }
416 
417  /* huffman decode tables */
418  for (int i = 0; i < 15;) {
419  uint16_t tmp_symbols[256];
420  int nb_codes_minus_one = mpa_huff_sizes_minus_one[i];
421  int j;
422 
423  for (j = 0; j <= nb_codes_minus_one; j++) {
424  uint8_t high = huff_sym[j] & 0xF0, low = huff_sym[j] & 0xF;
425 
426  tmp_symbols[j] = high << 1 | ((high && low) << 4) | low;
427  }
428 
430  huff_lens, 1,
431  tmp_symbols, 2, 2,
432  0, 0);
433  huff_lens += j;
434  huff_sym += j;
435  }
436  av_assert1(state.size == 0);
437 
438  offset = 0;
439  for (int i = 0; i < 2; i++) {
440  int bits = i == 0 ? 6 : 4;
443  offset += 1 << bits;
445  mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1,
447  }
449 
450  for (int i = 0; i < 9; i++) {
451  int k = 0;
452  for (int j = 0; j < 22; j++) {
453  ff_band_index_long[i][j] = k;
454  k += ff_band_size_long[i][j] >> 1;
455  }
456  ff_band_index_long[i][22] = k;
457  }
458 
459  for (int i = 0; i < 4; i++) {
460  if (ff_mpa_quant_bits[i] < 0) {
461  for (int j = 0; j < (1 << (-ff_mpa_quant_bits[i] + 1)); j++) {
462  int val1, val2, val3, steps;
463  int val = j;
465  val1 = val % steps;
466  val /= steps;
467  val2 = val % steps;
468  val3 = val / steps;
469  ff_division_tabs[i][j] = val1 + (val2 << 4) + (val3 << 8);
470  }
471  }
472  }
474 }
475 
477 {
478  static AVOnce init_static_once = AV_ONCE_INIT;
479 
481 }
libm.h
thread.h
ff_slen_table
const uint8_t ff_slen_table[2][16]
Definition: mpegaudiodec_common.c:52
mpa_hufflens
static const uint8_t mpa_hufflens[]
Definition: mpegaudiodec_common.c:73
ff_mpegaudiodec_common_init_static
av_cold void ff_mpegaudiodec_common_init_static(void)
Definition: mpegaudiodec_common.c:476
mpegaudiodec_common_init_static
static av_cold void mpegaudiodec_common_init_static(void)
Definition: mpegaudiodec_common.c:402
ff_mpa_quant_bits
const int ff_mpa_quant_bits[17]
Definition: mpegaudiodata.c:42
division_tab5
static int16_t division_tab5[1<< 8]
Definition: mpegaudiodec_common.c:41
mpa_huff_sizes_minus_one
static const uint8_t mpa_huff_sizes_minus_one[]
Definition: mpegaudiodec_common.c:310
mpa_quad_codes
static const uint8_t mpa_quad_codes[2][16]
Definition: mpegaudiodec_common.c:352
val
static double val(void *priv, double ch)
Definition: aeval.c:78
ff_mpa_huff_data
const uint8_t ff_mpa_huff_data[32][2]
Definition: mpegaudiodec_common.c:315
avassert.h
mpa_quad_bits
static const uint8_t mpa_quad_bits[2][16]
Definition: mpegaudiodec_common.c:357
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:205
ff_mpa_quant_steps
const int ff_mpa_quant_steps[17]
Definition: mpegaudiodata.c:34
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
ff_lsf_nsf_table
const uint8_t ff_lsf_nsf_table[6][3][4]
Definition: mpegaudiodec_common.c:57
huff_vlc_tables
static VLCElem huff_vlc_tables[128+128+128+130+128+154+166+142+204+190+170+542+460+662+414]
Definition: mpegaudiodec_common.c:69
VLCInitState
For static VLCs, the number of bits can often be hardcoded at each get_vlc2() callsite.
Definition: vlc.h:212
bits
uint8_t bits
Definition: vp3data.h:128
mpa_huffsymbols
static const uint8_t mpa_huffsymbols[]
Definition: mpegaudiodec_common.c:170
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
vlc_init
#define vlc_init(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
Definition: vlc.h:62
ff_huff_quad_vlc
VLC ff_huff_quad_vlc[2]
Definition: mpegaudiodec_common.c:70
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
NULL
#define NULL
Definition: coverity.c:32
AVOnce
#define AVOnce
Definition: thread.h:202
VLC::table_allocated
int table_allocated
Definition: vlc.h:39
mpegaudiodec_common_tablegen.h
shift
static int shift(int a, int b)
Definition: bonk.c:261
ff_huff_vlc
const VLCElem * ff_huff_vlc[16]
Definition: mpegaudiodec_common.c:67
VLCElem
Definition: vlc.h:32
state
static struct @395 state
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
ff_division_tabs
int16_t *const ff_division_tabs[4]
Definition: mpegaudiodec_common.c:44
mpegaudiodec_common_tableinit
static av_cold void mpegaudiodec_common_tableinit(void)
Definition: mpegaudiodec_common_tablegen.h:44
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
mod
static int mod(int a, int b)
Modulo operation with only positive remainders.
Definition: vf_v360.c:750
ff_band_index_long
uint16_t ff_band_index_long[9][23]
Definition: mpegaudiodec_common.c:395
ff_band_size_short
const uint8_t ff_band_size_short[9][13]
Definition: mpegaudiodec_common.c:383
steps
static const int16_t steps[16]
Definition: misc4.c:30
VLC
Definition: vlc.h:36
VLC::table
VLCElem * table
Definition: vlc.h:38
mpegaudiodata.h
ff_vlc_init_tables_from_lengths
const av_cold VLCElem * ff_vlc_init_tables_from_lengths(VLCInitState *state, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags)
Definition: vlc.c:366
VLC_INIT_STATE
#define VLC_INIT_STATE(_table)
Definition: vlc.h:217
ff_mpa_pretab
const uint8_t ff_mpa_pretab[2][22]
Definition: mpegaudiodec_common.c:397
division_tab3
static int16_t division_tab3[1<< 6]
Definition: mpegaudiodec_common.c:40
VLC_INIT_USE_STATIC
#define VLC_INIT_USE_STATIC
Definition: vlc.h:182
ff_band_size_long
const uint8_t ff_band_size_long[9][22]
Definition: mpegaudiodec_common.c:362
ff_scale_factor_modshift
uint16_t ff_scale_factor_modshift[64]
Definition: mpegaudiodec_common.c:38
division_tab9
static int16_t division_tab9[1<< 11]
Definition: mpegaudiodec_common.c:42
huff_quad_vlc_tables
static VLCElem huff_quad_vlc_tables[64+16]
Definition: mpegaudiodec_common.c:71