# HG changeset patch # User ods15 # Date 1159701090 0 # Node ID 203cd258fc2094e72c33347ee767102211b3dc8c # Parent 9b75ab171fa9cfc90c19103aa260f136eb4388c9 make ready_floor1_list() shared for vorbis_enc.c diff -r 9b75ab171fa9 -r 203cd258fc20 vorbis.c --- a/vorbis.c Sun Oct 01 05:09:20 2006 +0000 +++ b/vorbis.c Sun Oct 01 11:11:30 2006 +0000 @@ -88,10 +88,7 @@ int_fast16_t subclass_books[16][8]; uint_fast8_t multiplier; uint_fast16_t x_list_dim; - uint_fast16_t *x_list; - uint_fast16_t *x_list_order; - uint_fast16_t *low_neighbour; - uint_fast16_t *high_neighbour; + floor1_entry_t * list; } t1; } data; } vorbis_floor; @@ -253,6 +250,36 @@ return 0; } +void ff_vorbis_ready_floor1_list(floor1_entry_t * list, int values) { + int i; + list[0].sort = 0; + list[1].sort = 1; + for (i = 2; i < values; i++) { + int j; + list[i].low = 0; + list[i].high = 1; + list[i].sort = i; + for (j = 2; j < i; j++) { + int tmp = list[j].x; + if (tmp < list[i].x) { + if (tmp > list[list[i].low].x) list[i].low = j; + } else { + if (tmp < list[list[i].high].x) list[i].high = j; + } + } + } + for (i = 0; i < values - 1; i++) { + int j; + for (j = i + 1; j < values; j++) { + if (list[list[i].sort].x > list[list[j].sort].x) { + int tmp = list[i].sort; + list[i].sort = list[j].sort; + list[j].sort = tmp; + } + } + } +} + // Free all allocated memory ----------------------------------------- static void vorbis_free(vorbis_context *vc) { @@ -285,10 +312,7 @@ av_free(vc->floors[i].data.t0.lsp); } else { - av_free(vc->floors[i].data.t1.x_list); - av_free(vc->floors[i].data.t1.x_list_order); - av_free(vc->floors[i].data.t1.low_neighbour); - av_free(vc->floors[i].data.t1.high_neighbour); + av_free(vc->floors[i].data.t1.list); } } av_freep(&vc->floors); @@ -600,57 +624,23 @@ floor_setup->data.t1.x_list_dim+=floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]]; } - floor_setup->data.t1.x_list=(uint_fast16_t *)av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(uint_fast16_t)); - floor_setup->data.t1.x_list_order=(uint_fast16_t *)av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(uint_fast16_t)); - floor_setup->data.t1.low_neighbour=(uint_fast16_t *)av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(uint_fast16_t)); - floor_setup->data.t1.high_neighbour=(uint_fast16_t *)av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(uint_fast16_t)); + floor_setup->data.t1.list=(floor1_entry_t *)av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(floor1_entry_t)); rangebits=get_bits(gb, 4); - floor_setup->data.t1.x_list[0] = 0; - floor_setup->data.t1.x_list[1] = (1<data.t1.list[0].x = 0; + floor_setup->data.t1.list[1].x = (1<data.t1.partitions;++j) { for(k=0;kdata.t1.class_dimensions[floor_setup->data.t1.partition_class[j]];++k,++floor1_values) { - floor_setup->data.t1.x_list[floor1_values]=get_bits(gb, rangebits); + floor_setup->data.t1.list[floor1_values].x=get_bits(gb, rangebits); - AV_DEBUG(" %d. floor1 Y coord. %d \n", floor1_values, floor_setup->data.t1.x_list[floor1_values]); + AV_DEBUG(" %d. floor1 Y coord. %d \n", floor1_values, floor_setup->data.t1.list[floor1_values].x); } } // Precalculate order of x coordinates - needed for decode - - for(k=0;kdata.t1.x_list_dim;++k) { - floor_setup->data.t1.x_list_order[k]=k; - } - - for(k=0;kdata.t1.x_list_dim-1;++k) { // FIXME optimize sorting ? - for(j=k+1;jdata.t1.x_list_dim;++j) { - if(floor_setup->data.t1.x_list[floor_setup->data.t1.x_list_order[k]]>floor_setup->data.t1.x_list[floor_setup->data.t1.x_list_order[j]]) { - uint_fast16_t tmp=floor_setup->data.t1.x_list_order[k]; - floor_setup->data.t1.x_list_order[k]=floor_setup->data.t1.x_list_order[j]; - floor_setup->data.t1.x_list_order[j]=tmp; - } - } - } - -// Precalculate low and high neighbours - - for(k=2;kdata.t1.x_list_dim;++k) { - floor_setup->data.t1.low_neighbour[k]=0; - floor_setup->data.t1.high_neighbour[k]=1; // correct according to SPEC requirements - - for (j=0;jdata.t1.x_list[j]data.t1.x_list[k]) && - (floor_setup->data.t1.x_list[j]>floor_setup->data.t1.x_list[floor_setup->data.t1.low_neighbour[k]])) { - floor_setup->data.t1.low_neighbour[k]=j; - } - if ((floor_setup->data.t1.x_list[j]>floor_setup->data.t1.x_list[k]) && - (floor_setup->data.t1.x_list[j]data.t1.x_list[floor_setup->data.t1.high_neighbour[k]])) { - floor_setup->data.t1.high_neighbour[k]=j; - } - } - } + ff_vorbis_ready_floor1_list(floor_setup->data.t1.list, floor_setup->data.t1.x_list_dim); } else if(floor_setup->floor_type==0) { uint_fast8_t max_codebook_dim=0; @@ -1256,7 +1246,6 @@ int_fast16_t book; uint_fast16_t offset; uint_fast16_t i,j; - uint_fast16_t *floor_x_sort=vf->x_list_order; /*u*/int_fast16_t adx, ady, off, predicted; // WTF ? dy/adx= (unsigned)dy/adx ? int_fast16_t dy, err; uint_fast16_t lx,hx, ly, hy=0; @@ -1299,7 +1288,7 @@ floor1_Y[offset+j]=0; } - AV_DEBUG(" floor(%d) = %d \n", vf->x_list[offset+j], floor1_Y[offset+j]); + AV_DEBUG(" floor(%d) = %d \n", vf->list[offset+j].x, floor1_Y[offset+j]); } offset+=cdim; } @@ -1316,12 +1305,12 @@ uint_fast16_t high_neigh_offs; uint_fast16_t low_neigh_offs; - low_neigh_offs=vf->low_neighbour[i]; - high_neigh_offs=vf->high_neighbour[i]; + low_neigh_offs=vf->list[i].low; + high_neigh_offs=vf->list[i].high; dy=floor1_Y_final[high_neigh_offs]-floor1_Y_final[low_neigh_offs]; // render_point begin - adx=vf->x_list[high_neigh_offs]-vf->x_list[low_neigh_offs]; + adx=vf->list[high_neigh_offs].x-vf->list[low_neigh_offs].x; ady= ABS(dy); - err=ady*(vf->x_list[i]-vf->x_list[low_neigh_offs]); + err=ady*(vf->list[i].x-vf->list[low_neigh_offs].x); off=(int16_t)err/(int16_t)adx; if (dy<0) { predicted=floor1_Y_final[low_neigh_offs]-off; @@ -1359,7 +1348,7 @@ floor1_Y_final[i]=predicted; } - AV_DEBUG(" Decoded floor(%d) = %d / val %d \n", vf->x_list[i], floor1_Y_final[i], val); + AV_DEBUG(" Decoded floor(%d) = %d / val %d \n", vf->list[i].x, floor1_Y_final[i], val); } // Curve synth - connect the calculated dots and convert from dB scale FIXME optimize ? @@ -1373,11 +1362,11 @@ for(i=1;ix_list_dim;++i) { AV_DEBUG(" Looking at post %d \n", i); - if (floor1_flag[floor_x_sort[i]]) { // SPEC mispelled + if (floor1_flag[vf->list[i].sort]) { // SPEC mispelled int_fast16_t x, y, dy, base, sy; // if uncommented: dy = -32 adx = 2 base = 2blablabla ????? - hy=floor1_Y_final[floor_x_sort[i]]*vf->multiplier; - hx=vf->x_list[floor_x_sort[i]]; + hy=floor1_Y_final[vf->list[i].sort]*vf->multiplier; + hx=vf->list[vf->list[i].sort].x; dy=hy-ly; adx=hx-lx; @@ -1399,7 +1388,7 @@ AV_DEBUG(" vec[ %d ] = %d \n", x, y); - for(x=lx+1;(xx_list[1]);++x) { + for(x=lx+1;(xlist[1].x);++x) { err+=ady; if (err>=adx) { err-=adx; @@ -1433,8 +1422,8 @@ } } - if (hxx_list[1]) { - for(i=hx;ix_list[1];++i) { + if (hxlist[1].x) { + for(i=hx;ilist[1].x;++i) { vec[i]=ff_vorbis_floor1_inverse_db_table[hy]; } } diff -r 9b75ab171fa9 -r 203cd258fc20 vorbis.h --- a/vorbis.h Sun Oct 01 05:09:20 2006 +0000 +++ b/vorbis.h Sun Oct 01 11:11:30 2006 +0000 @@ -22,4 +22,13 @@ extern const float ff_vorbis_floor1_inverse_db_table[256]; extern const float * ff_vorbis_vwin[8]; +typedef struct { + uint_fast16_t x; + uint_fast16_t sort; + uint_fast16_t low; + uint_fast16_t high; +} floor1_entry_t; + +void ff_vorbis_ready_floor1_list(floor1_entry_t * list, int values); + #endif