PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/codecs_v2/audio/mp3/dec/src/pvmp3_imdct_synth.cpp

https://github.com/Andproject/platform_external_opencore
C++ | 368 lines | 178 code | 57 blank | 133 comment | 13 complexity | 81d011979bd91cfd980052d5385a7d10 MD5 | raw file
  1. /* ------------------------------------------------------------------
  2. * Copyright (C) 1998-2009 PacketVideo
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied.
  14. * See the License for the specific language governing permissions
  15. * and limitations under the License.
  16. * -------------------------------------------------------------------
  17. */
  18. /*
  19. ------------------------------------------------------------------------------
  20. PacketVideo Corp.
  21. MP3 Decoder Library
  22. Filename: pvmp3_imdct_synth.cpp
  23. ------------------------------------------------------------------------------
  24. INPUT AND OUTPUT DEFINITIONS
  25. Input
  26. int32 in[], Pointer to spec values of current channel
  27. int32 overlap[], Pointer to overlap values of current channel
  28. uint32 blk_type, Block type
  29. int16 mx_band, In case of mixed blocks, # of bands with long
  30. blocks (2 or 4) else 0
  31. int32 *Scratch_mem
  32. Returns
  33. int32 in[],
  34. ------------------------------------------------------------------------------
  35. FUNCTION DESCRIPTION
  36. The frequency lines are preprocessed by the "alias reduction" scheme
  37. and fed into the IMDCT matrix, each 18 into one transform block.
  38. The first half of the output values are added to the stored overlap
  39. values from the last block. These values are new output values and
  40. are input values for the polyphase filterbank. The second half of the
  41. output values is stored for overlap with the next data granule.
  42. The number of windowed samples is 12 for short blocks, and 36 for long
  43. blocks
  44. Windowing
  45. Depending on window_switching_flag[gr][ch], block_type[gr][ch] and
  46. mixed_block_flag[gr][ch] different shapes of windows are used.
  47. normal window
  48. start window
  49. stop window
  50. short windows
  51. Each of the three short blocks is windowed separately.
  52. The windowed short blocks must be overlapped and concatenated.
  53. Overlapping and adding with previous block
  54. The first half (18 values) of the current block (36 values) has to be
  55. overlapped with the second half of the previous block. The second half
  56. of the current block has to be stored for overlapping with the next block
  57. ------------------------------------------------------------------------------
  58. REQUIREMENTS
  59. ------------------------------------------------------------------------------
  60. REFERENCES
  61. [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
  62. ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
  63. ------------------------------------------------------------------------------
  64. PSEUDO-CODE
  65. ------------------------------------------------------------------------------
  66. */
  67. /*----------------------------------------------------------------------------
  68. ; INCLUDES
  69. ----------------------------------------------------------------------------*/
  70. #include "pvmp3_imdct_synth.h"
  71. #include "pv_mp3dec_fxd_op.h"
  72. #include "pvmp3_dec_defs.h"
  73. #include "pvmp3_mdct_18.h"
  74. #include "pvmp3_mdct_6.h"
  75. #include "mp3_mem_funcs.h"
  76. /*----------------------------------------------------------------------------
  77. ; MACROS
  78. ; Define module specific macros here
  79. ----------------------------------------------------------------------------*/
  80. /*----------------------------------------------------------------------------
  81. ; DEFINES
  82. ; Include all pre-processor statements here. Include conditional
  83. ; compile variables also.
  84. ----------------------------------------------------------------------------*/
  85. #define LONG 0
  86. #define START 1
  87. #define SHORT 2
  88. #define STOP 3
  89. /*----------------------------------------------------------------------------
  90. ; LOCAL FUNCTION DEFINITIONS
  91. ; Function Prototype declaration
  92. ----------------------------------------------------------------------------*/
  93. /*----------------------------------------------------------------------------
  94. ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
  95. ; Variable declaration - defined here and used outside this module
  96. ----------------------------------------------------------------------------*/
  97. /*
  98. * sin(pi/36*(k+0.5)),k=0..35
  99. */
  100. const int32 normal_win[36] =
  101. {
  102. Qfmt_31(0.08723877473068f), Qfmt_31(0.26105238444010f), Qfmt_31(0.43287922787620f),
  103. Qfmt_31(0.60141159900854f), Qfmt_31(0.76536686473018f), Qfmt_31(0.92349722647006f),
  104. Qfmt_31(0.53729960834682f), Qfmt_31(0.60876142900872f), Qfmt_31(0.67559020761566f),
  105. Qfmt_31(-0.73727733681012f), Qfmt_31(-0.79335334029124f), Qfmt_31(0.84339144581289f),
  106. Qfmt_31(0.88701083317822f), Qfmt_31(0.92387953251129f), Qfmt_31(-0.95371695074823f),
  107. Qfmt_31(-0.97629600711993f), Qfmt_31(-0.99144486137381f), Qfmt_31(-0.99904822158186f),
  108. Qfmt_31(0.99904822158186f), Qfmt_31(0.99144486137381f), Qfmt_31(0.97629600711993f),
  109. Qfmt_31(0.95371695074823f), Qfmt_31(0.92387953251129f), Qfmt_31(0.88701083317822f),
  110. Qfmt_31(0.84339144581289f), Qfmt_31(0.79335334029124f), Qfmt_31(0.73727733681012f),
  111. Qfmt_31(0.67559020761566f), Qfmt_31(0.60876142900872f), Qfmt_31(0.53729960834682f),
  112. Qfmt_31(0.46174861323503f), Qfmt_31(0.38268343236509f), Qfmt_31(0.30070579950427f),
  113. Qfmt_31(0.21643961393810f), Qfmt_31(0.13052619222005f), Qfmt_31(0.04361938736534f)
  114. };
  115. const int32 start_win[36] =
  116. {
  117. /* k=0..17 sin(pi/36*(k+0.5)), */
  118. Qfmt_31(0.08723877473068f), Qfmt_31(0.26105238444010f), Qfmt_31(0.43287922787620f),
  119. Qfmt_31(0.60141159900854f), Qfmt_31(0.76536686473018f), Qfmt_31(0.92349722647006f),
  120. Qfmt_31(0.53729960834682f), Qfmt_31(0.60876142900872f), Qfmt_31(0.67559020761566f),
  121. Qfmt_31(-0.73727733681012f), Qfmt_31(-0.79335334029124f), Qfmt_31(0.84339144581289f),
  122. Qfmt_31(0.88701083317822f), Qfmt_31(0.92387953251129f), Qfmt_31(-0.95371695074823f),
  123. Qfmt_31(-0.97629600711993f), Qfmt_31(-0.99144486137381f), Qfmt_31(-0.99904822158186f),
  124. Qfmt_31(0.99999990000000f), Qfmt_31(0.99999990000000f), Qfmt_31(0.99999990000000f),
  125. Qfmt_31(0.99999990000000f), Qfmt_31(0.99999990000000f), Qfmt_31(0.99999990000000f),
  126. /* k=24..29; sin(pi/12*(k-18+0.5)) */
  127. Qfmt_31(0.99144486137381f), Qfmt_31(0.92387953251129f), Qfmt_31(0.79335334029124f),
  128. Qfmt_31(0.60876142900872f), Qfmt_31(0.38268343236509f), Qfmt_31(0.13052619222005f),
  129. Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f),
  130. Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f)
  131. };
  132. const int32 stop_win[36] =
  133. {
  134. Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f),
  135. Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f),
  136. /* k=6..11; sin(pi/12*(k-6+0.5)) */
  137. Qfmt_31(0.13052619222005f), Qfmt_31(0.38268343236509f), Qfmt_31(0.60876142900872f),
  138. Qfmt_31(-0.79335334029124f), Qfmt_31(-0.92387953251129f), Qfmt_31(0.99144486137381f),
  139. Qfmt_31(0.99999990000000f), Qfmt_31(0.99999990000000f), Qfmt_31(-0.99999990000000f),
  140. Qfmt_31(-0.99999990000000f), Qfmt_31(-0.99999990000000f), Qfmt_31(-0.99999990000000f),
  141. /* k=18..35 sin(pi/36*(k+0.5)), */
  142. Qfmt_31(0.99904822158186f), Qfmt_31(0.99144486137381f), Qfmt_31(0.97629600711993f),
  143. Qfmt_31(0.95371695074823f), Qfmt_31(0.92387953251129f), Qfmt_31(0.88701083317822f),
  144. Qfmt_31(0.84339144581289f), Qfmt_31(0.79335334029124f), Qfmt_31(0.73727733681012f),
  145. Qfmt_31(0.67559020761566f), Qfmt_31(0.60876142900872f), Qfmt_31(0.53729960834682f),
  146. Qfmt_31(0.46174861323503f), Qfmt_31(0.38268343236509f), Qfmt_31(0.30070579950427f),
  147. Qfmt_31(0.21643961393810f), Qfmt_31(0.13052619222005f), Qfmt_31(0.04361938736534f)
  148. };
  149. const int32 short_win[12] =
  150. {
  151. /* k=0..11; sin(pi/12*(k+0.5)) */
  152. Qfmt_31(0.13052619222005f), Qfmt_31(0.38268343236509f), Qfmt_31(0.60876142900872f),
  153. Qfmt_31(0.79335334029124f), Qfmt_31(0.92387953251129f), Qfmt_31(0.99144486137381f),
  154. Qfmt_31(0.99144486137381f), Qfmt_31(0.92387953251129f), Qfmt_31(0.79335334029124f),
  155. Qfmt_31(0.60876142900872f), Qfmt_31(0.38268343236509f), Qfmt_31(0.13052619222005f),
  156. };
  157. /*----------------------------------------------------------------------------
  158. ; EXTERNAL FUNCTION REFERENCES
  159. ; Declare functions defined elsewhere and referenced in this module
  160. ----------------------------------------------------------------------------*/
  161. /*----------------------------------------------------------------------------
  162. ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
  163. ; Declare variables used in this module but defined elsewhere
  164. ----------------------------------------------------------------------------*/
  165. /*----------------------------------------------------------------------------
  166. ; FUNCTION CODE
  167. ----------------------------------------------------------------------------*/
  168. void pvmp3_imdct_synth(int32 in[SUBBANDS_NUMBER*FILTERBANK_BANDS],
  169. int32 overlap[SUBBANDS_NUMBER*FILTERBANK_BANDS],
  170. uint32 blk_type,
  171. int16 mx_band,
  172. int32 used_freq_lines,
  173. int32 *Scratch_mem)
  174. {
  175. int32 band;
  176. int32 bands2process = used_freq_lines + 2;
  177. if (bands2process > SUBBANDS_NUMBER)
  178. {
  179. bands2process = SUBBANDS_NUMBER; /* default */
  180. }
  181. /*
  182. * in case of mx_poly_band> 0, do
  183. * long transforms
  184. */
  185. for (band = 0; band < bands2process; band++)
  186. {
  187. uint32 current_blk_type = (band < mx_band) ? LONG : blk_type;
  188. int32 * out = in + (band * FILTERBANK_BANDS);
  189. int32 * history = overlap + (band * FILTERBANK_BANDS);
  190. switch (current_blk_type)
  191. {
  192. case LONG:
  193. pvmp3_mdct_18(out, history, normal_win);
  194. break;
  195. case START:
  196. pvmp3_mdct_18(out, history, start_win);
  197. break;
  198. case STOP:
  199. pvmp3_mdct_18(out, history, stop_win);
  200. break;
  201. case SHORT:
  202. {
  203. int32 *tmp_prev_ovr = &Scratch_mem[FILTERBANK_BANDS];
  204. int32 i;
  205. for (i = 0; i < 6; i++)
  206. {
  207. Scratch_mem[i ] = out[(i*3)];
  208. Scratch_mem[6 +i] = out[(i*3) + 1];
  209. Scratch_mem[12 +i] = out[(i*3) + 2];
  210. }
  211. pvmp3_mdct_6(&Scratch_mem[ 0], &tmp_prev_ovr[ 0]);
  212. pvmp3_mdct_6(&Scratch_mem[ 6], &tmp_prev_ovr[ 6]);
  213. pvmp3_mdct_6(&Scratch_mem[12], &tmp_prev_ovr[12]);
  214. for (i = 0; i < 6; i++)
  215. {
  216. int32 temp = history[i];
  217. /* next iteration overlap */
  218. history[i] = fxp_mul32_Q32(tmp_prev_ovr[ 6+i] << 1, short_win[6+i]);
  219. history[i] += fxp_mul32_Q32(Scratch_mem[12+i] << 1, short_win[ i]);
  220. out[i] = temp;
  221. }
  222. for (i = 0; i < 6; i++)
  223. {
  224. out[i+6] = fxp_mul32_Q32(Scratch_mem[i] << 1, short_win[i]);
  225. out[i+6] += history[i+6];
  226. /* next iteration overlap */
  227. history[i+6] = fxp_mul32_Q32(tmp_prev_ovr[12+i] << 1, short_win[6+i]);
  228. }
  229. for (i = 0; i < 6; i++)
  230. {
  231. out[i+12] = fxp_mul32_Q32(tmp_prev_ovr[ i] << 1, short_win[6+i]);
  232. out[i+12] += fxp_mul32_Q32(Scratch_mem[6+i] << 1, short_win[ i]);
  233. out[i+12] += history[i+12];
  234. history[12+i] = 0;
  235. }
  236. }
  237. break;
  238. }
  239. /*
  240. * Compensation for frequency inversion of polyphase filterbank
  241. * every odd time sample of every odd odd subband is mulitplied by -1 before
  242. * processing by the polyphase filter
  243. */
  244. if (band & 1)
  245. {
  246. for (int32 slot = 1; slot < FILTERBANK_BANDS; slot += 6)
  247. {
  248. int32 temp1 = out[slot ];
  249. int32 temp2 = out[slot+2];
  250. int32 temp3 = out[slot+4];
  251. out[slot ] = -temp1;
  252. out[slot+2] = -temp2;
  253. out[slot+4] = -temp3;
  254. }
  255. }
  256. }
  257. for (band = bands2process; band < SUBBANDS_NUMBER; band++)
  258. {
  259. int32 * out = in + (band * FILTERBANK_BANDS);
  260. int32 * history = overlap + (band * FILTERBANK_BANDS);
  261. int32 slot;
  262. if (band & 1)
  263. {
  264. for (slot = 0; slot < FILTERBANK_BANDS; slot += 6)
  265. {
  266. int32 temp1 = history[slot ];
  267. int32 temp2 = history[slot+1];
  268. int32 temp3 = history[slot+2];
  269. out[slot ] = temp1;
  270. out[slot+1] = -temp2;
  271. out[slot+2] = temp3;
  272. temp1 = history[slot+3];
  273. temp2 = history[slot+4];
  274. temp3 = history[slot+5];
  275. out[slot+3] = -temp1;
  276. out[slot+4] = temp2;
  277. out[slot+5] = -temp3;
  278. }
  279. }
  280. else
  281. {
  282. for (slot = 0; slot < FILTERBANK_BANDS; slot += 3)
  283. {
  284. int32 temp1 = history[slot ];
  285. int32 temp2 = history[slot+1];
  286. int32 temp3 = history[slot+2];
  287. out[slot ] = temp1;
  288. out[slot+1] = temp2;
  289. out[slot+2] = temp3;
  290. }
  291. }
  292. pv_memset(history, 0, FILTERBANK_BANDS*sizeof(*overlap));
  293. }
  294. }