machine.h 4.4 KB

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