vrshoot

diff libs/vorbis/scales.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/vorbis/scales.h	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,90 @@
     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: linear scale -> dB, Bark and Mel scales
    1.17 + last mod: $Id: scales.h 16227 2009-07-08 06:58:46Z xiphmont $
    1.18 +
    1.19 + ********************************************************************/
    1.20 +
    1.21 +#ifndef _V_SCALES_H_
    1.22 +#define _V_SCALES_H_
    1.23 +
    1.24 +#include <math.h>
    1.25 +#include "os.h"
    1.26 +
    1.27 +#ifdef _MSC_VER
    1.28 +/* MS Visual Studio doesn't have C99 inline keyword. */
    1.29 +#define inline __inline
    1.30 +#endif
    1.31 +
    1.32 +/* 20log10(x) */
    1.33 +#define VORBIS_IEEE_FLOAT32 1
    1.34 +#ifdef VORBIS_IEEE_FLOAT32
    1.35 +
    1.36 +static inline float unitnorm(float x){
    1.37 +  union {
    1.38 +    ogg_uint32_t i;
    1.39 +    float f;
    1.40 +  } ix;
    1.41 +  ix.f = x;
    1.42 +  ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
    1.43 +  return ix.f;
    1.44 +}
    1.45 +
    1.46 +/* Segher was off (too high) by ~ .3 decibel.  Center the conversion correctly. */
    1.47 +static inline float todB(const float *x){
    1.48 +  union {
    1.49 +    ogg_uint32_t i;
    1.50 +    float f;
    1.51 +  } ix;
    1.52 +  ix.f = *x;
    1.53 +  ix.i = ix.i&0x7fffffff;
    1.54 +  return (float)(ix.i * 7.17711438e-7f -764.6161886f);
    1.55 +}
    1.56 +
    1.57 +#define todB_nn(x) todB(x)
    1.58 +
    1.59 +#else
    1.60 +
    1.61 +static float unitnorm(float x){
    1.62 +  if(x<0)return(-1.f);
    1.63 +  return(1.f);
    1.64 +}
    1.65 +
    1.66 +#define todB(x)   (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
    1.67 +#define todB_nn(x)   (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
    1.68 +
    1.69 +#endif
    1.70 +
    1.71 +#define fromdB(x) (exp((x)*.11512925f))
    1.72 +
    1.73 +/* The bark scale equations are approximations, since the original
    1.74 +   table was somewhat hand rolled.  The below are chosen to have the
    1.75 +   best possible fit to the rolled tables, thus their somewhat odd
    1.76 +   appearance (these are more accurate and over a longer range than
    1.77 +   the oft-quoted bark equations found in the texts I have).  The
    1.78 +   approximations are valid from 0 - 30kHz (nyquist) or so.
    1.79 +
    1.80 +   all f in Hz, z in Bark */
    1.81 +
    1.82 +#define toBARK(n)   (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
    1.83 +#define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
    1.84 +#define toMEL(n)    (log(1.f+(n)*.001f)*1442.695f)
    1.85 +#define fromMEL(m)  (1000.f*exp((m)/1442.695f)-1000.f)
    1.86 +
    1.87 +/* Frequency to octave.  We arbitrarily declare 63.5 Hz to be octave
    1.88 +   0.0 */
    1.89 +
    1.90 +#define toOC(n)     (log(n)*1.442695f-5.965784f)
    1.91 +#define fromOC(o)   (exp(((o)+5.965784f)*.693147f))
    1.92 +
    1.93 +#endif