comparison twinvq.c @ 10108:eb28ab65409c libavcodec

Formatting K&R fixes
author vitor
date Thu, 27 Aug 2009 16:38:57 +0000
parents a04aca5587a7
children 89cd870ca180
comparison
equal deleted inserted replaced
10107:3b61bc6ce377 10108:eb28ab65409c
232 int j; 232 int j;
233 float p = 0.5f; 233 float p = 0.5f;
234 float q = 0.5f; 234 float q = 0.5f;
235 float two_cos_w = 2.0f*cos_val; 235 float two_cos_w = 2.0f*cos_val;
236 236
237 for (j=0; j + 1 < order; j += 2*2) { 237 for (j = 0; j + 1 < order; j += 2*2) {
238 // Unroll the loop once since order is a multiple of four 238 // Unroll the loop once since order is a multiple of four
239 q *= lsp[j ] - two_cos_w; 239 q *= lsp[j ] - two_cos_w;
240 p *= lsp[j+1] - two_cos_w; 240 p *= lsp[j+1] - two_cos_w;
241 241
242 q *= lsp[j+2] - two_cos_w; 242 q *= lsp[j+2] - two_cos_w;
256 { 256 {
257 int i; 257 int i;
258 const ModeTab *mtab = tctx->mtab; 258 const ModeTab *mtab = tctx->mtab;
259 int size_s = mtab->size / mtab->fmode[FT_SHORT].sub; 259 int size_s = mtab->size / mtab->fmode[FT_SHORT].sub;
260 260
261 for (i=0; i < size_s/2; i++) { 261 for (i = 0; i < size_s/2; i++) {
262 float cos_i = tctx->cos_tabs[0][i]; 262 float cos_i = tctx->cos_tabs[0][i];
263 lpc[i] = eval_lpc_spectrum(cos_vals, cos_i, mtab->n_lsp); 263 lpc[i] = eval_lpc_spectrum(cos_vals, cos_i, mtab->n_lsp);
264 lpc[size_s-i-1] = eval_lpc_spectrum(cos_vals, -cos_i, mtab->n_lsp); 264 lpc[size_s-i-1] = eval_lpc_spectrum(cos_vals, -cos_i, mtab->n_lsp);
265 } 265 }
266 } 266 }
268 static void interpolate(float *out, float v1, float v2, int size) 268 static void interpolate(float *out, float v1, float v2, int size)
269 { 269 {
270 int i; 270 int i;
271 float step = (v1 - v2)/(size + 1); 271 float step = (v1 - v2)/(size + 1);
272 272
273 for (i=0; i < size; i++) { 273 for (i = 0; i < size; i++) {
274 v2 += step; 274 v2 += step;
275 out[i] = v2; 275 out[i] = v2;
276 } 276 }
277 } 277 }
278 278
304 int i; 304 int i;
305 const ModeTab *mtab = tctx->mtab; 305 const ModeTab *mtab = tctx->mtab;
306 const float *cos_tab = tctx->cos_tabs[ftype]; 306 const float *cos_tab = tctx->cos_tabs[ftype];
307 307
308 // Fill the 's' 308 // Fill the 's'
309 for (i=0; i < size; i += step) 309 for (i = 0; i < size; i += step)
310 out[i] = 310 out[i] =
311 eval_lpc_spectrum(in, 311 eval_lpc_spectrum(in,
312 get_cos(i, part, cos_tab, size), 312 get_cos(i, part, cos_tab, size),
313 mtab->n_lsp); 313 mtab->n_lsp);
314 314
315 // Fill the 'iiiibiiii' 315 // Fill the 'iiiibiiii'
316 for (i=step; i <= size - 2*step; i += step) { 316 for (i = step; i <= size - 2*step; i += step) {
317 if (out[i + step] + out[i - step] > 1.95*out[i] || 317 if (out[i + step] + out[i - step] > 1.95*out[i] ||
318 out[i + step] >= out[i - step]) { 318 out[i + step] >= out[i - step]) {
319 interpolate(out + i - step + 1, out[i], out[i-step], step - 1); 319 interpolate(out + i - step + 1, out[i], out[i-step], step - 1);
320 } else { 320 } else {
321 out[i - step/2] = 321 out[i - step/2] =
352 const int16_t *cb0, const int16_t *cb1, int cb_len) 352 const int16_t *cb0, const int16_t *cb1, int cb_len)
353 { 353 {
354 int pos = 0; 354 int pos = 0;
355 int i, j; 355 int i, j;
356 356
357 for (i=0; i < tctx->n_div[ftype]; i++) { 357 for (i = 0; i < tctx->n_div[ftype]; i++) {
358 int tmp0, tmp1; 358 int tmp0, tmp1;
359 int sign0 = 1; 359 int sign0 = 1;
360 int sign1 = 1; 360 int sign1 = 1;
361 const int16_t *tab0, *tab1; 361 const int16_t *tab0, *tab1;
362 int length = tctx->length[ftype][i >= tctx->length_change[ftype]]; 362 int length = tctx->length[ftype][i >= tctx->length_change[ftype]];
381 tmp1 = get_bits(gb, bits); 381 tmp1 = get_bits(gb, bits);
382 382
383 tab0 = cb0 + tmp0*cb_len; 383 tab0 = cb0 + tmp0*cb_len;
384 tab1 = cb1 + tmp1*cb_len; 384 tab1 = cb1 + tmp1*cb_len;
385 385
386 for (j=0; j < length; j++) 386 for (j = 0; j < length; j++)
387 out[tctx->permut[ftype][pos+j]] = sign0*tab0[j] + sign1*tab1[j]; 387 out[tctx->permut[ftype][pos+j]] = sign0*tab0[j] + sign1*tab1[j];
388 388
389 pos += length; 389 pos += length;
390 } 390 }
391 391
445 445
446 const float *shape_end = shape + len; 446 const float *shape_end = shape + len;
447 int center; 447 int center;
448 448
449 // First peak centered around zero 449 // First peak centered around zero
450 for (i=0; i < width/2; i++) 450 for (i = 0; i < width/2; i++)
451 speech[i] += ppc_gain * *shape++; 451 speech[i] += ppc_gain * *shape++;
452 452
453 for (i=1; i < ROUNDED_DIV(len,width) ; i++) { 453 for (i = 1; i < ROUNDED_DIV(len,width) ; i++) {
454 center = very_broken_op(period, i); 454 center = very_broken_op(period, i);
455 for (j=-width/2; j < (width+1)/2; j++) 455 for (j = -width/2; j < (width+1)/2; j++)
456 speech[j+center] += ppc_gain * *shape++; 456 speech[j+center] += ppc_gain * *shape++;
457 } 457 }
458 458
459 // For the last block, be careful not to go beyond the end of the buffer 459 // For the last block, be careful not to go beyond the end of the buffer
460 center = very_broken_op(period, i); 460 center = very_broken_op(period, i);
461 for (j=-width/2; j < (width + 1)/2 && shape < shape_end; j++) 461 for (j = -width/2; j < (width + 1)/2 && shape < shape_end; j++)
462 speech[j+center] += ppc_gain * *shape++; 462 speech[j+center] += ppc_gain * *shape++;
463 } 463 }
464 464
465 static void decode_ppc(TwinContext *tctx, int period_coef, const float *shape, 465 static void decode_ppc(TwinContext *tctx, int period_coef, const float *shape,
466 float ppc_gain, float *speech) 466 float ppc_gain, float *speech)
495 int sub = mtab->fmode[ftype].sub; 495 int sub = mtab->fmode[ftype].sub;
496 float step = AMP_MAX / ((1 << GAIN_BITS) - 1); 496 float step = AMP_MAX / ((1 << GAIN_BITS) - 1);
497 float sub_step = SUB_AMP_MAX / ((1 << SUB_GAIN_BITS) - 1); 497 float sub_step = SUB_AMP_MAX / ((1 << SUB_GAIN_BITS) - 1);
498 498
499 if (ftype == FT_LONG) { 499 if (ftype == FT_LONG) {
500 for (i=0; i < tctx->avctx->channels; i++) 500 for (i = 0; i < tctx->avctx->channels; i++)
501 out[i] = (1./(1<<13)) * 501 out[i] = (1./(1<<13)) *
502 mulawinv(step * 0.5 + step * get_bits(gb, GAIN_BITS), 502 mulawinv(step * 0.5 + step * get_bits(gb, GAIN_BITS),
503 AMP_MAX, MULAW_MU); 503 AMP_MAX, MULAW_MU);
504 } else { 504 } else {
505 for (i=0; i < tctx->avctx->channels; i++) { 505 for (i = 0; i < tctx->avctx->channels; i++) {
506 float val = (1./(1<<23)) * 506 float val = (1./(1<<23)) *
507 mulawinv(step * 0.5 + step * get_bits(gb, GAIN_BITS), 507 mulawinv(step * 0.5 + step * get_bits(gb, GAIN_BITS),
508 AMP_MAX, MULAW_MU); 508 AMP_MAX, MULAW_MU);
509 509
510 for (j=0; j < sub; j++) { 510 for (j = 0; j < sub; j++) {
511 out[i*sub + j] = 511 out[i*sub + j] =
512 val*mulawinv(sub_step* 0.5 + 512 val*mulawinv(sub_step* 0.5 +
513 sub_step* get_bits(gb, SUB_GAIN_BITS), 513 sub_step* get_bits(gb, SUB_GAIN_BITS),
514 SUB_AMP_MAX, MULAW_MU); 514 SUB_AMP_MAX, MULAW_MU);
515 } 515 }
525 */ 525 */
526 static void rearrange_lsp(int order, float *lsp, float min_dist) 526 static void rearrange_lsp(int order, float *lsp, float min_dist)
527 { 527 {
528 int i; 528 int i;
529 float min_dist2 = min_dist * 0.5; 529 float min_dist2 = min_dist * 0.5;
530 for (i=1; i < order; i++) 530 for (i = 1; i < order; i++)
531 if (lsp[i] - lsp[i-1] < min_dist) { 531 if (lsp[i] - lsp[i-1] < min_dist) {
532 float avg = (lsp[i] + lsp[i-1]) * 0.5; 532 float avg = (lsp[i] + lsp[i-1]) * 0.5;
533 533
534 lsp[i-1] = avg - min_dist2; 534 lsp[i-1] = avg - min_dist2;
535 lsp[i ] = avg + min_dist2; 535 lsp[i ] = avg + min_dist2;
540 { 540 {
541 int i,j; 541 int i,j;
542 542
543 /* sort lsp in ascending order. float bubble agorithm, 543 /* sort lsp in ascending order. float bubble agorithm,
544 O(n) if data already sorted, O(n^2) - otherwise */ 544 O(n) if data already sorted, O(n^2) - otherwise */
545 for (i=0; i < lp_order - 1; i++) 545 for (i = 0; i < lp_order - 1; i++)
546 for (j=i; j >= 0 && lsp[j] > lsp[j+1]; j--) 546 for (j = i; j >= 0 && lsp[j] > lsp[j+1]; j--)
547 FFSWAP(float, lsp[j], lsp[j+1]); 547 FFSWAP(float, lsp[j], lsp[j+1]);
548 } 548 }
549 549
550 static void decode_lsp(TwinContext *tctx, int lpc_idx1, uint8_t *lpc_idx2, 550 static void decode_lsp(TwinContext *tctx, int lpc_idx1, uint8_t *lpc_idx2,
551 int lpc_hist_idx, float *lsp, float *hist) 551 int lpc_hist_idx, float *lsp, float *hist)
562 mtab->lsp_split == 4 ? -2 : 1, 562 mtab->lsp_split == 4 ? -2 : 1,
563 mtab->lsp_split == 4 ? -2 : 1, 563 mtab->lsp_split == 4 ? -2 : 1,
564 0 564 0
565 }; 565 };
566 566
567 j=0; 567 j = 0;
568 for (i=0; i < mtab->lsp_split; i++) { 568 for (i = 0; i < mtab->lsp_split; i++) {
569 int chunk_end = ((i + 1)*mtab->n_lsp + funny_rounding[i])/mtab->lsp_split; 569 int chunk_end = ((i + 1)*mtab->n_lsp + funny_rounding[i])/mtab->lsp_split;
570 for (; j < chunk_end; j++) 570 for (; j < chunk_end; j++)
571 lsp[j] = cb [lpc_idx1 * mtab->n_lsp + j] + 571 lsp[j] = cb [lpc_idx1 * mtab->n_lsp + j] +
572 cb2[lpc_idx2[i] * mtab->n_lsp + j]; 572 cb2[lpc_idx2[i] * mtab->n_lsp + j];
573 } 573 }
574 574
575 rearrange_lsp(mtab->n_lsp, lsp, 0.0001); 575 rearrange_lsp(mtab->n_lsp, lsp, 0.0001);
576 576
577 for (i=0; i < mtab->n_lsp; i++) { 577 for (i = 0; i < mtab->n_lsp; i++) {
578 float tmp1 = 1. - cb3[lpc_hist_idx*mtab->n_lsp + i]; 578 float tmp1 = 1. - cb3[lpc_hist_idx*mtab->n_lsp + i];
579 float tmp2 = hist[i] * cb3[lpc_hist_idx*mtab->n_lsp + i]; 579 float tmp2 = hist[i] * cb3[lpc_hist_idx*mtab->n_lsp + i];
580 hist[i] = lsp[i]; 580 hist[i] = lsp[i];
581 lsp[i] = lsp[i] * tmp1 + tmp2; 581 lsp[i] = lsp[i] * tmp1 + tmp2;
582 } 582 }
590 enum FrameType ftype, float *lpc) 590 enum FrameType ftype, float *lpc)
591 { 591 {
592 int i; 592 int i;
593 int size = tctx->mtab->size / tctx->mtab->fmode[ftype].sub; 593 int size = tctx->mtab->size / tctx->mtab->fmode[ftype].sub;
594 594
595 for (i=0; i < tctx->mtab->n_lsp; i++) 595 for (i = 0; i < tctx->mtab->n_lsp; i++)
596 lsp[i] = 2*cos(lsp[i]); 596 lsp[i] = 2*cos(lsp[i]);
597 597
598 switch (ftype) { 598 switch (ftype) {
599 case FT_LONG: 599 case FT_LONG:
600 eval_lpcenv_2parts(tctx, ftype, lsp, lpc, size, 8); 600 eval_lpcenv_2parts(tctx, ftype, lsp, lpc, size, 8);
631 631
632 wsize = types_sizes[wtype_to_wsize[wtype]]; 632 wsize = types_sizes[wtype_to_wsize[wtype]];
633 first_wsize = wsize; 633 first_wsize = wsize;
634 prev_buf = prev + (size - bsize)/2; 634 prev_buf = prev + (size - bsize)/2;
635 635
636 for (j=0; j < mtab->fmode[ftype].sub; j++) { 636 for (j = 0; j < mtab->fmode[ftype].sub; j++) {
637 int sub_wtype = ftype == FT_MEDIUM ? 8 : wtype; 637 int sub_wtype = ftype == FT_MEDIUM ? 8 : wtype;
638 638
639 if (!j && wtype == 4) 639 if (!j && wtype == 4)
640 sub_wtype = 4; 640 sub_wtype = 4;
641 else if (j == mtab->fmode[ftype].sub-1 && wtype == 7) 641 else if (j == mtab->fmode[ftype].sub-1 && wtype == 7)
668 { 668 {
669 const ModeTab *mtab = tctx->mtab; 669 const ModeTab *mtab = tctx->mtab;
670 float *prev_buf = tctx->prev_frame + tctx->last_block_pos[0]; 670 float *prev_buf = tctx->prev_frame + tctx->last_block_pos[0];
671 int i, j; 671 int i, j;
672 672
673 for (i=0; i < tctx->avctx->channels; i++) { 673 for (i = 0; i < tctx->avctx->channels; i++) {
674 imdct_and_window(tctx, ftype, wtype, 674 imdct_and_window(tctx, ftype, wtype,
675 tctx->spectrum + i*mtab->size, 675 tctx->spectrum + i*mtab->size,
676 prev_buf + 2*i*mtab->size, 676 prev_buf + 2*i*mtab->size,
677 i); 677 i);
678 } 678 }
679 679
680 if (tctx->avctx->channels == 2) { 680 if (tctx->avctx->channels == 2) {
681 for (i=0; i < mtab->size - tctx->last_block_pos[0]; i++) { 681 for (i = 0; i < mtab->size - tctx->last_block_pos[0]; i++) {
682 float f1 = prev_buf[ i]; 682 float f1 = prev_buf[ i];
683 float f2 = prev_buf[2*mtab->size + i]; 683 float f2 = prev_buf[2*mtab->size + i];
684 out[2*i ] = f1 + f2; 684 out[2*i ] = f1 + f2;
685 out[2*i + 1] = f1 - f2; 685 out[2*i + 1] = f1 - f2;
686 } 686 }
687 for (j=0; i < mtab->size; j++,i++) { 687 for (j = 0; i < mtab->size; j++,i++) {
688 float f1 = tctx->curr_frame[ j]; 688 float f1 = tctx->curr_frame[ j];
689 float f2 = tctx->curr_frame[2*mtab->size + j]; 689 float f2 = tctx->curr_frame[2*mtab->size + j];
690 out[2*i ] = f1 + f2; 690 out[2*i ] = f1 + f2;
691 out[2*i + 1] = f1 - f2; 691 out[2*i + 1] = f1 - f2;
692 } 692 }
711 float val = ((const float []) {0.4, 0.35, 0.28})[ftype]; 711 float val = ((const float []) {0.4, 0.35, 0.28})[ftype];
712 int bark_n_coef = mtab->fmode[ftype].bark_n_coef; 712 int bark_n_coef = mtab->fmode[ftype].bark_n_coef;
713 int fw_cb_len = mtab->fmode[ftype].bark_env_size / bark_n_coef; 713 int fw_cb_len = mtab->fmode[ftype].bark_env_size / bark_n_coef;
714 int idx = 0; 714 int idx = 0;
715 715
716 for (i=0; i < fw_cb_len; i++) 716 for (i = 0; i < fw_cb_len; i++)
717 for (j=0; j < bark_n_coef; j++, idx++) { 717 for (j = 0; j < bark_n_coef; j++, idx++) {
718 float tmp2 = 718 float tmp2 =
719 mtab->fmode[ftype].bark_cb[fw_cb_len*in[j] + i] * (1./4096); 719 mtab->fmode[ftype].bark_cb[fw_cb_len*in[j] + i] * (1./4096);
720 float st = use_hist ? 720 float st = use_hist ?
721 (1. - val) * tmp2 + val*hist[idx] + 1. : tmp2 + 1.; 721 (1. - val) * tmp2 + val*hist[idx] + 1. : tmp2 + 1.;
722 722
749 749
750 dequant(tctx, gb, out, ftype, 750 dequant(tctx, gb, out, ftype,
751 mtab->fmode[ftype].cb0, mtab->fmode[ftype].cb1, 751 mtab->fmode[ftype].cb0, mtab->fmode[ftype].cb1,
752 mtab->fmode[ftype].cb_len_read); 752 mtab->fmode[ftype].cb_len_read);
753 753
754 for (i=0; i < channels; i++) 754 for (i = 0; i < channels; i++)
755 for (j=0; j < sub; j++) 755 for (j = 0; j < sub; j++)
756 for (k=0; k < mtab->fmode[ftype].bark_n_coef; k++) 756 for (k = 0; k < mtab->fmode[ftype].bark_n_coef; k++)
757 bark1[i][j][k] = 757 bark1[i][j][k] =
758 get_bits(gb, mtab->fmode[ftype].bark_n_bit); 758 get_bits(gb, mtab->fmode[ftype].bark_n_bit);
759 759
760 for (i=0; i < channels; i++) 760 for (i = 0; i < channels; i++)
761 for (j=0; j < sub; j++) 761 for (j = 0; j < sub; j++)
762 bark_use_hist[i][j] = get_bits1(gb); 762 bark_use_hist[i][j] = get_bits1(gb);
763 763
764 dec_gain(tctx, gb, ftype, gain); 764 dec_gain(tctx, gb, ftype, gain);
765 765
766 for (i=0; i < channels; i++) { 766 for (i = 0; i < channels; i++) {
767 lpc_hist_idx[i] = get_bits(gb, tctx->mtab->lsp_bit0); 767 lpc_hist_idx[i] = get_bits(gb, tctx->mtab->lsp_bit0);
768 lpc_idx1 [i] = get_bits(gb, tctx->mtab->lsp_bit1); 768 lpc_idx1 [i] = get_bits(gb, tctx->mtab->lsp_bit1);
769 769
770 for (j=0; j < tctx->mtab->lsp_split; j++) 770 for (j = 0; j < tctx->mtab->lsp_split; j++)
771 lpc_idx2[i][j] = get_bits(gb, tctx->mtab->lsp_bit2); 771 lpc_idx2[i][j] = get_bits(gb, tctx->mtab->lsp_bit2);
772 } 772 }
773 773
774 if (ftype == FT_LONG) { 774 if (ftype == FT_LONG) {
775 int cb_len_p = (tctx->n_div[3] + mtab->ppc_shape_len*channels - 1)/ 775 int cb_len_p = (tctx->n_div[3] + mtab->ppc_shape_len*channels - 1)/
776 tctx->n_div[3]; 776 tctx->n_div[3];
777 dequant(tctx, gb, ppc_shape, FT_PPC, mtab->ppc_shape_cb, 777 dequant(tctx, gb, ppc_shape, FT_PPC, mtab->ppc_shape_cb,
778 mtab->ppc_shape_cb + cb_len_p*PPC_SHAPE_CB_SIZE, cb_len_p); 778 mtab->ppc_shape_cb + cb_len_p*PPC_SHAPE_CB_SIZE, cb_len_p);
779 } 779 }
780 780
781 for (i=0; i < channels; i++) { 781 for (i = 0; i < channels; i++) {
782 float *chunk = out + mtab->size * i; 782 float *chunk = out + mtab->size * i;
783 float lsp[tctx->mtab->n_lsp]; 783 float lsp[tctx->mtab->n_lsp];
784 784
785 for (j=0; j < sub; j++) { 785 for (j = 0; j < sub; j++) {
786 dec_bark_env(tctx, bark1[i][j], bark_use_hist[i][j], i, 786 dec_bark_env(tctx, bark1[i][j], bark_use_hist[i][j], i,
787 tctx->tmp_buf, gain[sub*i+j], ftype); 787 tctx->tmp_buf, gain[sub*i+j], ftype);
788 788
789 tctx->dsp.vector_fmul(chunk + block_size*j, tctx->tmp_buf, 789 tctx->dsp.vector_fmul(chunk + block_size*j, tctx->tmp_buf,
790 block_size); 790 block_size);
805 decode_lsp(tctx, lpc_idx1[i], lpc_idx2[i], lpc_hist_idx[i], lsp, 805 decode_lsp(tctx, lpc_idx1[i], lpc_idx2[i], lpc_hist_idx[i], lsp,
806 tctx->lsp_hist[i]); 806 tctx->lsp_hist[i]);
807 807
808 dec_lpc_spectrum_inv(tctx, lsp, ftype, tctx->tmp_buf); 808 dec_lpc_spectrum_inv(tctx, lsp, ftype, tctx->tmp_buf);
809 809
810 for (j=0; j < mtab->fmode[ftype].sub; j++) { 810 for (j = 0; j < mtab->fmode[ftype].sub; j++) {
811 tctx->dsp.vector_fmul(chunk, tctx->tmp_buf, block_size); 811 tctx->dsp.vector_fmul(chunk, tctx->tmp_buf, block_size);
812 chunk += block_size; 812 chunk += block_size;
813 } 813 }
814 } 814 }
815 } 815 }
877 int size_s = mtab->size / mtab->fmode[FT_SHORT].sub; 877 int size_s = mtab->size / mtab->fmode[FT_SHORT].sub;
878 int size_m = mtab->size / mtab->fmode[FT_MEDIUM].sub; 878 int size_m = mtab->size / mtab->fmode[FT_MEDIUM].sub;
879 int channels = tctx->avctx->channels; 879 int channels = tctx->avctx->channels;
880 float norm = channels == 1 ? 2. : 1.; 880 float norm = channels == 1 ? 2. : 1.;
881 881
882 for (i=0; i < 3; i++) { 882 for (i = 0; i < 3; i++) {
883 int bsize = tctx->mtab->size/tctx->mtab->fmode[i].sub; 883 int bsize = tctx->mtab->size/tctx->mtab->fmode[i].sub;
884 ff_mdct_init(&tctx->mdct_ctx[i], av_log2(bsize) + 1, 1, 884 ff_mdct_init(&tctx->mdct_ctx[i], av_log2(bsize) + 1, 1,
885 -sqrt(norm/bsize) / (1<<15)); 885 -sqrt(norm/bsize) / (1<<15));
886 } 886 }
887 887
889 889
890 tctx->spectrum = av_malloc(2*mtab->size*channels*sizeof(float)); 890 tctx->spectrum = av_malloc(2*mtab->size*channels*sizeof(float));
891 tctx->curr_frame = av_malloc(2*mtab->size*channels*sizeof(float)); 891 tctx->curr_frame = av_malloc(2*mtab->size*channels*sizeof(float));
892 tctx->prev_frame = av_malloc(2*mtab->size*channels*sizeof(float)); 892 tctx->prev_frame = av_malloc(2*mtab->size*channels*sizeof(float));
893 893
894 for(i=0; i < 3; i++) { 894 for (i = 0; i < 3; i++) {
895 int m = 4*mtab->size/mtab->fmode[i].sub; 895 int m = 4*mtab->size/mtab->fmode[i].sub;
896 double freq = 2*M_PI/m; 896 double freq = 2*M_PI/m;
897 tctx->cos_tabs[i] = av_malloc((m/4)*sizeof(*tctx->cos_tabs)); 897 tctx->cos_tabs[i] = av_malloc((m/4)*sizeof(*tctx->cos_tabs));
898 898
899 for (j=0; j <= m/8; j++) 899 for (j = 0; j <= m/8; j++)
900 tctx->cos_tabs[i][j] = cos((2*j + 1)*freq); 900 tctx->cos_tabs[i][j] = cos((2*j + 1)*freq);
901 for (j=1; j < m/8; j++) 901 for (j = 1; j < m/8; j++)
902 tctx->cos_tabs[i][m/4-j] = tctx->cos_tabs[i][j]; 902 tctx->cos_tabs[i][m/4-j] = tctx->cos_tabs[i][j];
903 } 903 }
904 904
905 905
906 ff_sine_window_init(ff_sine_windows[av_log2(size_m) - 7], size_m ); 906 ff_sine_window_init(ff_sine_windows[av_log2(size_m) - 7], size_m );
920 enum FrameType ftype) 920 enum FrameType ftype)
921 921
922 { 922 {
923 int i,j; 923 int i,j;
924 924
925 for (i=0; i < line_len[0]; i++) { 925 for (i = 0; i < line_len[0]; i++) {
926 int shift; 926 int shift;
927 927
928 if (num_blocks == 1 || 928 if (num_blocks == 1 ||
929 (ftype == FT_LONG && num_vect % num_blocks) || 929 (ftype == FT_LONG && num_vect % num_blocks) ||
930 (ftype != FT_LONG && num_vect & 1 ) || 930 (ftype != FT_LONG && num_vect & 1 ) ||
933 } else if (ftype == FT_LONG) { 933 } else if (ftype == FT_LONG) {
934 shift = i; 934 shift = i;
935 } else 935 } else
936 shift = i*i; 936 shift = i*i;
937 937
938 for (j=0; j < num_vect && (j+num_vect*i < block_size*num_blocks); j++) 938 for (j = 0; j < num_vect && (j+num_vect*i < block_size*num_blocks); j++)
939 tab[i*num_vect+j] = i*num_vect + (j + shift) % num_vect; 939 tab[i*num_vect+j] = i*num_vect + (j + shift) % num_vect;
940 } 940 }
941 } 941 }
942 942
943 /** 943 /**
958 static void transpose_perm(int16_t *out, int16_t *in, int num_vect, 958 static void transpose_perm(int16_t *out, int16_t *in, int num_vect,
959 const uint8_t line_len[2], int length_div) 959 const uint8_t line_len[2], int length_div)
960 { 960 {
961 int i,j; 961 int i,j;
962 int cont= 0; 962 int cont= 0;
963 for (i=0; i < num_vect; i++) 963 for (i = 0; i < num_vect; i++)
964 for (j=0; j < line_len[i >= length_div]; j++) 964 for (j = 0; j < line_len[i >= length_div]; j++)
965 out[cont++] = in[j*num_vect + i]; 965 out[cont++] = in[j*num_vect + i];
966 } 966 }
967 967
968 static void linear_perm(int16_t *out, int16_t *in, int n_blocks, int size) 968 static void linear_perm(int16_t *out, int16_t *in, int n_blocks, int size)
969 { 969 {
970 int block_size = size/n_blocks; 970 int block_size = size/n_blocks;
971 int i; 971 int i;
972 972
973 for (i=0; i < size; i++) 973 for (i = 0; i < size; i++)
974 out[i] = block_size * (in[i] % n_blocks) + in[i] / n_blocks; 974 out[i] = block_size * (in[i] % n_blocks) + in[i] / n_blocks;
975 } 975 }
976 976
977 static av_cold void construct_perm_table(TwinContext *tctx,enum FrameType ftype) 977 static av_cold void construct_perm_table(TwinContext *tctx,enum FrameType ftype)
978 { 978 {
1013 1013
1014 int bsize_no_main_cb[3]; 1014 int bsize_no_main_cb[3];
1015 int bse_bits[3]; 1015 int bse_bits[3];
1016 int i; 1016 int i;
1017 1017
1018 for (i=0; i < 3; i++) 1018 for (i = 0; i < 3; i++)
1019 // +1 for history usage switch 1019 // +1 for history usage switch
1020 bse_bits[i] = n_ch * 1020 bse_bits[i] = n_ch *
1021 (mtab->fmode[i].bark_n_coef * mtab->fmode[i].bark_n_bit + 1); 1021 (mtab->fmode[i].bark_n_coef * mtab->fmode[i].bark_n_bit + 1);
1022 1022
1023 bsize_no_main_cb[2] = bse_bits[2] + lsp_bits_per_block + ppc_bits + 1023 bsize_no_main_cb[2] = bse_bits[2] + lsp_bits_per_block + ppc_bits +
1024 WINDOW_TYPE_BITS + n_ch*GAIN_BITS; 1024 WINDOW_TYPE_BITS + n_ch*GAIN_BITS;
1025 1025
1026 for (i=0; i < 2; i++) 1026 for (i = 0; i < 2; i++)
1027 bsize_no_main_cb[i] = 1027 bsize_no_main_cb[i] =
1028 lsp_bits_per_block + n_ch*GAIN_BITS + WINDOW_TYPE_BITS + 1028 lsp_bits_per_block + n_ch*GAIN_BITS + WINDOW_TYPE_BITS +
1029 mtab->fmode[i].sub*(bse_bits[i] + n_ch*SUB_GAIN_BITS); 1029 mtab->fmode[i].sub*(bse_bits[i] + n_ch*SUB_GAIN_BITS);
1030 1030
1031 // The remaining bits are all used for the main spectrum coefficients 1031 // The remaining bits are all used for the main spectrum coefficients
1032 for (i=0; i < 4; i++) { 1032 for (i = 0; i < 4; i++) {
1033 int bit_size; 1033 int bit_size;
1034 int vect_size; 1034 int vect_size;
1035 int rounded_up, rounded_down, num_rounded_down, num_rounded_up; 1035 int rounded_up, rounded_down, num_rounded_down, num_rounded_up;
1036 if (i == 3) { 1036 if (i == 3) {
1037 bit_size = n_ch * mtab->ppc_shape_bit; 1037 bit_size = n_ch * mtab->ppc_shape_bit;
1060 tctx->length[i][0] = rounded_up; 1060 tctx->length[i][0] = rounded_up;
1061 tctx->length[i][1] = rounded_down; 1061 tctx->length[i][1] = rounded_down;
1062 tctx->length_change[i] = num_rounded_up; 1062 tctx->length_change[i] = num_rounded_up;
1063 } 1063 }
1064 1064
1065 for (i=0; i < 4; i++) 1065 for (i = 0; i < 4; i++)
1066 construct_perm_table(tctx, i); 1066 construct_perm_table(tctx, i);
1067 } 1067 }
1068 1068
1069 static av_cold int twin_decode_init(AVCodecContext *avctx) 1069 static av_cold int twin_decode_init(AVCodecContext *avctx)
1070 { 1070 {
1108 static av_cold int twin_decode_close(AVCodecContext *avctx) 1108 static av_cold int twin_decode_close(AVCodecContext *avctx)
1109 { 1109 {
1110 TwinContext *tctx = avctx->priv_data; 1110 TwinContext *tctx = avctx->priv_data;
1111 int i; 1111 int i;
1112 1112
1113 for (i=0; i < 3; i++) { 1113 for (i = 0; i < 3; i++) {
1114 ff_mdct_end(&tctx->mdct_ctx[i]); 1114 ff_mdct_end(&tctx->mdct_ctx[i]);
1115 av_free(tctx->cos_tabs[i]); 1115 av_free(tctx->cos_tabs[i]);
1116 } 1116 }
1117 1117
1118 1118