Rewrap EXTRA_DIST lines.
[platform/upstream/libvorbis.git] / lib / scales.h
index 991ee71..18bc4e7 100644 (file)
@@ -1,29 +1,69 @@
 /********************************************************************
  *                                                                  *
  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
- * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH    *
- * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.        *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
- * by the XIPHOPHORUS Company http://www.xiph.org/                  *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
+ * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: linear scale -> dB, Bark and Mel scales
- last mod: $Id: scales.h,v 1.12 2001/02/02 03:51:57 xiphmont Exp $
 
  ********************************************************************/
 
-#ifndef _V_SCALE_H_
+#ifndef _V_SCALES_H_
 #define _V_SCALES_H_
 
 #include <math.h>
+#include "os.h"
+
+#ifdef _MSC_VER
+/* MS Visual Studio doesn't have C99 inline keyword. */
+#define inline __inline
+#endif
 
 /* 20log10(x) */
-#define DYNAMIC_RANGE_dB 200.f
-#define todB(x)   ((x)==0?-400.f:log((x)*(x))*4.34294480f)
-#define todB_nn(x)   ((x)==0.f?-400.f:log(x)*8.6858896f)
+#define VORBIS_IEEE_FLOAT32 1
+#ifdef VORBIS_IEEE_FLOAT32
+
+static inline float unitnorm(float x){
+  union {
+    ogg_uint32_t i;
+    float f;
+  } ix;
+  ix.f = x;
+  ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
+  return ix.f;
+}
+
+/* Segher was off (too high) by ~ .3 decibel.  Center the conversion correctly. */
+static inline float todB(const float *x){
+  union {
+    ogg_uint32_t i;
+    float f;
+  } ix;
+  ix.f = *x;
+  ix.i = ix.i&0x7fffffff;
+  return (float)(ix.i * 7.17711438e-7f -764.6161886f);
+}
+
+#define todB_nn(x) todB(x)
+
+#else
+
+static float unitnorm(float x){
+  if(x<0)return(-1.f);
+  return(1.f);
+}
+
+#define todB(x)   (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
+#define todB_nn(x)   (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
+
+#endif
+
 #define fromdB(x) (exp((x)*.11512925f))
 
 /* The bark scale equations are approximations, since the original
@@ -47,4 +87,3 @@
 #define fromOC(o)   (exp(((o)+5.965784f)*.693147f))
 
 #endif
-