46 #define BACKSTEP_SIZE 512
48 #define LAST_BUF_SIZE 2 * BACKSTEP_SIZE + EXTRABYTES
100 0 + 128 + 128 + 128 + 130 + 128 + 154 + 166 +
101 142 + 204 + 190 + 170 + 542 + 460 + 662 + 414
104 0, 128, 128, 128, 130, 128, 154, 166,
105 142, 204, 190, 170, 542, 460, 662, 414
132 #define SCALE_GEN(v) \
133 { FIXR_OLD(1.0 * (v)), FIXR_OLD(0.7937005259 * (v)), FIXR_OLD(0.6299605249 * (v)) }
149 for (i = 0; i < 3; i++) {
159 if (s->sample_rate_index != 8)
164 if (s->sample_rate_index <= 2)
166 else if (s->sample_rate_index != 8)
180 l =
FFMIN(ra1 + ra2 + 2, 22);
188 if(s->sample_rate_index == 8)
193 if (s->sample_rate_index <= 2)
222 return (
int)((val + (1LL << (shift - 1))) >> shift);
236 val = (val + (1 << (shift - 1))) >> shift;
255 m = (m + (1 << (e - 1))) >> e;
266 for (i = 0; i < 64; i++) {
275 for (i = 0; i < 15; i++) {
278 norm = ((INT64_C(1) <<
n) *
FRAC_ONE) / ((1 <<
n) - 1);
282 av_dlog(NULL,
"%d: norm=%x s=%x %x %x\n", i, norm,
292 for (i = 1; i < 16; i++) {
295 uint8_t tmp_bits [512] = { 0 };
296 uint16_t tmp_codes[512] = { 0 };
301 for (x = 0; x < xsize; x++) {
302 for (y = 0; y < xsize; y++) {
303 tmp_bits [(x << 5) | y | ((x&&y)<<4)]= h->
bits [j ];
304 tmp_codes[(x << 5) | y | ((x&&
y)<<4)]= h->
codes[j++];
312 tmp_bits, 1, 1, tmp_codes, 2, 2,
319 for (i = 0; i < 2; i++) {
322 init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16,
329 for (i = 0; i < 9; i++) {
331 for (j = 0; j < 22; j++) {
342 for (i = 0; i < 4; i++) {
345 int val1, val2, val3, steps;
358 for (i = 0; i < 7; i++) {
362 f = tan((
double)i *
M_PI / 12.0);
363 v =
FIXR(f / (1.0 + f));
371 for (i = 7; i < 16; i++)
374 for (i = 0; i < 16; i++) {
378 for (j = 0; j < 2; j++) {
379 e = -(j + 1) * ((i + 1) >> 1);
384 av_dlog(NULL,
"is_table_lsf %d %d: %f %f\n",
390 for (i = 0; i < 8; i++) {
393 cs = 1.0 / sqrt(1.0 + ci * ci);
421 static int initialized_tables = 0;
424 if (!initialized_tables) {
426 initialized_tables = 1;
450 #define C3 FIXHR(0.86602540378443864676/2)
451 #define C4 FIXHR(0.70710678118654752439/2) //0.5 / cos(pi*(9)/36)
452 #define C5 FIXHR(0.51763809020504152469/2) //0.5 / cos(pi*(5)/36)
453 #define C6 FIXHR(1.93185165257813657349/4) //0.5 / cos(pi*(15)/36)
462 in1 = in[1*3] + in[0*3];
463 in2 = in[2*3] + in[1*3];
464 in3 = in[3*3] + in[2*3];
465 in4 = in[4*3] + in[3*3];
466 in5 = in[5*3] + in[4*3];
501 int bound, i,
v,
n, ch, j, mant;
506 bound = (s->mode_ext + 1) * 4;
511 for (i = 0; i < bound; i++) {
512 for (ch = 0; ch < s->nb_channels; ch++) {
516 for (i = bound; i <
SBLIMIT; i++)
520 for (i = 0; i < bound; i++) {
521 for (ch = 0; ch < s->nb_channels; ch++) {
522 if (allocation[ch][i])
526 for (i = bound; i <
SBLIMIT; i++) {
527 if (allocation[0][i]) {
534 for (j = 0; j < 12; j++) {
535 for (i = 0; i < bound; i++) {
536 for (ch = 0; ch < s->nb_channels; ch++) {
537 n = allocation[ch][i];
540 v =
l1_unscale(n, mant, scale_factors[ch][i]);
547 for (i = bound; i <
SBLIMIT; i++) {
548 n = allocation[0][i];
568 int table, bit_alloc_bits, i, j, ch, bound,
v;
572 int scale, qindex,
bits, steps, k, l,
m,
b;
576 s->sample_rate, s->lsf);
581 bound = (s->mode_ext + 1) * 4;
585 av_dlog(s->
avctx,
"bound=%d sblimit=%d\n", bound, sblimit);
593 for (i = 0; i < bound; i++) {
594 bit_alloc_bits = alloc_table[j];
595 for (ch = 0; ch < s->nb_channels; ch++)
596 bit_alloc[ch][i] =
get_bits(&s->
gb, bit_alloc_bits);
597 j += 1 << bit_alloc_bits;
599 for (i = bound; i < sblimit; i++) {
600 bit_alloc_bits = alloc_table[j];
604 j += 1 << bit_alloc_bits;
608 for (i = 0; i < sblimit; i++) {
609 for (ch = 0; ch < s->nb_channels; ch++) {
610 if (bit_alloc[ch][i])
616 for (i = 0; i < sblimit; i++) {
617 for (ch = 0; ch < s->nb_channels; ch++) {
618 if (bit_alloc[ch][i]) {
619 sf = scale_factors[ch][i];
620 switch (scale_code[ch][i]) {
648 for (k = 0; k < 3; k++) {
649 for (l = 0; l < 12; l += 3) {
651 for (i = 0; i < bound; i++) {
652 bit_alloc_bits = alloc_table[j];
653 for (ch = 0; ch < s->nb_channels; ch++) {
654 b = bit_alloc[ch][i];
656 scale = scale_factors[ch][i][k];
657 qindex = alloc_table[j+
b];
673 for (m = 0; m < 3; m++) {
686 j += 1 << bit_alloc_bits;
689 for (i = bound; i < sblimit; i++) {
690 bit_alloc_bits = alloc_table[j];
693 int mant, scale0, scale1;
694 scale0 = scale_factors[0][i][k];
695 scale1 = scale_factors[1][i][k];
696 qindex = alloc_table[j+
b];
719 for (m = 0; m < 3; m++) {
736 j += 1 << bit_alloc_bits;
739 for (i = sblimit; i <
SBLIMIT; i++) {
740 for (ch = 0; ch < s->nb_channels; ch++) {
751 #define SPLIT(dst,sf,n) \
753 int m = (sf * 171) >> 9; \
756 } else if (n == 4) { \
759 } else if (n == 5) { \
760 int m = (sf * 205) >> 10; \
763 } else if (n == 6) { \
764 int m = (sf * 171) >> 10; \
774 SPLIT(slen[3], sf, n3)
775 SPLIT(slen[2], sf, n2)
776 SPLIT(slen[1], sf, n1)
784 int len, i, j, k, l,
v0,
shift, gain, gains[3];
794 v0 = gain - ((g->
scale_factors[i] + pretab[i]) << shift) + 400;
796 for (j = len; j > 0; j--)
808 for (l = 0; l < 3; l++) {
810 for (j = len; j > 0; j--)
845 #define READ_FLIP_SIGN(dst,src) \
846 v = AV_RN32A(src) ^ (get_bits1(&s->gb) << 31); \
849 #define READ_FLIP_SIGN(dst,src) \
850 v = -get_bits1(&s->gb); \
851 *(dst) = (*(src) ^ v) - v;
855 int16_t *exponents,
int end_pos2)
859 int last_pos, bits_left;
865 for (i = 0; i < 3; i++) {
866 int j, k, l, linbits;
902 exponent= exponents[s_index];
949 while (s_index <= 572) {
952 if (pos >= end_pos) {
953 if (pos > end_pos2 && last_pos) {
958 av_log(s->
avctx,
AV_LOG_INFO,
"overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos);
976 static const int idxtab[16] = { 3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0 };
978 int pos = s_index + idxtab[code];
979 code ^= 8 >> idxtab[code];
1015 if (s->sample_rate_index != 8)
1027 for (j = len; j > 0; j--) {
1028 *dst++ = ptr[0*
len];
1029 *dst++ = ptr[1*
len];
1030 *dst++ = ptr[2*
len];
1034 memcpy(ptr1, tmp, len * 3 *
sizeof(*ptr1));
1038 #define ISQRT2 FIXR(0.70710678118654752440)
1043 int sf_max, sf,
len, non_zero_found;
1044 INTFLOAT (*is_tab)[16], *tab0, *
tab1, tmp0, tmp1, v1, v2;
1045 int non_zero_found_short[3];
1060 non_zero_found_short[0] = 0;
1061 non_zero_found_short[1] = 0;
1062 non_zero_found_short[2] = 0;
1069 for (l = 2; l >= 0; l--) {
1072 if (!non_zero_found_short[l]) {
1074 for (j = 0; j <
len; j++) {
1076 non_zero_found_short[l] = 1;
1086 for (j = 0; j <
len; j++) {
1096 for (j = 0; j <
len; j++) {
1107 non_zero_found = non_zero_found_short[0] |
1108 non_zero_found_short[1] |
1109 non_zero_found_short[2];
1111 for (i = g1->
long_end - 1;i >= 0;i--) {
1116 if (!non_zero_found) {
1117 for (j = 0; j <
len; j++) {
1124 k = (i == 21) ? 20 : i;
1130 for (j = 0; j <
len; j++) {
1140 for (j = 0; j <
len; j++) {
1158 for (i = 0; i < 576; i++) {
1161 tab0[i] = tmp0 + tmp1;
1162 tab1[i] = tmp0 - tmp1;
1178 #ifndef compute_antialias
1180 #define AA(j) do { \
1181 float tmp0 = ptr[-1-j]; \
1182 float tmp1 = ptr[ j]; \
1183 ptr[-1-j] = tmp0 * csa_table[j][0] - tmp1 * csa_table[j][1]; \
1184 ptr[ j] = tmp0 * csa_table[j][1] + tmp1 * csa_table[j][0]; \
1187 #define AA(j) do { \
1188 int tmp0 = ptr[-1-j]; \
1189 int tmp1 = ptr[ j]; \
1190 int tmp2 = MULH(tmp0 + tmp1, csa_table[j][0]); \
1191 ptr[-1-j] = 4 * (tmp2 - MULH(tmp1, csa_table[j][2])); \
1192 ptr[ j] = 4 * (tmp2 + MULH(tmp0, csa_table[j][3])); \
1212 for (i = n; i > 0; i--) {
1232 int i, j, mdct_long_end, sblimit;
1237 while (ptr >= ptr1) {
1241 if (p[0] | p[1] | p[2] | p[3] | p[4] | p[5])
1244 sblimit = ((ptr - g->
sb_hybrid) / 18) + 1;
1253 mdct_long_end = sblimit;
1260 buf = mdct_buf + 4*18*(mdct_long_end >> 2) + (mdct_long_end & 3);
1261 ptr = g->
sb_hybrid + 18 * mdct_long_end;
1263 for (j = mdct_long_end; j < sblimit; j++) {
1265 win =
RENAME(ff_mdct_win)[2 + (4 & -(j & 1))];
1266 out_ptr = sb_samples + j;
1268 for (i = 0; i < 6; i++) {
1269 *out_ptr = buf[4*i];
1273 for (i = 0; i < 6; i++) {
1274 *out_ptr =
MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*1)];
1275 buf[4*(i + 6*2)] =
MULH3(out2[i + 6], win[i + 6], 1);
1279 for (i = 0; i < 6; i++) {
1280 *out_ptr =
MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*2)];
1281 buf[4*(i + 6*0)] =
MULH3(out2[i + 6], win[i + 6], 1);
1285 for (i = 0; i < 6; i++) {
1286 buf[4*(i + 6*0)] =
MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*0)];
1287 buf[4*(i + 6*1)] =
MULH3(out2[i + 6], win[i + 6], 1);
1288 buf[4*(i + 6*2)] = 0;
1291 buf += (j&3) != 3 ? 1 : (4*18-3);
1294 for (j = sblimit; j <
SBLIMIT; j++) {
1296 out_ptr = sb_samples + j;
1297 for (i = 0; i < 18; i++) {
1298 *out_ptr = buf[4*i];
1302 buf += (j&3) != 3 ? 1 : (4*18-3);
1309 int nb_granules, main_data_begin;
1310 int gr, ch, blocksplit_flag, i, j, k,
n, bits_pos;
1312 int16_t exponents[576];
1321 if (s->nb_channels == 2)
1326 for (ch = 0; ch < s->nb_channels; ch++) {
1332 for (gr = 0; gr < nb_granules; gr++) {
1333 for (ch = 0; ch < s->nb_channels; ch++) {
1354 if (blocksplit_flag) {
1361 for (i = 0; i < 2; i++)
1363 for (i = 0; i < 3; i++)
1367 int region_address1, region_address2;
1370 for (i = 0; i < 3; i++)
1376 region_address1, region_address2);
1404 #if !UNCHECKED_BITSTREAM_READER
1408 for (gr = 0; gr < nb_granules && (s->
last_buf_size >> 3) < main_data_begin; gr++) {
1409 for (ch = 0; ch < s->nb_channels; ch++) {
1428 for (; gr < nb_granules; gr++) {
1429 for (ch = 0; ch < s->nb_channels; ch++) {
1435 int slen, slen1, slen2;
1440 av_dlog(s->
avctx,
"slen1=%d slen2=%d\n", slen1, slen2);
1445 for (i = 0; i <
n; i++)
1448 for (i = 0; i <
n; i++)
1452 for (i = 0; i < 18; i++)
1454 for (i = 0; i < 3; i++)
1457 for (i = 0; i < 21; i++)
1463 for (k = 0; k < 4; k++) {
1465 if ((g->
scfsi & (0x8 >> k)) == 0) {
1466 slen = (k < 2) ? slen1 : slen2;
1468 for (i = 0; i <
n; i++)
1471 for (i = 0; i <
n; i++)
1476 for (i = 0; i <
n; i++) {
1485 int tindex, tindex2, slen[4], sl, sf;
1500 }
else if (sf < 244) {
1512 }
else if (sf < 500) {
1523 for (k = 0; k < 4; k++) {
1527 for (i = 0; i <
n; i++)
1530 for (i = 0; i <
n; i++)
1548 for (ch = 0; ch < s->nb_channels; ch++) {
1558 return nb_granules * 18;
1564 int i, nb_frames, ch,
ret;
1570 if (s->error_protection)
1609 av_assert1(i <= buf_size - HEADER_SIZE && i >= 0);
1627 for (ch = 0; ch < s->nb_channels; ch++) {
1630 samples_ptr = samples[ch];
1633 samples_ptr = samples[0] + ch;
1634 sample_stride = s->nb_channels;
1636 for (i = 0; i < nb_frames; i++) {
1639 RENAME(ff_mpa_synth_window),
1642 samples_ptr += 32 * sample_stride;
1646 return nb_frames * 32 *
sizeof(
OUT_INT) * s->nb_channels;
1653 int buf_size = avpkt->
size;
1658 while(buf_size && !*buf){
1667 if (header>>8 ==
AV_RB32(
"TAG")>>8) {
1687 if (s->frame_size <= 0 || s->frame_size > buf_size) {
1690 }
else if (s->frame_size < buf_size) {
1692 buf_size= s->frame_size;
1731 #if CONFIG_MP3ADU_DECODER || CONFIG_MP3ADUFLOAT_DECODER
1733 int *got_frame_ptr,
AVPacket *avpkt)
1736 int buf_size = avpkt->
size;
1755 header =
AV_RB32(buf) | 0xffe00000;
1770 s->frame_size =
len;
1786 #if CONFIG_MP3ON4_DECODER || CONFIG_MP3ON4FLOAT_DECODER
1791 typedef struct MP3On4DecodeContext {
1796 } MP3On4DecodeContext;
1803 static const uint8_t mp3Frames[8] = { 0, 1, 1, 2, 3, 3, 4, 5 };
1806 static const uint8_t chan_offset[8][5] = {
1818 static const int16_t chan_layout[8] = {
1831 MP3On4DecodeContext *s = avctx->
priv_data;
1834 for (i = 0; i < s->frames; i++)
1843 MP3On4DecodeContext *s = avctx->
priv_data;
1864 s->syncword = 0xffe00000;
1866 s->syncword = 0xfff00000;
1875 if (!s->mp3decctx[0])
1882 s->mp3decctx[0]->adu_mode = 1;
1887 for (i = 1; i < s->frames; i++) {
1889 if (!s->mp3decctx[i])
1891 s->mp3decctx[i]->adu_mode = 1;
1892 s->mp3decctx[i]->avctx = avctx;
1893 s->mp3decctx[i]->mpadsp = s->mp3decctx[0]->mpadsp;
1898 decode_close_mp3on4(avctx);
1906 MP3On4DecodeContext *s = avctx->
priv_data;
1908 for (i = 0; i < s->frames; i++)
1913 static int decode_frame_mp3on4(
AVCodecContext *avctx,
void *data,
1914 int *got_frame_ptr,
AVPacket *avpkt)
1918 int buf_size = avpkt->
size;
1919 MP3On4DecodeContext *s = avctx->
priv_data;
1921 int fsize, len = buf_size, out_size = 0;
1940 for (fr = 0; fr < s->frames; fr++) {
1943 m = s->mp3decctx[fr];
1950 header = (
AV_RB32(buf) & 0x000fffff) | s->syncword;
1959 if (ch + m->nb_channels > avctx->
channels ||
1960 s->coff[fr] + m->nb_channels > avctx->
channels) {
1965 ch += m->nb_channels;
1967 outptr[0] = out_samples[s->coff[fr]];
1968 if (m->nb_channels > 1)
1969 outptr[1] = out_samples[s->coff[fr] + 1];
1974 if (m->nb_channels > 1)
1991 avctx->
sample_rate = s->mp3decctx[0]->sample_rate;