43 #define MUL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS)
45 #define SAMPLES_BUF_SIZE 4096
80 if (channels <= 0 || channels > 2){
81 av_log(avctx,
AV_LOG_ERROR,
"encoding %d channel(s) is not allowed in mp2\n", channels);
84 bitrate = bitrate / 1000;
87 avctx->
delay = 512 - 32 + 1;
132 av_dlog(avctx,
"%d kb/s, %d Hz, frame_size=%d bits, table=%d, padincr=%x\n",
152 v = (int)(pow(2.0, (3 - i) / 3.0) * (1 << 20));
192 for(j=31;j>=3;j-=2) tab[j] += tab[j - 2];
236 x1 =
MUL((t[8] - x2), xp[0]);
237 x2 =
MUL((t[8] + x2), xp[1]);
250 xr =
MUL(t[28],xp[0]);
254 xr =
MUL(t[4],xp[1]);
255 t[ 4] = (t[24] - xr);
256 t[24] = (t[24] + xr);
258 xr =
MUL(t[20],xp[2]);
262 xr =
MUL(t[12],xp[3]);
263 t[12] = (t[16] - xr);
264 t[16] = (t[16] + xr);
269 for (i = 0; i < 4; i++) {
270 xr =
MUL(tab[30-i*4],xp[0]);
271 tab[30-i*4] = (tab[i*4] - xr);
272 tab[ i*4] = (tab[i*4] + xr);
274 xr =
MUL(tab[ 2+i*4],xp[1]);
275 tab[ 2+i*4] = (tab[28-i*4] - xr);
276 tab[28-i*4] = (tab[28-i*4] + xr);
278 xr =
MUL(tab[31-i*4],xp[0]);
279 tab[31-i*4] = (tab[1+i*4] - xr);
280 tab[ 1+i*4] = (tab[1+i*4] + xr);
282 xr =
MUL(tab[ 3+i*4],xp[1]);
283 tab[ 3+i*4] = (tab[29-i*4] - xr);
284 tab[29-i*4] = (tab[29-i*4] + xr);
292 xr =
MUL(t1[0], *xp);
305 #define WSHIFT (WFRAC_BITS + 15 - FRAC_BITS)
310 int sum, offset, i, j;
320 s->
samples_buf[ch][offset + (31 - i)] = samples[0];
329 sum = p[0*64] * q[0*64];
330 sum += p[1*64] * q[1*64];
331 sum += p[2*64] * q[2*64];
332 sum += p[3*64] * q[3*64];
333 sum += p[4*64] * q[4*64];
334 sum += p[5*64] * q[5*64];
335 sum += p[6*64] * q[6*64];
336 sum += p[7*64] * q[7*64];
341 tmp1[0] = tmp[16] >>
WSHIFT;
342 for( i=1; i<=16; i++ ) tmp1[i] = (tmp[i+16]+tmp[16-i]) >>
WSHIFT;
343 for( i=17; i<=31; i++ ) tmp1[i] = (tmp[i+16]-tmp[80-i]) >>
WSHIFT;
361 unsigned char scale_code[
SBLIMIT],
362 unsigned char scale_factors[SBLIMIT][3],
363 int sb_samples[3][12][SBLIMIT],
366 int *p, vmax, v, n, i, j, k, code;
368 unsigned char *sf = &scale_factors[0][0];
370 for(j=0;j<sblimit;j++) {
373 p = &sb_samples[i][0][j];
386 index = (21 - n) * 3 - 3;
388 while (vmax <= s->scale_factor_table[index+1])
400 assert(index >=0 && index <= 63);
410 switch(d1 * 5 + d2) {
442 sf[1] = sf[2] = sf[0];
447 sf[0] = sf[1] = sf[2];
453 sf[0] = sf[2] = sf[1];
459 sf[1] = sf[2] = sf[0];
467 sf[0], sf[1], sf[2], d1, d2, code);
468 scale_code[j] = code;
486 #define SB_NOTALLOCATED 0
487 #define SB_ALLOCATED 1
498 int i, ch,
b, max_smr, max_ch, max_sb, current_frame_size, max_frame_size;
502 const unsigned char *alloc;
504 memcpy(smr, smr1, s->
nb_channels *
sizeof(
short) * SBLIMIT);
520 current_frame_size = 32;
534 if (smr[ch][i] > max_smr && subband_status[ch][i] !=
SB_NOMORE) {
535 max_smr = smr[ch][i];
543 av_dlog(
NULL,
"current=%d max=%d max_sb=%d max_ch=%d alloc=%d\n",
544 current_frame_size, max_frame_size, max_sb, max_ch,
550 for(i=0;i<max_sb;i++) {
551 alloc += 1 << alloc[0];
565 if (current_frame_size + incr <= max_frame_size) {
568 current_frame_size += incr;
570 smr[max_ch][max_sb] = smr1[max_ch][max_sb] -
quant_snr[alloc[
b]];
572 if (b == ((1 << alloc[0]) - 1))
573 subband_status[max_ch][max_sb] =
SB_NOMORE;
578 subband_status[max_ch][max_sb] =
SB_NOMORE;
581 *padding = max_frame_size - current_frame_size;
582 assert(*padding >= 0);
593 int i, j, k, l, bit_alloc_bits,
b, ch;
621 j += 1 << bit_alloc_bits;
675 q[m] = (
int)((a + 1.0) * steps * 0.5);
678 assert(q[m] >= 0 && q[m] < steps);
684 q[0] + steps * (q[1] + steps * q[2]));
693 j += 1 << bit_alloc_bits;
699 for(i=0;i<padding;i++)
707 const AVFrame *frame,
int *got_packet_ptr)
710 const int16_t *
samples = (
const int16_t *)frame->
data[0];
760 .supported_samplerates = (
const int[]){
761 44100, 48000, 32000, 22050, 24000, 16000, 0