Update header copyright dates, update copyright assignemnt
[platform/upstream/libvorbis.git] / lib / scales.h
1 /********************************************************************
2  *                                                                  *
3  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
4  * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5  * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH    *
6  * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.        *
7  *                                                                  *
8  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
9  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
10  *                                                                  *
11  ********************************************************************
12
13  function: linear scale -> dB, Bark and Mel scales
14  last mod: $Id: scales.h,v 1.12 2001/02/02 03:51:57 xiphmont Exp $
15
16  ********************************************************************/
17
18 #ifndef _V_SCALE_H_
19 #define _V_SCALES_H_
20
21 #include <math.h>
22
23 /* 20log10(x) */
24 #define DYNAMIC_RANGE_dB 200.f
25 #define todB(x)   ((x)==0?-400.f:log((x)*(x))*4.34294480f)
26 #define todB_nn(x)   ((x)==0.f?-400.f:log(x)*8.6858896f)
27 #define fromdB(x) (exp((x)*.11512925f))
28
29 /* The bark scale equations are approximations, since the original
30    table was somewhat hand rolled.  The below are chosen to have the
31    best possible fit to the rolled tables, thus their somewhat odd
32    appearance (these are more accurate and over a longer range than
33    the oft-quoted bark equations found in the texts I have).  The
34    approximations are valid from 0 - 30kHz (nyquist) or so.
35
36    all f in Hz, z in Bark */
37
38 #define toBARK(n)   (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
39 #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
40 #define toMEL(n)    (log(1.f+(n)*.001f)*1442.695f)
41 #define fromMEL(m)  (1000.f*exp((m)/1442.695f)-1000.f)
42
43 /* Frequency to octave.  We arbitrarily declare 63.5 Hz to be octave
44    0.0 */
45
46 #define toOC(n)     (log(n)*1.442695f-5.965784f)
47 #define fromOC(o)   (exp(((o)+5.965784f)*.693147f))
48
49 #endif
50