Increase preecho trigger sensitivity, even at low bitrate
[platform/upstream/libvorbis.git] / lib / os.h
1 #ifndef _OS_H
2 #define _OS_H
3 /********************************************************************
4  *                                                                  *
5  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
6  * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
7  * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH    *
8  * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.        *
9  *                                                                  *
10  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2000             *
11  * by Monty <monty@xiph.org> and the XIPHOPHORUS Company            *
12  * http://www.xiph.org/                                             *
13  *                                                                  *
14  ********************************************************************
15
16  function: #ifdef jail to whip a few platforms into the UNIX ideal.
17  last mod: $Id: os.h,v 1.21 2001/02/01 01:03:29 xiphmont Exp $
18
19  ********************************************************************/
20
21 #include <math.h>
22 #include <ogg/os_types.h>
23
24 #ifndef _V_IFDEFJAIL_H_
25 #  define _V_IFDEFJAIL_H_
26
27 #  ifdef __GNUC__
28 #    define STIN static inline
29 #  elif _WIN32
30 #    define STIN static __inline
31 #else
32 #  define STIN static
33 #endif
34
35 #ifndef M_PI
36 #  define M_PI (3.1415926536f)
37 #endif
38
39 #ifdef _WIN32
40 #  include <malloc.h>
41 #  define rint(x)   (floor((x)+0.5f)) 
42 #  define NO_FLOAT_MATH_LIB
43 #  define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
44 #endif
45
46 #ifdef DARWIN
47 #  define NO_FLOAT_MATH_LIB
48 #endif
49
50 #ifndef NO_FLOAT_MATH_LIB
51 #  define sqrt sqrtf
52 #  define log logf
53 #  define exp expf
54 #  define pow powf
55 #  define acos acosf
56 #  define atan atanf
57 #  define frexp frexpf
58 #  define rint rintf
59 #endif
60
61
62 #ifndef FAST_HYPOT
63 #  define FAST_HYPOT hypot
64 #endif
65
66 #endif
67
68 #ifdef HAVE_ALLOCA_H
69 #  include <alloca.h>
70 #endif
71
72 #ifdef USE_MEMORY_H
73 #  include <memory.h>
74 #endif
75
76 #ifndef min
77 #  define min(x,y)  ((x)>(y)?(y):(x))
78 #endif
79
80 #ifndef max
81 #  define max(x,y)  ((x)<(y)?(y):(x))
82 #endif
83
84 #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
85 #  define VORBIS_FPU_CONTROL
86 /* both GCC and MSVC are kinda stupid about rounding/casting to int.
87    Because of encapsulation constraints (GCC can't see inside the asm
88    block and so we end up doing stupid things like a store/load that
89    is collectively a noop), we do it this way */
90
91 /* we must set up the fpu before this works!! */
92
93 typedef ogg_int16_t vorbis_fpu_control;
94
95 static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
96   ogg_int16_t ret;
97   ogg_int16_t temp;
98   __asm__ __volatile__("fnstcw %0\n\t"
99           "movw %0,%%dx\n\t"
100           "orw $62463,%%dx\n\t"
101           "movw %%dx,%1\n\t"
102           "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
103   *fpu=ret;
104 }
105
106 static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
107   __asm__ __volatile__("fldcw %0":: "m"(fpu));
108 }
109
110 /* assumes the FPU is in round mode! */
111 static inline int vorbis_ftoi(double f){  /* yes, double!  Otherwise,
112                                              we get extra fst/fld to
113                                              truncate precision */
114   int i;
115   __asm__("fistl %0": "=m"(i) : "t"(f));
116   return(i);
117 }
118 #endif
119
120
121 #if defined(_WIN32) && !defined(__GNUC__)
122 #  define VORBIS_FPU_CONTROL
123
124 typedef ogg_int16_t vorbis_fpu_control;
125
126 static __inline int vorbis_ftoi(double f){
127         int i;
128         __asm{
129                 fld f
130                 fistp i
131         }
132         return i;
133 }
134
135 static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
136 }
137
138 static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
139 }
140
141 #endif
142
143
144 #ifndef VORBIS_FPU_CONTROL
145
146 typedef int vorbis_fpu_control;
147
148 static int vorbis_ftoi(double f){
149   return (int)(f+.5);
150 }
151
152 /* We don't have special code for this compiler/arch, so do it the slow way */
153 #  define vorbis_fpu_setround(vorbis_fpu_control) {}
154 #  define vorbis_fpu_restore(vorbis_fpu_control) {}
155
156 #endif
157
158 #endif /* _OS_H */