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

📄 floor1.c

📁 fix point版本的Ogg Vorbis decoder
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************** *                                                                  * * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   * * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     * * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       * *                                                                  * * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             * * by the XIPHOPHORUS Company http://www.xiph.org/                  * *                                                                  * ******************************************************************** function: floor backend 1 implementation last mod: $Id: floor1.c,v 1.20 2002/01/22 08:06:06 xiphmont Exp $ ********************************************************************/#include <stdlib.h>#include <string.h>#include <math.h>#include "ogg.h"#include "vorbis_codec.h"#include "codec_internal.h"#include "registry.h"#include "codebook.h"#include "misc.h"#include "scales.h"#define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */typedef struct {  int sorted_index[VIF_POSIT+2];  int forward_index[VIF_POSIT+2];  int reverse_index[VIF_POSIT+2];    int hineighbor[VIF_POSIT];  int loneighbor[VIF_POSIT];  int posts;  int n;  int quant_q;  vorbis_info_floor1 *vi;  long phrasebits;  long postbits;  long frames;} vorbis_look_floor1;typedef struct lsfit_acc{  long x0;  long x1;  long xa;  long ya;  long x2a;  long y2a;  long xya;   long n;  long an;  long un;  long edgey0;  long edgey1;} lsfit_acc;/***********************************************/ static void floor1_free_info(vorbis_info_floor *i){  vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;  if(info){    memset(info,0,sizeof(*info));    _ogg_free(info);  }}static void floor1_free_look(vorbis_look_floor *i){  vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;  if(look){    memset(look,0,sizeof(*look));    _ogg_free(look);  }}static int ilog(unsigned int v){  int ret=0;  while(v){    ret++;    v>>=1;  }  return(ret);}static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){  codec_setup_info     *ci=vi->codec_setup;  int j,k,count=0,maxclass=-1,rangebits;  vorbis_info_floor1 *info=_ogg_calloc(1,sizeof(*info));  /* read partitions */  info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */  for(j=0;j<info->partitions;j++){    info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */    if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];  }  /* read partition classes */  for(j=0;j<maxclass+1;j++){    info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */    info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */    if(info->class_subs[j]<0)      goto err_out;    if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);    if(info->class_book[j]<0 || info->class_book[j]>=ci->books)      goto err_out;    for(k=0;k<(1<<info->class_subs[j]);k++){      info->class_subbook[j][k]=oggpack_read(opb,8)-1;      if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)	goto err_out;    }  }  /* read the post list */  info->mult=oggpack_read(opb,2)+1;     /* only 1,2,3,4 legal now */   rangebits=oggpack_read(opb,4);  for(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]=oggpack_read(opb,rangebits);      if(t<0 || t>=(1<<rangebits))	goto err_out;    }  }  info->postlist[0]=0;  info->postlist[1]=1<<rangebits;  return(info);   err_out:  floor1_free_info(info);  return(NULL);}static int icomp(const void *a,const void *b){  return(**(int **)a-**(int **)b);}static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,vorbis_info_mode *mi,                              vorbis_info_floor *in){  int *sortpointer[VIF_POSIT+2];  vorbis_info_floor1 *info=(vorbis_info_floor1 *)in;  vorbis_look_floor1 *look=_ogg_calloc(1,sizeof(*look));  int i,j,n=0;  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(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];  n+=2;  look->posts=n;  /* also store a sorted position index */  for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;  qsort(sortpointer,n,sizeof(*sortpointer),icomp);  /* points from sort order back to range number */  for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;  /* points from range order to sorted position */  for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;  /* we actually need the post values too */  for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];    /* 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;  }  /* discover our neighbors for decode where we don't use fit flags     (that would push the neighbors outward) */  for(i=0;i<n-2;i++){    int lo=0;    int hi=1;    int lx=0;    int hx=look->n;    int currentx=info->postlist[i+2];    for(j=0;j<i+2;j++){      int x=info->postlist[j];      if(x>lx && x<currentx){	lo=j;	lx=x;      }      if(x<hx && x>currentx){	hi=j;	hx=x;      }    }    look->loneighbor[i]=lo;    look->hineighbor[i]=hi;  }  return(look);}static int render_point(int x0,int x1,int y0,int y1,int x){  y0&=0x7fff; /* mask off flag */  y1&=0x7fff;      {    int dy=y1-y0;    int adx=x1-x0;    int ady=abs(dy);    int err=ady*(x-x0);        int off=err/adx;    if(dy<0)return(y0-off);    return(y0+off);  }}static FIXP FLOOR_fromdB_LOOKUP[256]={	TO_FIXP(30,1.0649863e-07F), TO_FIXP(30,1.1341951e-07F), 	TO_FIXP(30,1.2079015e-07F), TO_FIXP(30,1.2863978e-07F),	TO_FIXP(30,1.3699951e-07F), TO_FIXP(30,1.4590251e-07F), 	TO_FIXP(30,1.5538408e-07F), TO_FIXP(30,1.6548181e-07F),	TO_FIXP(30,1.7623575e-07F), TO_FIXP(30,1.8768855e-07F), 	TO_FIXP(30,1.9988561e-07F), TO_FIXP(30,2.128753e-07F),	TO_FIXP(30,2.2670913e-07F), TO_FIXP(30,2.4144197e-07F), 	TO_FIXP(30,2.5713223e-07F), TO_FIXP(30,2.7384213e-07F),	TO_FIXP(30,2.9163793e-07F), TO_FIXP(30,3.1059021e-07F), 	TO_FIXP(30,3.3077411e-07F), TO_FIXP(30,3.5226968e-07F),	TO_FIXP(30,3.7516214e-07F), TO_FIXP(30,3.9954229e-07F), 	TO_FIXP(30,4.2550680e-07F), TO_FIXP(30,4.5315863e-07F),	TO_FIXP(30,4.8260743e-07F), TO_FIXP(30,5.1396998e-07F), 	TO_FIXP(30,5.4737065e-07F), TO_FIXP(30,5.8294187e-07F),	TO_FIXP(30,6.2082472e-07F), TO_FIXP(30,6.6116941e-07F), 	TO_FIXP(30,7.0413592e-07F), TO_FIXP(30,7.4989464e-07F),	TO_FIXP(30,7.9862701e-07F), TO_FIXP(30,8.5052630e-07F), 	TO_FIXP(30,9.0579828e-07F), TO_FIXP(30,9.6466216e-07F),	TO_FIXP(30,1.0273513e-06F), TO_FIXP(30,1.0941144e-06F), 	TO_FIXP(30,1.1652161e-06F), TO_FIXP(30,1.2409384e-06F),	TO_FIXP(30,1.3215816e-06F), TO_FIXP(30,1.4074654e-06F), 	TO_FIXP(30,1.4989305e-06F), TO_FIXP(30,1.5963394e-06F),	TO_FIXP(30,1.7000785e-06F), TO_FIXP(30,1.8105592e-06F), 	TO_FIXP(30,1.9282195e-06F), TO_FIXP(30,2.0535261e-06F),	TO_FIXP(30,2.1869758e-06F), TO_FIXP(30,2.3290978e-06F), 	TO_FIXP(30,2.4804557e-06F), TO_FIXP(30,2.6416497e-06F),

⌨️ 快捷键说明

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