vrshoot
annotate libs/vorbis/lookup.c @ 2:334d17aed7de
visual studio project files
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 02 Feb 2014 18:36:38 +0200 |
parents | |
children |
rev | line source |
---|---|
nuclear@0 | 1 /******************************************************************** |
nuclear@0 | 2 * * |
nuclear@0 | 3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * |
nuclear@0 | 4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
nuclear@0 | 5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
nuclear@0 | 6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
nuclear@0 | 7 * * |
nuclear@0 | 8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * |
nuclear@0 | 9 * by the Xiph.Org Foundation http://www.xiph.org/ * |
nuclear@0 | 10 * * |
nuclear@0 | 11 ******************************************************************** |
nuclear@0 | 12 |
nuclear@0 | 13 function: lookup based functions |
nuclear@0 | 14 last mod: $Id: lookup.c 16227 2009-07-08 06:58:46Z xiphmont $ |
nuclear@0 | 15 |
nuclear@0 | 16 ********************************************************************/ |
nuclear@0 | 17 |
nuclear@0 | 18 #include <math.h> |
nuclear@0 | 19 #include "lookup.h" |
nuclear@0 | 20 #include "lookup_data.h" |
nuclear@0 | 21 #include "os.h" |
nuclear@0 | 22 #include "misc.h" |
nuclear@0 | 23 |
nuclear@0 | 24 #ifdef FLOAT_LOOKUP |
nuclear@0 | 25 |
nuclear@0 | 26 /* interpolated lookup based cos function, domain 0 to PI only */ |
nuclear@0 | 27 float vorbis_coslook(float a){ |
nuclear@0 | 28 double d=a*(.31830989*(float)COS_LOOKUP_SZ); |
nuclear@0 | 29 int i=vorbis_ftoi(d-.5); |
nuclear@0 | 30 |
nuclear@0 | 31 return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]); |
nuclear@0 | 32 } |
nuclear@0 | 33 |
nuclear@0 | 34 /* interpolated 1./sqrt(p) where .5 <= p < 1. */ |
nuclear@0 | 35 float vorbis_invsqlook(float a){ |
nuclear@0 | 36 double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ; |
nuclear@0 | 37 int i=vorbis_ftoi(d-.5f); |
nuclear@0 | 38 return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]); |
nuclear@0 | 39 } |
nuclear@0 | 40 |
nuclear@0 | 41 /* interpolated 1./sqrt(p) where .5 <= p < 1. */ |
nuclear@0 | 42 float vorbis_invsq2explook(int a){ |
nuclear@0 | 43 return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN]; |
nuclear@0 | 44 } |
nuclear@0 | 45 |
nuclear@0 | 46 #include <stdio.h> |
nuclear@0 | 47 /* interpolated lookup based fromdB function, domain -140dB to 0dB only */ |
nuclear@0 | 48 float vorbis_fromdBlook(float a){ |
nuclear@0 | 49 int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f); |
nuclear@0 | 50 return (i<0)?1.f: |
nuclear@0 | 51 ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f: |
nuclear@0 | 52 FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]); |
nuclear@0 | 53 } |
nuclear@0 | 54 |
nuclear@0 | 55 #endif |
nuclear@0 | 56 |
nuclear@0 | 57 #ifdef INT_LOOKUP |
nuclear@0 | 58 /* interpolated 1./sqrt(p) where .5 <= a < 1. (.100000... to .111111...) in |
nuclear@0 | 59 16.16 format |
nuclear@0 | 60 |
nuclear@0 | 61 returns in m.8 format */ |
nuclear@0 | 62 long vorbis_invsqlook_i(long a,long e){ |
nuclear@0 | 63 long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1); |
nuclear@0 | 64 long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */ |
nuclear@0 | 65 long val=INVSQ_LOOKUP_I[i]- /* 1.16 */ |
nuclear@0 | 66 (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */ |
nuclear@0 | 67 d)>>16); /* result 1.16 */ |
nuclear@0 | 68 |
nuclear@0 | 69 e+=32; |
nuclear@0 | 70 if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */ |
nuclear@0 | 71 e=(e>>1)-8; |
nuclear@0 | 72 |
nuclear@0 | 73 return(val>>e); |
nuclear@0 | 74 } |
nuclear@0 | 75 |
nuclear@0 | 76 /* interpolated lookup based fromdB function, domain -140dB to 0dB only */ |
nuclear@0 | 77 /* a is in n.12 format */ |
nuclear@0 | 78 float vorbis_fromdBlook_i(long a){ |
nuclear@0 | 79 int i=(-a)>>(12-FROMdB2_SHIFT); |
nuclear@0 | 80 return (i<0)?1.f: |
nuclear@0 | 81 ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f: |
nuclear@0 | 82 FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]); |
nuclear@0 | 83 } |
nuclear@0 | 84 |
nuclear@0 | 85 /* interpolated lookup based cos function, domain 0 to PI only */ |
nuclear@0 | 86 /* a is in 0.16 format, where 0==0, 2^^16-1==PI, return 0.14 */ |
nuclear@0 | 87 long vorbis_coslook_i(long a){ |
nuclear@0 | 88 int i=a>>COS_LOOKUP_I_SHIFT; |
nuclear@0 | 89 int d=a&COS_LOOKUP_I_MASK; |
nuclear@0 | 90 return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>> |
nuclear@0 | 91 COS_LOOKUP_I_SHIFT); |
nuclear@0 | 92 } |
nuclear@0 | 93 |
nuclear@0 | 94 #endif |