scales.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
  5. * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
  6. * PLEASE READ THESE TERMS DISTRIBUTING. *
  7. * *
  8. * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
  9. * by Monty <monty@xiph.org> and The XIPHOPHORUS Company *
  10. * http://www.xiph.org/ *
  11. * *
  12. ********************************************************************
  13. function: linear scale -> dB, Bark and Mel scales
  14. last mod: $Id: scales.h,v 1.1.2.1 2000/03/29 03:49:29 xiphmont Exp $
  15. ********************************************************************/
  16. #ifndef _V_SCALE_H_
  17. #define _V_SCALES_H_
  18. #include <math.h>
  19. #define min(x,y) ((x)>(y)?(y):(x))
  20. #define max(x,y) ((x)<(y)?(y):(x))
  21. /* 20log10(x) */
  22. #define DYNAMIC_RANGE_dB 200.
  23. #define todB(x) ((x)==0?-9.e40:log(fabs(x))*8.6858896)
  24. #define fromdB(x) (exp((x)*.11512925))
  25. /* The bark scale equations are approximations, since the original
  26. table was somewhat hand rolled. The below are chosen to have the
  27. best possible fit to the rolled tables, thus their somewhat odd
  28. appearance (these are more accurate and over a longer range than
  29. the oft-quoted bark equations found in the texts I have). The
  30. approximations are valid from 0 - 30kHz (nyquist) or so.
  31. all f in Hz, z in Bark */
  32. #define toBARK(f) (13.1*atan(.00074*(f))+2.24*atan((f)*(f)*1.85e-8)+1e-4*(f))
  33. #define fromBARK(z) (102.*(z)-2.*pow(z,2.)+.4*pow(z,3)+pow(1.46,z)-1.)
  34. #define toMEL(f) (log(1.+(f)*.001)*1442.695)
  35. #define fromMEL(m) (1000.*exp((m)/1442.695)-1000.)
  36. /* Frequency to octave. We arbitrarily declare 250.0 Hz to be octave
  37. 0.0 */
  38. #define toOC(f) (log(f)*1.442695-7.965784)
  39. #define fromOC(o) (exp(((o)+7.965784)*.693147))
  40. #endif