comparison vorbis.c @ 3088:03582724f3de libavcodec

Correct the relation between floors of type 0 and block sizes.
author al
date Sun, 05 Feb 2006 10:16:20 +0000
parents d37c1e2f715d
children ede5c3c0a0eb
comparison
equal deleted inserted replaced
3087:526bc949ef31 3088:03582724f3de
168 } 168 }
169 av_freep(&vc->codebooks); 169 av_freep(&vc->codebooks);
170 170
171 for(i=0;i<vc->floor_count;++i) { 171 for(i=0;i<vc->floor_count;++i) {
172 if(vc->floors[i].floor_type==0) { 172 if(vc->floors[i].floor_type==0) {
173 av_free(vc->floors[i].data.t0.map); 173 av_free(vc->floors[i].data.t0.map[0]);
174 av_free(vc->floors[i].data.t0.map[1]);
174 av_free(vc->floors[i].data.t0.book_list); 175 av_free(vc->floors[i].data.t0.book_list);
175 av_free(vc->floors[i].data.t0.lsp); 176 av_free(vc->floors[i].data.t0.lsp);
176 } 177 }
177 else { 178 else {
178 av_free(vc->floors[i].data.t1.x_list); 179 av_free(vc->floors[i].data.t1.x_list);
416 417
417 // Process floors part 418 // Process floors part
418 419
419 static uint_fast8_t vorbis_floor0_decode(vorbis_context *vc, 420 static uint_fast8_t vorbis_floor0_decode(vorbis_context *vc,
420 vorbis_floor_data *vfu, float *vec); 421 vorbis_floor_data *vfu, float *vec);
422 static void create_map( vorbis_context * vc, uint_fast8_t floor_number );
421 static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc, 423 static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc,
422 vorbis_floor_data *vfu, float *vec); 424 vorbis_floor_data *vfu, float *vec);
423 static int vorbis_parse_setup_hdr_floors(vorbis_context *vc) { 425 static int vorbis_parse_setup_hdr_floors(vorbis_context *vc) {
424 GetBitContext *gb=&vc->gb; 426 GetBitContext *gb=&vc->gb;
425 uint_fast16_t i,j,k; 427 uint_fast16_t i,j,k;
571 573
572 if (floor_setup->data.t0.book_list[idx]>vc->codebook_count) 574 if (floor_setup->data.t0.book_list[idx]>vc->codebook_count)
573 return 1; 575 return 1;
574 } 576 }
575 } 577 }
578
579 create_map( vc, i );
576 580
577 /* allocate mem for lsp coefficients */ 581 /* allocate mem for lsp coefficients */
578 { 582 {
579 /* codebook dim is for padding if codebook dim doesn't * 583 /* codebook dim is for padding if codebook dim doesn't *
580 * divide order+1 then we need to read more data */ 584 * divide order+1 then we need to read more data */
738 return 0; 742 return 0;
739 } 743 }
740 744
741 // Process modes part 745 // Process modes part
742 746
743 static void create_map( vorbis_context * vc, uint_fast8_t mode_number ) 747 static void create_map( vorbis_context * vc, uint_fast8_t floor_number )
744 { 748 {
745 vorbis_floor * floors=vc->floors; 749 vorbis_floor * floors=vc->floors;
746 vorbis_floor0 * vf; 750 vorbis_floor0 * vf;
747 int idx; 751 int idx;
752 int_fast8_t blockflag;
748 int_fast32_t * map; 753 int_fast32_t * map;
749 int_fast32_t n; //TODO: could theoretically be smaller? 754 int_fast32_t n; //TODO: could theoretically be smaller?
750 755
751 n=(vc->modes[mode_number].blockflag ? 756 for (blockflag=0;blockflag<2;++blockflag)
752 vc->blocksize_1 : vc->blocksize_0) / 2; 757 {
753 floors[mode_number].data.t0.map= 758 n=(blockflag ? vc->blocksize_1 : vc->blocksize_0) / 2;
759 floors[floor_number].data.t0.map[blockflag]=
754 av_malloc((n+1) * sizeof(int_fast32_t)); // n+sentinel 760 av_malloc((n+1) * sizeof(int_fast32_t)); // n+sentinel
755 761
756 map=floors[mode_number].data.t0.map; 762 map=floors[floor_number].data.t0.map[blockflag];
757 vf=&floors[mode_number].data.t0; 763 vf=&floors[floor_number].data.t0;
758 764
759 for (idx=0; idx<n;++idx) { 765 for (idx=0; idx<n;++idx) {
760 map[idx]=floor( BARK((vf->rate*idx)/(2.0f*n)) * 766 map[idx]=floor( BARK((vf->rate*idx)/(2.0f*n)) *
761 ((vf->bark_map_size)/ 767 ((vf->bark_map_size)/
762 BARK(vf->rate/2.0f )) ); 768 BARK(vf->rate/2.0f )) );
763 if (vf->bark_map_size-1 < map[idx]) { 769 if (vf->bark_map_size-1 < map[idx]) {
764 map[idx]=vf->bark_map_size-1; 770 map[idx]=vf->bark_map_size-1;
765 } 771 }
766 } 772 }
767 map[n]=-1; 773 map[n]=-1;
768 vf->map_size=n; 774 vf->map_size[blockflag]=n;
775 }
769 776
770 # ifdef V_DEBUG 777 # ifdef V_DEBUG
771 for(idx=0;idx<=n;++idx) { 778 for(idx=0;idx<=n;++idx) {
772 AV_DEBUG("floor0 map: map at pos %d is %d\n", 779 AV_DEBUG("floor0 map: map at pos %d is %d\n",
773 idx, map[idx]); 780 idx, map[idx]);
791 mode_setup->windowtype=get_bits(gb, 16); //FIXME check 798 mode_setup->windowtype=get_bits(gb, 16); //FIXME check
792 mode_setup->transformtype=get_bits(gb, 16); //FIXME check 799 mode_setup->transformtype=get_bits(gb, 16); //FIXME check
793 mode_setup->mapping=get_bits(gb, 8); //FIXME check 800 mode_setup->mapping=get_bits(gb, 8); //FIXME check
794 801
795 AV_DEBUG(" %d mode: blockflag %d, windowtype %d, transformtype %d, mapping %d \n", i, mode_setup->blockflag, mode_setup->windowtype, mode_setup->transformtype, mode_setup->mapping); 802 AV_DEBUG(" %d mode: blockflag %d, windowtype %d, transformtype %d, mapping %d \n", i, mode_setup->blockflag, mode_setup->windowtype, mode_setup->transformtype, mode_setup->mapping);
796
797 if (vc->floors[i].floor_type == 0) { create_map( vc, i ); }
798 } 803 }
799 return 0; 804 return 0;
800 } 805 }
801 806
802 // Process the whole setup header using the functions above 807 // Process the whole setup header using the functions above
989 vorbis_floor_data *vfu, float *vec) { 994 vorbis_floor_data *vfu, float *vec) {
990 vorbis_floor0 * vf=&vfu->t0; 995 vorbis_floor0 * vf=&vfu->t0;
991 float * lsp=vf->lsp; 996 float * lsp=vf->lsp;
992 uint_fast32_t amplitude; 997 uint_fast32_t amplitude;
993 uint_fast32_t book_idx; 998 uint_fast32_t book_idx;
999 uint_fast8_t blockflag=vc->modes[vc->mode_number].blockflag;
994 1000
995 amplitude=get_bits(&vc->gb, vf->amplitude_bits); 1001 amplitude=get_bits(&vc->gb, vf->amplitude_bits);
996 if (amplitude>0) { 1002 if (amplitude>0) {
997 float last = 0; 1003 float last = 0;
998 uint_fast16_t lsp_len = 0; 1004 uint_fast16_t lsp_len = 0;
1047 1053
1048 AV_DEBUG("floor0 synth: map_size=%d; m=%d; wstep=%f\n", 1054 AV_DEBUG("floor0 synth: map_size=%d; m=%d; wstep=%f\n",
1049 vf->map_size, order, wstep); 1055 vf->map_size, order, wstep);
1050 1056
1051 i=0; 1057 i=0;
1052 while(i<vf->map_size) { 1058 while(i<vf->map_size[blockflag]) {
1053 int j, iter_cond=vf->map[i]; 1059 int j, iter_cond=vf->map[blockflag][i];
1054 float p=0.5f; 1060 float p=0.5f;
1055 float q=0.5f; 1061 float q=0.5f;
1056 float two_cos_w=2.0f*cos(wstep*iter_cond); // needed all times 1062 float two_cos_w=2.0f*cos(wstep*iter_cond); // needed all times
1057 1063
1058 /* similar part for the q and p products */ 1064 /* similar part for the q and p products */
1080 - vf->amplitude_offset ) * .11512925f 1086 - vf->amplitude_offset ) * .11512925f
1081 ); 1087 );
1082 } 1088 }
1083 1089
1084 /* fill vector */ 1090 /* fill vector */
1085 do { vec[i]=q; ++i; }while(vf->map[i]==iter_cond); 1091 do { vec[i]=q; ++i; }while(vf->map[blockflag][i]==iter_cond);
1086 } 1092 }
1087 } 1093 }
1088 } 1094 }
1089 else { 1095 else {
1090 /* this channel is unused */ 1096 /* this channel is unused */
1454 if (vc->mode_count==1) { 1460 if (vc->mode_count==1) {
1455 mode_number=0; 1461 mode_number=0;
1456 } else { 1462 } else {
1457 mode_number=get_bits(gb, ilog(vc->mode_count-1)); 1463 mode_number=get_bits(gb, ilog(vc->mode_count-1));
1458 } 1464 }
1465 vc->mode_number=mode_number;
1459 mapping=&vc->mappings[vc->modes[mode_number].mapping]; 1466 mapping=&vc->mappings[vc->modes[mode_number].mapping];
1460 1467
1461 AV_DEBUG(" Mode number: %d , mapping: %d , blocktype %d \n", mode_number, vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag); 1468 AV_DEBUG(" Mode number: %d , mapping: %d , blocktype %d \n", mode_number, vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag);
1462 1469
1463 if (vc->modes[mode_number].blockflag) { 1470 if (vc->modes[mode_number].blockflag) {