27 #include "libavutil/attributes.h"
28 #include "libavutil/avassert.h"
29 #include "libavutil/channel_layout.h"
46 #define BACKSTEP_SIZE 512
48 #define LAST_BUF_SIZE 2 * BACKSTEP_SIZE + EXTRABYTES
93 # define SHR(a,b) ((a)*(1.0f/(1<<(b))))
94 # define FIXR_OLD(a) ((int)((a) * FRAC_ONE + 0.5))
95 # define FIXR(x) ((float)(x))
96 # define FIXHR(x) ((float)(x))
97 # define MULH3(x, y, s) ((s)*(y)*(x))
98 # define MULLx(x, y, s) ((y)*(x))
99 # define RENAME(a) a ## _float
100 # define OUT_FMT AV_SAMPLE_FMT_FLT
101 # define OUT_FMT_P AV_SAMPLE_FMT_FLTP
103 # define SHR(a,b) ((a)>>(b))
105 # define FIXR_OLD(a) ((int)((a) * FRAC_ONE + 0.5))
106 # define FIXR(a) ((int)((a) * FRAC_ONE + 0.5))
107 # define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5))
108 # define MULH3(x, y, s) MULH((s)*(x), y)
109 # define MULLx(x, y, s) MULL(x,y,s)
110 # define RENAME(a) a ## _fixed
111 # define OUT_FMT AV_SAMPLE_FMT_S16
112 # define OUT_FMT_P AV_SAMPLE_FMT_S16P
117 #define HEADER_SIZE 4
125 0 + 128 + 128 + 128 + 130 + 128 + 154 + 166 +
126 142 + 204 + 190 + 170 + 542 + 460 + 662 + 414
129 0, 128, 128, 128, 130, 128, 154, 166,
130 142, 204, 190, 170, 542, 460, 662, 414
157 #define SCALE_GEN(v) \
158 { FIXR_OLD(1.0 * (v)), FIXR_OLD(0.7937005259 * (v)), FIXR_OLD(0.6299605249 * (v)) }
174 for (i = 0; i < 3; i++) {
184 if (s->sample_rate_index != 8)
189 if (s->sample_rate_index <= 2)
191 else if (s->sample_rate_index != 8)
205 l =
FFMIN(ra1 + ra2 + 2, 22);
213 if(s->sample_rate_index == 8)
218 if (s->sample_rate_index <= 2)
247 return (
int)((val + (1LL << (shift - 1))) >> shift);
261 val = (val + (1 << (shift - 1))) >> shift;
280 m = (m + (1 << (e - 1))) >> e;
291 for (i = 0; i < 64; i++) {
300 for (i = 0; i < 15; i++) {
303 norm = ((INT64_C(1) <<
n) *
FRAC_ONE) / ((1 <<
n) - 1);
307 av_dlog(NULL,
"%d: norm=%x s=%x %x %x\n", i, norm,
317 for (i = 1; i < 16; i++) {
320 uint8_t tmp_bits [512] = { 0 };
321 uint16_t tmp_codes[512] = { 0 };
326 for (x = 0; x < xsize; x++) {
327 for (y = 0; y < xsize; y++) {
328 tmp_bits [(x << 5) | y | ((x&&y)<<4)]= h->
bits [j ];
329 tmp_codes[(x << 5) | y | ((x&&
y)<<4)]= h->
codes[j++];
337 tmp_bits, 1, 1, tmp_codes, 2, 2,
344 for (i = 0; i < 2; i++) {
347 init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16,
354 for (i = 0; i < 9; i++) {
356 for (j = 0; j < 22; j++) {
367 for (i = 0; i < 4; i++) {
370 int val1, val2, val3, steps;
383 for (i = 0; i < 7; i++) {
387 f = tan((
double)i *
M_PI / 12.0);
388 v =
FIXR(f / (1.0 + f));
396 for (i = 7; i < 16; i++)
399 for (i = 0; i < 16; i++) {
403 for (j = 0; j < 2; j++) {
404 e = -(j + 1) * ((i + 1) >> 1);
409 av_dlog(NULL,
"is_table_lsf %d %d: %f %f\n",
415 for (i = 0; i < 8; i++) {
418 cs = 1.0 / sqrt(1.0 + ci * ci);
436 static int initialized_tables = 0;
439 if (!initialized_tables) {
441 initialized_tables = 1;
462 #define C3 FIXHR(0.86602540378443864676/2)
463 #define C4 FIXHR(0.70710678118654752439/2) //0.5 / cos(pi*(9)/36)
464 #define C5 FIXHR(0.51763809020504152469/2) //0.5 / cos(pi*(5)/36)
465 #define C6 FIXHR(1.93185165257813657349/4) //0.5 / cos(pi*(15)/36)
474 in1 = in[1*3] + in[0*3];
475 in2 = in[2*3] + in[1*3];
476 in3 = in[3*3] + in[2*3];
477 in4 = in[4*3] + in[3*3];
478 in5 = in[5*3] + in[4*3];
513 int bound, i,
v,
n, ch, j, mant;
518 bound = (s->mode_ext + 1) * 4;
523 for (i = 0; i < bound; i++) {
524 for (ch = 0; ch < s->nb_channels; ch++) {
528 for (i = bound; i <
SBLIMIT; i++)
532 for (i = 0; i < bound; i++) {
533 for (ch = 0; ch < s->nb_channels; ch++) {
534 if (allocation[ch][i])
538 for (i = bound; i <
SBLIMIT; i++) {
539 if (allocation[0][i]) {
546 for (j = 0; j < 12; j++) {
547 for (i = 0; i < bound; i++) {
548 for (ch = 0; ch < s->nb_channels; ch++) {
549 n = allocation[ch][i];
552 v =
l1_unscale(n, mant, scale_factors[ch][i]);
559 for (i = bound; i <
SBLIMIT; i++) {
560 n = allocation[0][i];
580 int table, bit_alloc_bits, i, j, ch, bound,
v;
588 s->sample_rate, s->lsf);
593 bound = (s->mode_ext + 1) * 4;
597 av_dlog(s->
avctx,
"bound=%d sblimit=%d\n", bound, sblimit);
605 for (i = 0; i < bound; i++) {
606 bit_alloc_bits = alloc_table[j];
607 for (ch = 0; ch < s->nb_channels; ch++)
608 bit_alloc[ch][i] =
get_bits(&s->
gb, bit_alloc_bits);
609 j += 1 << bit_alloc_bits;
611 for (i = bound; i < sblimit; i++) {
612 bit_alloc_bits = alloc_table[j];
616 j += 1 << bit_alloc_bits;
620 for (i = 0; i < sblimit; i++) {
621 for (ch = 0; ch < s->nb_channels; ch++) {
622 if (bit_alloc[ch][i])
628 for (i = 0; i < sblimit; i++) {
629 for (ch = 0; ch < s->nb_channels; ch++) {
630 if (bit_alloc[ch][i]) {
631 sf = scale_factors[ch][i];
632 switch (scale_code[ch][i]) {
660 for (k = 0; k < 3; k++) {
661 for (l = 0; l < 12; l += 3) {
663 for (i = 0; i < bound; i++) {
664 bit_alloc_bits = alloc_table[j];
665 for (ch = 0; ch < s->nb_channels; ch++) {
666 b = bit_alloc[ch][i];
668 scale = scale_factors[ch][i][k];
669 qindex = alloc_table[j+
b];
685 for (m = 0; m < 3; m++) {
698 j += 1 << bit_alloc_bits;
701 for (i = bound; i < sblimit; i++) {
702 bit_alloc_bits = alloc_table[j];
705 int mant, scale0, scale1;
706 scale0 = scale_factors[0][i][k];
707 scale1 = scale_factors[1][i][k];
708 qindex = alloc_table[j+
b];
731 for (m = 0; m < 3; m++) {
748 j += 1 << bit_alloc_bits;
751 for (i = sblimit; i <
SBLIMIT; i++) {
752 for (ch = 0; ch < s->nb_channels; ch++) {
763 #define SPLIT(dst,sf,n) \
765 int m = (sf * 171) >> 9; \
768 } else if (n == 4) { \
771 } else if (n == 5) { \
772 int m = (sf * 205) >> 10; \
775 } else if (n == 6) { \
776 int m = (sf * 171) >> 10; \
786 SPLIT(slen[3], sf, n3)
787 SPLIT(slen[2], sf, n2)
788 SPLIT(slen[1], sf, n1)
796 int len, i, j, k, l,
v0,
shift, gain, gains[3];
806 v0 = gain - ((g->
scale_factors[i] + pretab[i]) << shift) + 400;
808 for (j = len; j > 0; j--)
820 for (l = 0; l < 3; l++) {
822 for (j = len; j > 0; j--)
857 #define READ_FLIP_SIGN(dst,src) \
858 v = AV_RN32A(src) ^ (get_bits1(&s->gb) << 31); \
861 #define READ_FLIP_SIGN(dst,src) \
862 v = -get_bits1(&s->gb); \
863 *(dst) = (*(src) ^ v) - v;
867 int16_t *exponents,
int end_pos2)
871 int last_pos, bits_left;
877 for (i = 0; i < 3; i++) {
878 int j, k, l, linbits;
914 exponent= exponents[s_index];
961 while (s_index <= 572) {
964 if (pos >= end_pos) {
965 if (pos > end_pos2 && last_pos) {
970 av_log(s->
avctx,
AV_LOG_INFO,
"overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos);
988 static const int idxtab[16] = { 3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0 };
990 int pos = s_index + idxtab[code];
991 code ^= 8 >> idxtab[code];
1027 if (s->sample_rate_index != 8)
1039 for (j = len; j > 0; j--) {
1040 *dst++ = ptr[0*
len];
1041 *dst++ = ptr[1*
len];
1042 *dst++ = ptr[2*
len];
1046 memcpy(ptr1, tmp, len * 3 *
sizeof(*ptr1));
1050 #define ISQRT2 FIXR(0.70710678118654752440)
1055 int sf_max, sf,
len, non_zero_found;
1056 INTFLOAT (*is_tab)[16], *tab0, *
tab1, tmp0, tmp1, v1, v2;
1057 int non_zero_found_short[3];
1072 non_zero_found_short[0] = 0;
1073 non_zero_found_short[1] = 0;
1074 non_zero_found_short[2] = 0;
1081 for (l = 2; l >= 0; l--) {
1084 if (!non_zero_found_short[l]) {
1086 for (j = 0; j <
len; j++) {
1088 non_zero_found_short[l] = 1;
1098 for (j = 0; j <
len; j++) {
1108 for (j = 0; j <
len; j++) {
1119 non_zero_found = non_zero_found_short[0] |
1120 non_zero_found_short[1] |
1121 non_zero_found_short[2];
1123 for (i = g1->
long_end - 1;i >= 0;i--) {
1128 if (!non_zero_found) {
1129 for (j = 0; j <
len; j++) {
1136 k = (i == 21) ? 20 : i;
1142 for (j = 0; j <
len; j++) {
1152 for (j = 0; j <
len; j++) {
1170 for (i = 0; i < 576; i++) {
1173 tab0[i] = tmp0 + tmp1;
1174 tab1[i] = tmp0 - tmp1;
1190 #ifndef compute_antialias
1192 #define AA(j) do { \
1193 float tmp0 = ptr[-1-j]; \
1194 float tmp1 = ptr[ j]; \
1195 ptr[-1-j] = tmp0 * csa_table[j][0] - tmp1 * csa_table[j][1]; \
1196 ptr[ j] = tmp0 * csa_table[j][1] + tmp1 * csa_table[j][0]; \
1199 #define AA(j) do { \
1200 int tmp0 = ptr[-1-j]; \
1201 int tmp1 = ptr[ j]; \
1202 int tmp2 = MULH(tmp0 + tmp1, csa_table[j][0]); \
1203 ptr[-1-j] = 4 * (tmp2 - MULH(tmp1, csa_table[j][2])); \
1204 ptr[ j] = 4 * (tmp2 + MULH(tmp0, csa_table[j][3])); \
1224 for (i = n; i > 0; i--) {
1244 int i, j, mdct_long_end, sblimit;
1249 while (ptr >= ptr1) {
1253 if (p[0] | p[1] | p[2] | p[3] | p[4] | p[5])
1256 sblimit = ((ptr - g->
sb_hybrid) / 18) + 1;
1265 mdct_long_end = sblimit;
1272 buf = mdct_buf + 4*18*(mdct_long_end >> 2) + (mdct_long_end & 3);
1273 ptr = g->
sb_hybrid + 18 * mdct_long_end;
1275 for (j = mdct_long_end; j < sblimit; j++) {
1277 win =
RENAME(ff_mdct_win)[2 + (4 & -(j & 1))];
1278 out_ptr = sb_samples + j;
1280 for (i = 0; i < 6; i++) {
1281 *out_ptr = buf[4*i];
1285 for (i = 0; i < 6; i++) {
1286 *out_ptr =
MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*1)];
1287 buf[4*(i + 6*2)] =
MULH3(out2[i + 6], win[i + 6], 1);
1291 for (i = 0; i < 6; i++) {
1292 *out_ptr =
MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*2)];
1293 buf[4*(i + 6*0)] =
MULH3(out2[i + 6], win[i + 6], 1);
1297 for (i = 0; i < 6; i++) {
1298 buf[4*(i + 6*0)] =
MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*0)];
1299 buf[4*(i + 6*1)] =
MULH3(out2[i + 6], win[i + 6], 1);
1300 buf[4*(i + 6*2)] = 0;
1303 buf += (j&3) != 3 ? 1 : (4*18-3);
1306 for (j = sblimit; j <
SBLIMIT; j++) {
1308 out_ptr = sb_samples + j;
1309 for (i = 0; i < 18; i++) {
1310 *out_ptr = buf[4*i];
1314 buf += (j&3) != 3 ? 1 : (4*18-3);
1321 int nb_granules, main_data_begin;
1322 int gr, ch, blocksplit_flag, i, j, k,
n, bits_pos;
1324 int16_t exponents[576];
1333 if (s->nb_channels == 2)
1338 for (ch = 0; ch < s->nb_channels; ch++) {
1344 for (gr = 0; gr < nb_granules; gr++) {
1345 for (ch = 0; ch < s->nb_channels; ch++) {
1366 if (blocksplit_flag) {
1373 for (i = 0; i < 2; i++)
1375 for (i = 0; i < 3; i++)
1379 int region_address1, region_address2;
1382 for (i = 0; i < 3; i++)
1388 region_address1, region_address2);
1416 #if !UNCHECKED_BITSTREAM_READER
1420 for (gr = 0; gr < nb_granules && (s->
last_buf_size >> 3) < main_data_begin; gr++) {
1421 for (ch = 0; ch < s->nb_channels; ch++) {
1440 for (; gr < nb_granules; gr++) {
1441 for (ch = 0; ch < s->nb_channels; ch++) {
1447 int slen, slen1, slen2;
1452 av_dlog(s->
avctx,
"slen1=%d slen2=%d\n", slen1, slen2);
1457 for (i = 0; i <
n; i++)
1460 for (i = 0; i <
n; i++)
1464 for (i = 0; i < 18; i++)
1466 for (i = 0; i < 3; i++)
1469 for (i = 0; i < 21; i++)
1475 for (k = 0; k < 4; k++) {
1477 if ((g->
scfsi & (0x8 >> k)) == 0) {
1478 slen = (k < 2) ? slen1 : slen2;
1480 for (i = 0; i <
n; i++)
1483 for (i = 0; i <
n; i++)
1488 for (i = 0; i <
n; i++) {
1497 int tindex, tindex2, slen[4], sl, sf;
1512 }
else if (sf < 244) {
1524 }
else if (sf < 500) {
1535 for (k = 0; k < 4; k++) {
1539 for (i = 0; i <
n; i++)
1542 for (i = 0; i <
n; i++)
1560 for (ch = 0; ch < s->nb_channels; ch++) {
1570 return nb_granules * 18;
1576 int i, nb_frames, ch,
ret;
1582 if (s->error_protection)
1621 av_assert1(i <= buf_size - HEADER_SIZE && i >= 0);
1639 for (ch = 0; ch < s->nb_channels; ch++) {
1642 samples_ptr = samples[ch];
1645 samples_ptr = samples[0] + ch;
1646 sample_stride = s->nb_channels;
1648 for (i = 0; i < nb_frames; i++) {
1651 RENAME(ff_mpa_synth_window),
1654 samples_ptr += 32 * sample_stride;
1658 return nb_frames * 32 *
sizeof(
OUT_INT) * s->nb_channels;
1665 int buf_size = avpkt->
size;
1670 while(buf_size && !*buf){
1679 if (header>>8 ==
AV_RB32(
"TAG")>>8) {
1699 if (s->frame_size <= 0 || s->frame_size > buf_size) {
1702 }
else if (s->frame_size < buf_size) {
1704 buf_size= s->frame_size;
1741 #if CONFIG_MP3ADU_DECODER || CONFIG_MP3ADUFLOAT_DECODER
1743 int *got_frame_ptr,
AVPacket *avpkt)
1746 int buf_size = avpkt->
size;
1765 header =
AV_RB32(buf) | 0xffe00000;
1779 s->frame_size =
len;
1795 #if CONFIG_MP3ON4_DECODER || CONFIG_MP3ON4FLOAT_DECODER
1800 typedef struct MP3On4DecodeContext {
1805 } MP3On4DecodeContext;
1812 static const uint8_t mp3Frames[8] = { 0, 1, 1, 2, 3, 3, 4, 5 };
1815 static const uint8_t chan_offset[8][5] = {
1827 static const int16_t chan_layout[8] = {
1840 MP3On4DecodeContext *s = avctx->
priv_data;
1843 for (i = 0; i < s->frames; i++)
1852 MP3On4DecodeContext *s = avctx->
priv_data;
1873 s->syncword = 0xffe00000;
1875 s->syncword = 0xfff00000;
1884 if (!s->mp3decctx[0])
1891 s->mp3decctx[0]->adu_mode = 1;
1896 for (i = 1; i < s->frames; i++) {
1898 if (!s->mp3decctx[i])
1900 s->mp3decctx[i]->adu_mode = 1;
1901 s->mp3decctx[i]->avctx = avctx;
1902 s->mp3decctx[i]->mpadsp = s->mp3decctx[0]->mpadsp;
1907 decode_close_mp3on4(avctx);
1915 MP3On4DecodeContext *s = avctx->
priv_data;
1917 for (i = 0; i < s->frames; i++)
1922 static int decode_frame_mp3on4(
AVCodecContext *avctx,
void *data,
1923 int *got_frame_ptr,
AVPacket *avpkt)
1927 int buf_size = avpkt->
size;
1928 MP3On4DecodeContext *s = avctx->
priv_data;
1930 int fsize, len = buf_size, out_size = 0;
1949 for (fr = 0; fr < s->frames; fr++) {
1952 m = s->mp3decctx[fr];
1959 header = (
AV_RB32(buf) & 0x000fffff) | s->syncword;
1966 if (ch + m->nb_channels > avctx->
channels ||
1967 s->coff[fr] + m->nb_channels > avctx->
channels) {
1972 ch += m->nb_channels;
1974 outptr[0] = out_samples[s->coff[fr]];
1975 if (m->nb_channels > 1)
1976 outptr[1] = out_samples[s->coff[fr] + 1];
1989 avctx->
sample_rate = s->mp3decctx[0]->sample_rate;
1999 #if CONFIG_MP1_DECODER
2015 #if CONFIG_MP2_DECODER
2031 #if CONFIG_MP3_DECODER
2047 #if CONFIG_MP3ADU_DECODER
2055 .
decode = decode_frame_adu,
2063 #if CONFIG_MP3ON4_DECODER
2069 .priv_data_size =
sizeof(MP3On4DecodeContext),
2070 .
init = decode_init_mp3on4,
2071 .
close = decode_close_mp3on4,
2072 .
decode = decode_frame_mp3on4,
2074 .
flush = flush_mp3on4,
#define MPA_MAX_CODED_FRAME_SIZE
const char const char void * val
#define AV_CH_LAYOUT_7POINT1
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.
static int l1_unscale(int n, int mant, int scale_factor)
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.
#define AV_CH_LAYOUT_SURROUND
static void skip_bits_long(GetBitContext *s, int n)
static av_cold int init(AVCodecContext *avctx)
#define READ_FLIP_SIGN(dst, src)
static struct endianess table[]
static int8_t table_4_3_exp[TABLE_4_3_SIZE]
static void compute_stereo(MPADecodeContext *s, GranuleDef *g0, GranuleDef *g1)
uint8_t ** extended_data
pointers to the data planes/channels.
#define DECLARE_ALIGNED(n, t, v)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
const int ff_mpa_quant_bits[17]
static const uint8_t mpa_pretab[2][22]
#define AV_CH_LAYOUT_4POINT0
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
static void init_long_region(MPADecodeContext *s, GranuleDef *g, int ra1, int ra2)
#define AV_CH_LAYOUT_STEREO
static av_cold void decode_init_static(void)
uint8_t scale_factors[40]
#define AV_CH_LAYOUT_5POINT0
mpeg audio layer common tables.
static const int huff_vlc_tables_sizes[16]
static const uint8_t slen_table[2][16]
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
static av_always_inline void lsf_sf_expand(int *slen, int sf, int n1, int n2, int n3)
static int16_t division_tab5[1<< 8]
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
static av_cold int decode_init(AVCodecContext *avctx)
static int mp_decode_layer2(MPADecodeContext *s)
static int32_t scale_factor_mult[15][3]
av_cold void RENAME() ff_mpa_synth_init(MPA_INT *window)
static const uint8_t offset[511][2]
const int ff_mpa_quant_steps[17]
static void mpegaudio_tableinit(void)
const unsigned char *const ff_mpa_alloc_tables[5]
const char * name
Name of the codec implementation.
static const uint8_t mpa_huff_data[32][2]
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static const uint8_t mpa_quad_codes[2][16]
static int get_bits_count(const GetBitContext *s)
bitstream reader API header.
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
static int bit_alloc(AC3EncodeContext *s, int snr_offset)
Run the bit allocation with a given SNR offset.
static int16_t division_tab3[1<< 6]
#define AV_CH_LAYOUT_5POINT1
static int get_bits_left(GetBitContext *gb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static INTFLOAT csa_table[8][4]
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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_dlog(ac->avr,"%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
#define MODE_EXT_MS_STEREO
static VLC_TYPE huff_quad_vlc_tables[128+16][2]
enum AVSampleFormat request_sample_fmt
desired sample format
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
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.
preferred ID for decoding MPEG audio layer 1, 2 or 3
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static int mp_decode_layer1(MPADecodeContext *s)
#define AV_EF_BUFFER
detect improper bitstream length
Libavcodec external API header.
static const int32_t scale_factor_mult2[3][3]
#define av_unused
Disable warnings about deprecated features This is useful for sections of code kept for backward comp...
uint64_t channel_layout
Audio channel layout.
static int huffman_decode(MPADecodeContext *s, GranuleDef *g, int16_t *exponents, int end_pos2)
#define FF_ARRAY_ELEMS(a)
int bit_rate
the average bitrate
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
static void switch_buffer(MPADecodeContext *s, int *pos, int *end_pos, int *end_pos2)
static int mp_decode_layer3(MPADecodeContext *s)
static int16_t division_tab9[1<< 11]
uint32_t free_format_next_header
Reference: libavcodec/mpegaudiodec.c.
static void region_offset2size(GranuleDef *g)
Convert region offsets to region sizes and truncate size to big_values.
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static int16_t *const division_tabs[4]
static int l2_unscale_group(int steps, int mant, int scale_factor)
static int l3_unscale(int value, int exponent)
#define INIT_VLC_USE_NEW_STATIC
#define AV_EF_AGGRESSIVE
consider things that a sane encoder should not do as an error
static const uint8_t mpa_quad_bits[2][16]
static uint16_t band_index_long[9][23]
int frame_size
Number of samples per channel in an audio frame.
AVSampleFormat
Audio Sample Formats.
#define AV_LOG_INFO
Standard information.
static const int huff_quad_vlc_tables_sizes[2]
static INTFLOAT is_table_lsf[2][2][16]
int sb_hybrid[SBLIMIT *18]
static void compute_band_indexes(MPADecodeContext *s, GranuleDef *g)
int sample_rate
samples per second
MPA_INT synth_buf[MPA_MAX_CHANNELS][512 *2]
main external API structure.
static void close(AVCodecParserContext *s)
#define AV_EF_BITSTREAM
detect bitstream specification deviations
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
Replacements for frequently missing libm functions.
static unsigned int get_bits1(GetBitContext *s)
uint8_t count1table_select
static void skip_bits(GetBitContext *s, int n)
static void compute_imdct(MPADecodeContext *s, GranuleDef *g, INTFLOAT *sb_samples, INTFLOAT *mdct_buf)
static int mp_decode_frame(MPADecodeContext *s, OUT_INT **samples, const uint8_t *buf, int buf_size)
#define MODE_EXT_I_STEREO
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static void exponents_from_scale_factors(MPADecodeContext *s, GranuleDef *g, int16_t *exponents)
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
static const uint8_t band_size_long[9][22]
static const uint16_t scale[4]
av_cold void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
Initialize a float DSP context.
static void compute_antialias(MPADecodeContext *s, GranuleDef *g)
#define SPLIT(dst, sf, n)
static VLC huff_quad_vlc[2]
common internal api header.
static uint16_t scale_factor_modshift[64]
static void init_short_region(MPADecodeContext *s, GranuleDef *g)
static INTFLOAT is_table[2][16]
void RENAME() ff_mpa_synth_filter(MPADSPContext *s, MPA_INT *synth_buf_ptr, int *synth_buf_offset, MPA_INT *window, int *dither_state, OUT_INT *samples, int incr, MPA_INT *sb_samples)
mpeg audio declarations for both encoder and decoder.
static void imdct12(INTFLOAT *out, INTFLOAT *in)
static void reorder_block(MPADecodeContext *s, GranuleDef *g)
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.
INTFLOAT mdct_buf[MPA_MAX_CHANNELS][SBLIMIT *18]
int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf)
#define AVERROR_INVALIDDATA
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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_dlog(ac->avr,"%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-> out
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
static VLC_TYPE huff_vlc_tables[0+128+128+128+130+128+154+166+142+204+190+170+542+460+662+414][2]
int synth_buf_offset[MPA_MAX_CHANNELS]
static const uint8_t * align_get_bits(GetBitContext *s)
static enum AVSampleFormat sample_fmts[]
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int get_bitsz(GetBitContext *s, int n)
mpeg audio layer decoder tables.
int sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]
static const HuffTable mpa_huff_tables[16]
static void flush(AVCodecContext *avctx)
static const float ci_table[8]
#define AV_EF_COMPLIANT
consider all spec non compliancies as errors
#define AV_CH_LAYOUT_MONO
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
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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 void mp_flush(MPADecodeContext *ctx)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
GranuleDef granules[2][2]