00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include "libavutil/audioconvert.h"
00028 #include "avcodec.h"
00029 #include "ac3tab.h"
00030
00035 const uint16_t ff_ac3_frame_size_tab[38][3] = {
00036 { 64, 69, 96 },
00037 { 64, 70, 96 },
00038 { 80, 87, 120 },
00039 { 80, 88, 120 },
00040 { 96, 104, 144 },
00041 { 96, 105, 144 },
00042 { 112, 121, 168 },
00043 { 112, 122, 168 },
00044 { 128, 139, 192 },
00045 { 128, 140, 192 },
00046 { 160, 174, 240 },
00047 { 160, 175, 240 },
00048 { 192, 208, 288 },
00049 { 192, 209, 288 },
00050 { 224, 243, 336 },
00051 { 224, 244, 336 },
00052 { 256, 278, 384 },
00053 { 256, 279, 384 },
00054 { 320, 348, 480 },
00055 { 320, 349, 480 },
00056 { 384, 417, 576 },
00057 { 384, 418, 576 },
00058 { 448, 487, 672 },
00059 { 448, 488, 672 },
00060 { 512, 557, 768 },
00061 { 512, 558, 768 },
00062 { 640, 696, 960 },
00063 { 640, 697, 960 },
00064 { 768, 835, 1152 },
00065 { 768, 836, 1152 },
00066 { 896, 975, 1344 },
00067 { 896, 976, 1344 },
00068 { 1024, 1114, 1536 },
00069 { 1024, 1115, 1536 },
00070 { 1152, 1253, 1728 },
00071 { 1152, 1254, 1728 },
00072 { 1280, 1393, 1920 },
00073 { 1280, 1394, 1920 },
00074 };
00075
00080 const uint8_t ff_ac3_channels_tab[8] = {
00081 2, 1, 2, 3, 3, 4, 4, 5
00082 };
00083
00087 const uint16_t avpriv_ac3_channel_layout_tab[8] = {
00088 AV_CH_LAYOUT_STEREO,
00089 AV_CH_LAYOUT_MONO,
00090 AV_CH_LAYOUT_STEREO,
00091 AV_CH_LAYOUT_SURROUND,
00092 AV_CH_LAYOUT_2_1,
00093 AV_CH_LAYOUT_4POINT0,
00094 AV_CH_LAYOUT_2_2,
00095 AV_CH_LAYOUT_5POINT0
00096 };
00097
00098 #define COMMON_CHANNEL_MAP \
00099 { { 0, 1, }, { 0, 1, 2, } },\
00100 { { 0, }, { 0, 1, } },\
00101 { { 0, 1, }, { 0, 1, 2, } },\
00102 { { 0, 2, 1, }, { 0, 2, 1, 3, } },\
00103 { { 0, 1, 2, }, { 0, 1, 3, 2, } },\
00104 { { 0, 2, 1, 3, }, { 0, 2, 1, 4, 3, } },
00105
00110 const uint8_t ff_ac3_enc_channel_map[8][2][6] = {
00111 COMMON_CHANNEL_MAP
00112 { { 0, 1, 2, 3, }, { 0, 1, 3, 4, 2, } },
00113 { { 0, 2, 1, 3, 4, }, { 0, 2, 1, 4, 5, 3 } },
00114 };
00115
00120 const uint8_t ff_ac3_dec_channel_map[8][2][6] = {
00121 COMMON_CHANNEL_MAP
00122 { { 0, 1, 2, 3, }, { 0, 1, 4, 2, 3, } },
00123 { { 0, 2, 1, 3, 4, }, { 0, 2, 1, 5, 3, 4 } },
00124 };
00125
00126
00127 const uint16_t ff_ac3_sample_rate_tab[3] = { 48000, 44100, 32000 };
00128
00129
00130 const uint16_t ff_ac3_bitrate_tab[19] = {
00131 32, 40, 48, 56, 64, 80, 96, 112, 128,
00132 160, 192, 224, 256, 320, 384, 448, 512, 576, 640
00133 };
00134
00139 const uint8_t ff_ac3_rematrix_band_tab[5] = { 13, 25, 37, 61, 253 };
00140
00144 const uint8_t ff_eac3_default_cpl_band_struct[18] = {
00145 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1
00146 };
00147
00148
00149
00150
00151 DECLARE_ALIGNED(16, const int16_t, ff_ac3_window)[AC3_WINDOW_SIZE/2] = {
00152 4, 7, 12, 16, 21, 28, 34, 42,
00153 51, 61, 72, 84, 97, 111, 127, 145,
00154 164, 184, 207, 231, 257, 285, 315, 347,
00155 382, 419, 458, 500, 544, 591, 641, 694,
00156 750, 810, 872, 937, 1007, 1079, 1155, 1235,
00157 1318, 1406, 1497, 1593, 1692, 1796, 1903, 2016,
00158 2132, 2253, 2379, 2509, 2644, 2783, 2927, 3076,
00159 3230, 3389, 3552, 3721, 3894, 4072, 4255, 4444,
00160 4637, 4835, 5038, 5246, 5459, 5677, 5899, 6127,
00161 6359, 6596, 6837, 7083, 7334, 7589, 7848, 8112,
00162 8380, 8652, 8927, 9207, 9491, 9778,10069,10363,
00163 10660,10960,11264,11570,11879,12190,12504,12820,
00164 13138,13458,13780,14103,14427,14753,15079,15407,
00165 15735,16063,16392,16720,17049,17377,17705,18032,
00166 18358,18683,19007,19330,19651,19970,20287,20602,
00167 20914,21225,21532,21837,22139,22438,22733,23025,
00168 23314,23599,23880,24157,24430,24699,24964,25225,
00169 25481,25732,25979,26221,26459,26691,26919,27142,
00170 27359,27572,27780,27983,28180,28373,28560,28742,
00171 28919,29091,29258,29420,29577,29729,29876,30018,
00172 30155,30288,30415,30538,30657,30771,30880,30985,
00173 31086,31182,31274,31363,31447,31528,31605,31678,
00174 31747,31814,31877,31936,31993,32046,32097,32145,
00175 32190,32232,32272,32310,32345,32378,32409,32438,
00176 32465,32490,32513,32535,32556,32574,32592,32608,
00177 32623,32636,32649,32661,32671,32681,32690,32698,
00178 32705,32712,32718,32724,32729,32733,32737,32741,
00179 32744,32747,32750,32752,32754,32756,32757,32759,
00180 32760,32761,32762,32763,32764,32764,32765,32765,
00181 32766,32766,32766,32766,32767,32767,32767,32767,
00182 32767,32767,32767,32767,32767,32767,32767,32767,
00183 32767,32767,32767,32767,32767,32767,32767,32767,
00184 };
00185
00186 const uint8_t ff_ac3_log_add_tab[260]= {
00187 0x40,0x3f,0x3e,0x3d,0x3c,0x3b,0x3a,0x39,0x38,0x37,
00188 0x36,0x35,0x34,0x34,0x33,0x32,0x31,0x30,0x2f,0x2f,
00189 0x2e,0x2d,0x2c,0x2c,0x2b,0x2a,0x29,0x29,0x28,0x27,
00190 0x26,0x26,0x25,0x24,0x24,0x23,0x23,0x22,0x21,0x21,
00191 0x20,0x20,0x1f,0x1e,0x1e,0x1d,0x1d,0x1c,0x1c,0x1b,
00192 0x1b,0x1a,0x1a,0x19,0x19,0x18,0x18,0x17,0x17,0x16,
00193 0x16,0x15,0x15,0x15,0x14,0x14,0x13,0x13,0x13,0x12,
00194 0x12,0x12,0x11,0x11,0x11,0x10,0x10,0x10,0x0f,0x0f,
00195 0x0f,0x0e,0x0e,0x0e,0x0d,0x0d,0x0d,0x0d,0x0c,0x0c,
00196 0x0c,0x0c,0x0b,0x0b,0x0b,0x0b,0x0a,0x0a,0x0a,0x0a,
00197 0x0a,0x09,0x09,0x09,0x09,0x09,0x08,0x08,0x08,0x08,
00198 0x08,0x08,0x07,0x07,0x07,0x07,0x07,0x07,0x06,0x06,
00199 0x06,0x06,0x06,0x06,0x06,0x06,0x05,0x05,0x05,0x05,
00200 0x05,0x05,0x05,0x05,0x04,0x04,0x04,0x04,0x04,0x04,
00201 0x04,0x04,0x04,0x04,0x04,0x03,0x03,0x03,0x03,0x03,
00202 0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x02,
00203 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
00204 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x01,0x01,
00205 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00206 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00207 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00208 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
00209 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
00210 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
00211 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
00212 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
00213 };
00214
00215 const uint16_t ff_ac3_hearing_threshold_tab[AC3_CRITICAL_BANDS][3]= {
00216 { 0x04d0,0x04f0,0x0580 },
00217 { 0x04d0,0x04f0,0x0580 },
00218 { 0x0440,0x0460,0x04b0 },
00219 { 0x0400,0x0410,0x0450 },
00220 { 0x03e0,0x03e0,0x0420 },
00221 { 0x03c0,0x03d0,0x03f0 },
00222 { 0x03b0,0x03c0,0x03e0 },
00223 { 0x03b0,0x03b0,0x03d0 },
00224 { 0x03a0,0x03b0,0x03c0 },
00225 { 0x03a0,0x03a0,0x03b0 },
00226 { 0x03a0,0x03a0,0x03b0 },
00227 { 0x03a0,0x03a0,0x03b0 },
00228 { 0x03a0,0x03a0,0x03a0 },
00229 { 0x0390,0x03a0,0x03a0 },
00230 { 0x0390,0x0390,0x03a0 },
00231 { 0x0390,0x0390,0x03a0 },
00232 { 0x0380,0x0390,0x03a0 },
00233 { 0x0380,0x0380,0x03a0 },
00234 { 0x0370,0x0380,0x03a0 },
00235 { 0x0370,0x0380,0x03a0 },
00236 { 0x0360,0x0370,0x0390 },
00237 { 0x0360,0x0370,0x0390 },
00238 { 0x0350,0x0360,0x0390 },
00239 { 0x0350,0x0360,0x0390 },
00240 { 0x0340,0x0350,0x0380 },
00241 { 0x0340,0x0350,0x0380 },
00242 { 0x0330,0x0340,0x0380 },
00243 { 0x0320,0x0340,0x0370 },
00244 { 0x0310,0x0320,0x0360 },
00245 { 0x0300,0x0310,0x0350 },
00246 { 0x02f0,0x0300,0x0340 },
00247 { 0x02f0,0x02f0,0x0330 },
00248 { 0x02f0,0x02f0,0x0320 },
00249 { 0x02f0,0x02f0,0x0310 },
00250 { 0x0300,0x02f0,0x0300 },
00251 { 0x0310,0x0300,0x02f0 },
00252 { 0x0340,0x0320,0x02f0 },
00253 { 0x0390,0x0350,0x02f0 },
00254 { 0x03e0,0x0390,0x0300 },
00255 { 0x0420,0x03e0,0x0310 },
00256 { 0x0460,0x0420,0x0330 },
00257 { 0x0490,0x0450,0x0350 },
00258 { 0x04a0,0x04a0,0x03c0 },
00259 { 0x0460,0x0490,0x0410 },
00260 { 0x0440,0x0460,0x0470 },
00261 { 0x0440,0x0440,0x04a0 },
00262 { 0x0520,0x0480,0x0460 },
00263 { 0x0800,0x0630,0x0440 },
00264 { 0x0840,0x0840,0x0450 },
00265 { 0x0840,0x0840,0x04e0 },
00266 };
00267
00268 const uint8_t ff_ac3_bap_tab[64]= {
00269 0, 1, 1, 1, 1, 1, 2, 2, 3, 3,
00270 3, 4, 4, 5, 5, 6, 6, 6, 6, 7,
00271 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
00272 9, 10, 10, 10, 10, 11, 11, 11, 11, 12,
00273 12, 12, 12, 13, 13, 13, 13, 14, 14, 14,
00274 14, 14, 14, 14, 14, 15, 15, 15, 15, 15,
00275 15, 15, 15, 15,
00276 };
00277
00278 const uint8_t ff_ac3_slow_decay_tab[4]={
00279 0x0f, 0x11, 0x13, 0x15,
00280 };
00281
00282 const uint8_t ff_ac3_fast_decay_tab[4]={
00283 0x3f, 0x53, 0x67, 0x7b,
00284 };
00285
00286 const uint16_t ff_ac3_slow_gain_tab[4]= {
00287 0x540, 0x4d8, 0x478, 0x410,
00288 };
00289
00290 const uint16_t ff_ac3_db_per_bit_tab[4]= {
00291 0x000, 0x700, 0x900, 0xb00,
00292 };
00293
00294 const int16_t ff_ac3_floor_tab[8]= {
00295 0x2f0, 0x2b0, 0x270, 0x230, 0x1f0, 0x170, 0x0f0, 0xf800,
00296 };
00297
00298 const uint16_t ff_ac3_fast_gain_tab[8]= {
00299 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400,
00300 };
00301
00305 const uint16_t ff_eac3_default_chmap[8] = {
00306 AC3_CHMAP_L | AC3_CHMAP_R,
00307 AC3_CHMAP_C,
00308 AC3_CHMAP_L | AC3_CHMAP_R,
00309 AC3_CHMAP_L | AC3_CHMAP_C | AC3_CHMAP_R,
00310 AC3_CHMAP_L | AC3_CHMAP_R | AC3_CHMAP_C_SUR,
00311 AC3_CHMAP_L | AC3_CHMAP_C | AC3_CHMAP_R | AC3_CHMAP_C_SUR,
00312 AC3_CHMAP_L | AC3_CHMAP_R | AC3_CHMAP_L_SUR | AC3_CHMAP_R_SUR,
00313 AC3_CHMAP_L | AC3_CHMAP_C | AC3_CHMAP_R | AC3_CHMAP_L_SUR | AC3_CHMAP_R_SUR
00314 };