doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scales.h
Go to the documentation of this file.
1 /********************************************************************
2  * *
3  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
7  * *
8  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
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.26 2002/07/11 06:40:50 xiphmont Exp $
15 
16  ********************************************************************/
17 
18 #ifndef _V_SCALES_H_
19 #define _V_SCALES_H_
20 
21 #include <math.h>
22 #include "os.h"
23 
24 /* 20log10(x) */
25 #define VORBIS_IEEE_FLOAT32 1
26 #ifdef VORBIS_IEEE_FLOAT32
27 
28 static float unitnorm(float x){
29  ogg_uint32_t *ix=(ogg_uint32_t *)&x;
30  *ix=(*ix&0x80000000UL)|(0x3f800000UL);
31  return(x);
32 }
33 
34 static float FABS(float *x){
35  ogg_uint32_t *ix=(ogg_uint32_t *)x;
36  *ix&=0x7fffffffUL;
37  return(*x);
38 }
39 
40 static float todB(const float *x){
41  float calc;
43  calc = ((*i) & 0x7fffffff);
44  calc *= 7.1771144e-7f;
45  calc += -764.27118f;
46  return calc;
47 }
48 
49 #define todB_nn(x) todB(x)
50 
51 #else
52 
53 static float unitnorm(float x){
54  if(x<0)return(-1.f);
55  return(1.f);
56 }
57 
58 #define FABS(x) fabs(*(x))
59 
60 #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
61 #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
62 
63 #endif
64 
65 #define fromdB(x) (exp((x)*.11512925f))
66 
67 /* The bark scale equations are approximations, since the original
68  table was somewhat hand rolled. The below are chosen to have the
69  best possible fit to the rolled tables, thus their somewhat odd
70  appearance (these are more accurate and over a longer range than
71  the oft-quoted bark equations found in the texts I have). The
72  approximations are valid from 0 - 30kHz (nyquist) or so.
73 
74  all f in Hz, z in Bark */
75 
76 #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
77 #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
78 #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
79 #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
80 
81 /* Frequency to octave. We arbitrarily declare 63.5 Hz to be octave
82  0.0 */
83 
84 #define toOC(n) (log(n)*1.442695f-5.965784f)
85 #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
86 
87 #endif
88 
u_int32_t ogg_uint32_t
Definition: os_types.h:139
GLenum GLint x
Definition: glext.h:2849
int i
Definition: process.py:33
tuple f
Definition: idal.py:89
int32_t ogg_int32_t
Definition: os_types.h:138