#include <math.h>
#include "lookup.h"
#include "lookup_data.h"
#include "os.h"
#include "misc.h"
#ifdef FLOAT_LOOKUP
float vorbis_coslook(float a){
double d=a*(.31830989*(float)COS_LOOKUP_SZ);
int i=vorbis_ftoi(d-.5);
return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
}
float vorbis_invsqlook(float a){
double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
int i=vorbis_ftoi(d-.5f);
return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
}
float vorbis_invsq2explook(int a){
return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
}
#include <stdio.h>
float vorbis_fromdBlook(float a){
int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
return (i<0)?1.f:
((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
}
#endif
#ifdef INT_LOOKUP
long vorbis_invsqlook_i(long a,long e){
long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT);
long val=INVSQ_LOOKUP_I[i]-
(((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])*
d)>>16);
e+=32;
if(e&1)val=(val*5792)>>13;
e=(e>>1)-8;
return(val>>e);
}
float vorbis_fromdBlook_i(long a){
int i=(-a)>>(12-FROMdB2_SHIFT);
return (i<0)?1.f:
((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
}
long vorbis_coslook_i(long a){
int i=a>>COS_LOOKUP_I_SHIFT;
int d=a&COS_LOOKUP_I_MASK;
return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
COS_LOOKUP_I_SHIFT);
}
#endif