dbf-halloween2015

annotate libs/vorbis/scales.h @ 1:c3f5c32cb210

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