46 #define BACKSTEP_SIZE 512
48 #define LAST_BUF_SIZE 2 * BACKSTEP_SIZE + EXTRABYTES
101 0 + 128 + 128 + 128 + 130 + 128 + 154 + 166 +
102 142 + 204 + 190 + 170 + 542 + 460 + 662 + 414
105 0, 128, 128, 128, 130, 128, 154, 166,
106 142, 204, 190, 170, 542, 460, 662, 414
133 #define SCALE_GEN(v) \
134 { FIXR_OLD(1.0 * (v)), FIXR_OLD(0.7937005259 * (v)), FIXR_OLD(0.6299605249 * (v)) }
150 for (i = 0; i < 3; i++) {
160 if (s->sample_rate_index != 8)
165 if (s->sample_rate_index <= 2)
167 else if (s->sample_rate_index != 8)
181 l =
FFMIN(ra1 + ra2 + 2, 22);
189 if(s->sample_rate_index == 8)
194 if (s->sample_rate_index <= 2)
223 return (
int)((val + (1LL << (shift - 1))) >> shift);
237 val = (val + (1 << (shift - 1))) >> shift;
256 m = (m + (1 << (e - 1))) >> e;
267 for (i = 0; i < 64; i++) {
276 for (i = 0; i < 15; i++) {
279 norm = ((INT64_C(1) <<
n) *
FRAC_ONE) / ((1 <<
n) - 1);
293 for (i = 1; i < 16; i++) {
296 uint8_t tmp_bits [512] = { 0 };
297 uint16_t tmp_codes[512] = { 0 };
302 for (x = 0; x < xsize; x++) {
303 for (y = 0; y < xsize; y++) {
304 tmp_bits [(x << 5) | y | ((x&&y)<<4)]= h->
bits [j ];
305 tmp_codes[(x << 5) | y | ((x&&y)<<4)]= h->
codes[j++];
313 tmp_bits, 1, 1, tmp_codes, 2, 2,
320 for (i = 0; i < 2; i++) {
323 init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16,
330 for (i = 0; i < 9; i++) {
332 for (j = 0; j < 22; j++) {
343 for (i = 0; i < 4; i++) {
346 int val1, val2, val3, steps;
359 for (i = 0; i < 7; i++) {
363 f = tan((
double)i *
M_PI / 12.0);
364 v =
FIXR(f / (1.0 + f));
372 for (i = 7; i < 16; i++)
375 for (i = 0; i < 16; i++) {
379 for (j = 0; j < 2; j++) {
380 e = -(j + 1) * ((i + 1) >> 1);
391 for (i = 0; i < 8; i++) {
394 cs = 1.0 / sqrt(1.0 + ci * ci);
422 static int initialized_tables = 0;
425 if (!initialized_tables) {
427 initialized_tables = 1;
453 #define C3 FIXHR(0.86602540378443864676/2)
454 #define C4 FIXHR(0.70710678118654752439/2) //0.5 / cos(pi*(9)/36)
455 #define C5 FIXHR(0.51763809020504152469/2) //0.5 / cos(pi*(5)/36)
456 #define C6 FIXHR(1.93185165257813657349/4) //0.5 / cos(pi*(15)/36)
465 in1 = in[1*3] + in[0*3];
466 in2 = in[2*3] + in[1*3];
467 in3 = in[3*3] + in[2*3];
468 in4 = in[4*3] + in[3*3];
469 in5 = in[5*3] + in[4*3];
509 bound = (s->mode_ext + 1) * 4;
514 for (i = 0; i <
bound; i++) {
515 for (ch = 0; ch < s->nb_channels; ch++) {
519 for (i = bound; i <
SBLIMIT; i++)
523 for (i = 0; i <
bound; i++) {
524 for (ch = 0; ch < s->nb_channels; ch++) {
525 if (allocation[ch][i])
529 for (i = bound; i <
SBLIMIT; i++) {
530 if (allocation[0][i]) {
537 for (j = 0; j < 12; j++) {
538 for (i = 0; i <
bound; i++) {
539 for (ch = 0; ch < s->nb_channels; ch++) {
540 n = allocation[
ch][i];
543 v =
l1_unscale(n, mant, scale_factors[ch][i]);
550 for (i = bound; i <
SBLIMIT; i++) {
551 n = allocation[0][i];
575 int scale, qindex,
bits, steps, k, l, m,
b;
579 s->sample_rate, s->lsf);
584 bound = (s->mode_ext + 1) * 4;
588 ff_dlog(s->
avctx,
"bound=%d sblimit=%d\n", bound, sblimit);
596 for (i = 0; i <
bound; i++) {
597 bit_alloc_bits = alloc_table[j];
598 for (ch = 0; ch < s->nb_channels; ch++)
599 bit_alloc[ch][i] =
get_bits(&s->
gb, bit_alloc_bits);
600 j += 1 << bit_alloc_bits;
602 for (i = bound; i < sblimit; i++) {
603 bit_alloc_bits = alloc_table[j];
607 j += 1 << bit_alloc_bits;
611 for (i = 0; i < sblimit; i++) {
612 for (ch = 0; ch < s->nb_channels; ch++) {
613 if (bit_alloc[ch][i])
619 for (i = 0; i < sblimit; i++) {
620 for (ch = 0; ch < s->nb_channels; ch++) {
621 if (bit_alloc[ch][i]) {
622 sf = scale_factors[
ch][i];
623 switch (scale_code[ch][i]) {
651 for (k = 0; k < 3; k++) {
652 for (l = 0; l < 12; l += 3) {
654 for (i = 0; i <
bound; i++) {
655 bit_alloc_bits = alloc_table[j];
656 for (ch = 0; ch < s->nb_channels; ch++) {
657 b = bit_alloc[
ch][i];
659 scale = scale_factors[
ch][i][k];
660 qindex = alloc_table[j+
b];
676 for (m = 0; m < 3; m++) {
689 j += 1 << bit_alloc_bits;
692 for (i = bound; i < sblimit; i++) {
693 bit_alloc_bits = alloc_table[j];
696 int mant, scale0, scale1;
697 scale0 = scale_factors[0][i][k];
698 scale1 = scale_factors[1][i][k];
699 qindex = alloc_table[j+
b];
722 for (m = 0; m < 3; m++) {
739 j += 1 << bit_alloc_bits;
742 for (i = sblimit; i <
SBLIMIT; i++) {
743 for (ch = 0; ch < s->nb_channels; ch++) {
754 #define SPLIT(dst,sf,n) \
756 int m = (sf * 171) >> 9; \
759 } else if (n == 4) { \
762 } else if (n == 5) { \
763 int m = (sf * 205) >> 10; \
766 } else if (n == 6) { \
767 int m = (sf * 171) >> 10; \
777 SPLIT(slen[3], sf, n3)
778 SPLIT(slen[2], sf, n2)
779 SPLIT(slen[1], sf, n1)
787 int len, i, j, k, l,
v0,
shift, gain, gains[3];
797 v0 = gain - ((g->
scale_factors[i] + pretab[i]) << shift) + 400;
799 for (j = len; j > 0; j--)
811 for (l = 0; l < 3; l++) {
813 for (j = len; j > 0; j--)
842 #define READ_FLIP_SIGN(dst,src) \
843 v = AV_RN32A(src) ^ (get_bits1(&s->gb) << 31); \
846 #define READ_FLIP_SIGN(dst,src) \
847 v = -get_bits1(&s->gb); \
848 *(dst) = (*(src) ^ v) - v;
852 int16_t *exponents,
int end_pos2)
856 int last_pos, bits_left;
862 for (i = 0; i < 3; i++) {
863 int j, k, l, linbits;
899 exponent= exponents[s_index];
946 while (s_index <= 572) {
949 if (pos >= end_pos) {
950 if (pos > end_pos2 && last_pos) {
955 av_log(s->
avctx,
AV_LOG_INFO,
"overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos);
973 static const int idxtab[16] = { 3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0 };
975 int pos = s_index + idxtab[code];
976 code ^= 8 >> idxtab[code];
1012 if (s->sample_rate_index != 8)
1024 for (j = len; j > 0; j--) {
1025 *dst++ = ptr[0*
len];
1026 *dst++ = ptr[1*
len];
1027 *dst++ = ptr[2*
len];
1031 memcpy(ptr1, tmp, len * 3 *
sizeof(*ptr1));
1035 #define ISQRT2 FIXR(0.70710678118654752440)
1040 int sf_max, sf,
len, non_zero_found;
1041 INTFLOAT (*is_tab)[16], *tab0, *
tab1, tmp0, tmp1, v1, v2;
1042 int non_zero_found_short[3];
1057 non_zero_found_short[0] = 0;
1058 non_zero_found_short[1] = 0;
1059 non_zero_found_short[2] = 0;
1066 for (l = 2; l >= 0; l--) {
1069 if (!non_zero_found_short[l]) {
1071 for (j = 0; j <
len; j++) {
1073 non_zero_found_short[l] = 1;
1083 for (j = 0; j <
len; j++) {
1093 for (j = 0; j <
len; j++) {
1104 non_zero_found = non_zero_found_short[0] |
1105 non_zero_found_short[1] |
1106 non_zero_found_short[2];
1108 for (i = g1->
long_end - 1;i >= 0;i--) {
1113 if (!non_zero_found) {
1114 for (j = 0; j <
len; j++) {
1121 k = (i == 21) ? 20 : i;
1127 for (j = 0; j <
len; j++) {
1137 for (j = 0; j <
len; j++) {
1155 for (i = 0; i < 576; i++) {
1158 tab0[i] = tmp0 + tmp1;
1159 tab1[i] = tmp0 - tmp1;
1175 #ifndef compute_antialias
1177 #define AA(j) do { \
1178 float tmp0 = ptr[-1-j]; \
1179 float tmp1 = ptr[ j]; \
1180 ptr[-1-j] = tmp0 * csa_table[j][0] - tmp1 * csa_table[j][1]; \
1181 ptr[ j] = tmp0 * csa_table[j][1] + tmp1 * csa_table[j][0]; \
1184 #define AA(j) do { \
1185 int tmp0 = ptr[-1-j]; \
1186 int tmp1 = ptr[ j]; \
1187 int tmp2 = MULH(tmp0 + tmp1, csa_table[j][0]); \
1188 ptr[-1-j] = 4 * (tmp2 - MULH(tmp1, csa_table[j][2])); \
1189 ptr[ j] = 4 * (tmp2 + MULH(tmp0, csa_table[j][3])); \
1209 for (i = n; i > 0; i--) {
1229 int i, j, mdct_long_end, sblimit;
1234 while (ptr >= ptr1) {
1238 if (p[0] | p[1] | p[2] | p[3] | p[4] | p[5])
1241 sblimit = ((ptr - g->
sb_hybrid) / 18) + 1;
1250 mdct_long_end = sblimit;
1257 buf = mdct_buf + 4*18*(mdct_long_end >> 2) + (mdct_long_end & 3);
1258 ptr = g->
sb_hybrid + 18 * mdct_long_end;
1260 for (j = mdct_long_end; j < sblimit; j++) {
1262 win =
RENAME(ff_mdct_win)[2 + (4 & -(j & 1))];
1263 out_ptr = sb_samples + j;
1265 for (i = 0; i < 6; i++) {
1266 *out_ptr = buf[4*i];
1270 for (i = 0; i < 6; i++) {
1271 *out_ptr =
MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*1)];
1272 buf[4*(i + 6*2)] =
MULH3(out2[i + 6], win[i + 6], 1);
1276 for (i = 0; i < 6; i++) {
1277 *out_ptr =
MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*2)];
1278 buf[4*(i + 6*0)] =
MULH3(out2[i + 6], win[i + 6], 1);
1282 for (i = 0; i < 6; i++) {
1283 buf[4*(i + 6*0)] =
MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*0)];
1284 buf[4*(i + 6*1)] =
MULH3(out2[i + 6], win[i + 6], 1);
1285 buf[4*(i + 6*2)] = 0;
1288 buf += (j&3) != 3 ? 1 : (4*18-3);
1291 for (j = sblimit; j <
SBLIMIT; j++) {
1293 out_ptr = sb_samples + j;
1294 for (i = 0; i < 18; i++) {
1295 *out_ptr = buf[4*i];
1299 buf += (j&3) != 3 ? 1 : (4*18-3);
1306 int nb_granules, main_data_begin;
1307 int gr,
ch, blocksplit_flag, i, j, k,
n, bits_pos;
1309 int16_t exponents[576];
1318 if (s->nb_channels == 2)
1323 for (ch = 0; ch < s->nb_channels; ch++) {
1329 for (gr = 0; gr < nb_granules; gr++) {
1330 for (ch = 0; ch < s->nb_channels; ch++) {
1351 if (blocksplit_flag) {
1358 for (i = 0; i < 2; i++)
1360 for (i = 0; i < 3; i++)
1364 int region_address1, region_address2;
1367 for (i = 0; i < 3; i++)
1373 region_address1, region_address2);
1403 for (gr = 0; gr < nb_granules && (s->
last_buf_size >> 3) < main_data_begin; gr++) {
1404 for (ch = 0; ch < s->nb_channels; ch++) {
1425 for (; gr < nb_granules; gr++) {
1426 for (ch = 0; ch < s->nb_channels; ch++) {
1432 int slen, slen1, slen2;
1437 ff_dlog(s->
avctx,
"slen1=%d slen2=%d\n", slen1, slen2);
1442 for (i = 0; i <
n; i++)
1445 for (i = 0; i <
n; i++)
1449 for (i = 0; i < 18; i++)
1451 for (i = 0; i < 3; i++)
1454 for (i = 0; i < 21; i++)
1460 for (k = 0; k < 4; k++) {
1462 if ((g->
scfsi & (0x8 >> k)) == 0) {
1463 slen = (k < 2) ? slen1 : slen2;
1465 for (i = 0; i <
n; i++)
1468 for (i = 0; i <
n; i++)
1473 for (i = 0; i <
n; i++) {
1482 int tindex, tindex2, slen[4], sl, sf;
1497 }
else if (sf < 244) {
1509 }
else if (sf < 500) {
1520 for (k = 0; k < 4; k++) {
1524 for (i = 0; i <
n; i++)
1527 for (i = 0; i <
n; i++)
1545 for (ch = 0; ch < s->nb_channels; ch++) {
1555 return nb_granules * 18;
1561 int i, nb_frames,
ch, ret;
1567 if (s->error_protection)
1606 av_assert1(i <= buf_size - HEADER_SIZE && i >= 0);
1624 for (ch = 0; ch < s->nb_channels; ch++) {
1627 samples_ptr = samples[
ch];
1630 samples_ptr = samples[0] +
ch;
1631 sample_stride = s->nb_channels;
1633 for (i = 0; i < nb_frames; i++) {
1636 RENAME(ff_mpa_synth_window),
1639 samples_ptr += 32 * sample_stride;
1643 return nb_frames * 32 *
sizeof(
OUT_INT) * s->nb_channels;
1650 int buf_size = avpkt->
size;
1656 while(buf_size && !*buf){
1666 if (header>>8 ==
AV_RB32(
"TAG")>>8) {
1674 }
else if (ret == 1) {
1685 if (s->frame_size <= 0) {
1688 }
else if (s->frame_size < buf_size) {
1690 buf_size= s->frame_size;
1713 return buf_size + skipped;
1729 #if CONFIG_MP3ADU_DECODER || CONFIG_MP3ADUFLOAT_DECODER
1731 int *got_frame_ptr,
AVPacket *avpkt)
1734 int buf_size = avpkt->
size;
1753 header =
AV_RB32(buf) | 0xffe00000;
1767 s->frame_size =
len;
1783 #if CONFIG_MP3ON4_DECODER || CONFIG_MP3ON4FLOAT_DECODER
1788 typedef struct MP3On4DecodeContext {
1793 } MP3On4DecodeContext;
1800 static const uint8_t mp3Frames[8] = { 0, 1, 1, 2, 3, 3, 4, 5 };
1803 static const uint8_t chan_offset[8][5] = {
1815 static const int16_t chan_layout[8] = {
1828 MP3On4DecodeContext *s = avctx->
priv_data;
1831 for (i = 0; i < s->frames; i++)
1840 MP3On4DecodeContext *s = avctx->
priv_data;
1861 s->syncword = 0xffe00000;
1863 s->syncword = 0xfff00000;
1872 if (!s->mp3decctx[0])
1879 s->mp3decctx[0]->adu_mode = 1;
1884 for (i = 1; i < s->frames; i++) {
1886 if (!s->mp3decctx[i])
1888 s->mp3decctx[i]->adu_mode = 1;
1889 s->mp3decctx[i]->avctx = avctx;
1890 s->mp3decctx[i]->mpadsp = s->mp3decctx[0]->mpadsp;
1891 s->mp3decctx[i]->fdsp = s->mp3decctx[0]->fdsp;
1896 decode_close_mp3on4(avctx);
1904 MP3On4DecodeContext *s = avctx->
priv_data;
1906 for (i = 0; i < s->frames; i++)
1911 static int decode_frame_mp3on4(
AVCodecContext *avctx,
void *data,
1912 int *got_frame_ptr,
AVPacket *avpkt)
1916 int buf_size = avpkt->
size;
1917 MP3On4DecodeContext *s = avctx->
priv_data;
1919 int fsize, len = buf_size, out_size = 0;
1938 for (fr = 0; fr < s->frames; fr++) {
1941 m = s->mp3decctx[fr];
1948 header = (
AV_RB32(buf) & 0x000fffff) | s->syncword;
1956 if (ch + m->nb_channels > avctx->
channels ||
1957 s->coff[fr] + m->nb_channels > avctx->
channels) {
1962 ch += m->nb_channels;
1964 outptr[0] = out_samples[s->coff[fr]];
1965 if (m->nb_channels > 1)
1966 outptr[1] = out_samples[s->coff[fr] + 1];
1971 if (m->nb_channels > 1)
1988 avctx->
sample_rate = s->mp3decctx[0]->sample_rate;
static av_cold void decode_init_static(void)
#define MPA_MAX_CODED_FRAME_SIZE
static int32_t scale_factor_mult[15][3]
#define AV_EF_AGGRESSIVE
consider things that a sane encoder should not do as an error
static double bound(const double threshold, const double val)
const char const char void * val
static int16_t division_tab9[1<< 11]
#define AV_CH_LAYOUT_7POINT1
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static uint32_t table_4_3_value[TABLE_4_3_SIZE]
static const uint8_t lsf_nsf_table[6][3][4]
static int shift(int a, int b)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
Reference: libavcodec/mpegaudiodec.c.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
#define AV_CH_LAYOUT_SURROUND
static void skip_bits_long(GetBitContext *s, int n)
static void exponents_from_scale_factors(MPADecodeContext *s, GranuleDef *g, int16_t *exponents)
static int8_t table_4_3_exp[TABLE_4_3_SIZE]
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
#define AV_EF_BUFFER
detect improper bitstream length
const int ff_mpa_quant_bits[17]
static const uint8_t mpa_pretab[2][22]
#define AV_CH_LAYOUT_4POINT0
#define AV_EF_BITSTREAM
detect bitstream specification deviations
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#define AV_CH_LAYOUT_STEREO
static av_always_inline void lsf_sf_expand(int *slen, int sf, int n1, int n2, int n3)
uint8_t scale_factors[40]
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
static void imdct12(INTFLOAT *out, INTFLOAT *in)
#define AV_CH_LAYOUT_5POINT0
mpeg audio layer common tables.
static const uint8_t slen_table[2][16]
Macro definitions for various function/variable attributes.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
enum AVSampleFormat sample_fmt
audio sample format
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
const int ff_mpa_quant_steps[17]
static int l2_unscale_group(int steps, int mant, int scale_factor)
static av_cold void mpegaudio_tableinit(void)
const unsigned char *const ff_mpa_alloc_tables[5]
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static const uint8_t mpa_huff_data[32][2]
#define SPLIT(dst, sf, n)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
static INTFLOAT csa_table[8][4]
static int l3_unscale(int value, int exponent)
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
static const uint8_t mpa_quad_codes[2][16]
static int get_bits_count(const GetBitContext *s)
bitstream reader API header.
static void switch_buffer(MPADecodeContext *s, int *pos, int *end_pos, int *end_pos2)
static av_cold int decode_close(AVCodecContext *avctx)
static const uint8_t header[24]
static int bit_alloc(AC3EncodeContext *s, int snr_offset)
Run the bit allocation with a given SNR offset.
#define AV_CH_LAYOUT_5POINT1
static int get_bits_left(GetBitContext *gb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define MODE_EXT_MS_STEREO
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
enum AVSampleFormat request_sample_fmt
desired sample format
static const struct endianess table[]
void(* butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len)
Calculate the sum and difference of two vectors of floats.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static void init_long_region(MPADecodeContext *s, GranuleDef *g, int ra1, int ra2)
static uint16_t band_index_long[9][23]
static av_cold int decode_init(AVCodecContext *avctx)
int flags
AV_CODEC_FLAG_*.
simple assert() macros that are a bit more flexible than ISO C assert().
static const uint8_t offset[127][2]
static VLC_TYPE huff_quad_vlc_tables[128+16][2]
static VLC_TYPE huff_vlc_tables[0+128+128+128+130+128+154+166+142+204+190+170+542+460+662+414][2]
uint64_t channel_layout
Audio channel layout.
static const int32_t scale_factor_mult2[3][3]
#define READ_FLIP_SIGN(dst, src)
audio channel layout utility functions
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
static void compute_band_indexes(MPADecodeContext *s, GranuleDef *g)
GLsizei GLboolean const GLfloat * value
uint32_t free_format_next_header
Reference: libavcodec/mpegaudiodec.c.
static int mp_decode_layer2(MPADecodeContext *s)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define FF_ARRAY_ELEMS(a)
static const uint8_t mpa_quad_bits[2][16]
int frame_size
Number of samples per channel in an audio frame.
#define AV_LOG_INFO
Standard information.
Libavcodec external API header.
int sb_hybrid[SBLIMIT *18]
static const int huff_vlc_tables_sizes[16]
int sample_rate
samples per second
MPA_INT synth_buf[MPA_MAX_CHANNELS][512 *2]
static int mp_decode_layer3(MPADecodeContext *s)
static int mp_decode_frame(MPADecodeContext *s, OUT_INT **samples, const uint8_t *buf, int buf_size)
main external API structure.
static void compute_antialias(MPADecodeContext *s, GranuleDef *g)
static INTFLOAT is_table[2][16]
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static void mp_flush(MPADecodeContext *ctx)
Replacements for frequently missing libm functions.
static void reorder_block(MPADecodeContext *s, GranuleDef *g)
static unsigned int get_bits1(GetBitContext *s)
uint8_t count1table_select
static void skip_bits(GetBitContext *s, int n)
#define MODE_EXT_I_STEREO
static const int huff_quad_vlc_tables_sizes[2]
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static uint16_t scale_factor_modshift[64]
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
static INTFLOAT is_table_lsf[2][2][16]
static int16_t division_tab5[1<< 8]
static void init_short_region(MPADecodeContext *s, GranuleDef *g)
static const uint8_t band_size_long[9][22]
static void compute_stereo(MPADecodeContext *s, GranuleDef *g0, GranuleDef *g1)
static int16_t *const division_tabs[4]
static void compute_imdct(MPADecodeContext *s, GranuleDef *g, INTFLOAT *sb_samples, INTFLOAT *mdct_buf)
common internal api header.
#define INIT_VLC_USE_NEW_STATIC
mpeg audio declarations for both encoder and decoder.
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_YASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
const int ff_mpa_sblimit_table[5]
int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int bit_size, int sync_extension)
Parse MPEG-4 systems extradata to retrieve audio configuration.
static int mp_decode_layer1(MPADecodeContext *s)
INTFLOAT mdct_buf[MPA_MAX_CHANNELS][SBLIMIT *18]
int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf)
int channels
number of audio channels
const uint8_t ff_mpeg4audio_channels[8]
MPA_DECODE_HEADER uint8_t last_buf[LAST_BUF_SIZE]
VLC_TYPE(* table)[2]
code, bits
int synth_buf_offset[MPA_MAX_CHANNELS]
static const uint8_t * align_get_bits(GetBitContext *s)
static VLC huff_quad_vlc[2]
static int huffman_decode(MPADecodeContext *s, GranuleDef *g, int16_t *exponents, int end_pos2)
static int64_t fsize(FILE *f)
mpeg audio layer decoder tables.
static int l1_unscale(int n, int mant, int scale_factor)
int sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]
static const HuffTable mpa_huff_tables[16]
static const float ci_table[8]
uint8_t ** extended_data
pointers to the data planes/channels.
#define AV_CH_LAYOUT_MONO
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static void region_offset2size(GranuleDef *g)
Convert region offsets to region sizes and truncate size to big_values.
This structure stores compressed data.
av_cold void ff_mpadsp_init(MPADSPContext *s)
int nb_samples
number of audio samples (per channel) described by this frame
static void flush(AVCodecContext *avctx)
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
static int alloc_table(VLC *vlc, int size, int use_static)
static const uint8_t band_size_short[9][13]
int adu_mode
0 for standard mp3, 1 for adu formatted mp3
static int16_t division_tab3[1<< 6]
GranuleDef granules[2][2]