/********************************************************************1* *2* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *3* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *4* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *5* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *6* *7* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 *8* by the Xiph.Org Foundation https://xiph.org/ *9* *10********************************************************************1112function: linear scale -> dB, Bark and Mel scales1314********************************************************************/1516#ifndef _V_SCALES_H_17#define _V_SCALES_H_1819#include <math.h>20#include "os.h"2122#ifdef _MSC_VER23/* MS Visual Studio doesn't have C99 inline keyword. */24#define inline __inline25#endif2627/* 20log10(x) */28#define VORBIS_IEEE_FLOAT32 129#ifdef VORBIS_IEEE_FLOAT323031static inline float unitnorm(float x){32union {33ogg_uint32_t i;34float f;35} ix;36ix.f = x;37ix.i = (ix.i & 0x80000000U) | (0x3f800000U);38return ix.f;39}4041/* Segher was off (too high) by ~ .3 decibel. Center the conversion correctly. */42static inline float todB(const float *x){43union {44ogg_uint32_t i;45float f;46} ix;47ix.f = *x;48ix.i = ix.i&0x7fffffff;49return (float)(ix.i * 7.17711438e-7f -764.6161886f);50}5152#define todB_nn(x) todB(x)5354#else5556static float unitnorm(float x){57if(x<0)return(-1.f);58return(1.f);59}6061#define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)62#define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)6364#endif6566#define fromdB(x) (exp((x)*.11512925f))6768/* The bark scale equations are approximations, since the original69table was somewhat hand rolled. The below are chosen to have the70best possible fit to the rolled tables, thus their somewhat odd71appearance (these are more accurate and over a longer range than72the oft-quoted bark equations found in the texts I have). The73approximations are valid from 0 - 30kHz (nyquist) or so.7475all f in Hz, z in Bark */7677#define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))78#define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)79#define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)80#define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)8182/* Frequency to octave. We arbitrarily declare 63.5 Hz to be octave830.0 */8485#define toOC(n) (log(n)*1.442695f-5.965784f)86#define fromOC(o) (exp(((o)+5.965784f)*.693147f))8788#endif899091