Merge branch_beta3 onto the mainline.
[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-2000             *
9  * by Monty <monty@xiph.org> and the XIPHOPHORUS Company            *
10  * http://www.xiph.org/                                             *
11  *                                                                  *
12  ********************************************************************
13
14  function: linear scale -> dB, Bark and Mel scales
15  last mod: $Id: scales.h,v 1.7 2000/11/06 00:07:02 xiphmont Exp $
16
17  ********************************************************************/
18
19 #ifndef _V_SCALE_H_
20 #define _V_SCALES_H_
21
22 #include <math.h>
23
24 /* 20log10(x) */
25 #define DYNAMIC_RANGE_dB 200.
26 #define todB(x)   ((x)==0?-9.e38:log(fabs(x))*8.6858896)
27 #define todB_nn(x)   ((x)==0?-9.e38:log(x)*8.6858896)
28 #define fromdB(x) (exp((x)*.11512925))
29
30
31 /* The bark scale equations are approximations, since the original
32    table was somewhat hand rolled.  The below are chosen to have the
33    best possible fit to the rolled tables, thus their somewhat odd
34    appearance (these are more accurate and over a longer range than
35    the oft-quoted bark equations found in the texts I have).  The
36    approximations are valid from 0 - 30kHz (nyquist) or so.
37
38    all f in Hz, z in Bark */
39
40 #define toBARK(f)   (13.1*atan(.00074*(f))+2.24*atan((f)*(f)*1.85e-8)+1e-4*(f))
41 #define fromBARK(z) (102.*(z)-2.*pow(z,2.)+.4*pow(z,3)+pow(1.46,z)-1.)
42 #define toMEL(f)    (log(1.+(f)*.001)*1442.695)
43 #define fromMEL(m)  (1000.*exp((m)/1442.695)-1000.)
44
45 /* Frequency to octave.  We arbitrarily declare 125.0 Hz to be octave
46    0.0 */
47
48 #define toOC(f)     (log(f)*1.442695-6.965784)
49 #define fromOC(o)   (exp(((o)+6.965784)*.693147))
50
51 #endif
52