scales.h 2.11 KB
Newer Older
Monty's avatar
 
Monty committed
1
2
/********************************************************************
 *                                                                  *
Monty's avatar
   
Monty committed
3
 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
Monty's avatar
 
Monty committed
4
 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
Monty's avatar
   
Monty committed
5
6
 * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH    *
 * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.        *
Monty's avatar
 
Monty committed
7
 *                                                                  *
Monty's avatar
   
Monty committed
8
9
 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2000             *
 * by Monty <monty@xiph.org> and the XIPHOPHORUS Company            *
Monty's avatar
 
Monty committed
10
11
12
13
 * http://www.xiph.org/                                             *
 *                                                                  *
 ********************************************************************

Monty's avatar
   
Monty committed
14
 function: linear scale -> dB, Bark and Mel scales
Monty's avatar
   
Monty committed
15
 last mod: $Id: scales.h,v 1.8 2000/11/07 00:15:08 xiphmont Exp $
Monty's avatar
 
Monty committed
16
17
18

 ********************************************************************/

Monty's avatar
   
Monty committed
19
20
#ifndef _V_SCALE_H_
#define _V_SCALES_H_
Monty's avatar
 
Monty committed
21
22
23

#include <math.h>

Monty's avatar
   
Monty committed
24
/* 20log10(x) */
Monty's avatar
   
Monty committed
25
#define DYNAMIC_RANGE_dB 200.
Monty's avatar
   
Monty committed
26
27
#define todB(x)   ((x)==0?-9.e20:log(fabs(x))*8.6858896)
#define todB_nn(x)   ((x)==0?-400:log(x)*8.6858896)
Monty's avatar
   
Monty committed
28
29
30
#define fromdB(x) (exp((x)*.11512925))


Monty's avatar
   
Monty committed
31
/* The bark scale equations are approximations, since the original
Monty's avatar
   
Monty committed
32
33
34
   table was somewhat hand rolled.  The below are chosen to have the
   best possible fit to the rolled tables, thus their somewhat odd
   appearance (these are more accurate and over a longer range than
Monty's avatar
   
Monty committed
35
36
   the oft-quoted bark equations found in the texts I have).  The
   approximations are valid from 0 - 30kHz (nyquist) or so.
Monty's avatar
 
Monty committed
37

Monty's avatar
   
Monty committed
38
39
   all f in Hz, z in Bark */

Monty's avatar
   
Monty committed
40
#define toBARK(f)   (13.1*atan(.00074*(f))+2.24*atan((f)*(f)*1.85e-8)+1e-4*(f))
Monty's avatar
   
Monty committed
41
#define fromBARK(z) (102.*(z)-2.*pow(z,2.)+.4*pow(z,3)+pow(1.46,z)-1.)
Monty's avatar
   
Monty committed
42
#define toMEL(f)    (log(1.+(f)*.001)*1442.695)
Monty's avatar
   
Monty committed
43
#define fromMEL(m)  (1000.*exp((m)/1442.695)-1000.)
Monty's avatar
 
Monty committed
44

Monty's avatar
   
Monty committed
45
/* Frequency to octave.  We arbitrarily declare 125.0 Hz to be octave
Monty's avatar
   
Monty committed
46
47
   0.0 */

Monty's avatar
   
Monty committed
48
49
#define toOC(f)     (log(f)*1.442695-6.965784)
#define fromOC(o)   (exp(((o)+6.965784)*.693147))
Monty's avatar
   
Monty committed
50

Monty's avatar
 
Monty committed
51
#endif
Monty's avatar
   
Monty committed
52