Debian Codegraph @

libmp3lame/machine.h

raw
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 #include <stdio.h>
28 #include <assert.h>
29
30 #ifdef STDC_HEADERS
31 # include <stdlib.h>
32 # include <string.h>
33 #else
34 # ifndef HAVE_STRCHR
35 # define strchr index
36 # define strrchr rindex
37 # endif
38 char *strchr(), *strrchr();
39 # ifndef HAVE_MEMCPY
40 # define memcpy(d, s, n) bcopy ((s), (d), (n))
41 # define memmove(d, s, n) bcopy ((s), (d), (n))
42 # endif
43 #endif
44
45 #if defined(__riscos__) && defined(FPA10)
46 # include "ymath.h"
47 #else
48 # include <math.h>
49 #endif
50 #include <limits.h>
51
52 #include <ctype.h>
53
54 #ifdef HAVE_ERRNO_H
55 # include <errno.h>
56 #endif
57 #ifdef HAVE_FCNTL_H
58 # include <fcntl.h>
59 #endif
60
61 #if defined(macintosh)
62 # include <types.h>
63 # include <stat.h>
64 #else
65 # include <sys/types.h>
66 # include <sys/stat.h>
67 #endif
68
69 #ifdef HAVE_INTTYPES_H
70 # include <inttypes.h>
71 #else
72 # ifdef HAVE_STDINT_H
73 # include <stdint.h>
74 # endif
75 #endif
76
77 #ifdef WITH_DMALLOC
78 #include <dmalloc.h>
79 #endif
80
81 /*
82 * 3 different types of pow() functions:
83 * - table lookup
84 * - pow()
85 * - exp() on some machines this is claimed to be faster than pow()
86 */
87
88 #define POW20(x) (assert(0 <= (x+Q_MAX2) && x < Q_MAX), pow20[x+Q_MAX2])
89 /*#define POW20(x) pow(2.0,((double)(x)-210)*.25) */
90 /*#define POW20(x) exp( ((double)(x)-210)*(.25*LOG2) ) */
91
92 #define IPOW20(x) (assert(0 <= x && x < Q_MAX), ipow20[x])
93 /*#define IPOW20(x) exp( -((double)(x)-210)*.1875*LOG2 ) */
94 /*#define IPOW20(x) pow(2.0,-((double)(x)-210)*.1875) */
95
96 /* in case this is used without configure */
97 #ifndef inline
98 # define inline
99 #endif
100
101 #if defined(_MSC_VER)
102 # undef inline
103 # define inline _inline
104 #elif defined(__SASC) || defined(__GNUC__) || defined(__ICC) || defined(__ECC)
105 /* if __GNUC__ we always want to inline, not only if the user requests it */
106 # undef inline
107 # define inline __inline
108 #endif
109
110 #if defined(_MSC_VER)
111 # pragma warning( disable : 4244 )
112 /*# pragma warning( disable : 4305 ) */
113 #endif
114
115 /*
116 * FLOAT for variables which require at least 32 bits
117 * FLOAT8 for variables which require at least 64 bits
118 *
119 * On some machines, 64 bit will be faster than 32 bit. Also, some math
120 * routines require 64 bit float, so setting FLOAT=float will result in a
121 * lot of conversions.
122 */
123
124 #if ( defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) )
125 # define WIN32_LEAN_AND_MEAN
126 # include <windows.h>
127 # include <float.h>
128 # define FLOAT_MAX FLT_MAX
129 #else
130 # ifndef FLOAT
131 typedef float FLOAT;
132 # ifdef FLT_MAX
133 # define FLOAT_MAX FLT_MAX
134 # else
135 # define FLOAT_MAX 1e37 /* approx */
136 # endif
137 # endif
138 #endif
139
140 #ifndef FLOAT8
141 typedef double FLOAT8;
142 # ifdef DBL_MAX
143 # define FLOAT8_MAX DBL_MAX
144 # else
145 # define FLOAT8_MAX 1e99 /* approx */
146 # endif
147 #else
148 # ifdef FLT_MAX
149 # define FLOAT8_MAX FLT_MAX
150 # else
151 # define FLOAT8_MAX 1e37 /* approx */
152 # endif
153 #endif
154
155 /* sample_t must be floating point, at least 32 bits */
156 typedef FLOAT sample_t;
157
158 #define dimension_of(array) (sizeof(array)/sizeof(array[0]))
159 #define beyond(array) (array+dimension_of(array))
160 #define compiletime_assert(expression) enum{static_assert_##FILE##_##LINE = 1/((expression)?1:0)}
161 #define lame_calloc(TYPE, COUNT) ((TYPE*)calloc(COUNT, sizeof(TYPE)))
162 #define multiple_of(CHUNK, COUNT) (\
163 ( (COUNT) < 1 || (CHUNK) < 1 || (COUNT) % (CHUNK) == 0 ) \
164 ? (COUNT) \
165 : ((COUNT) + (CHUNK) - (COUNT) % (CHUNK)) \
166 )
167
168 #if 1
169 #define EQ(a,b) (\
170 (fabs(a) > fabs(b)) \
171 ? (fabs((a)-(b)) <= (fabs(a) * 1e-6f)) \
172 : (fabs((a)-(b)) <= (fabs(b) * 1e-6f)))
173 #else
174 #define EQ(a,b) (fabs((a)-(b))<1E-37)
175 #endif
176
177 #define NEQ(a,b) (!EQ(a,b))
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 #endif
188
189 /* end of machine.h */