-
- for(i=0;i<n;i++){
- if(c->dec_maxlength<c->dec_codelengths[i])
- c->dec_maxlength=c->dec_codelengths[i];
- if(c->dec_codelengths[i]<=c->dec_firsttablen){
- ogg_uint32_t orig=bitreverse(c->codelist[i]);
- for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
- c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
- }
- }
-
- /* now fill in 'unused' entries in the firsttable with hi/lo search
- hints for the non-direct-hits */
- {
- ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
- long lo=0,hi=0;
-
- for(i=0;i<tabn;i++){
- ogg_uint32_t word=i<<(32-c->dec_firsttablen);
- if(c->dec_firsttable[bitreverse(word)]==0){
- while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
- while( hi<n && word>=(c->codelist[hi]&mask))hi++;
-
- /* we only actually have 15 bits per hint to play with here.
- In order to overflow gracefully (nothing breaks, efficiency
- just drops), encode as the difference from the extremes. */
- {
- unsigned long loval=lo;
- unsigned long hival=n-hi;
-
- if(loval>0x7fff)loval=0x7fff;
- if(hival>0x7fff)hival=0x7fff;
- c->dec_firsttable[bitreverse(word)]=
- 0x80000000UL | (loval<<15) | hival;
- }
- }
- }
- }
- }
-
- return(0);
- err_out:
- vorbis_book_clear(c);
- return(-1);
-}
-
-static float _dist(int el,float *ref, float *b,int step){
- int i;
- float acc=0.f;
- for(i=0;i<el;i++){
- float val=(ref[i]-b[i*step]);
- acc+=val*val;
- }
- return(acc);
-}
-
-int _best(codebook *book, float *a, int step){
- encode_aux_threshmatch *tt=book->c->thresh_tree;
-
-#if 0
- encode_aux_nearestmatch *nt=book->c->nearest_tree;
- encode_aux_pigeonhole *pt=book->c->pigeon_tree;
-#endif
- int dim=book->dim;
- int k,o;
- /*int savebest=-1;
- float saverr;*/
-
- /* do we have a threshhold encode hint? */
- if(tt){
- int index=0,i;
- /* find the quant val of each scalar */
- for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
-
- i=tt->threshvals>>1;
- if(a[o]<tt->quantthresh[i]){
-
- for(;i>0;i--)
- if(a[o]>=tt->quantthresh[i-1])
- break;
-
- }else{
-
- for(i++;i<tt->threshvals-1;i++)
- if(a[o]<tt->quantthresh[i])break;
-