1159b3361Sopenharmony_ci/*
2159b3361Sopenharmony_ci *      Machine dependent defines/includes for LAME.
3159b3361Sopenharmony_ci *
4159b3361Sopenharmony_ci *      Copyright (c) 1999 A.L. Faber
5159b3361Sopenharmony_ci *
6159b3361Sopenharmony_ci * This library is free software; you can redistribute it and/or
7159b3361Sopenharmony_ci * modify it under the terms of the GNU Library General Public
8159b3361Sopenharmony_ci * License as published by the Free Software Foundation; either
9159b3361Sopenharmony_ci * version 2 of the License, or (at your option) any later version.
10159b3361Sopenharmony_ci *
11159b3361Sopenharmony_ci * This library is distributed in the hope that it will be useful,
12159b3361Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
13159b3361Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14159b3361Sopenharmony_ci * Library General Public License for more details.
15159b3361Sopenharmony_ci *
16159b3361Sopenharmony_ci * You should have received a copy of the GNU Library General Public
17159b3361Sopenharmony_ci * License along with this library; if not, write to the
18159b3361Sopenharmony_ci * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19159b3361Sopenharmony_ci * Boston, MA 02111-1307, USA.
20159b3361Sopenharmony_ci */
21159b3361Sopenharmony_ci
22159b3361Sopenharmony_ci#ifndef LAME_MACHINE_H
23159b3361Sopenharmony_ci#define LAME_MACHINE_H
24159b3361Sopenharmony_ci
25159b3361Sopenharmony_ci#include "version.h"
26159b3361Sopenharmony_ci
27159b3361Sopenharmony_ci#include <stdio.h>
28159b3361Sopenharmony_ci#include <assert.h>
29159b3361Sopenharmony_ci
30159b3361Sopenharmony_ci#ifdef STDC_HEADERS
31159b3361Sopenharmony_ci# include <stdlib.h>
32159b3361Sopenharmony_ci# include <string.h>
33159b3361Sopenharmony_ci#else
34159b3361Sopenharmony_ci# ifndef HAVE_STRCHR
35159b3361Sopenharmony_ci#  define strchr index
36159b3361Sopenharmony_ci#  define strrchr rindex
37159b3361Sopenharmony_ci# endif
38159b3361Sopenharmony_cichar   *strchr(), *strrchr();
39159b3361Sopenharmony_ci# ifndef HAVE_MEMCPY
40159b3361Sopenharmony_ci#  define memcpy(d, s, n) bcopy ((s), (d), (n))
41159b3361Sopenharmony_ci#  define memmove(d, s, n) bcopy ((s), (d), (n))
42159b3361Sopenharmony_ci# endif
43159b3361Sopenharmony_ci#endif
44159b3361Sopenharmony_ci
45159b3361Sopenharmony_ci#if  defined(__riscos__)  &&  defined(FPA10)
46159b3361Sopenharmony_ci# include "ymath.h"
47159b3361Sopenharmony_ci#else
48159b3361Sopenharmony_ci# include <math.h>
49159b3361Sopenharmony_ci#endif
50159b3361Sopenharmony_ci#include <limits.h>
51159b3361Sopenharmony_ci
52159b3361Sopenharmony_ci#include <ctype.h>
53159b3361Sopenharmony_ci
54159b3361Sopenharmony_ci#ifdef HAVE_ERRNO_H
55159b3361Sopenharmony_ci# include <errno.h>
56159b3361Sopenharmony_ci#endif
57159b3361Sopenharmony_ci#ifdef HAVE_FCNTL_H
58159b3361Sopenharmony_ci# include <fcntl.h>
59159b3361Sopenharmony_ci#endif
60159b3361Sopenharmony_ci
61159b3361Sopenharmony_ci#if defined(macintosh)
62159b3361Sopenharmony_ci# include <types.h>
63159b3361Sopenharmony_ci# include <stat.h>
64159b3361Sopenharmony_ci#else
65159b3361Sopenharmony_ci# include <sys/types.h>
66159b3361Sopenharmony_ci# include <sys/stat.h>
67159b3361Sopenharmony_ci#endif
68159b3361Sopenharmony_ci
69159b3361Sopenharmony_ci#ifdef HAVE_INTTYPES_H
70159b3361Sopenharmony_ci# include <inttypes.h>
71159b3361Sopenharmony_ci#else
72159b3361Sopenharmony_ci# ifdef HAVE_STDINT_H
73159b3361Sopenharmony_ci#  include <stdint.h>
74159b3361Sopenharmony_ci# endif
75159b3361Sopenharmony_ci#endif
76159b3361Sopenharmony_ci
77159b3361Sopenharmony_ci#ifdef WITH_DMALLOC
78159b3361Sopenharmony_ci#include <dmalloc.h>
79159b3361Sopenharmony_ci#endif
80159b3361Sopenharmony_ci
81159b3361Sopenharmony_ci/*
82159b3361Sopenharmony_ci * 3 different types of pow() functions:
83159b3361Sopenharmony_ci *   - table lookup
84159b3361Sopenharmony_ci *   - pow()
85159b3361Sopenharmony_ci *   - exp()   on some machines this is claimed to be faster than pow()
86159b3361Sopenharmony_ci */
87159b3361Sopenharmony_ci
88159b3361Sopenharmony_ci#define POW20(x) (assert(0 <= (x+Q_MAX2) && x < Q_MAX), pow20[x+Q_MAX2])
89159b3361Sopenharmony_ci/*#define POW20(x)  pow(2.0,((double)(x)-210)*.25) */
90159b3361Sopenharmony_ci/*#define POW20(x)  exp( ((double)(x)-210)*(.25*LOG2) ) */
91159b3361Sopenharmony_ci
92159b3361Sopenharmony_ci#define IPOW20(x)  (assert(0 <= x && x < Q_MAX), ipow20[x])
93159b3361Sopenharmony_ci/*#define IPOW20(x)  exp( -((double)(x)-210)*.1875*LOG2 ) */
94159b3361Sopenharmony_ci/*#define IPOW20(x)  pow(2.0,-((double)(x)-210)*.1875) */
95159b3361Sopenharmony_ci
96159b3361Sopenharmony_ci/* in case this is used without configure */
97159b3361Sopenharmony_ci#ifndef inline
98159b3361Sopenharmony_ci# define inline
99159b3361Sopenharmony_ci#endif
100159b3361Sopenharmony_ci
101159b3361Sopenharmony_ci#if defined(_MSC_VER)
102159b3361Sopenharmony_ci# undef inline
103159b3361Sopenharmony_ci# define inline _inline
104159b3361Sopenharmony_ci#elif defined(__SASC) || defined(__GNUC__) || defined(__ICC) || defined(__ECC)
105159b3361Sopenharmony_ci/* if __GNUC__ we always want to inline, not only if the user requests it */
106159b3361Sopenharmony_ci# undef inline
107159b3361Sopenharmony_ci# define inline __inline
108159b3361Sopenharmony_ci#endif
109159b3361Sopenharmony_ci
110159b3361Sopenharmony_ci#if    defined(_MSC_VER)
111159b3361Sopenharmony_ci# pragma warning( disable : 4244 )
112159b3361Sopenharmony_ci/*# pragma warning( disable : 4305 ) */
113159b3361Sopenharmony_ci#endif
114159b3361Sopenharmony_ci
115159b3361Sopenharmony_ci/*
116159b3361Sopenharmony_ci * FLOAT    for variables which require at least 32 bits
117159b3361Sopenharmony_ci * FLOAT8   for variables which require at least 64 bits
118159b3361Sopenharmony_ci *
119159b3361Sopenharmony_ci * On some machines, 64 bit will be faster than 32 bit.  Also, some math
120159b3361Sopenharmony_ci * routines require 64 bit float, so setting FLOAT=float will result in a
121159b3361Sopenharmony_ci * lot of conversions.
122159b3361Sopenharmony_ci */
123159b3361Sopenharmony_ci
124159b3361Sopenharmony_ci#if ( defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) )
125159b3361Sopenharmony_ci# define WIN32_LEAN_AND_MEAN
126159b3361Sopenharmony_ci# include <windows.h>
127159b3361Sopenharmony_ci# include <float.h>
128159b3361Sopenharmony_ci# define FLOAT_MAX FLT_MAX
129159b3361Sopenharmony_ci#else
130159b3361Sopenharmony_ci# ifndef FLOAT
131159b3361Sopenharmony_citypedef float FLOAT;
132159b3361Sopenharmony_ci#  ifdef FLT_MAX
133159b3361Sopenharmony_ci#   define FLOAT_MAX FLT_MAX
134159b3361Sopenharmony_ci#  else
135159b3361Sopenharmony_ci#   define FLOAT_MAX 1e37 /* approx */
136159b3361Sopenharmony_ci#  endif
137159b3361Sopenharmony_ci# endif
138159b3361Sopenharmony_ci#endif
139159b3361Sopenharmony_ci
140159b3361Sopenharmony_ci#ifndef FLOAT8
141159b3361Sopenharmony_citypedef double FLOAT8;
142159b3361Sopenharmony_ci# ifdef DBL_MAX
143159b3361Sopenharmony_ci#  define FLOAT8_MAX DBL_MAX
144159b3361Sopenharmony_ci# else
145159b3361Sopenharmony_ci#  define FLOAT8_MAX 1e99 /* approx */
146159b3361Sopenharmony_ci# endif
147159b3361Sopenharmony_ci#else
148159b3361Sopenharmony_ci# ifdef FLT_MAX
149159b3361Sopenharmony_ci#  define FLOAT8_MAX FLT_MAX
150159b3361Sopenharmony_ci# else
151159b3361Sopenharmony_ci#  define FLOAT8_MAX 1e37 /* approx */
152159b3361Sopenharmony_ci# endif
153159b3361Sopenharmony_ci#endif
154159b3361Sopenharmony_ci
155159b3361Sopenharmony_ci/* sample_t must be floating point, at least 32 bits */
156159b3361Sopenharmony_citypedef FLOAT sample_t;
157159b3361Sopenharmony_ci
158159b3361Sopenharmony_ci#define dimension_of(array) (sizeof(array)/sizeof(array[0]))
159159b3361Sopenharmony_ci#define beyond(array) (array+dimension_of(array))
160159b3361Sopenharmony_ci#define compiletime_assert(expression) enum{static_assert_##FILE##_##LINE = 1/((expression)?1:0)}
161159b3361Sopenharmony_ci#define lame_calloc(TYPE, COUNT) ((TYPE*)calloc(COUNT, sizeof(TYPE)))
162159b3361Sopenharmony_ci#define multiple_of(CHUNK, COUNT) (\
163159b3361Sopenharmony_ci  ( (COUNT) < 1 || (CHUNK) < 1 || (COUNT) % (CHUNK) == 0 ) \
164159b3361Sopenharmony_ci  ? (COUNT) \
165159b3361Sopenharmony_ci  : ((COUNT) + (CHUNK) - (COUNT) % (CHUNK)) \
166159b3361Sopenharmony_ci  )
167159b3361Sopenharmony_ci
168159b3361Sopenharmony_ci#if 1
169159b3361Sopenharmony_ci#define EQ(a,b) (\
170159b3361Sopenharmony_ci(fabs(a) > fabs(b)) \
171159b3361Sopenharmony_ci ? (fabs((a)-(b)) <= (fabs(a) * 1e-6f)) \
172159b3361Sopenharmony_ci : (fabs((a)-(b)) <= (fabs(b) * 1e-6f)))
173159b3361Sopenharmony_ci#else
174159b3361Sopenharmony_ci#define EQ(a,b) (fabs((a)-(b))<1E-37)
175159b3361Sopenharmony_ci#endif
176159b3361Sopenharmony_ci
177159b3361Sopenharmony_ci#define NEQ(a,b) (!EQ(a,b))
178159b3361Sopenharmony_ci
179159b3361Sopenharmony_ci#ifdef _MSC_VER
180159b3361Sopenharmony_ci#  if _MSC_VER < 1400
181159b3361Sopenharmony_ci#  define fabsf fabs
182159b3361Sopenharmony_ci#  define powf pow
183159b3361Sopenharmony_ci#  define log10f log10
184159b3361Sopenharmony_ci#  endif
185159b3361Sopenharmony_ci#endif
186159b3361Sopenharmony_ci
187159b3361Sopenharmony_ci#endif
188159b3361Sopenharmony_ci
189159b3361Sopenharmony_ci/* end of machine.h */
190