[Ffmpeg-devel] [PATCH] move ready_floor1 to vorbis.h , change some sruct internals in vorbis.c

Oded Shimon ods15
Sun Oct 1 12:48:06 CEST 2006


On Sun, Oct 01, 2006 at 12:39:51PM +0200, Michael Niedermayer wrote:
> Hi
> 
> On Sun, Oct 01, 2006 at 12:18:21PM +0200, Oded Shimon wrote:
> > On Sun, Oct 01, 2006 at 12:07:44PM +0200, Michael Niedermayer wrote:
> > > Hi
> > > 
> > > On Sun, Oct 01, 2006 at 11:38:35AM +0200, Oded Shimon wrote:
> > > > first step to make functions common between vorbis.c and vorbis_enc.c .
> > > > 
> > > > OK to commit?
> > > > 
> > > > BTW, the floor calculation in vorbis.c is inlined (render_line) right in 
> > > > the floor decode function, so it would be somewhat harder for me to split 
> > > > that out...
> > > > 
> > > > All of the common functions I am putting in vorbis.h . They are mostly 
> > > > small, biggest of them is this one, maybe the codebook len2vlc . So I 
> > > > don't think they deserve a seperate file...
> > > 
> > > i have no objections to putting speed critical functions as static inline
> > > in vorbis.h but functions which are used just during init should be shared
> > > at both source and object level
> > 
> > 2 problems - global namespace pollution (ff_nth_root ??), 
> 
> i see no problem here
> 
> 
> > and, where 
> > should i put the code?? in vorbis.c ? vorbis_data.c ? vorbis_common.c ?
> 
> not vorbis_data.c, iam fine with the other 2 options
> you could also rename vorbis_data.c to vorbis_common.c if you want, its all
> pretty much the same

ok, vorbis.c then. New patch.

- ods15
-------------- next part --------------
Index: vorbis.c
===================================================================
--- vorbis.c	(revision 6398)
+++ vorbis.c	(working copy)
@@ -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<<rangebits);
+            floor_setup->data.t1.list[0].x = 0;
+            floor_setup->data.t1.list[1].x = (1<<rangebits);
 
             for(j=0;j<floor_setup->data.t1.partitions;++j) {
                 for(k=0;k<floor_setup->data.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;k<floor_setup->data.t1.x_list_dim;++k) {
-                floor_setup->data.t1.x_list_order[k]=k;
-            }
-
-            for(k=0;k<floor_setup->data.t1.x_list_dim-1;++k) {   // FIXME optimize sorting ?
-                for(j=k+1;j<floor_setup->data.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;k<floor_setup->data.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;j<k;++j) {
-                    if ((floor_setup->data.t1.x_list[j]<floor_setup->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]<floor_setup->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;i<vf->x_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;(x<hx) && (x<vf->x_list[1]);++x) {
+            for(x=lx+1;(x<hx) && (x<vf->list[1].x);++x) {
                 err+=ady;
                 if (err>=adx) {
                     err-=adx;
@@ -1433,8 +1422,8 @@
         }
     }
 
-    if (hx<vf->x_list[1]) {
-        for(i=hx;i<vf->x_list[1];++i) {
+    if (hx<vf->list[1].x) {
+        for(i=hx;i<vf->list[1].x;++i) {
             vec[i]=ff_vorbis_floor1_inverse_db_table[hy];
         }
     }
Index: vorbis.h
===================================================================
--- vorbis.h	(revision 6398)
+++ vorbis.h	(working copy)
@@ -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



More information about the ffmpeg-devel mailing list