imdct.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Source last modified: $Id: imdct.c,v 1.1 2005/02/26 01:47:35 jrecker Exp $
  3. *
  4. * Portions Copyright (c) 1995-2005 RealNetworks, Inc. All Rights Reserved.
  5. *
  6. * The contents of this file, and the files included with this file,
  7. * are subject to the current version of the RealNetworks Public
  8. * Source License (the "RPSL") available at
  9. * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10. * the file under the current version of the RealNetworks Community
  11. * Source License (the "RCSL") available at
  12. * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13. * will apply. You may also obtain the license terms directly from
  14. * RealNetworks. You may not use this file except in compliance with
  15. * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16. * to this file, the RCSL. Please see the applicable RPSL or RCSL for
  17. * the rights, obligations and limitations governing use of the
  18. * contents of the file.
  19. *
  20. * This file is part of the Helix DNA Technology. RealNetworks is the
  21. * developer of the Original Code and owns the copyrights in the
  22. * portions it created.
  23. *
  24. * This file, and the files included with this file, is distributed
  25. * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  26. * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  27. * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  28. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  29. * ENJOYMENT OR NON-INFRINGEMENT.
  30. *
  31. * Technology Compatibility Kit Test Suite(s) Location:
  32. * http://www.helixcommunity.org/content/tck
  33. *
  34. * Contributor(s):
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. /**************************************************************************************
  38. * Fixed-point HE-AAC decoder
  39. * Jon Recker (jrecker@real.com)
  40. * February 2005
  41. *
  42. * imdct.c - inverse MDCT
  43. **************************************************************************************/
  44. #include "coder.h"
  45. #include "assembly.h"
  46. #define RND_VAL (1 << (FBITS_OUT_IMDCT-1))
  47. #ifndef AAC_ENABLE_SBR
  48. /**************************************************************************************
  49. * Function: DecWindowOverlap
  50. *
  51. * Description: apply synthesis window, do overlap-add, clip to 16-bit PCM,
  52. * for winSequence LONG-LONG
  53. *
  54. * Inputs: input buffer (output of type-IV DCT)
  55. * overlap buffer (saved from last time)
  56. * number of channels
  57. * window type (sin or KBD) for input buffer
  58. * window type (sin or KBD) for overlap buffer
  59. *
  60. * Outputs: one channel, one frame of 16-bit PCM, interleaved by nChans
  61. *
  62. * Return: none
  63. *
  64. * Notes: this processes one channel at a time, but skips every other sample in
  65. * the output buffer (pcm) for stereo interleaving
  66. * this should fit in registers on ARM
  67. *
  68. * TODO: ARM5E version with saturating overlap/add (QADD)
  69. * asm code with free pointer updates, better load scheduling
  70. **************************************************************************************/
  71. /*__attribute__ ((section (".data")))*/ static void DecWindowOverlap(int *buf0, int *over0, short *pcm0, int nChans, int winTypeCurr, int winTypePrev)
  72. {
  73. int in, w0, w1, f0, f1;
  74. int *buf1, *over1;
  75. short *pcm1;
  76. const int *wndPrev, *wndCurr;
  77. buf0 += (1024 >> 1);
  78. buf1 = buf0 - 1;
  79. pcm1 = pcm0 + (1024 - 1) * nChans;
  80. over1 = over0 + 1024 - 1;
  81. wndPrev = (winTypePrev == 1 ? kbdWindow + kbdWindowOffset[1] : sinWindow + sinWindowOffset[1]);
  82. if (winTypeCurr == winTypePrev) {
  83. /* cut window loads in half since current and overlap sections use same symmetric window */
  84. do {
  85. w0 = *wndPrev++;
  86. w1 = *wndPrev++;
  87. in = *buf0++;
  88. f0 = MULSHIFT32(w0, in);
  89. f1 = MULSHIFT32(w1, in);
  90. in = *over0;
  91. *pcm0 = CLIPTOSHORT( (in - f0 + RND_VAL) >> FBITS_OUT_IMDCT );
  92. pcm0 += nChans;
  93. in = *over1;
  94. *pcm1 = CLIPTOSHORT( (in + f1 + RND_VAL) >> FBITS_OUT_IMDCT );
  95. pcm1 -= nChans;
  96. in = *buf1--;
  97. *over1-- = MULSHIFT32(w0, in);
  98. *over0++ = MULSHIFT32(w1, in);
  99. } while (over0 < over1);
  100. } else {
  101. /* different windows for current and overlap parts - should still fit in registers on ARM w/o stack spill */
  102. wndCurr = (winTypeCurr == 1 ? kbdWindow + kbdWindowOffset[1] : sinWindow + sinWindowOffset[1]);
  103. do {
  104. w0 = *wndPrev++;
  105. w1 = *wndPrev++;
  106. in = *buf0++;
  107. f0 = MULSHIFT32(w0, in);
  108. f1 = MULSHIFT32(w1, in);
  109. in = *over0;
  110. *pcm0 = CLIPTOSHORT( (in - f0 + RND_VAL) >> FBITS_OUT_IMDCT );
  111. pcm0 += nChans;
  112. in = *over1;
  113. *pcm1 = CLIPTOSHORT( (in + f1 + RND_VAL) >> FBITS_OUT_IMDCT );
  114. pcm1 -= nChans;
  115. w0 = *wndCurr++;
  116. w1 = *wndCurr++;
  117. in = *buf1--;
  118. *over1-- = MULSHIFT32(w0, in);
  119. *over0++ = MULSHIFT32(w1, in);
  120. } while (over0 < over1);
  121. }
  122. }
  123. /**************************************************************************************
  124. * Function: DecWindowOverlapLongStart
  125. *
  126. * Description: apply synthesis window, do overlap-add, clip to 16-bit PCM,
  127. * for winSequence LONG-START
  128. *
  129. * Inputs: input buffer (output of type-IV DCT)
  130. * overlap buffer (saved from last time)
  131. * number of channels
  132. * window type (sin or KBD) for input buffer
  133. * window type (sin or KBD) for overlap buffer
  134. *
  135. * Outputs: one channel, one frame of 16-bit PCM, interleaved by nChans
  136. *
  137. * Return: none
  138. *
  139. * Notes: this processes one channel at a time, but skips every other sample in
  140. * the output buffer (pcm) for stereo interleaving
  141. * this should fit in registers on ARM
  142. *
  143. * TODO: ARM5E version with saturating overlap/add (QADD)
  144. * asm code with free pointer updates, better load scheduling
  145. **************************************************************************************/
  146. /*__attribute__ ((section (".data")))*/ static void DecWindowOverlapLongStart(int *buf0, int *over0, short *pcm0, int nChans, int winTypeCurr, int winTypePrev)
  147. {
  148. int i, in, w0, w1, f0, f1;
  149. int *buf1, *over1;
  150. short *pcm1;
  151. const int *wndPrev, *wndCurr;
  152. buf0 += (1024 >> 1);
  153. buf1 = buf0 - 1;
  154. pcm1 = pcm0 + (1024 - 1) * nChans;
  155. over1 = over0 + 1024 - 1;
  156. wndPrev = (winTypePrev == 1 ? kbdWindow + kbdWindowOffset[1] : sinWindow + sinWindowOffset[1]);
  157. i = 448; /* 2 outputs, 2 overlaps per loop */
  158. do {
  159. w0 = *wndPrev++;
  160. w1 = *wndPrev++;
  161. in = *buf0++;
  162. f0 = MULSHIFT32(w0, in);
  163. f1 = MULSHIFT32(w1, in);
  164. in = *over0;
  165. *pcm0 = CLIPTOSHORT( (in - f0 + RND_VAL) >> FBITS_OUT_IMDCT );
  166. pcm0 += nChans;
  167. in = *over1;
  168. *pcm1 = CLIPTOSHORT( (in + f1 + RND_VAL) >> FBITS_OUT_IMDCT );
  169. pcm1 -= nChans;
  170. in = *buf1--;
  171. *over1-- = 0; /* Wn = 0 for n = (2047, 2046, ... 1600) */
  172. *over0++ = in >> 1; /* Wn = 1 for n = (1024, 1025, ... 1471) */
  173. } while (--i);
  174. wndCurr = (winTypeCurr == 1 ? kbdWindow + kbdWindowOffset[0] : sinWindow + sinWindowOffset[0]);
  175. /* do 64 more loops - 2 outputs, 2 overlaps per loop */
  176. do {
  177. w0 = *wndPrev++;
  178. w1 = *wndPrev++;
  179. in = *buf0++;
  180. f0 = MULSHIFT32(w0, in);
  181. f1 = MULSHIFT32(w1, in);
  182. in = *over0;
  183. *pcm0 = CLIPTOSHORT( (in - f0 + RND_VAL) >> FBITS_OUT_IMDCT );
  184. pcm0 += nChans;
  185. in = *over1;
  186. *pcm1 = CLIPTOSHORT( (in + f1 + RND_VAL) >> FBITS_OUT_IMDCT );
  187. pcm1 -= nChans;
  188. w0 = *wndCurr++; /* W[0], W[1], ... --> W[255], W[254], ... */
  189. w1 = *wndCurr++; /* W[127], W[126], ... --> W[128], W[129], ... */
  190. in = *buf1--;
  191. *over1-- = MULSHIFT32(w0, in); /* Wn = short window for n = (1599, 1598, ... , 1536) */
  192. *over0++ = MULSHIFT32(w1, in); /* Wn = short window for n = (1472, 1473, ... , 1535) */
  193. } while (over0 < over1);
  194. }
  195. /**************************************************************************************
  196. * Function: DecWindowOverlapLongStop
  197. *
  198. * Description: apply synthesis window, do overlap-add, clip to 16-bit PCM,
  199. * for winSequence LONG-STOP
  200. *
  201. * Inputs: input buffer (output of type-IV DCT)
  202. * overlap buffer (saved from last time)
  203. * number of channels
  204. * window type (sin or KBD) for input buffer
  205. * window type (sin or KBD) for overlap buffer
  206. *
  207. * Outputs: one channel, one frame of 16-bit PCM, interleaved by nChans
  208. *
  209. * Return: none
  210. *
  211. * Notes: this processes one channel at a time, but skips every other sample in
  212. * the output buffer (pcm) for stereo interleaving
  213. * this should fit in registers on ARM
  214. *
  215. * TODO: ARM5E version with saturating overlap/add (QADD)
  216. * asm code with free pointer updates, better load scheduling
  217. **************************************************************************************/
  218. /*__attribute__ ((section (".data")))*/ static void DecWindowOverlapLongStop(int *buf0, int *over0, short *pcm0, int nChans, int winTypeCurr, int winTypePrev)
  219. {
  220. int i, in, w0, w1, f0, f1;
  221. int *buf1, *over1;
  222. short *pcm1;
  223. const int *wndPrev, *wndCurr;
  224. buf0 += (1024 >> 1);
  225. buf1 = buf0 - 1;
  226. pcm1 = pcm0 + (1024 - 1) * nChans;
  227. over1 = over0 + 1024 - 1;
  228. wndPrev = (winTypePrev == 1 ? kbdWindow + kbdWindowOffset[0] : sinWindow + sinWindowOffset[0]);
  229. wndCurr = (winTypeCurr == 1 ? kbdWindow + kbdWindowOffset[1] : sinWindow + sinWindowOffset[1]);
  230. i = 448; /* 2 outputs, 2 overlaps per loop */
  231. do {
  232. /* Wn = 0 for n = (0, 1, ... 447) */
  233. /* Wn = 1 for n = (576, 577, ... 1023) */
  234. in = *buf0++;
  235. f1 = in >> 1; /* scale since skipping multiply by Q31 */
  236. in = *over0;
  237. *pcm0 = CLIPTOSHORT( (in + RND_VAL) >> FBITS_OUT_IMDCT );
  238. pcm0 += nChans;
  239. in = *over1;
  240. *pcm1 = CLIPTOSHORT( (in + f1 + RND_VAL) >> FBITS_OUT_IMDCT );
  241. pcm1 -= nChans;
  242. w0 = *wndCurr++;
  243. w1 = *wndCurr++;
  244. in = *buf1--;
  245. *over1-- = MULSHIFT32(w0, in);
  246. *over0++ = MULSHIFT32(w1, in);
  247. } while (--i);
  248. /* do 64 more loops - 2 outputs, 2 overlaps per loop */
  249. do {
  250. w0 = *wndPrev++; /* W[0], W[1], ...W[63] */
  251. w1 = *wndPrev++; /* W[127], W[126], ... W[64] */
  252. in = *buf0++;
  253. f0 = MULSHIFT32(w0, in);
  254. f1 = MULSHIFT32(w1, in);
  255. in = *over0;
  256. *pcm0 = CLIPTOSHORT( (in - f0 + RND_VAL) >> FBITS_OUT_IMDCT );
  257. pcm0 += nChans;
  258. in = *over1;
  259. *pcm1 = CLIPTOSHORT( (in + f1 + RND_VAL) >> FBITS_OUT_IMDCT );
  260. pcm1 -= nChans;
  261. w0 = *wndCurr++;
  262. w1 = *wndCurr++;
  263. in = *buf1--;
  264. *over1-- = MULSHIFT32(w0, in);
  265. *over0++ = MULSHIFT32(w1, in);
  266. } while (over0 < over1);
  267. }
  268. /**************************************************************************************
  269. * Function: DecWindowOverlapShort
  270. *
  271. * Description: apply synthesis window, do overlap-add, clip to 16-bit PCM,
  272. * for winSequence EIGHT-SHORT (does all 8 short blocks)
  273. *
  274. * Inputs: input buffer (output of type-IV DCT)
  275. * overlap buffer (saved from last time)
  276. * number of channels
  277. * window type (sin or KBD) for input buffer
  278. * window type (sin or KBD) for overlap buffer
  279. *
  280. * Outputs: one channel, one frame of 16-bit PCM, interleaved by nChans
  281. *
  282. * Return: none
  283. *
  284. * Notes: this processes one channel at a time, but skips every other sample in
  285. * the output buffer (pcm) for stereo interleaving
  286. * this should fit in registers on ARM
  287. *
  288. * TODO: ARM5E version with saturating overlap/add (QADD)
  289. * asm code with free pointer updates, better load scheduling
  290. **************************************************************************************/
  291. /*__attribute__ ((section (".data"))) */ static void DecWindowOverlapShort(int *buf0, int *over0, short *pcm0, int nChans, int winTypeCurr, int winTypePrev)
  292. {
  293. int i, in, w0, w1, f0, f1;
  294. int *buf1, *over1;
  295. short *pcm1;
  296. const int *wndPrev, *wndCurr;
  297. wndPrev = (winTypePrev == 1 ? kbdWindow + kbdWindowOffset[0] : sinWindow + sinWindowOffset[0]);
  298. wndCurr = (winTypeCurr == 1 ? kbdWindow + kbdWindowOffset[0] : sinWindow + sinWindowOffset[0]);
  299. /* pcm[0-447] = 0 + overlap[0-447] */
  300. i = 448;
  301. do {
  302. f0 = *over0++;
  303. f1 = *over0++;
  304. *pcm0 = CLIPTOSHORT( (f0 + RND_VAL) >> FBITS_OUT_IMDCT ); pcm0 += nChans;
  305. *pcm0 = CLIPTOSHORT( (f1 + RND_VAL) >> FBITS_OUT_IMDCT ); pcm0 += nChans;
  306. i -= 2;
  307. } while (i);
  308. /* pcm[448-575] = Wp[0-127] * block0[0-127] + overlap[448-575] */
  309. pcm1 = pcm0 + (128 - 1) * nChans;
  310. over1 = over0 + 128 - 1;
  311. buf0 += 64;
  312. buf1 = buf0 - 1;
  313. do {
  314. w0 = *wndPrev++; /* W[0], W[1], ...W[63] */
  315. w1 = *wndPrev++; /* W[127], W[126], ... W[64] */
  316. in = *buf0++;
  317. f0 = MULSHIFT32(w0, in);
  318. f1 = MULSHIFT32(w1, in);
  319. in = *over0;
  320. *pcm0 = CLIPTOSHORT( (in - f0 + RND_VAL) >> FBITS_OUT_IMDCT );
  321. pcm0 += nChans;
  322. in = *over1;
  323. *pcm1 = CLIPTOSHORT( (in + f1 + RND_VAL) >> FBITS_OUT_IMDCT );
  324. pcm1 -= nChans;
  325. w0 = *wndCurr++;
  326. w1 = *wndCurr++;
  327. in = *buf1--;
  328. /* save over0/over1 for next short block, in the slots just vacated */
  329. *over1-- = MULSHIFT32(w0, in);
  330. *over0++ = MULSHIFT32(w1, in);
  331. } while (over0 < over1);
  332. /* pcm[576-703] = Wc[128-255] * block0[128-255] + Wc[0-127] * block1[0-127] + overlap[576-703]
  333. * pcm[704-831] = Wc[128-255] * block1[128-255] + Wc[0-127] * block2[0-127] + overlap[704-831]
  334. * pcm[832-959] = Wc[128-255] * block2[128-255] + Wc[0-127] * block3[0-127] + overlap[832-959]
  335. */
  336. for (i = 0; i < 3; i++) {
  337. pcm0 += 64 * nChans;
  338. pcm1 = pcm0 + (128 - 1) * nChans;
  339. over0 += 64;
  340. over1 = over0 + 128 - 1;
  341. buf0 += 64;
  342. buf1 = buf0 - 1;
  343. wndCurr -= 128;
  344. do {
  345. w0 = *wndCurr++; /* W[0], W[1], ...W[63] */
  346. w1 = *wndCurr++; /* W[127], W[126], ... W[64] */
  347. in = *buf0++;
  348. f0 = MULSHIFT32(w0, in);
  349. f1 = MULSHIFT32(w1, in);
  350. in = *(over0 - 128); /* from last short block */
  351. in += *(over0 + 0); /* from last full frame */
  352. *pcm0 = CLIPTOSHORT( (in - f0 + RND_VAL) >> FBITS_OUT_IMDCT );
  353. pcm0 += nChans;
  354. in = *(over1 - 128); /* from last short block */
  355. in += *(over1 + 0); /* from last full frame */
  356. *pcm1 = CLIPTOSHORT( (in + f1 + RND_VAL) >> FBITS_OUT_IMDCT );
  357. pcm1 -= nChans;
  358. /* save over0/over1 for next short block, in the slots just vacated */
  359. in = *buf1--;
  360. *over1-- = MULSHIFT32(w0, in);
  361. *over0++ = MULSHIFT32(w1, in);
  362. } while (over0 < over1);
  363. }
  364. /* pcm[960-1023] = Wc[128-191] * block3[128-191] + Wc[0-63] * block4[0-63] + overlap[960-1023]
  365. * over[0-63] = Wc[192-255] * block3[192-255] + Wc[64-127] * block4[64-127]
  366. */
  367. pcm0 += 64 * nChans;
  368. over0 -= 832; /* points at overlap[64] */
  369. over1 = over0 + 128 - 1; /* points at overlap[191] */
  370. buf0 += 64;
  371. buf1 = buf0 - 1;
  372. wndCurr -= 128;
  373. do {
  374. w0 = *wndCurr++; /* W[0], W[1], ...W[63] */
  375. w1 = *wndCurr++; /* W[127], W[126], ... W[64] */
  376. in = *buf0++;
  377. f0 = MULSHIFT32(w0, in);
  378. f1 = MULSHIFT32(w1, in);
  379. in = *(over0 + 768); /* from last short block */
  380. in += *(over0 + 896); /* from last full frame */
  381. *pcm0 = CLIPTOSHORT( (in - f0 + RND_VAL) >> FBITS_OUT_IMDCT );
  382. pcm0 += nChans;
  383. in = *(over1 + 768); /* from last short block */
  384. *(over1 - 128) = in + f1;
  385. in = *buf1--;
  386. *over1-- = MULSHIFT32(w0, in); /* save in overlap[128-191] */
  387. *over0++ = MULSHIFT32(w1, in); /* save in overlap[64-127] */
  388. } while (over0 < over1);
  389. /* over0 now points at overlap[128] */
  390. /* over[64-191] = Wc[128-255] * block4[128-255] + Wc[0-127] * block5[0-127]
  391. * over[192-319] = Wc[128-255] * block5[128-255] + Wc[0-127] * block6[0-127]
  392. * over[320-447] = Wc[128-255] * block6[128-255] + Wc[0-127] * block7[0-127]
  393. * over[448-576] = Wc[128-255] * block7[128-255]
  394. */
  395. for (i = 0; i < 3; i++) {
  396. over0 += 64;
  397. over1 = over0 + 128 - 1;
  398. buf0 += 64;
  399. buf1 = buf0 - 1;
  400. wndCurr -= 128;
  401. do {
  402. w0 = *wndCurr++; /* W[0], W[1], ...W[63] */
  403. w1 = *wndCurr++; /* W[127], W[126], ... W[64] */
  404. in = *buf0++;
  405. f0 = MULSHIFT32(w0, in);
  406. f1 = MULSHIFT32(w1, in);
  407. /* from last short block */
  408. *(over0 - 128) -= f0;
  409. *(over1 - 128)+= f1;
  410. in = *buf1--;
  411. *over1-- = MULSHIFT32(w0, in);
  412. *over0++ = MULSHIFT32(w1, in);
  413. } while (over0 < over1);
  414. }
  415. /* over[576-1024] = 0 */
  416. i = 448;
  417. over0 += 64;
  418. do {
  419. *over0++ = 0;
  420. *over0++ = 0;
  421. *over0++ = 0;
  422. *over0++ = 0;
  423. i -= 4;
  424. } while (i);
  425. }
  426. #endif /* !AAC_ENABLE_SBR */
  427. /**************************************************************************************
  428. * Function: IMDCT
  429. *
  430. * Description: inverse transform and convert to 16-bit PCM
  431. *
  432. * Inputs: valid AACDecInfo struct
  433. * index of current channel (0 for SCE/LFE, 0 or 1 for CPE)
  434. * output channel (range = [0, nChans-1])
  435. *
  436. * Outputs: complete frame of decoded PCM, after inverse transform
  437. *
  438. * Return: 0 if successful, -1 if error
  439. *
  440. * Notes: If AAC_ENABLE_SBR is defined at compile time then window + overlap
  441. * does NOT clip to 16-bit PCM and does NOT interleave channels
  442. * If AAC_ENABLE_SBR is NOT defined at compile time, then window + overlap
  443. * does clip to 16-bit PCM and interleaves channels
  444. * If SBR is enabled at compile time, but we don't know whether it is
  445. * actually used for this frame (e.g. the first frame of a stream),
  446. * we need to produce both clipped 16-bit PCM in outbuf AND
  447. * unclipped 32-bit PCM in the SBR input buffer. In this case we make
  448. * a separate pass over the 32-bit PCM to produce 16-bit PCM output.
  449. * This inflicts a slight performance hit when decoding non-SBR files.
  450. **************************************************************************************/
  451. int IMDCT(AACDecInfo *aacDecInfo, int ch, int chOut, short *outbuf)
  452. {
  453. int i;
  454. PSInfoBase *psi;
  455. ICSInfo *icsInfo;
  456. /* validate pointers */
  457. if (!aacDecInfo || !aacDecInfo->psInfoBase)
  458. return -1;
  459. psi = (PSInfoBase *)(aacDecInfo->psInfoBase);
  460. icsInfo = (ch == 1 && psi->commonWin == 1) ? &(psi->icsInfo[0]) : &(psi->icsInfo[ch]);
  461. outbuf += chOut;
  462. /* optimized type-IV DCT (operates inplace) */
  463. if (icsInfo->winSequence == 2) {
  464. /* 8 short blocks */
  465. for (i = 0; i < 8; i++)
  466. DCT4(0, psi->coef[ch] + i*128, psi->gbCurrent[ch]);
  467. } else {
  468. /* 1 long block */
  469. DCT4(1, psi->coef[ch], psi->gbCurrent[ch]);
  470. }
  471. #ifdef AAC_ENABLE_SBR
  472. /* window, overlap-add, don't clip to short (send to SBR decoder)
  473. * store the decoded 32-bit samples in top half (second AAC_MAX_NSAMPS samples) of coef buffer
  474. */
  475. if (icsInfo->winSequence == 0)
  476. DecWindowOverlapNoClip(psi->coef[ch], psi->overlap[chOut], psi->sbrWorkBuf[ch], icsInfo->winShape, psi->prevWinShape[chOut]);
  477. else if (icsInfo->winSequence == 1)
  478. DecWindowOverlapLongStartNoClip(psi->coef[ch], psi->overlap[chOut], psi->sbrWorkBuf[ch], icsInfo->winShape, psi->prevWinShape[chOut]);
  479. else if (icsInfo->winSequence == 2)
  480. DecWindowOverlapShortNoClip(psi->coef[ch], psi->overlap[chOut], psi->sbrWorkBuf[ch], icsInfo->winShape, psi->prevWinShape[chOut]);
  481. else if (icsInfo->winSequence == 3)
  482. DecWindowOverlapLongStopNoClip(psi->coef[ch], psi->overlap[chOut], psi->sbrWorkBuf[ch], icsInfo->winShape, psi->prevWinShape[chOut]);
  483. if (!aacDecInfo->sbrEnabled) {
  484. for (i = 0; i < AAC_MAX_NSAMPS; i++) {
  485. *outbuf = CLIPTOSHORT((psi->sbrWorkBuf[ch][i] + RND_VAL) >> FBITS_OUT_IMDCT);
  486. outbuf += aacDecInfo->nChans;
  487. }
  488. }
  489. aacDecInfo->rawSampleBuf[ch] = psi->sbrWorkBuf[ch];
  490. aacDecInfo->rawSampleBytes = sizeof(int);
  491. aacDecInfo->rawSampleFBits = FBITS_OUT_IMDCT;
  492. #else
  493. /* window, overlap-add, round to PCM - optimized for each window sequence */
  494. if (icsInfo->winSequence == 0)
  495. DecWindowOverlap(psi->coef[ch], psi->overlap[chOut], outbuf, aacDecInfo->nChans, icsInfo->winShape, psi->prevWinShape[chOut]);
  496. else if (icsInfo->winSequence == 1)
  497. DecWindowOverlapLongStart(psi->coef[ch], psi->overlap[chOut], outbuf, aacDecInfo->nChans, icsInfo->winShape, psi->prevWinShape[chOut]);
  498. else if (icsInfo->winSequence == 2)
  499. DecWindowOverlapShort(psi->coef[ch], psi->overlap[chOut], outbuf, aacDecInfo->nChans, icsInfo->winShape, psi->prevWinShape[chOut]);
  500. else if (icsInfo->winSequence == 3)
  501. DecWindowOverlapLongStop(psi->coef[ch], psi->overlap[chOut], outbuf, aacDecInfo->nChans, icsInfo->winShape, psi->prevWinShape[chOut]);
  502. aacDecInfo->rawSampleBuf[ch] = 0;
  503. aacDecInfo->rawSampleBytes = 0;
  504. aacDecInfo->rawSampleFBits = 0;
  505. #endif
  506. psi->prevWinShape[chOut] = icsInfo->winShape;
  507. return 0;
  508. }