1 /*
2  *      Machine dependent defines/includes for LAME.
3  *
4  *      Copyright (c) 1999 A.L. Faber
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #ifndef LAME_MACHINE_H
23 #define LAME_MACHINE_H
24 
25 #include "version.h"
26 
27 #if (LAME_RELEASE_VERSION == 0)
28 #undef NDEBUG
29 #endif
30 
31 #include <stdio.h>
32 #include <assert.h>
33 
34 #ifdef STDC_HEADERS
35 # include <stdlib.h>
36 # include <string.h>
37 #else
38 # ifndef HAVE_STRCHR
39 #  define strchr index
40 #  define strrchr rindex
41 # endif
42 char   *strchr(), *strrchr();
43 # ifndef HAVE_MEMCPY
44 #  define memcpy(d, s, n) bcopy ((s), (d), (n))
45 #  define memmove(d, s, n) bcopy ((s), (d), (n))
46 # endif
47 #endif
48 
49 #if  defined(__riscos__)  &&  defined(FPA10)
50 # include "ymath.h"
51 #else
52 # include <math.h>
53 #endif
54 #include <limits.h>
55 
56 #include <ctype.h>
57 
58 #ifdef HAVE_ERRNO_H
59 # include <errno.h>
60 #endif
61 #ifdef HAVE_FCNTL_H
62 # include <fcntl.h>
63 #endif
64 
65 #if defined(macintosh)
66 # include <types.h>
67 # include <stat.h>
68 #else
69 # include <sys/types.h>
70 # include <sys/stat.h>
71 #endif
72 
73 #ifdef HAVE_INTTYPES_H
74 # include <inttypes.h>
75 #else
76 # ifdef HAVE_STDINT_H
77 #  include <stdint.h>
78 # endif
79 #endif
80 
81 #ifdef WITH_DMALLOC
82 #include <dmalloc.h>
83 #endif
84 
85 /*
86  * 3 different types of pow() functions:
87  *   - table lookup
88  *   - pow()
89  *   - exp()   on some machines this is claimed to be faster than pow()
90  */
91 
92 #define POW20(x) (assert(0 <= (x+Q_MAX2) && x < Q_MAX), pow20[x+Q_MAX2])
93 /*#define POW20(x)  pow(2.0,((double)(x)-210)*.25) */
94 /*#define POW20(x)  exp( ((double)(x)-210)*(.25*LOG2) ) */
95 
96 #define IPOW20(x)  (assert(0 <= x && x < Q_MAX), ipow20[x])
97 /*#define IPOW20(x)  exp( -((double)(x)-210)*.1875*LOG2 ) */
98 /*#define IPOW20(x)  pow(2.0,-((double)(x)-210)*.1875) */
99 
100 /* in case this is used without configure */
101 #ifndef inline
102 # define inline
103 #endif
104 
105 #if defined(_MSC_VER)
106 # undef inline
107 # define inline _inline
108 #elif defined(__SASC) || defined(__GNUC__) || defined(__ICC) || defined(__ECC)
109 /* if __GNUC__ we always want to inline, not only if the user requests it */
110 # undef inline
111 # define inline __inline
112 #endif
113 
114 #if    defined(_MSC_VER)
115 # pragma warning( disable : 4244 )
116 /*# pragma warning( disable : 4305 ) */
117 #endif
118 
119 /*
120  * FLOAT    for variables which require at least 32 bits
121  * FLOAT8   for variables which require at least 64 bits
122  *
123  * On some machines, 64 bit will be faster than 32 bit.  Also, some math
124  * routines require 64 bit float, so setting FLOAT=float will result in a
125  * lot of conversions.
126  */
127 
128 #if ( defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) )
129 # define WIN32_LEAN_AND_MEAN
130 # include <windows.h>
131 # include <float.h>
132 # define FLOAT_MAX FLT_MAX
133 #else
134 # ifndef FLOAT
135 typedef float FLOAT;
136 #  ifdef FLT_MAX
137 #   define FLOAT_MAX FLT_MAX
138 #  else
139 #   define FLOAT_MAX 1e37 /* approx */
140 #  endif
141 # endif
142 #endif
143 
144 #ifndef FLOAT8
145 typedef double FLOAT8;
146 # ifdef DBL_MAX
147 #  define FLOAT8_MAX DBL_MAX
148 # else
149 #  define FLOAT8_MAX 1e99 /* approx */
150 # endif
151 #else
152 # ifdef FLT_MAX
153 #  define FLOAT8_MAX FLT_MAX
154 # else
155 #  define FLOAT8_MAX 1e37 /* approx */
156 # endif
157 #endif
158 
159 /* sample_t must be floating point, at least 32 bits */
160 typedef FLOAT sample_t;
161 
162 #define dimension_of(array) (sizeof(array)/sizeof(array[0]))
163 #define beyond(array) (array+dimension_of(array))
164 #define compiletime_assert(expression) extern char static_assert_##FILE##_##LINE[expression?1:0]
165 
166 #if 1
167 #define EQ(a,b) (\
168 (fabs(a) > fabs(b)) \
169  ? (fabs((a)-(b)) <= (fabs(a) * 1e-6f)) \
170  : (fabs((a)-(b)) <= (fabs(b) * 1e-6f)))
171 #else
172 #define EQ(a,b) (fabs((a)-(b))<1E-37)
173 #endif
174 
175 #define NEQ(a,b) (!EQ(a,b))
176 
177 #endif
178 
179 #ifdef _MSC_VER
180 #  if _MSC_VER < 1400
181 #  define fabsf fabs
182 #  define powf pow
183 #  define log10f log10
184 #  endif
185 #endif
186 
187 
188 /* end of lame-machine.h */
189