examples/SFExamples/oggvorbiscodec94/src/libvorbis/lib/lookup.c

00001 /********************************************************************
00002  *                                                                  *
00003  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
00004  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
00005  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
00006  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
00007  *                                                                  *
00008  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
00009  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
00010  *                                                                  *
00011  ********************************************************************
00012 
00013   function: lookup based functions
00014   last mod: $Id: lookup.c 7187 2004-07-20 07:24:27Z xiphmont $
00015 
00016  ********************************************************************/
00017 
00018 #include <math.h>
00019 #include "lookup.h"
00020 #include "lookup_data.h"
00021 #include "os.h"
00022 #include "misc.h"
00023 
00024 #ifdef FLOAT_LOOKUP
00025 
00026 /* interpolated lookup based cos function, domain 0 to PI only */
00027 float vorbis_coslook(float a){
00028   double d=a*(.31830989*(float)COS_LOOKUP_SZ);
00029   int i=vorbis_ftoi(d-.5);
00030 
00031   return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
00032 }
00033 
00034 /* interpolated 1./sqrt(p) where .5 <= p < 1. */
00035 float vorbis_invsqlook(float a){
00036   double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
00037   int i=vorbis_ftoi(d-.5f);
00038   return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
00039 }
00040 
00041 /* interpolated 1./sqrt(p) where .5 <= p < 1. */
00042 float vorbis_invsq2explook(int a){
00043   return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
00044 }
00045 
00046 #include <stdio.h>
00047 /* interpolated lookup based fromdB function, domain -140dB to 0dB only */
00048 float vorbis_fromdBlook(float a){
00049   int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
00050   return (i<0)?1.f:
00051     ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
00052      FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
00053 }
00054 
00055 #endif
00056 
00057 #ifdef INT_LOOKUP
00058 /* interpolated 1./sqrt(p) where .5 <= a < 1. (.100000... to .111111...) in
00059    16.16 format 
00060 
00061    returns in m.8 format */
00062 long vorbis_invsqlook_i(long a,long e){
00063   long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1); 
00064   long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /*  0.16 */
00065   long val=INVSQ_LOOKUP_I[i]-                                /*  1.16 */
00066     (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])*               /*  0.16 */
00067       d)>>16);                                               /* result 1.16 */
00068   
00069   e+=32;
00070   if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
00071   e=(e>>1)-8;
00072 
00073   return(val>>e);
00074 }
00075 
00076 /* interpolated lookup based fromdB function, domain -140dB to 0dB only */
00077 /* a is in n.12 format */
00078 float vorbis_fromdBlook_i(long a){
00079   int i=(-a)>>(12-FROMdB2_SHIFT);
00080   return (i<0)?1.f:
00081     ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
00082      FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
00083 }
00084 
00085 /* interpolated lookup based cos function, domain 0 to PI only */
00086 /* a is in 0.16 format, where 0==0, 2^^16-1==PI, return 0.14 */
00087 long vorbis_coslook_i(long a){
00088   int i=a>>COS_LOOKUP_I_SHIFT;
00089   int d=a&COS_LOOKUP_I_MASK;
00090   return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
00091                            COS_LOOKUP_I_SHIFT);
00092 }
00093 
00094 #endif

Generated by  doxygen 1.6.2