Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.         mpg123lib_intern: Common non-public stuff for libmpg123
  3.  
  4.         copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
  5.         see COPYING and AUTHORS files in distribution or http://mpg123.org
  6.  
  7.         derived from the old mpg123.h
  8. */
  9.  
  10. #ifndef MPG123_H_INTERN
  11. #define MPG123_H_INTERN
  12.  
  13. #define MPG123_RATES 9
  14. #define MPG123_ENCODINGS 10
  15.  
  16. #include "config.h" /* Load this before _anything_ */
  17.  
  18. /* ABI conformance for other compilers.
  19.    mpg123 needs 16byte-aligned stack for SSE and friends.
  20.    gcc provides that, but others don't necessarily. */
  21. #ifdef ABI_ALIGN_FUN
  22. #ifndef attribute_align_arg
  23. #if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__>1)
  24. #    define attribute_align_arg __attribute__((force_align_arg_pointer))
  25. /* The gcc that can align the stack does not need the check... nor does it work with gcc 4.3+, anyway. */
  26. #else
  27. #    define attribute_align_arg
  28. #    define NEED_ALIGNCHECK /* Other compilers get code to catch misaligned stack. */
  29. #endif
  30. #endif
  31. #else
  32. #define attribute_align_arg
  33. /* We won't try the align check... */
  34. #endif
  35.  
  36. /* export DLL symbols */
  37. #if defined(WIN32) && defined(DYNAMIC_BUILD)
  38. #define BUILD_MPG123_DLL
  39. #endif
  40. #include "compat.h"
  41. #include "mpg123.h"
  42.  
  43. #define SKIP_JUNK 1
  44.  
  45. #ifndef M_PI
  46. # define M_PI       3.14159265358979323846
  47. #endif
  48. #ifndef M_SQRT2
  49. # define M_SQRT2        1.41421356237309504880
  50. #endif
  51.  
  52. #ifdef SUNOS
  53. #define memmove(dst,src,size) bcopy(src,dst,size)
  54. #endif
  55.  
  56. /* some stuff has to go back to mpg123.h */
  57. #ifdef REAL_IS_FLOAT
  58. #  define real float
  59. #  define REAL_SCANF "%f"
  60. #  define REAL_PRINTF "%f"
  61. #elif defined(REAL_IS_LONG_DOUBLE)
  62. #  define real long double
  63. #  define REAL_SCANF "%Lf"
  64. #  define REAL_PRINTF "%Lf"
  65. #elif defined(REAL_IS_FIXED)
  66. /* Disable some output formats for fixed point decoder... */
  67.  
  68. # define real long
  69.  
  70. /*
  71.   for fixed-point decoders, use pre-calculated tables to avoid expensive floating-point maths
  72.   undef this macro for run-time calculation
  73. */
  74. #define PRECALC_TABLES
  75.  
  76. # define REAL_RADIX                             24
  77. # define REAL_FACTOR                    16777216.0
  78.  
  79. static inline long double_to_long_rounded(double x, double scalefac)
  80. {
  81.         x *= scalefac;
  82.         x += (x > 0) ? 0.5 : -0.5;
  83.         return (long)x;
  84. }
  85.  
  86. static inline long scale_rounded(long x, int shift)
  87. {
  88.         x += (x >> 31);
  89.         x >>= (shift - 1);
  90.         x += (x & 1);
  91.         return (x >> 1);
  92. }
  93.  
  94. # ifdef __GNUC__
  95. #  if defined(OPT_I386)
  96. /* for i386_nofpu decoder */
  97. #   define REAL_MUL_ASM(x, y, radix) \
  98. ({ \
  99.         long _x=(x), _y=(y); \
  100.         __asm__ ( \
  101.                 "imull %1 \n\t" \
  102.                 "shrdl %2, %%edx, %0 \n\t" \
  103.                 : "+&a" (_x) \
  104.                 : "mr" (_y), "I" (radix) \
  105.                 : "%edx", "cc" \
  106.         ); \
  107.         _x; \
  108. })
  109.  
  110. #   define REAL_MUL_SCALE_LAYER3_ASM(x, y, radix) \
  111. ({ \
  112.         long _x=(x), _y=(y), _radix=(radix); \
  113.         __asm__ ( \
  114.                 "imull %1 \n\t" \
  115.                 "shrdl %%cl, %%edx, %0 \n\t" \
  116.                 : "+&a" (_x) \
  117.                 : "mr" (_y), "c" (_radix) \
  118.                 : "%edx", "cc" \
  119.         ); \
  120.         _x; \
  121. })
  122. #  elif defined(OPT_PPC)
  123. /* for powerpc */
  124. #   define REAL_MUL_ASM(x, y, radix) \
  125. ({ \
  126.         long _x=(x), _y=(y), _mull, _mulh; \
  127.         __asm__ ( \
  128.                 "mullw %0, %2, %3 \n\t" \
  129.                 "mulhw %1, %2, %3 \n\t" \
  130.                 "srwi %0, %0, %4 \n\t" \
  131.                 "rlwimi %0, %1, %5, 0, %6 \n\t" \
  132.                 : "=&r" (_mull), "=&r" (_mulh) \
  133.                 : "%r" (_x), "r" (_y), "i" (radix), "i" (32-(radix)), "i" ((radix)-1) \
  134.         ); \
  135.         _mull; \
  136. })
  137.  
  138. #   define REAL_MUL_SCALE_LAYER3_ASM(x, y, radix) \
  139. ({ \
  140.         long _x=(x), _y=(y), _radix=(radix), _mull, _mulh, _radix2; \
  141.         __asm__ ( \
  142.                 "mullw %0, %3, %4 \n\t" \
  143.                 "mulhw %1, %3, %4 \n\t" \
  144.                 "subfic %2, %5, 32 \n\t" \
  145.                 "srw %0, %0, %5 \n\t" \
  146.                 "slw %1, %1, %2 \n\t" \
  147.                 "or %0, %0, %1 \n\t" \
  148.                 : "=&r" (_mull), "=&r" (_mulh), "=&r" (_radix2) \
  149.                 : "%r" (_x), "r" (_y), "r" (_radix) \
  150.                 : "cc" \
  151.         ); \
  152.         _mull; \
  153. })
  154. #  elif defined(OPT_ARM)
  155. /* for arm */
  156. #   define REAL_MUL_ASM(x, y, radix) \
  157. ({ \
  158.         long _x=(x), _y=(y), _mull, _mulh; \
  159.         __asm__ ( \
  160.                 "smull %0, %1, %2, %3 \n\t" \
  161.                 "mov %0, %0, lsr %4 \n\t" \
  162.                 "orr %0, %0, %1, lsl %5 \n\t" \
  163.                 : "=&r" (_mull), "=&r" (_mulh) \
  164.                 : "%r" (_x), "r" (_y), "M" (radix), "M" (32-(radix)) \
  165.         ); \
  166.         _mull; \
  167. })
  168.  
  169. #   define REAL_MUL_SCALE_LAYER3_ASM(x, y, radix) \
  170. ({ \
  171.         long _x=(x), _y=(y), _radix=(radix), _mull, _mulh, _radix2; \
  172.         __asm__ ( \
  173.                 "smull %0, %1, %3, %4 \n\t" \
  174.                 "mov %0, %0, lsr %5 \n\t" \
  175.                 "rsb %2, %5, #32 \n\t" \
  176.                 "orr %0, %0, %1, lsl %2 \n\t" \
  177.                 : "=&r" (_mull), "=&r" (_mulh), "=&r" (_radix2) \
  178.                 : "%r" (_x), "r" (_y), "r" (_radix) \
  179.         ); \
  180.         _mull; \
  181. })
  182. #  endif
  183. # endif
  184.  
  185. /* I just changed the (int) to (long) there... seemed right. */
  186. # define DOUBLE_TO_REAL(x)                                      (double_to_long_rounded(x, REAL_FACTOR))
  187. # define DOUBLE_TO_REAL_15(x)                           (double_to_long_rounded(x, 32768.0))
  188. # define DOUBLE_TO_REAL_POW43(x)                        (double_to_long_rounded(x, 8192.0))
  189. # define DOUBLE_TO_REAL_SCALE_LAYER12(x)        (double_to_long_rounded(x, 1073741824.0))
  190. # define DOUBLE_TO_REAL_SCALE_LAYER3(x, y)      (double_to_long_rounded(x, pow(2.0,gainpow2_scale[y])))
  191. # define REAL_TO_DOUBLE(x)                                      ((double)(x) / REAL_FACTOR)
  192. # ifdef REAL_MUL_ASM
  193. #  define REAL_MUL(x, y)                                        REAL_MUL_ASM(x, y, REAL_RADIX)
  194. #  define REAL_MUL_15(x, y)                                     REAL_MUL_ASM(x, y, 15)
  195. #  define REAL_MUL_SCALE_LAYER12(x, y)          REAL_MUL_ASM(x, y, 15 + 30 - REAL_RADIX)
  196. # else
  197. #  define REAL_MUL(x, y)                                        (((long long)(x) * (long long)(y)) >> REAL_RADIX)
  198. #  define REAL_MUL_15(x, y)                                     (((long long)(x) * (long long)(y)) >> 15)
  199. #  define REAL_MUL_SCALE_LAYER12(x, y)          (((long long)(x) * (long long)(y)) >> (15 + 30 - REAL_RADIX))
  200. # endif
  201. # ifdef REAL_MUL_SCALE_LAYER3_ASM
  202. #  define REAL_MUL_SCALE_LAYER3(x, y, z)        REAL_MUL_SCALE_LAYER3_ASM(x, y, 13 + gainpow2_scale[z] - REAL_RADIX)
  203. # else
  204. #  define REAL_MUL_SCALE_LAYER3(x, y, z)        (((long long)(x) * (long long)(y)) >> (13 + gainpow2_scale[z] - REAL_RADIX))
  205. # endif
  206. # define REAL_SCALE_LAYER12(x)                          ((long)((x) >> (30 - REAL_RADIX)))
  207. # define REAL_SCALE_LAYER3(x, y)                        ((long)((x) >> (gainpow2_scale[y] - REAL_RADIX)))
  208. # ifdef ACCURATE_ROUNDING
  209. #  define REAL_MUL_SYNTH(x, y)                          REAL_MUL(x, y)
  210. #  define REAL_SCALE_DCT64(x)                           (x)
  211. #  define REAL_SCALE_WINDOW(x)                          (x)
  212. # else
  213. #  define REAL_MUL_SYNTH(x, y)                          ((x) * (y))
  214. #  define REAL_SCALE_DCT64(x)                           ((x) >> 8)
  215. #  define REAL_SCALE_WINDOW(x)                          scale_rounded(x, 16)
  216. # endif
  217. #  define REAL_SCANF "%ld"
  218. #  define REAL_PRINTF "%ld"
  219.  
  220. #else
  221. #  define real double
  222. #  define REAL_SCANF "%lf"
  223. #  define REAL_PRINTF "%f"
  224. #endif
  225.  
  226. #ifndef REAL_IS_FIXED
  227. # if (defined SIZEOF_INT32_T) && (SIZEOF_INT32_T != 4)
  228. #  error "Bad 32bit types!!!"
  229. # endif
  230. #endif
  231.  
  232. #ifndef DOUBLE_TO_REAL
  233. # define DOUBLE_TO_REAL(x)                                      (real)(x)
  234. #endif
  235. #ifndef DOUBLE_TO_REAL_15
  236. # define DOUBLE_TO_REAL_15(x)                           (real)(x)
  237. #endif
  238. #ifndef DOUBLE_TO_REAL_POW43
  239. # define DOUBLE_TO_REAL_POW43(x)                        (real)(x)
  240. #endif
  241. #ifndef DOUBLE_TO_REAL_SCALE_LAYER12
  242. # define DOUBLE_TO_REAL_SCALE_LAYER12(x)        (real)(x)
  243. #endif
  244. #ifndef DOUBLE_TO_REAL_SCALE_LAYER3
  245. # define DOUBLE_TO_REAL_SCALE_LAYER3(x, y)      (real)(x)
  246. #endif
  247. #ifndef REAL_TO_DOUBLE
  248. # define REAL_TO_DOUBLE(x)                                      (x)
  249. #endif
  250.  
  251. #ifndef REAL_MUL
  252. # define REAL_MUL(x, y)                                         ((x) * (y))
  253. #endif
  254. #ifndef REAL_MUL_SYNTH
  255. # define REAL_MUL_SYNTH(x, y)                           ((x) * (y))
  256. #endif
  257. #ifndef REAL_MUL_15
  258. # define REAL_MUL_15(x, y)                                      ((x) * (y))
  259. #endif
  260. #ifndef REAL_MUL_SCALE_LAYER12
  261. # define REAL_MUL_SCALE_LAYER12(x, y)           ((x) * (y))
  262. #endif
  263. #ifndef REAL_MUL_SCALE_LAYER3
  264. # define REAL_MUL_SCALE_LAYER3(x, y, z)         ((x) * (y))
  265. #endif
  266. #ifndef REAL_SCALE_LAYER12
  267. # define REAL_SCALE_LAYER12(x)                          (x)
  268. #endif
  269. #ifndef REAL_SCALE_LAYER3
  270. # define REAL_SCALE_LAYER3(x, y)                        (x)
  271. #endif
  272. #ifndef REAL_SCALE_DCT64
  273. # define REAL_SCALE_DCT64(x)                            (x)
  274. #endif
  275.  
  276. /* used to be: AUDIOBUFSIZE = n*64 with n=1,2,3 ...
  277.    now: factor on minimum frame buffer size (which takes upsampling into account) */
  278. #define         AUDIOBUFSIZE            2
  279.  
  280. #include "true.h"
  281.  
  282. #define         MAX_NAME_SIZE           81
  283. #define         SBLIMIT                 32
  284. #define         SCALE_BLOCK             12
  285. #define         SSLIMIT                 18
  286.  
  287. /* Same as MPG_M_* */
  288. #define         MPG_MD_STEREO           0
  289. #define         MPG_MD_JOINT_STEREO     1
  290. #define         MPG_MD_DUAL_CHANNEL     2
  291. #define         MPG_MD_MONO             3
  292.  
  293. /* We support short or float output samples...
  294.    Short integer amplitude is scaled by this. */
  295. #define SHORT_SCALE 32768
  296. /* That scales a short-scaled value to a 32bit integer scaled one
  297.    value = 2**31/2**15 */
  298. #define S32_RESCALE 65536
  299.  
  300. /* Pre Shift fo 16 to 8 bit converter table */
  301. #define AUSHIFT (3)
  302.  
  303. #include "optimize.h"
  304. #include "decode.h"
  305. #include "parse.h"
  306. #include "frame.h"
  307.  
  308. /* fr is a mpg123_handle* by convention here... */
  309. #define NOQUIET  0 /*(!(fr->p.flags & MPG123_QUIET))*/
  310. #define VERBOSE  (NOQUIET && fr->p.verbose)
  311. #define VERBOSE2 (NOQUIET && fr->p.verbose > 1)
  312. #define VERBOSE3 (NOQUIET && fr->p.verbose > 2)
  313. #define VERBOSE4 (NOQUIET && fr->p.verbose > 3)
  314. #define PVERB(mp, level) 0 /*(!((mp)->flags & MPG123_QUIET) && (mp)->verbose >= (level)) */
  315.  
  316. int decode_update(mpg123_handle *mh);
  317. /* residing in format.c  */
  318. off_t samples_to_bytes(mpg123_handle *fr , off_t s);
  319. off_t bytes_to_samples(mpg123_handle *fr , off_t b);
  320.  
  321. #endif
  322.