annotate src/libvorbis-1.3.3/lib/scales.h @ 22:b07fe9e906dc

Portaudio: add missed file
author Chris Cannam
date Tue, 26 Mar 2013 12:14:11 +0000
parents 05aa0afa9217
children
rev   line source
Chris@1 1 /********************************************************************
Chris@1 2 * *
Chris@1 3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
Chris@1 4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
Chris@1 5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
Chris@1 6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
Chris@1 7 * *
Chris@1 8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 *
Chris@1 9 * by the Xiph.Org Foundation http://www.xiph.org/ *
Chris@1 10 * *
Chris@1 11 ********************************************************************
Chris@1 12
Chris@1 13 function: linear scale -> dB, Bark and Mel scales
Chris@1 14 last mod: $Id: scales.h 16227 2009-07-08 06:58:46Z xiphmont $
Chris@1 15
Chris@1 16 ********************************************************************/
Chris@1 17
Chris@1 18 #ifndef _V_SCALES_H_
Chris@1 19 #define _V_SCALES_H_
Chris@1 20
Chris@1 21 #include <math.h>
Chris@1 22 #include "os.h"
Chris@1 23
Chris@1 24 #ifdef _MSC_VER
Chris@1 25 /* MS Visual Studio doesn't have C99 inline keyword. */
Chris@1 26 #define inline __inline
Chris@1 27 #endif
Chris@1 28
Chris@1 29 /* 20log10(x) */
Chris@1 30 #define VORBIS_IEEE_FLOAT32 1
Chris@1 31 #ifdef VORBIS_IEEE_FLOAT32
Chris@1 32
Chris@1 33 static inline float unitnorm(float x){
Chris@1 34 union {
Chris@1 35 ogg_uint32_t i;
Chris@1 36 float f;
Chris@1 37 } ix;
Chris@1 38 ix.f = x;
Chris@1 39 ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
Chris@1 40 return ix.f;
Chris@1 41 }
Chris@1 42
Chris@1 43 /* Segher was off (too high) by ~ .3 decibel. Center the conversion correctly. */
Chris@1 44 static inline float todB(const float *x){
Chris@1 45 union {
Chris@1 46 ogg_uint32_t i;
Chris@1 47 float f;
Chris@1 48 } ix;
Chris@1 49 ix.f = *x;
Chris@1 50 ix.i = ix.i&0x7fffffff;
Chris@1 51 return (float)(ix.i * 7.17711438e-7f -764.6161886f);
Chris@1 52 }
Chris@1 53
Chris@1 54 #define todB_nn(x) todB(x)
Chris@1 55
Chris@1 56 #else
Chris@1 57
Chris@1 58 static float unitnorm(float x){
Chris@1 59 if(x<0)return(-1.f);
Chris@1 60 return(1.f);
Chris@1 61 }
Chris@1 62
Chris@1 63 #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
Chris@1 64 #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
Chris@1 65
Chris@1 66 #endif
Chris@1 67
Chris@1 68 #define fromdB(x) (exp((x)*.11512925f))
Chris@1 69
Chris@1 70 /* The bark scale equations are approximations, since the original
Chris@1 71 table was somewhat hand rolled. The below are chosen to have the
Chris@1 72 best possible fit to the rolled tables, thus their somewhat odd
Chris@1 73 appearance (these are more accurate and over a longer range than
Chris@1 74 the oft-quoted bark equations found in the texts I have). The
Chris@1 75 approximations are valid from 0 - 30kHz (nyquist) or so.
Chris@1 76
Chris@1 77 all f in Hz, z in Bark */
Chris@1 78
Chris@1 79 #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
Chris@1 80 #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
Chris@1 81 #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
Chris@1 82 #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
Chris@1 83
Chris@1 84 /* Frequency to octave. We arbitrarily declare 63.5 Hz to be octave
Chris@1 85 0.0 */
Chris@1 86
Chris@1 87 #define toOC(n) (log(n)*1.442695f-5.965784f)
Chris@1 88 #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
Chris@1 89
Chris@1 90 #endif