dbf-halloween2015

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/vorbis/lookup.c	Sun Nov 01 00:36:56 2015 +0200
     1.3 @@ -0,0 +1,94 @@
     1.4 +/********************************************************************
     1.5 + *                                                                  *
     1.6 + * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
     1.7 + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
     1.8 + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
     1.9 + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
    1.10 + *                                                                  *
    1.11 + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
    1.12 + * by the Xiph.Org Foundation http://www.xiph.org/                  *
    1.13 + *                                                                  *
    1.14 + ********************************************************************
    1.15 +
    1.16 +  function: lookup based functions
    1.17 +  last mod: $Id: lookup.c 16227 2009-07-08 06:58:46Z xiphmont $
    1.18 +
    1.19 + ********************************************************************/
    1.20 +
    1.21 +#include <math.h>
    1.22 +#include "lookup.h"
    1.23 +#include "lookup_data.h"
    1.24 +#include "os.h"
    1.25 +#include "misc.h"
    1.26 +
    1.27 +#ifdef FLOAT_LOOKUP
    1.28 +
    1.29 +/* interpolated lookup based cos function, domain 0 to PI only */
    1.30 +float vorbis_coslook(float a){
    1.31 +  double d=a*(.31830989*(float)COS_LOOKUP_SZ);
    1.32 +  int i=vorbis_ftoi(d-.5);
    1.33 +
    1.34 +  return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
    1.35 +}
    1.36 +
    1.37 +/* interpolated 1./sqrt(p) where .5 <= p < 1. */
    1.38 +float vorbis_invsqlook(float a){
    1.39 +  double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
    1.40 +  int i=vorbis_ftoi(d-.5f);
    1.41 +  return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
    1.42 +}
    1.43 +
    1.44 +/* interpolated 1./sqrt(p) where .5 <= p < 1. */
    1.45 +float vorbis_invsq2explook(int a){
    1.46 +  return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
    1.47 +}
    1.48 +
    1.49 +#include <stdio.h>
    1.50 +/* interpolated lookup based fromdB function, domain -140dB to 0dB only */
    1.51 +float vorbis_fromdBlook(float a){
    1.52 +  int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
    1.53 +  return (i<0)?1.f:
    1.54 +    ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
    1.55 +     FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
    1.56 +}
    1.57 +
    1.58 +#endif
    1.59 +
    1.60 +#ifdef INT_LOOKUP
    1.61 +/* interpolated 1./sqrt(p) where .5 <= a < 1. (.100000... to .111111...) in
    1.62 +   16.16 format
    1.63 +
    1.64 +   returns in m.8 format */
    1.65 +long vorbis_invsqlook_i(long a,long e){
    1.66 +  long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
    1.67 +  long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /*  0.16 */
    1.68 +  long val=INVSQ_LOOKUP_I[i]-                                /*  1.16 */
    1.69 +    (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])*               /*  0.16 */
    1.70 +      d)>>16);                                               /* result 1.16 */
    1.71 +
    1.72 +  e+=32;
    1.73 +  if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
    1.74 +  e=(e>>1)-8;
    1.75 +
    1.76 +  return(val>>e);
    1.77 +}
    1.78 +
    1.79 +/* interpolated lookup based fromdB function, domain -140dB to 0dB only */
    1.80 +/* a is in n.12 format */
    1.81 +float vorbis_fromdBlook_i(long a){
    1.82 +  int i=(-a)>>(12-FROMdB2_SHIFT);
    1.83 +  return (i<0)?1.f:
    1.84 +    ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
    1.85 +     FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
    1.86 +}
    1.87 +
    1.88 +/* interpolated lookup based cos function, domain 0 to PI only */
    1.89 +/* a is in 0.16 format, where 0==0, 2^^16-1==PI, return 0.14 */
    1.90 +long vorbis_coslook_i(long a){
    1.91 +  int i=a>>COS_LOOKUP_I_SHIFT;
    1.92 +  int d=a&COS_LOOKUP_I_MASK;
    1.93 +  return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
    1.94 +                           COS_LOOKUP_I_SHIFT);
    1.95 +}
    1.96 +
    1.97 +#endif