dbf-halloween2015

annotate libs/vorbis/lookup.c @ 1:c3f5c32cb210

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