examples/SFExamples/oggvorbiscodec94/src/libvorbis/lib/os.h

00001 #ifndef _OS_H
00002 #define _OS_H
00003 /********************************************************************
00004  *                                                                  *
00005  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
00006  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
00007  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
00008  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
00009  *                                                                  *
00010  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
00011  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
00012  *                                                                  *
00013  ********************************************************************
00014 
00015  function: #ifdef jail to whip a few platforms into the UNIX ideal.
00016  last mod: $Id: os.h 7543 2004-08-13 01:48:19Z conrad $
00017 
00018  ********************************************************************/
00019 
00020 #ifdef HAVE_CONFIG_H
00021 #include "config.h"
00022 #endif
00023 
00024 #include <math.h>
00025 #include "ogg/os_types.h"
00026 
00027 #include "misc.h"
00028 
00029 //OggVorbis libraries provide an option to use faster 32 bit multiplications which is less accurate than
00030 //the 64 bit multiplications. This is useful for slow CPUs or without native 64 bit multiplications. It is 
00031 //told by the originators that the resulting audio degradation is mostly inaudible. We have the option
00032 //to disable by commenting _LOW_ACCURACY_ macro below. 
00033 #define _LOW_ACCURACY_
00034 
00035 #ifndef _V_IFDEFJAIL_H_
00036 #  define _V_IFDEFJAIL_H_
00037 
00038 #  ifdef __GNUC__
00039 #    define STIN static __inline__
00040 #  elif _WIN32
00041 #    define STIN static __inline
00042 #  else
00043 #    define STIN static
00044 #  endif
00045 
00046 #ifdef DJGPP
00047 #  define rint(x)   (floor((x)+0.5f))
00048 #endif
00049 
00050 #ifndef M_PI
00051 #  define M_PI (3.1415926536f)
00052 #endif
00053 
00054 #if defined(_WIN32) && !defined(__SYMBIAN32__)
00055 #  include <malloc.h>
00056 #  define rint(x)   (floor((x)+0.5f)) 
00057 #  define NO_FLOAT_MATH_LIB
00058 #  define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
00059 #endif
00060 
00061 #if defined(__SYMBIAN32__) && defined(__WINS__)
00062 void *_alloca(size_t size);
00063 #  define alloca _alloca
00064 #endif
00065 
00066 #ifndef FAST_HYPOT
00067 #  define FAST_HYPOT hypot
00068 #endif
00069 
00070 #endif
00071 
00072 #ifdef HAVE_ALLOCA_H
00073 #  include <alloca.h>
00074 #endif
00075 
00076 #ifdef USE_MEMORY_H
00077 #  include <memory.h>
00078 #endif
00079 
00080 #ifndef min
00081 #  define min(x,y)  ((x)>(y)?(y):(x))
00082 #endif
00083 
00084 #ifndef max
00085 #  define max(x,y)  ((x)<(y)?(y):(x))
00086 #endif
00087 
00088 #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
00089 #  define VORBIS_FPU_CONTROL
00090 /* both GCC and MSVC are kinda stupid about rounding/casting to int.
00091    Because of encapsulation constraints (GCC can't see inside the asm
00092    block and so we end up doing stupid things like a store/load that
00093    is collectively a noop), we do it this way */
00094 
00095 /* we must set up the fpu before this works!! */
00096 
00097 typedef ogg_int16_t vorbis_fpu_control;
00098 
00099 static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
00100   ogg_int16_t ret;
00101   ogg_int16_t temp;
00102   __asm__ __volatile__("fnstcw %0\n\t"
00103           "movw %0,%%dx\n\t"
00104           "orw $62463,%%dx\n\t"
00105           "movw %%dx,%1\n\t"
00106           "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
00107   *fpu=ret;
00108 }
00109 
00110 static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
00111   __asm__ __volatile__("fldcw %0":: "m"(fpu));
00112 }
00113 
00114 /* assumes the FPU is in round mode! */
00115 static inline int vorbis_ftoi(double f){  /* yes, double!  Otherwise,
00116                                              we get extra fst/fld to
00117                                              truncate precision */
00118   int i;
00119   __asm__("fistl %0": "=m"(i) : "t"(f));
00120   return(i);
00121 }
00122 #endif
00123 
00124 /* GCCXML is removed from here because it does not recognize __asm. So control goes to the #ifndef VORBIS_FPU_CONTROL block below*/
00125 #if defined(_WIN32) && !defined(__GNUC__) && !defined(__BORLANDC__) && !defined(__GCCXML__)
00126 #  define VORBIS_FPU_CONTROL
00127 
00128 typedef ogg_int16_t vorbis_fpu_control;
00129 
00130 static __inline int vorbis_ftoi(double f){
00131         int i;
00132         __asm
00133         {
00134                 fld f
00135                 fistp i
00136         }
00137         
00138         return(i);
00139         
00140 }
00141 
00142 static __inline void vorbis_fpu_setround(vorbis_fpu_control */*fpu*/){
00143 }
00144 
00145 static __inline void vorbis_fpu_restore(vorbis_fpu_control /*fpu*/){
00146 }
00147 
00148 #endif
00149 
00150 
00151 #ifndef VORBIS_FPU_CONTROL
00152 
00153 typedef int vorbis_fpu_control;
00154 
00155 static int vorbis_ftoi(double f){
00156   return (int)(f+.5);
00157 }
00158 
00159 /* We don't have special code for this compiler/arch, so do it the slow way */
00160 #  define vorbis_fpu_setround(vorbis_fpu_control) {}
00161 #  define vorbis_fpu_restore(vorbis_fpu_control) {}
00162 
00163 #endif
00164 
00165 #endif /* _OS_H */

Generated by  doxygen 1.6.2