⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 floor1.java

📁 java ogg player library. for play back ogg audio
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* JOrbis * Copyright (C) 2000 ymnk, JCraft,Inc. *   * Written by: 2000 ymnk<ymnk@jcraft.com> *    * Many thanks to  *   Monty <monty@xiph.org> and  *   The XIPHOPHORUS Company http://www.xiph.org/ . * JOrbis has been based on their awesome works, Vorbis codec. *    * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * as published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version.    * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU Library General Public License for more details. *  * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package com.jcraft.jorbis;import com.jcraft.jogg.*;class Floor1 extends FuncFloor{  static final int floor1_rangedb=140;  static final int VIF_POSIT=63;  void pack(Object i, Buffer opb){    InfoFloor1 info=(InfoFloor1)i;    int count=0;    int rangebits;    int maxposit=info.postlist[1];    int maxclass=-1;    /* save out partitions */    opb.write(info.partitions,5);          /* only 0 to 31 legal */    for(int j=0;j<info.partitions;j++){      opb.write(info.partitionclass[j],4); /* only 0 to 15 legal */      if(maxclass<info.partitionclass[j])        maxclass=info.partitionclass[j];    }    /* save out partition classes */    for(int j=0;j<maxclass+1;j++){      opb.write(info.class_dim[j]-1,3); /* 1 to 8 */      opb.write(info.class_subs[j],2); /* 0 to 3 */      if(info.class_subs[j]!=0){        opb.write(info.class_book[j],8);      }      for(int k=0;k<(1<<info.class_subs[j]);k++){        opb.write(info.class_subbook[j][k]+1,8);      }    }    /* save out the post list */    opb.write(info.mult-1,2);     /* only 1,2,3,4 legal now */    opb.write(ilog2(maxposit),4);    rangebits=ilog2(maxposit);    for(int j=0,k=0;j<info.partitions;j++){      count+=info.class_dim[info.partitionclass[j]];      for(;k<count;k++){        opb.write(info.postlist[k+2],rangebits);      }    }  }  Object unpack(Info vi , Buffer opb){    int count=0,maxclass=-1,rangebits;    InfoFloor1 info=new InfoFloor1();    /* read partitions */    info.partitions=opb.read(5);            /* only 0 to 31 legal */    for(int j=0;j<info.partitions;j++){      info.partitionclass[j]=opb.read(4); /* only 0 to 15 legal */      if(maxclass<info.partitionclass[j])        maxclass=info.partitionclass[j];    }    /* read partition classes */    for(int j=0;j<maxclass+1;j++){      info.class_dim[j]=opb.read(3)+1; /* 1 to 8 */      info.class_subs[j]=opb.read(2);  /* 0,1,2,3 bits */      if(info.class_subs[j]<0){        //goto err_out;	info.free();        return(null);      }      if(info.class_subs[j]!=0){        info.class_book[j]=opb.read(8);      }      if(info.class_book[j]<0 || info.class_book[j]>=vi.books){        //goto err_out;	info.free();        return(null);      }      for(int k=0;k<(1<<info.class_subs[j]);k++){        info.class_subbook[j][k]=opb.read(8)-1;        if(info.class_subbook[j][k]<-1 || info.class_subbook[j][k]>=vi.books){          //goto err_out;  	  info.free();          return(null);	}      }    }    /* read the post list */    info.mult=opb.read(2)+1;     /* only 1,2,3,4 legal now */    rangebits=opb.read(4);    for(int j=0,k=0;j<info.partitions;j++){      count+=info.class_dim[info.partitionclass[j]];      for(;k<count;k++){        int t=info.postlist[k+2]=opb.read(rangebits);        if(t<0 || t>=(1<<rangebits)){          //goto err_out;  	  info.free();          return(null);	}      }    }    info.postlist[0]=0;    info.postlist[1]=1<<rangebits;    return(info);//  err_out://    info.free();//    return(null);  }  Object look(DspState vd, InfoMode mi, Object i){    int _n=0;    int[] sortpointer=new int[VIF_POSIT+2];//    Info vi=vd.vi;    InfoFloor1 info=(InfoFloor1)i;    LookFloor1 look=new LookFloor1();    look.vi=info;    look.n=info.postlist[1];    /* we drop each position value in-between already decoded values,     and use linear interpolation to predict each new value past the     edges.  The positions are read in the order of the position     list... we precompute the bounding positions in the lookup.  Of     course, the neighbors can change (if a position is declined), but     this is an initial mapping */    for(int j=0;j<info.partitions;j++){      _n+=info.class_dim[info.partitionclass[j]];    }    _n+=2;    look.posts=_n;    /* also store a sorted position index */    for(int j=0;j<_n;j++){      sortpointer[j]=j;    }//    qsort(sortpointer,n,sizeof(int),icomp); // !!    int foo;     for(int j=0; j<_n-1; j++){      for(int k=j; k<_n; k++){        if(info.postlist[sortpointer[j]]>info.postlist[sortpointer[k]]){          foo=sortpointer[k];          sortpointer[k]=sortpointer[j];          sortpointer[j]=foo;	}      }    }    /* points from sort order back to range number */    for(int j=0;j<_n;j++){      look.forward_index[j]=sortpointer[j];    }    /* points from range order to sorted position */    for(int j=0;j<_n;j++){      look.reverse_index[look.forward_index[j]]=j;    }    /* we actually need the post values too */    for(int j=0;j<_n;j++){      look.sorted_index[j]=info.postlist[look.forward_index[j]];    }    /* quantize values to multiplier spec */    switch(info.mult){    case 1: /* 1024 -> 256 */	look.quant_q=256;	break;    case 2: /* 1024 -> 128 */	look.quant_q=128;	break;    case 3: /* 1024 -> 86 */	look.quant_q=86;	break;    case 4: /* 1024 -> 64 */	look.quant_q=64;	break;    default:	look.quant_q=-1;    }    /* discover our neighbors for decode where we don't use fit flags       (that would push the neighbors outward) */    for(int j=0;j<_n-2;j++){      int lo=0;      int hi=1;      int lx=0;      int hx=look.n;      int currentx=info.postlist[j+2];      for(int k=0;k<j+2;k++){        int x=info.postlist[k];        if(x>lx && x<currentx){          lo=k;          lx=x;        }	if(x<hx && x>currentx){	  hi=k;          hx=x;        }      }      look.loneighbor[j]=lo;      look.hineighbor[j]=hi;    }    return look;  }  void free_info(Object i){}  void free_look(Object i){}  void free_state(Object vs){}  int forward(Block vb, Object i,  float[] in, float[] out, Object vs){return 0;}  Object inverse1(Block vb, Object ii, Object memo){    //System.err.println("Floor1.inverse "+i.getClass()+"]");    LookFloor1 look=(LookFloor1)ii;    InfoFloor1 info=look.vi;    CodeBook[] books=vb.vd.fullbooks;    /* unpack wrapped/predicted values from stream */    if(vb.opb.read(1)==1){      int[] fit_value=null;      if(memo instanceof int[]){        fit_value=(int[])memo;      }      if(fit_value==null || fit_value.length<look.posts){        fit_value=new int[look.posts];      }      else{        for(int i=0; i<fit_value.length; i++) fit_value[i]=0;      }      fit_value[0]=vb.opb.read(ilog(look.quant_q-1));      fit_value[1]=vb.opb.read(ilog(look.quant_q-1));      /* partition by partition */      for(int i=0,j=2;i<info.partitions;i++){        int clss=info.partitionclass[i];        int cdim=info.class_dim[clss];        int csubbits=info.class_subs[clss];        int csub=1<<csubbits;	int cval=0;	/* decode the partition's first stage cascade value */	if(csubbits!=0){	   cval=books[info.class_book[clss]].decode(vb.opb);	   if(cval==-1){              //goto eop;             return(null);	   }	}	for(int k=0;k<cdim;k++){          int book=info.class_subbook[clss][cval&(csub-1)];          cval>>>=csubbits;          if(book>=0){            if((fit_value[j+k]=books[book].decode(vb.opb))==-1){              //goto eop;              return(null);	    }          }          else{            fit_value[j+k]=0;	  }	}	j+=cdim;      }      /* unwrap positive values and reconsitute via linear interpolation */      for(int i=2;i<look.posts;i++){        int predicted=render_point(info.postlist[look.loneighbor[i-2]],				   info.postlist[look.hineighbor[i-2]],				   fit_value[look.loneighbor[i-2]],				   fit_value[look.hineighbor[i-2]],				   info.postlist[i]);	int hiroom=look.quant_q-predicted;	int loroom=predicted;	int room=(hiroom<loroom?hiroom:loroom)<<1;	int val=fit_value[i];	if(val!=0){          if(val>=room){	    if(hiroom>loroom){	      val = val-loroom;            }            else{  	      val = -1-(val-hiroom);            }          }          else{	    if((val&1)!=0){	      val= -((val+1)>>>1);            }            else{	      val>>=1;            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -