decode_i386.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * decode_i396.c: Mpeg Layer-1,2,3 audio decoder
  3. *
  4. * Copyright (C) 1999-2010 The L.A.M.E. project
  5. *
  6. * Initially written by Michael Hipp, see also AUTHORS and README.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Library General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Library General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public
  19. * License along with this library; if not, write to the
  20. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. * Boston, MA 02111-1307, USA.
  22. *
  23. *
  24. * Slighlty optimized for machines without autoincrement/decrement.
  25. * The performance is highly compiler dependend. Maybe
  26. * the decode.c version for 'normal' processor may be faster
  27. * even for Intel processors.
  28. */
  29. /* $Id: decode_i386.c,v 1.22 2010/03/22 14:30:19 robert Exp $ */
  30. #ifdef HAVE_CONFIG_H
  31. #include <config.h>
  32. #endif
  33. #ifdef STDC_HEADERS
  34. # include <stdlib.h>
  35. # include <string.h>
  36. #else
  37. # ifndef HAVE_STRCHR
  38. # define strchr index
  39. # define strrchr rindex
  40. # endif
  41. char *strchr(), *strrchr();
  42. # ifndef HAVE_MEMCPY
  43. # define memcpy(d, s, n) bcopy ((s), (d), (n))
  44. # define memmove(d, s, n) bcopy ((s), (d), (n))
  45. # endif
  46. #endif
  47. #if defined(__riscos__) && defined(FPA10)
  48. #include "ymath.h"
  49. #else
  50. #include <math.h>
  51. #endif
  52. #include "decode_i386.h"
  53. #include "dct64_i386.h"
  54. #include "tabinit.h"
  55. #ifdef WITH_DMALLOC
  56. #include <dmalloc.h>
  57. #endif
  58. /* old WRITE_SAMPLE_CLIPPED */
  59. #define WRITE_SAMPLE_CLIPPED(TYPE,samples,sum,clip) \
  60. if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
  61. else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
  62. else { *(samples) = (TYPE)((sum)>0 ? (sum)+0.5 : (sum)-0.5) ; }
  63. #define WRITE_SAMPLE_UNCLIPPED(TYPE,samples,sum,clip) \
  64. *samples = (TYPE)sum;
  65. /* *INDENT-OFF* */
  66. /* versions: clipped (when TYPE == short) and unclipped (when TYPE == real) of synth_1to1_mono* functions */
  67. #define SYNTH_1TO1_MONO_CLIPCHOICE(TYPE,SYNTH_1TO1) \
  68. TYPE samples_tmp[64]; \
  69. TYPE *tmp1 = samples_tmp; \
  70. int i,ret; \
  71. int pnt1 = 0; \
  72. \
  73. ret = SYNTH_1TO1 (mp,bandPtr,0,(unsigned char *) samples_tmp,&pnt1); \
  74. out += *pnt; \
  75. \
  76. for(i=0;i<32;i++) { \
  77. *( (TYPE *) out) = *tmp1; \
  78. out += sizeof(TYPE); \
  79. tmp1 += 2; \
  80. } \
  81. *pnt += 32*sizeof(TYPE); \
  82. \
  83. return ret;
  84. /* *INDENT-ON* */
  85. int
  86. synth_1to1_mono(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt)
  87. {
  88. SYNTH_1TO1_MONO_CLIPCHOICE(short, synth_1to1)
  89. } int
  90. synth_1to1_mono_unclipped(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt)
  91. {
  92. SYNTH_1TO1_MONO_CLIPCHOICE(real, synth_1to1_unclipped)
  93. }
  94. /* *INDENT-OFF* */
  95. /* versions: clipped (when TYPE == short) and unclipped (when TYPE == real) of synth_1to1* functions */
  96. #define SYNTH_1TO1_CLIPCHOICE(TYPE,WRITE_SAMPLE) \
  97. static const int step = 2; \
  98. int bo; \
  99. TYPE *samples = (TYPE *) (out + *pnt); \
  100. \
  101. real *b0,(*buf)[0x110]; \
  102. int clip = 0; \
  103. int bo1; \
  104. \
  105. bo = mp->synth_bo; \
  106. \
  107. if(!channel) { \
  108. bo--; \
  109. bo &= 0xf; \
  110. buf = mp->synth_buffs[0]; \
  111. } \
  112. else { \
  113. samples++; \
  114. buf = mp->synth_buffs[1]; \
  115. } \
  116. \
  117. if(bo & 0x1) { \
  118. b0 = buf[0]; \
  119. bo1 = bo; \
  120. dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr); \
  121. } \
  122. else { \
  123. b0 = buf[1]; \
  124. bo1 = bo+1; \
  125. dct64(buf[0]+bo,buf[1]+bo+1,bandPtr); \
  126. } \
  127. \
  128. mp->synth_bo = bo; \
  129. \
  130. { \
  131. int j; \
  132. real *window = decwin + 16 - bo1; \
  133. \
  134. for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step) \
  135. { \
  136. real sum; \
  137. sum = window[0x0] * b0[0x0]; \
  138. sum -= window[0x1] * b0[0x1]; \
  139. sum += window[0x2] * b0[0x2]; \
  140. sum -= window[0x3] * b0[0x3]; \
  141. sum += window[0x4] * b0[0x4]; \
  142. sum -= window[0x5] * b0[0x5]; \
  143. sum += window[0x6] * b0[0x6]; \
  144. sum -= window[0x7] * b0[0x7]; \
  145. sum += window[0x8] * b0[0x8]; \
  146. sum -= window[0x9] * b0[0x9]; \
  147. sum += window[0xA] * b0[0xA]; \
  148. sum -= window[0xB] * b0[0xB]; \
  149. sum += window[0xC] * b0[0xC]; \
  150. sum -= window[0xD] * b0[0xD]; \
  151. sum += window[0xE] * b0[0xE]; \
  152. sum -= window[0xF] * b0[0xF]; \
  153. \
  154. WRITE_SAMPLE (TYPE,samples,sum,clip); \
  155. } \
  156. \
  157. { \
  158. real sum; \
  159. sum = window[0x0] * b0[0x0]; \
  160. sum += window[0x2] * b0[0x2]; \
  161. sum += window[0x4] * b0[0x4]; \
  162. sum += window[0x6] * b0[0x6]; \
  163. sum += window[0x8] * b0[0x8]; \
  164. sum += window[0xA] * b0[0xA]; \
  165. sum += window[0xC] * b0[0xC]; \
  166. sum += window[0xE] * b0[0xE]; \
  167. WRITE_SAMPLE (TYPE,samples,sum,clip); \
  168. b0-=0x10,window-=0x20,samples+=step; \
  169. } \
  170. window += bo1<<1; \
  171. \
  172. for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step) \
  173. { \
  174. real sum; \
  175. sum = -window[-0x1] * b0[0x0]; \
  176. sum -= window[-0x2] * b0[0x1]; \
  177. sum -= window[-0x3] * b0[0x2]; \
  178. sum -= window[-0x4] * b0[0x3]; \
  179. sum -= window[-0x5] * b0[0x4]; \
  180. sum -= window[-0x6] * b0[0x5]; \
  181. sum -= window[-0x7] * b0[0x6]; \
  182. sum -= window[-0x8] * b0[0x7]; \
  183. sum -= window[-0x9] * b0[0x8]; \
  184. sum -= window[-0xA] * b0[0x9]; \
  185. sum -= window[-0xB] * b0[0xA]; \
  186. sum -= window[-0xC] * b0[0xB]; \
  187. sum -= window[-0xD] * b0[0xC]; \
  188. sum -= window[-0xE] * b0[0xD]; \
  189. sum -= window[-0xF] * b0[0xE]; \
  190. sum -= window[-0x0] * b0[0xF]; \
  191. \
  192. WRITE_SAMPLE (TYPE,samples,sum,clip); \
  193. } \
  194. } \
  195. *pnt += 64*sizeof(TYPE); \
  196. \
  197. return clip;
  198. /* *INDENT-ON* */
  199. int
  200. synth_1to1(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
  201. {
  202. SYNTH_1TO1_CLIPCHOICE(short, WRITE_SAMPLE_CLIPPED)
  203. } int
  204. synth_1to1_unclipped(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
  205. {
  206. SYNTH_1TO1_CLIPCHOICE(real, WRITE_SAMPLE_UNCLIPPED)
  207. }