examples/SFExamples/oggvorbiscodec94/src/libvorbis/lib/scales.h

00001 /********************************************************************
00002  *                                                                  *
00003  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
00004  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
00005  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
00006  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
00007  *                                                                  *
00008  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
00009  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
00010  *                                                                  *
00011  ********************************************************************
00012 
00013  function: linear scale -> dB, Bark and Mel scales
00014  last mod: $Id: scales.h 9959 2005-09-05 11:04:48Z msmith $
00015 
00016  ********************************************************************/
00017 
00018 #ifndef _V_SCALES_H_
00019 #define _V_SCALES_H_
00020 
00021 #include <math.h>
00022 #include "os.h"
00023 
00024 /* 20log10(x) */
00025 #define VORBIS_IEEE_FLOAT32 1
00026 #ifdef VORBIS_IEEE_FLOAT32
00027 
00028 static float unitnorm(float x){
00029   union {
00030     ogg_uint32_t i;
00031     float f;
00032   } ix;
00033   ix.f = x;
00034   ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
00035   return ix.f;
00036 }
00037 
00038 /* Segher was off (too high) by ~ .3 decibel.  Center the conversion correctly. */
00039 static float todB(const float *x){
00040   union {
00041     ogg_uint32_t i;
00042     float f;
00043   } ix;
00044   ix.f = *x;
00045   ix.i = ix.i&0x7fffffff;
00046   return (float)(ix.i * 7.17711438e-7f -764.6161886f);
00047 }
00048 
00049 #define todB_nn(x) todB(x)
00050 
00051 #else
00052 
00053 static float unitnorm(float x){
00054   if(x<0)return(-1.f);
00055   return(1.f);
00056 }
00057 
00058 #define todB(x)   (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
00059 #define todB_nn(x)   (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
00060 
00061 #endif 
00062 
00063 #define fromdB(x) (exp((x)*.11512925f))  
00064 
00065 /* The bark scale equations are approximations, since the original
00066    table was somewhat hand rolled.  The below are chosen to have the
00067    best possible fit to the rolled tables, thus their somewhat odd
00068    appearance (these are more accurate and over a longer range than
00069    the oft-quoted bark equations found in the texts I have).  The
00070    approximations are valid from 0 - 30kHz (nyquist) or so.
00071 
00072    all f in Hz, z in Bark */
00073 
00074 #define toBARK(n)   (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
00075 #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
00076 #define toMEL(n)    (log(1.f+(n)*.001f)*1442.695f)
00077 #define fromMEL(m)  (1000.f*exp((m)/1442.695f)-1000.f)
00078 
00079 /* Frequency to octave.  We arbitrarily declare 63.5 Hz to be octave
00080    0.0 */
00081 
00082 #define toOC(n)     (log(n)*1.442695f-5.965784f)
00083 #define fromOC(o)   (exp(((o)+5.965784f)*.693147f))
00084 
00085 #endif
00086 

Generated by  doxygen 1.6.2