You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10155 lines
411 KiB

  1. From 022f1b86ef2f992c1c5623719e403b9b28e1becc Mon Sep 17 00:00:00 2001
  2. From: Wim Taymans <wtaymans@redhat.com>
  3. Date: Mon, 24 Jun 2019 16:26:20 +0200
  4. Subject: Remove HCR, RVLC, error concealment
  5. ---
  6. Makefile.am | 7 -
  7. Makefile.vc | 7 -
  8. libAACdec/src/aac_ram.h | 3 -
  9. libAACdec/src/aac_rom.cpp | 96 --
  10. libAACdec/src/aac_rom.h | 4 +-
  11. libAACdec/src/aacdec_hcr.cpp | 1498 ---------------------------
  12. libAACdec/src/aacdec_hcr.h | 128 ---
  13. libAACdec/src/aacdec_hcr_bit.cpp | 164 ---
  14. libAACdec/src/aacdec_hcr_bit.h | 114 ---
  15. libAACdec/src/aacdec_hcr_types.h | 432 --------
  16. libAACdec/src/aacdec_hcrs.cpp | 1551 ----------------------------
  17. libAACdec/src/aacdec_hcrs.h | 176 ----
  18. libAACdec/src/aacdecoder.cpp | 91 +-
  19. libAACdec/src/aacdecoder.h | 3 -
  20. libAACdec/src/aacdecoder_lib.cpp | 73 +-
  21. libAACdec/src/block.cpp | 59 +-
  22. libAACdec/src/channel.cpp | 19 +-
  23. libAACdec/src/channelinfo.h | 22 -
  24. libAACdec/src/conceal.cpp | 2095 --------------------------------------
  25. libAACdec/src/conceal.h | 152 ---
  26. libAACdec/src/conceal_types.h | 203 ----
  27. libAACdec/src/rvlc.cpp | 1217 ----------------------
  28. libAACdec/src/rvlc.h | 153 ---
  29. libAACdec/src/rvlc_info.h | 204 ----
  30. libAACdec/src/rvlcbit.cpp | 148 ---
  31. libAACdec/src/rvlcbit.h | 111 --
  32. libAACdec/src/rvlcconceal.cpp | 787 --------------
  33. libAACdec/src/rvlcconceal.h | 127 ---
  34. libAACdec/src/usacdec_lpd.cpp | 20 +-
  35. 29 files changed, 21 insertions(+), 9643 deletions(-)
  36. delete mode 100644 libAACdec/src/aacdec_hcr.cpp
  37. delete mode 100644 libAACdec/src/aacdec_hcr.h
  38. delete mode 100644 libAACdec/src/aacdec_hcr_bit.cpp
  39. delete mode 100644 libAACdec/src/aacdec_hcr_bit.h
  40. delete mode 100644 libAACdec/src/aacdec_hcr_types.h
  41. delete mode 100644 libAACdec/src/aacdec_hcrs.cpp
  42. delete mode 100644 libAACdec/src/aacdec_hcrs.h
  43. delete mode 100644 libAACdec/src/conceal.cpp
  44. delete mode 100644 libAACdec/src/conceal.h
  45. delete mode 100644 libAACdec/src/conceal_types.h
  46. delete mode 100644 libAACdec/src/rvlc.cpp
  47. delete mode 100644 libAACdec/src/rvlc.h
  48. delete mode 100644 libAACdec/src/rvlc_info.h
  49. delete mode 100644 libAACdec/src/rvlcbit.cpp
  50. delete mode 100644 libAACdec/src/rvlcbit.h
  51. delete mode 100644 libAACdec/src/rvlcconceal.cpp
  52. delete mode 100644 libAACdec/src/rvlcconceal.h
  53. --- a/Makefile.am
  54. +++ b/Makefile.am
  55. @@ -50,9 +50,6 @@ AACDEC_SRC = \
  56. libAACdec/src/aac_ram.cpp \
  57. libAACdec/src/aac_rom.cpp \
  58. libAACdec/src/aacdec_drc.cpp \
  59. - libAACdec/src/aacdec_hcr.cpp \
  60. - libAACdec/src/aacdec_hcr_bit.cpp \
  61. - libAACdec/src/aacdec_hcrs.cpp \
  62. libAACdec/src/aacdec_pns.cpp \
  63. libAACdec/src/aacdec_tns.cpp \
  64. libAACdec/src/aacdecoder.cpp \
  65. @@ -60,12 +57,8 @@ AACDEC_SRC = \
  66. libAACdec/src/block.cpp \
  67. libAACdec/src/channel.cpp \
  68. libAACdec/src/channelinfo.cpp \
  69. - libAACdec/src/conceal.cpp \
  70. libAACdec/src/ldfiltbank.cpp \
  71. libAACdec/src/pulsedata.cpp \
  72. - libAACdec/src/rvlc.cpp \
  73. - libAACdec/src/rvlcbit.cpp \
  74. - libAACdec/src/rvlcconceal.cpp \
  75. libAACdec/src/stereo.cpp \
  76. libAACdec/src/usacdec_ace_d4t64.cpp \
  77. libAACdec/src/usacdec_ace_ltp.cpp \
  78. --- a/Makefile.vc
  79. +++ b/Makefile.vc
  80. @@ -34,9 +34,6 @@ AACDEC_SRC = \
  81. libAACdec/src/aac_ram.cpp \
  82. libAACdec/src/aac_rom.cpp \
  83. libAACdec/src/aacdec_drc.cpp \
  84. - libAACdec/src/aacdec_hcr.cpp \
  85. - libAACdec/src/aacdec_hcr_bit.cpp \
  86. - libAACdec/src/aacdec_hcrs.cpp \
  87. libAACdec/src/aacdec_pns.cpp \
  88. libAACdec/src/aacdec_tns.cpp \
  89. libAACdec/src/aacdecoder.cpp \
  90. @@ -44,12 +41,8 @@ AACDEC_SRC = \
  91. libAACdec/src/block.cpp \
  92. libAACdec/src/channel.cpp \
  93. libAACdec/src/channelinfo.cpp \
  94. - libAACdec/src/conceal.cpp \
  95. libAACdec/src/ldfiltbank.cpp \
  96. libAACdec/src/pulsedata.cpp \
  97. - libAACdec/src/rvlc.cpp \
  98. - libAACdec/src/rvlcbit.cpp \
  99. - libAACdec/src/rvlcconceal.cpp \
  100. libAACdec/src/stereo.cpp \
  101. libAACdec/src/usacdec_ace_d4t64.cpp \
  102. libAACdec/src/usacdec_ace_ltp.cpp \
  103. --- a/libAACdec/src/aac_ram.h
  104. +++ b/libAACdec/src/aac_ram.h
  105. @@ -111,9 +111,6 @@ amm-info@iis.fraunhofer.de
  106. #include "ac_arith_coder.h"
  107. -#include "aacdec_hcr_types.h"
  108. -#include "aacdec_hcr.h"
  109. -
  110. /* End of formal fix.h */
  111. #define MAX_SYNCHS 10
  112. --- a/libAACdec/src/aac_rom.cpp
  113. +++ b/libAACdec/src/aac_rom.cpp
  114. @@ -1583,102 +1583,6 @@ const SCHAR *aQuantTable[] = {
  115. aValTab24, /* 30 6 */
  116. aValTab24}; /* 31 6 */
  117. -/* arrays for HCR_TABLE_INFO structures */
  118. -/* maximum length of codeword in each codebook */
  119. -/* codebook: 0,1, 2,3, 4, 5, 6, 7, 8, 9,
  120. - * 10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 */
  121. -const UCHAR aMaxCwLen[MAX_CB] = {0, 11, 9, 20, 16, 13, 11, 14, 12, 17, 14,
  122. - 49, 0, 0, 0, 0, 14, 17, 21, 21, 25, 25,
  123. - 29, 29, 29, 29, 33, 33, 33, 37, 37, 41};
  124. -
  125. -/* 11 13 15 17 19
  126. - * 21 23 25 27 39 31 */
  127. -/* CB: 0 1 2 3 4 5 6 7 8 9 10 12 14 16 18 20
  128. - * 22 24 26 28 30 */
  129. -const UCHAR aDimCb[MAX_CB] = {
  130. - 2, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2,
  131. - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; /* codebook dimension -
  132. - zero cb got a
  133. - dimension of 2 */
  134. -
  135. -/* 11 13 15 17 19
  136. - * 21 23 25 27 39 31 */
  137. -/* CB: 0 1 2 3 4 5 6 7 8 9 10 12 14 16 18 20
  138. - * 22 24 26 28 30 */
  139. -const UCHAR aDimCbShift[MAX_CB] = {
  140. - 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,
  141. - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; /* codebook dimension */
  142. -
  143. -/* 1 -> decode sign bits */
  144. -/* 0 -> decode no sign bits 11 13 15 17 19 21
  145. - * 23 25 27 39 31 */
  146. -/* CB: 0 1 2 3 4 5 6 7 8 9 10 12 14 16 18 20 22
  147. - * 24 26 28 30 */
  148. -const UCHAR aSignCb[MAX_CB] = {0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0,
  149. - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
  150. -
  151. -/* arrays for HCR_CB_PAIRS structures */
  152. -const UCHAR aMinOfCbPair[MAX_CB_PAIRS] = {0, 1, 3, 5, 7, 9, 16, 17,
  153. - 18, 19, 20, 21, 22, 23, 24, 25,
  154. - 26, 27, 28, 29, 30, 31, 11};
  155. -const UCHAR aMaxOfCbPair[MAX_CB_PAIRS] = {0, 2, 4, 6, 8, 10, 16, 17,
  156. - 18, 19, 20, 21, 22, 23, 24, 25,
  157. - 26, 27, 28, 29, 30, 31, 11};
  158. -
  159. -/* priorities of codebooks */
  160. -const UCHAR aCbPriority[MAX_CB] = {0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
  161. - 22, 0, 0, 0, 0, 6, 7, 8, 9, 10, 11,
  162. - 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
  163. -
  164. -const SCHAR aCodebook2StartInt[] = {STOP_THIS_STATE, /* cb 0 */
  165. - BODY_ONLY, /* cb 1 */
  166. - BODY_ONLY, /* cb 2 */
  167. - BODY_SIGN__BODY, /* cb 3 */
  168. - BODY_SIGN__BODY, /* cb 4 */
  169. - BODY_ONLY, /* cb 5 */
  170. - BODY_ONLY, /* cb 6 */
  171. - BODY_SIGN__BODY, /* cb 7 */
  172. - BODY_SIGN__BODY, /* cb 8 */
  173. - BODY_SIGN__BODY, /* cb 9 */
  174. - BODY_SIGN__BODY, /* cb 10 */
  175. - BODY_SIGN_ESC__BODY, /* cb 11 */
  176. - STOP_THIS_STATE, /* cb 12 */
  177. - STOP_THIS_STATE, /* cb 13 */
  178. - STOP_THIS_STATE, /* cb 14 */
  179. - STOP_THIS_STATE, /* cb 15 */
  180. - BODY_SIGN_ESC__BODY, /* cb 16 */
  181. - BODY_SIGN_ESC__BODY, /* cb 17 */
  182. - BODY_SIGN_ESC__BODY, /* cb 18 */
  183. - BODY_SIGN_ESC__BODY, /* cb 19 */
  184. - BODY_SIGN_ESC__BODY, /* cb 20 */
  185. - BODY_SIGN_ESC__BODY, /* cb 21 */
  186. - BODY_SIGN_ESC__BODY, /* cb 22 */
  187. - BODY_SIGN_ESC__BODY, /* cb 23 */
  188. - BODY_SIGN_ESC__BODY, /* cb 24 */
  189. - BODY_SIGN_ESC__BODY, /* cb 25 */
  190. - BODY_SIGN_ESC__BODY, /* cb 26 */
  191. - BODY_SIGN_ESC__BODY, /* cb 27 */
  192. - BODY_SIGN_ESC__BODY, /* cb 28 */
  193. - BODY_SIGN_ESC__BODY, /* cb 29 */
  194. - BODY_SIGN_ESC__BODY, /* cb 30 */
  195. - BODY_SIGN_ESC__BODY}; /* cb 31 */
  196. -
  197. -const STATEFUNC aStateConstant2State[] = {
  198. - NULL, /* 0 = STOP_THIS_STATE */
  199. - Hcr_State_BODY_ONLY, /* 1 = BODY_ONLY */
  200. - Hcr_State_BODY_SIGN__BODY, /* 2 = BODY_SIGN__BODY */
  201. - Hcr_State_BODY_SIGN__SIGN, /* 3 = BODY_SIGN__SIGN */
  202. - Hcr_State_BODY_SIGN_ESC__BODY, /* 4 = BODY_SIGN_ESC__BODY */
  203. - Hcr_State_BODY_SIGN_ESC__SIGN, /* 5 = BODY_SIGN_ESC__SIGN */
  204. - Hcr_State_BODY_SIGN_ESC__ESC_PREFIX, /* 6 = BODY_SIGN_ESC__ESC_PREFIX */
  205. - Hcr_State_BODY_SIGN_ESC__ESC_WORD}; /* 7 = BODY_SIGN_ESC__ESC_WORD */
  206. -
  207. -/* CB: 0 1 2 3 4 5 6 7 8 9 10 12
  208. - * 14 16 18 20 22 24 26 28 30 */
  209. -const USHORT aLargestAbsoluteValue[MAX_CB] = {
  210. - 0, 1, 1, 2, 2, 4, 4, 7, 7, 12, 12,
  211. - 8191, 0, 0, 0, 0, 15, 31, 47, 63, 95, 127,
  212. - 159, 191, 223, 255, 319, 383, 511, 767, 1023, 2047}; /* lav */
  213. /* CB: 11 13
  214. * 15 17 19 21 23 25 27 39 31 */
  215. --- a/libAACdec/src/aac_rom.h
  216. +++ b/libAACdec/src/aac_rom.h
  217. @@ -105,8 +105,6 @@ amm-info@iis.fraunhofer.de
  218. #include "common_fix.h"
  219. #include "FDK_audio.h"
  220. -#include "aacdec_hcr_types.h"
  221. -#include "aacdec_hcrs.h"
  222. #define PCM_DEC FIXP_DBL
  223. #define MAXVAL_PCM_DEC MAXVAL_DBL
  224. @@ -165,7 +163,7 @@ typedef struct {
  225. extern const CodeBookDescription AACcodeBookDescriptionTable[13];
  226. extern const CodeBookDescription AACcodeBookDescriptionSCL;
  227. -extern const STATEFUNC aStateConstant2State[];
  228. +#define MAX_CB 32 /* last used CB is cb #31 when VCB11 is used */
  229. extern const SCHAR aCodebook2StartInt[];
  230. --- a/libAACdec/src/aacdec_hcr.cpp
  231. +++ /dev/null
  232. @@ -1,1498 +0,0 @@
  233. -/* -----------------------------------------------------------------------------
  234. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  235. -
  236. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  237. -Forschung e.V. All rights reserved.
  238. -
  239. - 1. INTRODUCTION
  240. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  241. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  242. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  243. -a wide variety of Android devices.
  244. -
  245. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  246. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  247. -full-bandwidth communications codec by independent studies and is widely
  248. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  249. -specifications.
  250. -
  251. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  252. -those of Fraunhofer) may be obtained through Via Licensing
  253. -(www.vialicensing.com) or through the respective patent owners individually for
  254. -the purpose of encoding or decoding bit streams in products that are compliant
  255. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  256. -Android devices already license these patent claims through Via Licensing or
  257. -directly from the patent owners, and therefore FDK AAC Codec software may
  258. -already be covered under those patent licenses when it is used for those
  259. -licensed purposes only.
  260. -
  261. -Commercially-licensed AAC software libraries, including floating-point versions
  262. -with enhanced sound quality, are also available from Fraunhofer. Users are
  263. -encouraged to check the Fraunhofer website for additional applications
  264. -information and documentation.
  265. -
  266. -2. COPYRIGHT LICENSE
  267. -
  268. -Redistribution and use in source and binary forms, with or without modification,
  269. -are permitted without payment of copyright license fees provided that you
  270. -satisfy the following conditions:
  271. -
  272. -You must retain the complete text of this software license in redistributions of
  273. -the FDK AAC Codec or your modifications thereto in source code form.
  274. -
  275. -You must retain the complete text of this software license in the documentation
  276. -and/or other materials provided with redistributions of the FDK AAC Codec or
  277. -your modifications thereto in binary form. You must make available free of
  278. -charge copies of the complete source code of the FDK AAC Codec and your
  279. -modifications thereto to recipients of copies in binary form.
  280. -
  281. -The name of Fraunhofer may not be used to endorse or promote products derived
  282. -from this library without prior written permission.
  283. -
  284. -You may not charge copyright license fees for anyone to use, copy or distribute
  285. -the FDK AAC Codec software or your modifications thereto.
  286. -
  287. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  288. -that you changed the software and the date of any change. For modified versions
  289. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  290. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  291. -AAC Codec Library for Android."
  292. -
  293. -3. NO PATENT LICENSE
  294. -
  295. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  296. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  297. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  298. -software.
  299. -
  300. -You may use this FDK AAC Codec software or modifications thereto only for
  301. -purposes that are authorized by appropriate patent licenses.
  302. -
  303. -4. DISCLAIMER
  304. -
  305. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  306. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  307. -including but not limited to the implied warranties of merchantability and
  308. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  309. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  310. -or consequential damages, including but not limited to procurement of substitute
  311. -goods or services; loss of use, data, or profits, or business interruption,
  312. -however caused and on any theory of liability, whether in contract, strict
  313. -liability, or tort (including negligence), arising in any way out of the use of
  314. -this software, even if advised of the possibility of such damage.
  315. -
  316. -5. CONTACT INFORMATION
  317. -
  318. -Fraunhofer Institute for Integrated Circuits IIS
  319. -Attention: Audio and Multimedia Departments - FDK AAC LL
  320. -Am Wolfsmantel 33
  321. -91058 Erlangen, Germany
  322. -
  323. -www.iis.fraunhofer.de/amm
  324. -amm-info@iis.fraunhofer.de
  325. ------------------------------------------------------------------------------ */
  326. -
  327. -/**************************** AAC decoder library ******************************
  328. -
  329. - Author(s): Robert Weidner (DSP Solutions)
  330. -
  331. - Description: HCR Decoder: HCR initialization, preprocess HCR sideinfo,
  332. - decode priority codewords (PCWs)
  333. -
  334. -*******************************************************************************/
  335. -
  336. -#include "aacdec_hcr.h"
  337. -
  338. -#include "aacdec_hcr_types.h"
  339. -#include "aacdec_hcr_bit.h"
  340. -#include "aacdec_hcrs.h"
  341. -#include "aac_ram.h"
  342. -#include "aac_rom.h"
  343. -#include "channel.h"
  344. -#include "block.h"
  345. -
  346. -#include "aacdecoder.h" /* for ID_CPE, ID_SCE ... */
  347. -#include "FDK_bitstream.h"
  348. -
  349. -extern int mlFileChCurr;
  350. -
  351. -static void errDetectorInHcrSideinfoShrt(SCHAR cb, SHORT numLine,
  352. - UINT *errorWord);
  353. -
  354. -static void errDetectorInHcrLengths(SCHAR lengthOfLongestCodeword,
  355. - SHORT lengthOfReorderedSpectralData,
  356. - UINT *errorWord);
  357. -
  358. -static void HcrCalcNumCodeword(H_HCR_INFO pHcr);
  359. -static void HcrSortCodebookAndNumCodewordInSection(H_HCR_INFO pHcr);
  360. -static void HcrPrepareSegmentationGrid(H_HCR_INFO pHcr);
  361. -static void HcrExtendedSectionInfo(H_HCR_INFO pHcr);
  362. -
  363. -static void DeriveNumberOfExtendedSortedSectionsInSets(
  364. - UINT numSegment, USHORT *pNumExtendedSortedCodewordInSection,
  365. - int numExtendedSortedCodewordInSectionIdx,
  366. - USHORT *pNumExtendedSortedSectionsInSets,
  367. - int numExtendedSortedSectionsInSetsIdx);
  368. -
  369. -static INT DecodeEscapeSequence(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  370. - INT quantSpecCoef, INT *pLeftStartOfSegment,
  371. - SCHAR *pRemainingBitsInSegment,
  372. - int *pNumDecodedBits);
  373. -
  374. -static int DecodePCW_Sign(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  375. - UINT codebookDim, const SCHAR *pQuantVal,
  376. - FIXP_DBL *pQuantSpecCoef, int *quantSpecCoefIdx,
  377. - INT *pLeftStartOfSegment,
  378. - SCHAR *pRemainingBitsInSegment, int *pNumDecodedBits);
  379. -
  380. -static const SCHAR *DecodePCW_Body(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  381. - const UINT *pCurrentTree,
  382. - const SCHAR *pQuantValBase,
  383. - INT *pLeftStartOfSegment,
  384. - SCHAR *pRemainingBitsInSegment,
  385. - int *pNumDecodedBits);
  386. -
  387. -static void DecodePCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO pHcr);
  388. -
  389. -static void HcrReorderQuantizedSpectralCoefficients(
  390. - H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  391. - const SamplingRateInfo *pSamplingRateInfo);
  392. -
  393. -static UCHAR errDetectPcwSegmentation(SCHAR remainingBitsInSegment,
  394. - H_HCR_INFO pHcr, PCW_TYPE kind,
  395. - FIXP_DBL *qsc_base_of_cw,
  396. - UCHAR dimension);
  397. -
  398. -static void errDetectWithinSegmentationFinal(H_HCR_INFO pHcr);
  399. -
  400. -/*---------------------------------------------------------------------------------------------
  401. - description: Check if codebook and numSect are within allowed range
  402. -(short only)
  403. ---------------------------------------------------------------------------------------------
  404. -*/
  405. -static void errDetectorInHcrSideinfoShrt(SCHAR cb, SHORT numLine,
  406. - UINT *errorWord) {
  407. - if (cb < ZERO_HCB || cb >= MAX_CB_CHECK || cb == BOOKSCL) {
  408. - *errorWord |= CB_OUT_OF_RANGE_SHORT_BLOCK;
  409. - }
  410. - if (numLine < 0 || numLine > 1024) {
  411. - *errorWord |= LINE_IN_SECT_OUT_OF_RANGE_SHORT_BLOCK;
  412. - }
  413. -}
  414. -
  415. -/*---------------------------------------------------------------------------------------------
  416. - description: Check both HCR lengths
  417. ---------------------------------------------------------------------------------------------
  418. -*/
  419. -static void errDetectorInHcrLengths(SCHAR lengthOfLongestCodeword,
  420. - SHORT lengthOfReorderedSpectralData,
  421. - UINT *errorWord) {
  422. - if (lengthOfReorderedSpectralData < lengthOfLongestCodeword) {
  423. - *errorWord |= HCR_SI_LENGTHS_FAILURE;
  424. - }
  425. -}
  426. -
  427. -/*---------------------------------------------------------------------------------------------
  428. - description: Decode (and adapt if necessary) the two HCR sideinfo
  429. -components: 'reordered_spectral_data_length' and 'longest_codeword_length'
  430. ---------------------------------------------------------------------------------------------
  431. -*/
  432. -
  433. -void CHcr_Read(HANDLE_FDK_BITSTREAM bs,
  434. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  435. - const MP4_ELEMENT_ID globalHcrType) {
  436. - SHORT lengOfReorderedSpectralData;
  437. - SCHAR lengOfLongestCodeword;
  438. -
  439. - pAacDecoderChannelInfo->pDynData->specificTo.aac.lenOfReorderedSpectralData =
  440. - 0;
  441. - pAacDecoderChannelInfo->pDynData->specificTo.aac.lenOfLongestCodeword = 0;
  442. -
  443. - /* ------- SI-Value No 1 ------- */
  444. - lengOfReorderedSpectralData = FDKreadBits(bs, 14) + ERROR_LORSD;
  445. - if (globalHcrType == ID_CPE) {
  446. - if ((lengOfReorderedSpectralData >= 0) &&
  447. - (lengOfReorderedSpectralData <= CPE_TOP_LENGTH)) {
  448. - pAacDecoderChannelInfo->pDynData->specificTo.aac
  449. - .lenOfReorderedSpectralData =
  450. - lengOfReorderedSpectralData; /* the decoded value is within range */
  451. - } else {
  452. - if (lengOfReorderedSpectralData > CPE_TOP_LENGTH) {
  453. - pAacDecoderChannelInfo->pDynData->specificTo.aac
  454. - .lenOfReorderedSpectralData =
  455. - CPE_TOP_LENGTH; /* use valid maximum */
  456. - }
  457. - }
  458. - } else if (globalHcrType == ID_SCE || globalHcrType == ID_LFE ||
  459. - globalHcrType == ID_CCE) {
  460. - if ((lengOfReorderedSpectralData >= 0) &&
  461. - (lengOfReorderedSpectralData <= SCE_TOP_LENGTH)) {
  462. - pAacDecoderChannelInfo->pDynData->specificTo.aac
  463. - .lenOfReorderedSpectralData =
  464. - lengOfReorderedSpectralData; /* the decoded value is within range */
  465. - } else {
  466. - if (lengOfReorderedSpectralData > SCE_TOP_LENGTH) {
  467. - pAacDecoderChannelInfo->pDynData->specificTo.aac
  468. - .lenOfReorderedSpectralData =
  469. - SCE_TOP_LENGTH; /* use valid maximum */
  470. - }
  471. - }
  472. - }
  473. -
  474. - /* ------- SI-Value No 2 ------- */
  475. - lengOfLongestCodeword = FDKreadBits(bs, 6) + ERROR_LOLC;
  476. - if ((lengOfLongestCodeword >= 0) &&
  477. - (lengOfLongestCodeword <= LEN_OF_LONGEST_CW_TOP_LENGTH)) {
  478. - pAacDecoderChannelInfo->pDynData->specificTo.aac.lenOfLongestCodeword =
  479. - lengOfLongestCodeword; /* the decoded value is within range */
  480. - } else {
  481. - if (lengOfLongestCodeword > LEN_OF_LONGEST_CW_TOP_LENGTH) {
  482. - pAacDecoderChannelInfo->pDynData->specificTo.aac.lenOfLongestCodeword =
  483. - LEN_OF_LONGEST_CW_TOP_LENGTH; /* use valid maximum */
  484. - }
  485. - }
  486. -}
  487. -
  488. -/*---------------------------------------------------------------------------------------------
  489. - description: Set up HCR - must be called before every call to
  490. -HcrDecoder(). For short block a sorting algorithm is applied to get the SI in
  491. -the order that HCR could assemble the qsc's as if it is a long block.
  492. ------------------------------------------------------------------------------------------------
  493. - return: error log
  494. ---------------------------------------------------------------------------------------------
  495. -*/
  496. -
  497. -UINT HcrInit(H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  498. - const SamplingRateInfo *pSamplingRateInfo,
  499. - HANDLE_FDK_BITSTREAM bs) {
  500. - CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
  501. - SHORT *pNumLinesInSec;
  502. - UCHAR *pCodeBk;
  503. - SHORT numSection;
  504. - SCHAR cb;
  505. - int numLine;
  506. - int i;
  507. -
  508. - pHcr->decInOut.lengthOfReorderedSpectralData =
  509. - pAacDecoderChannelInfo->pDynData->specificTo.aac
  510. - .lenOfReorderedSpectralData;
  511. - pHcr->decInOut.lengthOfLongestCodeword =
  512. - pAacDecoderChannelInfo->pDynData->specificTo.aac.lenOfLongestCodeword;
  513. - pHcr->decInOut.pQuantizedSpectralCoefficientsBase =
  514. - pAacDecoderChannelInfo->pSpectralCoefficient;
  515. - pHcr->decInOut.quantizedSpectralCoefficientsIdx = 0;
  516. - pHcr->decInOut.pCodebook =
  517. - pAacDecoderChannelInfo->pDynData->specificTo.aac.aCodeBooks4Hcr;
  518. - pHcr->decInOut.pNumLineInSect =
  519. - pAacDecoderChannelInfo->pDynData->specificTo.aac.aNumLineInSec4Hcr;
  520. - pHcr->decInOut.numSection =
  521. - pAacDecoderChannelInfo->pDynData->specificTo.aac.numberSection;
  522. - pHcr->decInOut.errorLog = 0;
  523. - pHcr->nonPcwSideinfo.pResultBase =
  524. - SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
  525. -
  526. - FDKsyncCache(bs);
  527. - pHcr->decInOut.bitstreamAnchor = (INT)FDKgetValidBits(bs);
  528. -
  529. - if (!IsLongBlock(&pAacDecoderChannelInfo->icsInfo)) /* short block */
  530. - {
  531. - SHORT band;
  532. - SHORT maxBand;
  533. - SCHAR group;
  534. - SCHAR winGroupLen;
  535. - SCHAR window;
  536. - SCHAR numUnitInBand;
  537. - SCHAR cntUnitInBand;
  538. - SCHAR groupWin;
  539. - SCHAR cb_prev;
  540. -
  541. - UCHAR *pCodeBook;
  542. - const SHORT *BandOffsets;
  543. - SCHAR numOfGroups;
  544. -
  545. - pCodeBook = pAacDecoderChannelInfo->pDynData->aCodeBook; /* in */
  546. - pNumLinesInSec = pHcr->decInOut.pNumLineInSect; /* out */
  547. - pCodeBk = pHcr->decInOut.pCodebook; /* out */
  548. - BandOffsets =
  549. - GetScaleFactorBandOffsets(pIcsInfo, pSamplingRateInfo); /* aux */
  550. - numOfGroups = GetWindowGroups(pIcsInfo);
  551. -
  552. - numLine = 0;
  553. - numSection = 0;
  554. - cb = pCodeBook[0];
  555. - cb_prev = pCodeBook[0];
  556. -
  557. - /* convert HCR-sideinfo into a unitwise manner: When the cb changes, a new
  558. - * section starts */
  559. -
  560. - *pCodeBk++ = cb_prev;
  561. -
  562. - maxBand = GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->icsInfo);
  563. - for (band = 0; band < maxBand;
  564. - band++) { /* from low to high sfbs i.e. from low to high frequencies */
  565. - numUnitInBand =
  566. - ((BandOffsets[band + 1] - BandOffsets[band]) >>
  567. - FOUR_LOG_DIV_TWO_LOG); /* get the number of units in current sfb */
  568. - for (cntUnitInBand = numUnitInBand; cntUnitInBand != 0;
  569. - cntUnitInBand--) { /* for every unit in the band */
  570. - for (window = 0, group = 0; group < numOfGroups; group++) {
  571. - winGroupLen = (SCHAR)GetWindowGroupLength(
  572. - &pAacDecoderChannelInfo->icsInfo, group);
  573. - for (groupWin = winGroupLen; groupWin != 0; groupWin--, window++) {
  574. - cb = pCodeBook[group * 16 + band];
  575. - if (cb != cb_prev) {
  576. - errDetectorInHcrSideinfoShrt(cb, numLine,
  577. - &pHcr->decInOut.errorLog);
  578. - if (pHcr->decInOut.errorLog != 0) {
  579. - return (pHcr->decInOut.errorLog);
  580. - }
  581. - *pCodeBk++ = cb;
  582. - *pNumLinesInSec++ = numLine;
  583. - numSection++;
  584. -
  585. - cb_prev = cb;
  586. - numLine = LINES_PER_UNIT;
  587. - } else {
  588. - numLine += LINES_PER_UNIT;
  589. - }
  590. - }
  591. - }
  592. - }
  593. - }
  594. -
  595. - numSection++;
  596. -
  597. - errDetectorInHcrSideinfoShrt(cb, numLine, &pHcr->decInOut.errorLog);
  598. - if (numSection <= 0 || numSection > 1024 / 2) {
  599. - pHcr->decInOut.errorLog |= NUM_SECT_OUT_OF_RANGE_SHORT_BLOCK;
  600. - }
  601. - errDetectorInHcrLengths(pHcr->decInOut.lengthOfLongestCodeword,
  602. - pHcr->decInOut.lengthOfReorderedSpectralData,
  603. - &pHcr->decInOut.errorLog);
  604. - if (pHcr->decInOut.errorLog != 0) {
  605. - return (pHcr->decInOut.errorLog);
  606. - }
  607. -
  608. - *pCodeBk = cb;
  609. - *pNumLinesInSec = numLine;
  610. - pHcr->decInOut.numSection = numSection;
  611. -
  612. - } else /* end short block prepare SI */
  613. - { /* long block */
  614. - errDetectorInHcrLengths(pHcr->decInOut.lengthOfLongestCodeword,
  615. - pHcr->decInOut.lengthOfReorderedSpectralData,
  616. - &pHcr->decInOut.errorLog);
  617. - numSection = pHcr->decInOut.numSection;
  618. - pNumLinesInSec = pHcr->decInOut.pNumLineInSect;
  619. - pCodeBk = pHcr->decInOut.pCodebook;
  620. - if (numSection <= 0 || numSection > 64) {
  621. - pHcr->decInOut.errorLog |= NUM_SECT_OUT_OF_RANGE_LONG_BLOCK;
  622. - numSection = 0;
  623. - }
  624. -
  625. - for (i = numSection; i != 0; i--) {
  626. - cb = *pCodeBk++;
  627. -
  628. - if (cb < ZERO_HCB || cb >= MAX_CB_CHECK || cb == BOOKSCL) {
  629. - pHcr->decInOut.errorLog |= CB_OUT_OF_RANGE_LONG_BLOCK;
  630. - }
  631. -
  632. - numLine = *pNumLinesInSec++;
  633. - /* FDK_ASSERT(numLine > 0); */
  634. -
  635. - if ((numLine <= 0) || (numLine > 1024)) {
  636. - pHcr->decInOut.errorLog |= LINE_IN_SECT_OUT_OF_RANGE_LONG_BLOCK;
  637. - }
  638. - }
  639. - if (pHcr->decInOut.errorLog != 0) {
  640. - return (pHcr->decInOut.errorLog);
  641. - }
  642. - }
  643. -
  644. - pCodeBk = pHcr->decInOut.pCodebook;
  645. - for (i = 0; i < numSection; i++) {
  646. - if ((*pCodeBk == NOISE_HCB) || (*pCodeBk == INTENSITY_HCB2) ||
  647. - (*pCodeBk == INTENSITY_HCB)) {
  648. - *pCodeBk = 0;
  649. - }
  650. - pCodeBk++;
  651. - }
  652. -
  653. - /* HCR-sideinfo-input is complete and seems to be valid */
  654. -
  655. - return (pHcr->decInOut.errorLog);
  656. -}
  657. -
  658. -/*---------------------------------------------------------------------------------------------
  659. - description: This function decodes the codewords of the spectral
  660. -coefficients from the bitstream according to the HCR algorithm and stores the
  661. -quantized spectral coefficients in correct order in the output buffer.
  662. ---------------------------------------------------------------------------------------------
  663. -*/
  664. -
  665. -UINT HcrDecoder(H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  666. - const SamplingRateInfo *pSamplingRateInfo,
  667. - HANDLE_FDK_BITSTREAM bs) {
  668. - int pTmp1, pTmp2, pTmp3, pTmp4;
  669. - int pTmp5;
  670. -
  671. - INT bitCntOffst;
  672. - INT saveBitCnt = (INT)FDKgetValidBits(bs); /* save bitstream position */
  673. -
  674. - HcrCalcNumCodeword(pHcr);
  675. -
  676. - HcrSortCodebookAndNumCodewordInSection(pHcr);
  677. -
  678. - HcrPrepareSegmentationGrid(pHcr);
  679. -
  680. - HcrExtendedSectionInfo(pHcr);
  681. -
  682. - if ((pHcr->decInOut.errorLog & HCR_FATAL_PCW_ERROR_MASK) != 0) {
  683. - return (pHcr->decInOut.errorLog); /* sideinfo is massively corrupt, return
  684. - from HCR without having decoded
  685. - anything */
  686. - }
  687. -
  688. - DeriveNumberOfExtendedSortedSectionsInSets(
  689. - pHcr->segmentInfo.numSegment,
  690. - pHcr->sectionInfo.pNumExtendedSortedCodewordInSection,
  691. - pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx,
  692. - pHcr->sectionInfo.pNumExtendedSortedSectionsInSets,
  693. - pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx);
  694. -
  695. - /* store */
  696. - pTmp1 = pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx;
  697. - pTmp2 = pHcr->sectionInfo.extendedSortedCodebookIdx;
  698. - pTmp3 = pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx;
  699. - pTmp4 = pHcr->decInOut.quantizedSpectralCoefficientsIdx;
  700. - pTmp5 = pHcr->sectionInfo.maxLenOfCbInExtSrtSecIdx;
  701. -
  702. - /* ------- decode meaningful PCWs ------ */
  703. - DecodePCWs(bs, pHcr);
  704. -
  705. - if ((pHcr->decInOut.errorLog & HCR_FATAL_PCW_ERROR_MASK) == 0) {
  706. - /* ------ decode the non-PCWs -------- */
  707. - DecodeNonPCWs(bs, pHcr);
  708. - }
  709. -
  710. - errDetectWithinSegmentationFinal(pHcr);
  711. -
  712. - /* restore */
  713. - pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx = pTmp1;
  714. - pHcr->sectionInfo.extendedSortedCodebookIdx = pTmp2;
  715. - pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx = pTmp3;
  716. - pHcr->decInOut.quantizedSpectralCoefficientsIdx = pTmp4;
  717. - pHcr->sectionInfo.maxLenOfCbInExtSrtSecIdx = pTmp5;
  718. -
  719. - HcrReorderQuantizedSpectralCoefficients(pHcr, pAacDecoderChannelInfo,
  720. - pSamplingRateInfo);
  721. -
  722. - /* restore bitstream position */
  723. - bitCntOffst = (INT)FDKgetValidBits(bs) - saveBitCnt;
  724. - if (bitCntOffst) {
  725. - FDKpushBiDirectional(bs, bitCntOffst);
  726. - }
  727. -
  728. - return (pHcr->decInOut.errorLog);
  729. -}
  730. -
  731. -/*---------------------------------------------------------------------------------------------
  732. - description: This function reorders the quantized spectral coefficients
  733. -sectionwise for long- and short-blocks and compares to the LAV (Largest Absolute
  734. -Value of the current codebook) -- a counter is incremented if there is an error
  735. - detected.
  736. - Additional for short-blocks a unit-based-deinterleaving is
  737. -applied. Moreover (for short blocks) the scaling is derived (compare plain
  738. -huffman decoder).
  739. ---------------------------------------------------------------------------------------------
  740. -*/
  741. -
  742. -static void HcrReorderQuantizedSpectralCoefficients(
  743. - H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  744. - const SamplingRateInfo *pSamplingRateInfo) {
  745. - INT qsc;
  746. - UINT abs_qsc;
  747. - UINT i, j;
  748. - USHORT numSpectralValuesInSection;
  749. - FIXP_DBL *pTeVa;
  750. - USHORT lavErrorCnt = 0;
  751. -
  752. - UINT numSection = pHcr->decInOut.numSection;
  753. - SPECTRAL_PTR pQuantizedSpectralCoefficientsBase =
  754. - pHcr->decInOut.pQuantizedSpectralCoefficientsBase;
  755. - FIXP_DBL *pQuantizedSpectralCoefficients =
  756. - SPEC_LONG(pHcr->decInOut.pQuantizedSpectralCoefficientsBase);
  757. - const UCHAR *pCbDimShift = aDimCbShift;
  758. - const USHORT *pLargestAbsVal = aLargestAbsoluteValue;
  759. - UCHAR *pSortedCodebook = pHcr->sectionInfo.pSortedCodebook;
  760. - USHORT *pNumSortedCodewordInSection =
  761. - pHcr->sectionInfo.pNumSortedCodewordInSection;
  762. - USHORT *pReorderOffset = pHcr->sectionInfo.pReorderOffset;
  763. - FIXP_DBL pTempValues[1024];
  764. - FIXP_DBL *pBak = pTempValues;
  765. -
  766. - FDKmemclear(pTempValues, 1024 * sizeof(FIXP_DBL));
  767. -
  768. - /* long and short: check if decoded huffman-values (quantized spectral
  769. - * coefficients) are within range */
  770. - for (i = numSection; i != 0; i--) {
  771. - numSpectralValuesInSection = *pNumSortedCodewordInSection++
  772. - << pCbDimShift[*pSortedCodebook];
  773. - pTeVa = &pTempValues[*pReorderOffset++];
  774. - for (j = numSpectralValuesInSection; j != 0; j--) {
  775. - qsc = *pQuantizedSpectralCoefficients++;
  776. - abs_qsc = fAbs(qsc);
  777. - if (abs_qsc <= pLargestAbsVal[*pSortedCodebook]) {
  778. - *pTeVa++ = (FIXP_DBL)qsc; /* the qsc value is within range */
  779. - } else { /* line is too high .. */
  780. - if (abs_qsc ==
  781. - Q_VALUE_INVALID) { /* .. because of previous marking --> dont set
  782. - LAV flag (would be confusing), just copy out
  783. - the already marked value */
  784. - *pTeVa++ = (FIXP_DBL)qsc;
  785. - } else { /* .. because a too high value was decoded for this cb --> set
  786. - LAV flag */
  787. - *pTeVa++ = (FIXP_DBL)Q_VALUE_INVALID;
  788. - lavErrorCnt += 1;
  789. - }
  790. - }
  791. - }
  792. - pSortedCodebook++;
  793. - }
  794. -
  795. - if (!IsLongBlock(&pAacDecoderChannelInfo->icsInfo)) {
  796. - FIXP_DBL *pOut;
  797. - FIXP_DBL locMax;
  798. - FIXP_DBL tmp;
  799. - SCHAR groupoffset;
  800. - SCHAR group;
  801. - SCHAR band;
  802. - SCHAR groupwin;
  803. - SCHAR window;
  804. - SCHAR numWinGroup;
  805. - SHORT interm;
  806. - SCHAR numSfbTransm;
  807. - SCHAR winGroupLen;
  808. - SHORT index;
  809. - INT msb;
  810. - INT lsb;
  811. -
  812. - SHORT *pScaleFacHcr = pAacDecoderChannelInfo->pDynData->aScaleFactor;
  813. - SHORT *pSfbSclHcr = pAacDecoderChannelInfo->pDynData->aSfbScale;
  814. - const SHORT *BandOffsets = GetScaleFactorBandOffsets(
  815. - &pAacDecoderChannelInfo->icsInfo, pSamplingRateInfo);
  816. -
  817. - pBak = pTempValues;
  818. - /* deinterleave unitwise for short blocks */
  819. - for (window = 0; window < (8); window++) {
  820. - pOut = SPEC(pQuantizedSpectralCoefficientsBase, window,
  821. - pAacDecoderChannelInfo->granuleLength);
  822. - for (i = 0; i < (LINES_PER_UNIT_GROUP); i++) {
  823. - pTeVa = pBak + (window << FOUR_LOG_DIV_TWO_LOG) +
  824. - i * 32; /* distance of lines between unit groups has to be
  825. - constant for every framelength (32)! */
  826. - for (j = (LINES_PER_UNIT); j != 0; j--) {
  827. - *pOut++ = *pTeVa++;
  828. - }
  829. - }
  830. - }
  831. -
  832. - /* short blocks only */
  833. - /* derive global scaling-value for every sfb and every window (as it is done
  834. - * in plain-huffman-decoder at short blocks) */
  835. - groupoffset = 0;
  836. -
  837. - numWinGroup = GetWindowGroups(&pAacDecoderChannelInfo->icsInfo);
  838. - numSfbTransm =
  839. - GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->icsInfo);
  840. -
  841. - for (group = 0; group < numWinGroup; group++) {
  842. - winGroupLen =
  843. - GetWindowGroupLength(&pAacDecoderChannelInfo->icsInfo, group);
  844. - for (band = 0; band < numSfbTransm; band++) {
  845. - interm = group * 16 + band;
  846. - msb = pScaleFacHcr[interm] >> 2;
  847. - lsb = pScaleFacHcr[interm] & 3;
  848. - for (groupwin = 0; groupwin < winGroupLen; groupwin++) {
  849. - window = groupoffset + groupwin;
  850. - pBak = SPEC(pQuantizedSpectralCoefficientsBase, window,
  851. - pAacDecoderChannelInfo->granuleLength);
  852. - locMax = FL2FXCONST_DBL(0.0f);
  853. - for (index = BandOffsets[band]; index < BandOffsets[band + 1];
  854. - index += LINES_PER_UNIT) {
  855. - pTeVa = &pBak[index];
  856. - for (i = LINES_PER_UNIT; i != 0; i--) {
  857. - tmp = (*pTeVa < FL2FXCONST_DBL(0.0f)) ? -*pTeVa++ : *pTeVa++;
  858. - locMax = fixMax(tmp, locMax);
  859. - }
  860. - }
  861. - if (fixp_abs(locMax) > (FIXP_DBL)MAX_QUANTIZED_VALUE) {
  862. - locMax = (FIXP_DBL)MAX_QUANTIZED_VALUE;
  863. - }
  864. - pSfbSclHcr[window * 16 + band] =
  865. - msb - GetScaleFromValue(
  866. - locMax, lsb); /* save global scale maxima in this sfb */
  867. - }
  868. - }
  869. - groupoffset +=
  870. - GetWindowGroupLength(&pAacDecoderChannelInfo->icsInfo, group);
  871. - }
  872. - } else {
  873. - /* copy straight for long-blocks */
  874. - pQuantizedSpectralCoefficients =
  875. - SPEC_LONG(pQuantizedSpectralCoefficientsBase);
  876. - for (i = 1024; i != 0; i--) {
  877. - *pQuantizedSpectralCoefficients++ = *pBak++;
  878. - }
  879. - }
  880. -
  881. - if (lavErrorCnt != 0) {
  882. - pHcr->decInOut.errorLog |= LAV_VIOLATION;
  883. - }
  884. -}
  885. -
  886. -/*---------------------------------------------------------------------------------------------
  887. - description: This function calculates the number of codewords
  888. - for each section (numCodewordInSection) and the number of
  889. -codewords for all sections (numCodeword). For zero and intensity codebooks a
  890. -entry is also done in the variable numCodewordInSection. It is assumed that the
  891. -codebook is a two tuples codebook. This is needed later for the calculation of
  892. -the base addresses for the reordering of the quantize spectral coefficients at
  893. -the end of the hcr tool. The variable numCodeword contain the number of
  894. -codewords which are really in the bitstream. Zero or intensity codebooks does
  895. -not increase the variable numCodewords.
  896. ------------------------------------------------------------------------------------------------
  897. - return: -
  898. ---------------------------------------------------------------------------------------------
  899. -*/
  900. -
  901. -static void HcrCalcNumCodeword(H_HCR_INFO pHcr) {
  902. - int hcrSection;
  903. - UINT numCodeword;
  904. -
  905. - UINT numSection = pHcr->decInOut.numSection;
  906. - UCHAR *pCodebook = pHcr->decInOut.pCodebook;
  907. - SHORT *pNumLineInSection = pHcr->decInOut.pNumLineInSect;
  908. - const UCHAR *pCbDimShift = aDimCbShift;
  909. -
  910. - USHORT *pNumCodewordInSection = pHcr->sectionInfo.pNumCodewordInSection;
  911. -
  912. - numCodeword = 0;
  913. - for (hcrSection = numSection; hcrSection != 0; hcrSection--) {
  914. - *pNumCodewordInSection = *pNumLineInSection++ >> pCbDimShift[*pCodebook];
  915. - if (*pCodebook != 0) {
  916. - numCodeword += *pNumCodewordInSection;
  917. - }
  918. - pNumCodewordInSection++;
  919. - pCodebook++;
  920. - }
  921. - pHcr->sectionInfo.numCodeword = numCodeword;
  922. -}
  923. -
  924. -/*---------------------------------------------------------------------------------------------
  925. - description: This function calculates the number
  926. - of sorted codebooks and sorts the codebooks and the
  927. -numCodewordInSection according to the priority.
  928. ---------------------------------------------------------------------------------------------
  929. -*/
  930. -
  931. -static void HcrSortCodebookAndNumCodewordInSection(H_HCR_INFO pHcr) {
  932. - UINT i, j, k;
  933. - UCHAR temp;
  934. - UINT counter;
  935. - UINT startOffset;
  936. - UINT numZeroSection;
  937. - UCHAR *pDest;
  938. - UINT numSectionDec;
  939. -
  940. - UINT numSection = pHcr->decInOut.numSection;
  941. - UCHAR *pCodebook = pHcr->decInOut.pCodebook;
  942. - UCHAR *pSortedCodebook = pHcr->sectionInfo.pSortedCodebook;
  943. - USHORT *pNumCodewordInSection = pHcr->sectionInfo.pNumCodewordInSection;
  944. - USHORT *pNumSortedCodewordInSection =
  945. - pHcr->sectionInfo.pNumSortedCodewordInSection;
  946. - UCHAR *pCodebookSwitch = pHcr->sectionInfo.pCodebookSwitch;
  947. - USHORT *pReorderOffset = pHcr->sectionInfo.pReorderOffset;
  948. - const UCHAR *pCbPriority = aCbPriority;
  949. - const UCHAR *pMinOfCbPair = aMinOfCbPair;
  950. - const UCHAR *pMaxOfCbPair = aMaxOfCbPair;
  951. - const UCHAR *pCbDimShift = aDimCbShift;
  952. -
  953. - UINT searchStart = 0;
  954. -
  955. - /* calculate *pNumSortedSection and store the priorities in array
  956. - * pSortedCdebook */
  957. - pDest = pSortedCodebook;
  958. - numZeroSection = 0;
  959. - for (i = numSection; i != 0; i--) {
  960. - if (pCbPriority[*pCodebook] == 0) {
  961. - numZeroSection += 1;
  962. - }
  963. - *pDest++ = pCbPriority[*pCodebook++];
  964. - }
  965. - pHcr->sectionInfo.numSortedSection =
  966. - numSection - numZeroSection; /* numSortedSection contains no zero or
  967. - intensity section */
  968. - pCodebook = pHcr->decInOut.pCodebook;
  969. -
  970. - /* sort priorities of the codebooks in array pSortedCdebook[] */
  971. - numSectionDec = numSection - 1;
  972. - if (numSectionDec > 0) {
  973. - counter = numSectionDec;
  974. - for (j = numSectionDec; j != 0; j--) {
  975. - for (i = 0; i < counter; i++) {
  976. - /* swap priorities */
  977. - if (pSortedCodebook[i + 1] > pSortedCodebook[i]) {
  978. - temp = pSortedCodebook[i];
  979. - pSortedCodebook[i] = pSortedCodebook[i + 1];
  980. - pSortedCodebook[i + 1] = temp;
  981. - }
  982. - }
  983. - counter -= 1;
  984. - }
  985. - }
  986. -
  987. - /* clear codebookSwitch array */
  988. - for (i = numSection; i != 0; i--) {
  989. - *pCodebookSwitch++ = 0;
  990. - }
  991. - pCodebookSwitch = pHcr->sectionInfo.pCodebookSwitch;
  992. -
  993. - /* sort sectionCodebooks and numCodwordsInSection and calculate
  994. - * pReorderOffst[j] */
  995. - for (j = 0; j < numSection; j++) {
  996. - for (i = searchStart; i < numSection; i++) {
  997. - if (pCodebookSwitch[i] == 0 &&
  998. - (pMinOfCbPair[pSortedCodebook[j]] == pCodebook[i] ||
  999. - pMaxOfCbPair[pSortedCodebook[j]] == pCodebook[i])) {
  1000. - pCodebookSwitch[i] = 1;
  1001. - pSortedCodebook[j] = pCodebook[i]; /* sort codebook */
  1002. - pNumSortedCodewordInSection[j] =
  1003. - pNumCodewordInSection[i]; /* sort NumCodewordInSection */
  1004. -
  1005. - startOffset = 0;
  1006. - for (k = 0; k < i; k++) { /* make entry in pReorderOffst */
  1007. - startOffset += pNumCodewordInSection[k] << pCbDimShift[pCodebook[k]];
  1008. - }
  1009. - pReorderOffset[j] =
  1010. - startOffset; /* offset for reordering the codewords */
  1011. -
  1012. - if (i == searchStart) {
  1013. - k = i;
  1014. - while (pCodebookSwitch[k++] == 1) searchStart++;
  1015. - }
  1016. - break;
  1017. - }
  1018. - }
  1019. - }
  1020. -}
  1021. -
  1022. -/*---------------------------------------------------------------------------------------------
  1023. - description: This function calculates the segmentation, which includes
  1024. -numSegment, leftStartOfSegment, rightStartOfSegment and remainingBitsInSegment.
  1025. - The segmentation could be visualized a as kind of
  1026. -'overlay-grid' for the bitstream-block holding the HCR-encoded
  1027. -quantized-spectral-coefficients.
  1028. ---------------------------------------------------------------------------------------------
  1029. -*/
  1030. -
  1031. -static void HcrPrepareSegmentationGrid(H_HCR_INFO pHcr) {
  1032. - USHORT i, j;
  1033. - USHORT numSegment = 0;
  1034. - INT segmentStart = 0;
  1035. - UCHAR segmentWidth;
  1036. - UCHAR lastSegmentWidth;
  1037. - UCHAR sortedCodebook;
  1038. - UCHAR endFlag = 0;
  1039. - INT intermediateResult;
  1040. -
  1041. - SCHAR lengthOfLongestCodeword = pHcr->decInOut.lengthOfLongestCodeword;
  1042. - SHORT lengthOfReorderedSpectralData =
  1043. - pHcr->decInOut.lengthOfReorderedSpectralData;
  1044. - UINT numSortedSection = pHcr->sectionInfo.numSortedSection;
  1045. - UCHAR *pSortedCodebook = pHcr->sectionInfo.pSortedCodebook;
  1046. - USHORT *pNumSortedCodewordInSection =
  1047. - pHcr->sectionInfo.pNumSortedCodewordInSection;
  1048. - INT *pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  1049. - INT *pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  1050. - SCHAR *pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  1051. - const UCHAR *pMaxCwLength = aMaxCwLen;
  1052. -
  1053. - for (i = numSortedSection; i != 0; i--) {
  1054. - sortedCodebook = *pSortedCodebook++;
  1055. - segmentWidth =
  1056. - fMin((INT)pMaxCwLength[sortedCodebook], (INT)lengthOfLongestCodeword);
  1057. -
  1058. - for (j = *pNumSortedCodewordInSection; j != 0; j--) {
  1059. - /* width allows a new segment */
  1060. - intermediateResult = segmentStart;
  1061. - if ((segmentStart + segmentWidth) <= lengthOfReorderedSpectralData) {
  1062. - /* store segment start, segment length and increment the number of
  1063. - * segments */
  1064. - *pLeftStartOfSegment++ = intermediateResult;
  1065. - *pRightStartOfSegment++ = intermediateResult + segmentWidth - 1;
  1066. - *pRemainingBitsInSegment++ = segmentWidth;
  1067. - segmentStart += segmentWidth;
  1068. - numSegment += 1;
  1069. - }
  1070. - /* width does not allow a new segment */
  1071. - else {
  1072. - /* correct the last segment length */
  1073. - pLeftStartOfSegment--;
  1074. - pRightStartOfSegment--;
  1075. - pRemainingBitsInSegment--;
  1076. - segmentStart = *pLeftStartOfSegment;
  1077. -
  1078. - lastSegmentWidth = lengthOfReorderedSpectralData - segmentStart;
  1079. - *pRemainingBitsInSegment = lastSegmentWidth;
  1080. - *pRightStartOfSegment = segmentStart + lastSegmentWidth - 1;
  1081. - endFlag = 1;
  1082. - break;
  1083. - }
  1084. - }
  1085. - pNumSortedCodewordInSection++;
  1086. - if (endFlag != 0) {
  1087. - break;
  1088. - }
  1089. - }
  1090. - pHcr->segmentInfo.numSegment = numSegment;
  1091. -}
  1092. -
  1093. -/*---------------------------------------------------------------------------------------------
  1094. - description: This function adapts the sorted section boundaries to the
  1095. -boundaries of segmentation. If the section lengths does not fit completely into
  1096. -the current segment, the section is spitted into two so called 'extended
  1097. - sections'. The extended-section-info
  1098. -(pNumExtendedSortedCodewordInSectin and pExtendedSortedCodebook) is updated in
  1099. -this case.
  1100. -
  1101. ---------------------------------------------------------------------------------------------
  1102. -*/
  1103. -
  1104. -static void HcrExtendedSectionInfo(H_HCR_INFO pHcr) {
  1105. - UINT srtSecCnt = 0; /* counter for sorted sections */
  1106. - UINT xSrtScCnt = 0; /* counter for extended sorted sections */
  1107. - UINT remainNumCwInSortSec;
  1108. - UINT inSegmentRemainNumCW;
  1109. -
  1110. - UINT numSortedSection = pHcr->sectionInfo.numSortedSection;
  1111. - UCHAR *pSortedCodebook = pHcr->sectionInfo.pSortedCodebook;
  1112. - USHORT *pNumSortedCodewordInSection =
  1113. - pHcr->sectionInfo.pNumSortedCodewordInSection;
  1114. - UCHAR *pExtendedSortedCoBo = pHcr->sectionInfo.pExtendedSortedCodebook;
  1115. - USHORT *pNumExtSortCwInSect =
  1116. - pHcr->sectionInfo.pNumExtendedSortedCodewordInSection;
  1117. - UINT numSegment = pHcr->segmentInfo.numSegment;
  1118. - UCHAR *pMaxLenOfCbInExtSrtSec = pHcr->sectionInfo.pMaxLenOfCbInExtSrtSec;
  1119. - SCHAR lengthOfLongestCodeword = pHcr->decInOut.lengthOfLongestCodeword;
  1120. - const UCHAR *pMaxCwLength = aMaxCwLen;
  1121. -
  1122. - remainNumCwInSortSec = pNumSortedCodewordInSection[srtSecCnt];
  1123. - inSegmentRemainNumCW = numSegment;
  1124. -
  1125. - while (srtSecCnt < numSortedSection) {
  1126. - if (inSegmentRemainNumCW < remainNumCwInSortSec) {
  1127. - pNumExtSortCwInSect[xSrtScCnt] = inSegmentRemainNumCW;
  1128. - pExtendedSortedCoBo[xSrtScCnt] = pSortedCodebook[srtSecCnt];
  1129. -
  1130. - remainNumCwInSortSec -= inSegmentRemainNumCW;
  1131. - inSegmentRemainNumCW = numSegment;
  1132. - /* data of a sorted section was not integrated in extended sorted section
  1133. - */
  1134. - } else if (inSegmentRemainNumCW == remainNumCwInSortSec) {
  1135. - pNumExtSortCwInSect[xSrtScCnt] = inSegmentRemainNumCW;
  1136. - pExtendedSortedCoBo[xSrtScCnt] = pSortedCodebook[srtSecCnt];
  1137. -
  1138. - srtSecCnt++;
  1139. - remainNumCwInSortSec = pNumSortedCodewordInSection[srtSecCnt];
  1140. - inSegmentRemainNumCW = numSegment;
  1141. - /* data of a sorted section was integrated in extended sorted section */
  1142. - } else { /* inSegmentRemainNumCW > remainNumCwInSortSec */
  1143. - pNumExtSortCwInSect[xSrtScCnt] = remainNumCwInSortSec;
  1144. - pExtendedSortedCoBo[xSrtScCnt] = pSortedCodebook[srtSecCnt];
  1145. -
  1146. - inSegmentRemainNumCW -= remainNumCwInSortSec;
  1147. - srtSecCnt++;
  1148. - remainNumCwInSortSec = pNumSortedCodewordInSection[srtSecCnt];
  1149. - /* data of a sorted section was integrated in extended sorted section */
  1150. - }
  1151. - pMaxLenOfCbInExtSrtSec[xSrtScCnt] =
  1152. - fMin((INT)pMaxCwLength[pExtendedSortedCoBo[xSrtScCnt]],
  1153. - (INT)lengthOfLongestCodeword);
  1154. -
  1155. - xSrtScCnt += 1;
  1156. -
  1157. - if (xSrtScCnt >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
  1158. - pHcr->decInOut.errorLog |= EXTENDED_SORTED_COUNTER_OVERFLOW;
  1159. - return;
  1160. - }
  1161. - }
  1162. - pNumExtSortCwInSect[xSrtScCnt] = 0;
  1163. -}
  1164. -
  1165. -/*---------------------------------------------------------------------------------------------
  1166. - description: This function calculates the number of extended sorted
  1167. -sections which belong to the sets. Each set from set 0 (one and only set for the
  1168. -PCWs) till to the last set gets a entry in the array to which
  1169. - 'pNumExtendedSortedSectinsInSets' points to.
  1170. -
  1171. - Calculation: The entrys in
  1172. -pNumExtendedSortedCodewordInSectin are added untill the value numSegment is
  1173. -reached. Then the sum_variable is cleared and the calculation starts from the
  1174. -beginning. As much extended sorted Sections are summed up to reach the value
  1175. -numSegment, as much is the current entry in *pNumExtendedSortedCodewordInSectin.
  1176. ---------------------------------------------------------------------------------------------
  1177. -*/
  1178. -static void DeriveNumberOfExtendedSortedSectionsInSets(
  1179. - UINT numSegment, USHORT *pNumExtendedSortedCodewordInSection,
  1180. - int numExtendedSortedCodewordInSectionIdx,
  1181. - USHORT *pNumExtendedSortedSectionsInSets,
  1182. - int numExtendedSortedSectionsInSetsIdx) {
  1183. - USHORT counter = 0;
  1184. - UINT cwSum = 0;
  1185. - USHORT *pNumExSortCwInSec = pNumExtendedSortedCodewordInSection;
  1186. - USHORT *pNumExSortSecInSets = pNumExtendedSortedSectionsInSets;
  1187. -
  1188. - while (pNumExSortCwInSec[numExtendedSortedCodewordInSectionIdx] != 0) {
  1189. - cwSum += pNumExSortCwInSec[numExtendedSortedCodewordInSectionIdx];
  1190. - numExtendedSortedCodewordInSectionIdx++;
  1191. - if (numExtendedSortedCodewordInSectionIdx >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
  1192. - return;
  1193. - }
  1194. - if (cwSum > numSegment) {
  1195. - return;
  1196. - }
  1197. - counter++;
  1198. - if (counter > 1024 / 4) {
  1199. - return;
  1200. - }
  1201. - if (cwSum == numSegment) {
  1202. - pNumExSortSecInSets[numExtendedSortedSectionsInSetsIdx] = counter;
  1203. - numExtendedSortedSectionsInSetsIdx++;
  1204. - if (numExtendedSortedSectionsInSetsIdx >= MAX_HCR_SETS) {
  1205. - return;
  1206. - }
  1207. - counter = 0;
  1208. - cwSum = 0;
  1209. - }
  1210. - }
  1211. - pNumExSortSecInSets[numExtendedSortedSectionsInSetsIdx] =
  1212. - counter; /* save last entry for the last - probably shorter - set */
  1213. -}
  1214. -
  1215. -/*---------------------------------------------------------------------------------------------
  1216. - description: This function decodes all priority codewords (PCWs) in a
  1217. -spectrum (within set 0). The calculation of the PCWs is managed in two loops.
  1218. -The loopcounter of the outer loop is set to the first value pointer
  1219. - pNumExtendedSortedSectionsInSets points to. This value
  1220. -represents the number of extended sorted sections within set 0. The loopcounter
  1221. -of the inner loop is set to the first value pointer
  1222. - pNumExtendedSortedCodewordInSectin points to. The value
  1223. -represents the number of extended sorted codewords in sections (the original
  1224. -sections have been splitted to go along with the borders of the sets). Each time
  1225. -the number of the extended sorted codewords in sections are de- coded, the
  1226. -pointer 'pNumExtendedSortedCodewordInSectin' is incremented by one.
  1227. ---------------------------------------------------------------------------------------------
  1228. -*/
  1229. -static void DecodePCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO pHcr) {
  1230. - UINT i;
  1231. - USHORT extSortSec;
  1232. - USHORT curExtSortCwInSec;
  1233. - UCHAR codebook;
  1234. - UCHAR dimension;
  1235. - const UINT *pCurrentTree;
  1236. - const SCHAR *pQuantValBase;
  1237. - const SCHAR *pQuantVal;
  1238. -
  1239. - USHORT *pNumExtendedSortedCodewordInSection =
  1240. - pHcr->sectionInfo.pNumExtendedSortedCodewordInSection;
  1241. - int numExtendedSortedCodewordInSectionIdx =
  1242. - pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx;
  1243. - UCHAR *pExtendedSortedCodebook = pHcr->sectionInfo.pExtendedSortedCodebook;
  1244. - int extendedSortedCodebookIdx = pHcr->sectionInfo.extendedSortedCodebookIdx;
  1245. - USHORT *pNumExtendedSortedSectionsInSets =
  1246. - pHcr->sectionInfo.pNumExtendedSortedSectionsInSets;
  1247. - int numExtendedSortedSectionsInSetsIdx =
  1248. - pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx;
  1249. - FIXP_DBL *pQuantizedSpectralCoefficients =
  1250. - SPEC_LONG(pHcr->decInOut.pQuantizedSpectralCoefficientsBase);
  1251. - int quantizedSpectralCoefficientsIdx =
  1252. - pHcr->decInOut.quantizedSpectralCoefficientsIdx;
  1253. - INT *pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  1254. - SCHAR *pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  1255. - UCHAR *pMaxLenOfCbInExtSrtSec = pHcr->sectionInfo.pMaxLenOfCbInExtSrtSec;
  1256. - int maxLenOfCbInExtSrtSecIdx = pHcr->sectionInfo.maxLenOfCbInExtSrtSecIdx;
  1257. - UCHAR maxAllowedCwLen;
  1258. - int numDecodedBits;
  1259. - const UCHAR *pCbDimension = aDimCb;
  1260. - const UCHAR *pCbSign = aSignCb;
  1261. -
  1262. - /* clear result array */
  1263. - FDKmemclear(pQuantizedSpectralCoefficients + quantizedSpectralCoefficientsIdx,
  1264. - 1024 * sizeof(FIXP_DBL));
  1265. -
  1266. - /* decode all PCWs in the extended sorted section(s) belonging to set 0 */
  1267. - for (extSortSec =
  1268. - pNumExtendedSortedSectionsInSets[numExtendedSortedSectionsInSetsIdx];
  1269. - extSortSec != 0; extSortSec--) {
  1270. - codebook =
  1271. - pExtendedSortedCodebook[extendedSortedCodebookIdx]; /* get codebook for
  1272. - this extended
  1273. - sorted section
  1274. - and increment ptr
  1275. - to cb of next
  1276. - ext. sort sec */
  1277. - extendedSortedCodebookIdx++;
  1278. - if (extendedSortedCodebookIdx >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
  1279. - return;
  1280. - }
  1281. - dimension = pCbDimension[codebook]; /* get dimension of codebook of this
  1282. - extended sort. sec. */
  1283. - pCurrentTree =
  1284. - aHuffTable[codebook]; /* convert codebook to pointer to QSCs */
  1285. - pQuantValBase =
  1286. - aQuantTable[codebook]; /* convert codebook to index to table of QSCs */
  1287. - maxAllowedCwLen = pMaxLenOfCbInExtSrtSec[maxLenOfCbInExtSrtSecIdx];
  1288. - maxLenOfCbInExtSrtSecIdx++;
  1289. - if (maxLenOfCbInExtSrtSecIdx >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
  1290. - return;
  1291. - }
  1292. -
  1293. - /* switch for decoding with different codebooks: */
  1294. - if (pCbSign[codebook] ==
  1295. - 0) { /* no sign bits follow after the codeword-body */
  1296. - /* PCW_BodyONLY */
  1297. - /*==============*/
  1298. -
  1299. - for (curExtSortCwInSec = pNumExtendedSortedCodewordInSection
  1300. - [numExtendedSortedCodewordInSectionIdx];
  1301. - curExtSortCwInSec != 0; curExtSortCwInSec--) {
  1302. - numDecodedBits = 0;
  1303. -
  1304. - /* decode PCW_BODY */
  1305. - pQuantVal = DecodePCW_Body(
  1306. - bs, pHcr->decInOut.bitstreamAnchor, pCurrentTree, pQuantValBase,
  1307. - pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits);
  1308. -
  1309. - /* result is written out here because NO sign bits follow the body */
  1310. - for (i = dimension; i != 0; i--) {
  1311. - pQuantizedSpectralCoefficients[quantizedSpectralCoefficientsIdx] =
  1312. - (FIXP_DBL)*pQuantVal++; /* write quant. spec. coef. into
  1313. - spectrum; sign is already valid */
  1314. - quantizedSpectralCoefficientsIdx++;
  1315. - if (quantizedSpectralCoefficientsIdx >= 1024) {
  1316. - return;
  1317. - }
  1318. - }
  1319. -
  1320. - /* one more PCW should be decoded */
  1321. -
  1322. - if (maxAllowedCwLen < (numDecodedBits + ERROR_PCW_BODY_ONLY_TOO_LONG)) {
  1323. - pHcr->decInOut.errorLog |= TOO_MANY_PCW_BODY_BITS_DECODED;
  1324. - }
  1325. -
  1326. - if (1 == errDetectPcwSegmentation(
  1327. - *pRemainingBitsInSegment - ERROR_PCW_BODY, pHcr, PCW_BODY,
  1328. - pQuantizedSpectralCoefficients +
  1329. - quantizedSpectralCoefficientsIdx - dimension,
  1330. - dimension)) {
  1331. - return;
  1332. - }
  1333. - pLeftStartOfSegment++; /* update pointer for decoding the next PCW */
  1334. - pRemainingBitsInSegment++; /* update pointer for decoding the next PCW
  1335. - */
  1336. - }
  1337. - } else if ((codebook < 11) && (pCbSign[codebook] ==
  1338. - 1)) { /* possibly there follow 1,2,3 or 4
  1339. - sign bits after the codeword-body */
  1340. - /* PCW_Body and PCW_Sign */
  1341. - /*=======================*/
  1342. -
  1343. - for (curExtSortCwInSec = pNumExtendedSortedCodewordInSection
  1344. - [numExtendedSortedCodewordInSectionIdx];
  1345. - curExtSortCwInSec != 0; curExtSortCwInSec--) {
  1346. - int err;
  1347. - numDecodedBits = 0;
  1348. -
  1349. - pQuantVal = DecodePCW_Body(
  1350. - bs, pHcr->decInOut.bitstreamAnchor, pCurrentTree, pQuantValBase,
  1351. - pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits);
  1352. -
  1353. - err = DecodePCW_Sign(
  1354. - bs, pHcr->decInOut.bitstreamAnchor, dimension, pQuantVal,
  1355. - pQuantizedSpectralCoefficients, &quantizedSpectralCoefficientsIdx,
  1356. - pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits);
  1357. - if (err != 0) {
  1358. - return;
  1359. - }
  1360. - /* one more PCW should be decoded */
  1361. -
  1362. - if (maxAllowedCwLen < (numDecodedBits + ERROR_PCW_BODY_SIGN_TOO_LONG)) {
  1363. - pHcr->decInOut.errorLog |= TOO_MANY_PCW_BODY_SIGN_BITS_DECODED;
  1364. - }
  1365. -
  1366. - if (1 == errDetectPcwSegmentation(
  1367. - *pRemainingBitsInSegment - ERROR_PCW_BODY_SIGN, pHcr,
  1368. - PCW_BODY_SIGN,
  1369. - pQuantizedSpectralCoefficients +
  1370. - quantizedSpectralCoefficientsIdx - dimension,
  1371. - dimension)) {
  1372. - return;
  1373. - }
  1374. - pLeftStartOfSegment++;
  1375. - pRemainingBitsInSegment++;
  1376. - }
  1377. - } else if ((pCbSign[codebook] == 1) &&
  1378. - (codebook >= 11)) { /* possibly there follow some sign bits and
  1379. - maybe one or two escape sequences after
  1380. - the cw-body */
  1381. - /* PCW_Body, PCW_Sign and maybe PCW_Escape */
  1382. - /*=========================================*/
  1383. -
  1384. - for (curExtSortCwInSec = pNumExtendedSortedCodewordInSection
  1385. - [numExtendedSortedCodewordInSectionIdx];
  1386. - curExtSortCwInSec != 0; curExtSortCwInSec--) {
  1387. - int err;
  1388. - numDecodedBits = 0;
  1389. -
  1390. - /* decode PCW_BODY */
  1391. - pQuantVal = DecodePCW_Body(
  1392. - bs, pHcr->decInOut.bitstreamAnchor, pCurrentTree, pQuantValBase,
  1393. - pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits);
  1394. -
  1395. - err = DecodePCW_Sign(
  1396. - bs, pHcr->decInOut.bitstreamAnchor, dimension, pQuantVal,
  1397. - pQuantizedSpectralCoefficients, &quantizedSpectralCoefficientsIdx,
  1398. - pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits);
  1399. - if (err != 0) {
  1400. - return;
  1401. - }
  1402. -
  1403. - /* decode PCW_ESCAPE if present */
  1404. - quantizedSpectralCoefficientsIdx -= DIMENSION_OF_ESCAPE_CODEBOOK;
  1405. -
  1406. - if (fixp_abs(pQuantizedSpectralCoefficients
  1407. - [quantizedSpectralCoefficientsIdx]) ==
  1408. - (FIXP_DBL)ESCAPE_VALUE) {
  1409. - pQuantizedSpectralCoefficients[quantizedSpectralCoefficientsIdx] =
  1410. - (FIXP_DBL)DecodeEscapeSequence(
  1411. - bs, pHcr->decInOut.bitstreamAnchor,
  1412. - pQuantizedSpectralCoefficients
  1413. - [quantizedSpectralCoefficientsIdx],
  1414. - pLeftStartOfSegment, pRemainingBitsInSegment,
  1415. - &numDecodedBits);
  1416. - }
  1417. - quantizedSpectralCoefficientsIdx++;
  1418. - if (quantizedSpectralCoefficientsIdx >= 1024) {
  1419. - return;
  1420. - }
  1421. -
  1422. - if (fixp_abs(pQuantizedSpectralCoefficients
  1423. - [quantizedSpectralCoefficientsIdx]) ==
  1424. - (FIXP_DBL)ESCAPE_VALUE) {
  1425. - pQuantizedSpectralCoefficients[quantizedSpectralCoefficientsIdx] =
  1426. - (FIXP_DBL)DecodeEscapeSequence(
  1427. - bs, pHcr->decInOut.bitstreamAnchor,
  1428. - pQuantizedSpectralCoefficients
  1429. - [quantizedSpectralCoefficientsIdx],
  1430. - pLeftStartOfSegment, pRemainingBitsInSegment,
  1431. - &numDecodedBits);
  1432. - }
  1433. - quantizedSpectralCoefficientsIdx++;
  1434. - if (quantizedSpectralCoefficientsIdx >= 1024) {
  1435. - return;
  1436. - }
  1437. -
  1438. - /* one more PCW should be decoded */
  1439. -
  1440. - if (maxAllowedCwLen <
  1441. - (numDecodedBits + ERROR_PCW_BODY_SIGN_ESC_TOO_LONG)) {
  1442. - pHcr->decInOut.errorLog |= TOO_MANY_PCW_BODY_SIGN_ESC_BITS_DECODED;
  1443. - }
  1444. -
  1445. - if (1 == errDetectPcwSegmentation(
  1446. - *pRemainingBitsInSegment - ERROR_PCW_BODY_SIGN_ESC, pHcr,
  1447. - PCW_BODY_SIGN_ESC,
  1448. - pQuantizedSpectralCoefficients +
  1449. - quantizedSpectralCoefficientsIdx -
  1450. - DIMENSION_OF_ESCAPE_CODEBOOK,
  1451. - DIMENSION_OF_ESCAPE_CODEBOOK)) {
  1452. - return;
  1453. - }
  1454. - pLeftStartOfSegment++;
  1455. - pRemainingBitsInSegment++;
  1456. - }
  1457. - }
  1458. -
  1459. - /* all PCWs belonging to this extended section should be decoded */
  1460. - numExtendedSortedCodewordInSectionIdx++;
  1461. - if (numExtendedSortedCodewordInSectionIdx >= MAX_SFB_HCR + MAX_HCR_SETS) {
  1462. - return;
  1463. - }
  1464. - }
  1465. - /* all PCWs should be decoded */
  1466. -
  1467. - numExtendedSortedSectionsInSetsIdx++;
  1468. - if (numExtendedSortedSectionsInSetsIdx >= MAX_HCR_SETS) {
  1469. - return;
  1470. - }
  1471. -
  1472. - /* Write back indexes into structure */
  1473. - pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx =
  1474. - numExtendedSortedCodewordInSectionIdx;
  1475. - pHcr->sectionInfo.extendedSortedCodebookIdx = extendedSortedCodebookIdx;
  1476. - pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx =
  1477. - numExtendedSortedSectionsInSetsIdx;
  1478. - pHcr->decInOut.quantizedSpectralCoefficientsIdx =
  1479. - quantizedSpectralCoefficientsIdx;
  1480. - pHcr->sectionInfo.maxLenOfCbInExtSrtSecIdx = maxLenOfCbInExtSrtSecIdx;
  1481. -}
  1482. -
  1483. -/*---------------------------------------------------------------------------------------------
  1484. - description: This function checks immediately after every decoded PCW,
  1485. -whether out of the current segment too many bits have been read or not. If an
  1486. -error occurrs, probably the sideinfo or the HCR-bitstream block holding the
  1487. -huffman encoded quantized spectral coefficients is distorted. In this case the
  1488. -two or four quantized spectral coefficients belonging to the current codeword
  1489. - are marked (for being detected by concealment later).
  1490. ---------------------------------------------------------------------------------------------
  1491. -*/
  1492. -static UCHAR errDetectPcwSegmentation(SCHAR remainingBitsInSegment,
  1493. - H_HCR_INFO pHcr, PCW_TYPE kind,
  1494. - FIXP_DBL *qsc_base_of_cw,
  1495. - UCHAR dimension) {
  1496. - SCHAR i;
  1497. - if (remainingBitsInSegment < 0) {
  1498. - /* log the error */
  1499. - switch (kind) {
  1500. - case PCW_BODY:
  1501. - pHcr->decInOut.errorLog |= SEGMENT_OVERRIDE_ERR_PCW_BODY;
  1502. - break;
  1503. - case PCW_BODY_SIGN:
  1504. - pHcr->decInOut.errorLog |= SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN;
  1505. - break;
  1506. - case PCW_BODY_SIGN_ESC:
  1507. - pHcr->decInOut.errorLog |= SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN_ESC;
  1508. - break;
  1509. - }
  1510. - /* mark the erred lines */
  1511. - for (i = dimension; i != 0; i--) {
  1512. - *qsc_base_of_cw++ = (FIXP_DBL)Q_VALUE_INVALID;
  1513. - }
  1514. - return 1;
  1515. - }
  1516. - return 0;
  1517. -}
  1518. -
  1519. -/*---------------------------------------------------------------------------------------------
  1520. - description: This function checks if all segments are empty after
  1521. -decoding. There are _no lines markded_ as invalid because it could not be traced
  1522. -back where from the remaining bits are.
  1523. ---------------------------------------------------------------------------------------------
  1524. -*/
  1525. -static void errDetectWithinSegmentationFinal(H_HCR_INFO pHcr) {
  1526. - UCHAR segmentationErrorFlag = 0;
  1527. - USHORT i;
  1528. - SCHAR *pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  1529. - UINT numSegment = pHcr->segmentInfo.numSegment;
  1530. -
  1531. - for (i = numSegment; i != 0; i--) {
  1532. - if (*pRemainingBitsInSegment++ != 0) {
  1533. - segmentationErrorFlag = 1;
  1534. - }
  1535. - }
  1536. - if (segmentationErrorFlag == 1) {
  1537. - pHcr->decInOut.errorLog |= BIT_IN_SEGMENTATION_ERROR;
  1538. - }
  1539. -}
  1540. -
  1541. -/*---------------------------------------------------------------------------------------------
  1542. - description: This function walks one step within the decoding tree. Which
  1543. -branch is taken depends on the decoded carryBit input parameter.
  1544. ---------------------------------------------------------------------------------------------
  1545. -*/
  1546. -void CarryBitToBranchValue(UCHAR carryBit, UINT treeNode, UINT *branchValue,
  1547. - UINT *branchNode) {
  1548. - if (carryBit == 0) {
  1549. - *branchNode =
  1550. - (treeNode & MASK_LEFT) >> LEFT_OFFSET; /* MASK_LEFT: 00FFF000 */
  1551. - } else {
  1552. - *branchNode = treeNode & MASK_RIGHT; /* MASK_RIGHT: 00000FFF */
  1553. - }
  1554. -
  1555. - *branchValue = *branchNode & CLR_BIT_10; /* clear bit 10 (if set) */
  1556. -}
  1557. -
  1558. -/*---------------------------------------------------------------------------------------------
  1559. - description: Decodes the body of a priority codeword (PCW)
  1560. ------------------------------------------------------------------------------------------------
  1561. - return: - return value is pointer to first of two or four quantized
  1562. -spectral coefficients
  1563. ---------------------------------------------------------------------------------------------
  1564. -*/
  1565. -static const SCHAR *DecodePCW_Body(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  1566. - const UINT *pCurrentTree,
  1567. - const SCHAR *pQuantValBase,
  1568. - INT *pLeftStartOfSegment,
  1569. - SCHAR *pRemainingBitsInSegment,
  1570. - int *pNumDecodedBits) {
  1571. - UCHAR carryBit;
  1572. - UINT branchNode;
  1573. - UINT treeNode;
  1574. - UINT branchValue;
  1575. - const SCHAR *pQuantVal;
  1576. -
  1577. - /* decode PCW_BODY */
  1578. - treeNode = *pCurrentTree; /* get first node of current tree belonging to
  1579. - current codebook */
  1580. -
  1581. - /* decode whole PCW-codeword-body */
  1582. - while (1) {
  1583. - carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment,
  1584. - pLeftStartOfSegment, /* dummy */
  1585. - FROM_LEFT_TO_RIGHT);
  1586. - *pRemainingBitsInSegment -= 1;
  1587. - *pNumDecodedBits += 1;
  1588. -
  1589. - CarryBitToBranchValue(carryBit, treeNode, &branchValue, &branchNode);
  1590. -
  1591. - if ((branchNode & TEST_BIT_10) ==
  1592. - TEST_BIT_10) { /* test bit 10 ; if set --> codeword-body is complete */
  1593. - break; /* end of branch in tree reached i.e. a whole PCW-Body is decoded
  1594. - */
  1595. - } else {
  1596. - treeNode = *(
  1597. - pCurrentTree +
  1598. - branchValue); /* update treeNode for further step in decoding tree */
  1599. - }
  1600. - }
  1601. -
  1602. - pQuantVal =
  1603. - pQuantValBase + branchValue; /* update pointer to valid first of 2 or 4
  1604. - quantized values */
  1605. -
  1606. - return pQuantVal;
  1607. -}
  1608. -
  1609. -/*---------------------------------------------------------------------------------------------
  1610. - description: This function decodes one escape sequence. In case of a
  1611. -escape codebook and in case of the absolute value of the quantized spectral
  1612. -value == 16, a escapeSequence is decoded in two steps:
  1613. - 1. escape prefix
  1614. - 2. escape word
  1615. ---------------------------------------------------------------------------------------------
  1616. -*/
  1617. -
  1618. -static INT DecodeEscapeSequence(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  1619. - INT quantSpecCoef, INT *pLeftStartOfSegment,
  1620. - SCHAR *pRemainingBitsInSegment,
  1621. - int *pNumDecodedBits) {
  1622. - UINT i;
  1623. - INT sign;
  1624. - UINT escapeOnesCounter = 0;
  1625. - UINT carryBit;
  1626. - INT escape_word = 0;
  1627. -
  1628. - /* decode escape prefix */
  1629. - while (1) {
  1630. - carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment,
  1631. - pLeftStartOfSegment, /* dummy */
  1632. - FROM_LEFT_TO_RIGHT);
  1633. - *pRemainingBitsInSegment -= 1;
  1634. - *pNumDecodedBits += 1;
  1635. -
  1636. - if (carryBit != 0) {
  1637. - escapeOnesCounter += 1;
  1638. - } else {
  1639. - escapeOnesCounter += 4;
  1640. - break;
  1641. - }
  1642. - }
  1643. -
  1644. - /* decode escape word */
  1645. - for (i = escapeOnesCounter; i != 0; i--) {
  1646. - carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment,
  1647. - pLeftStartOfSegment, /* dummy */
  1648. - FROM_LEFT_TO_RIGHT);
  1649. - *pRemainingBitsInSegment -= 1;
  1650. - *pNumDecodedBits += 1;
  1651. -
  1652. - escape_word <<= 1;
  1653. - escape_word = escape_word | carryBit;
  1654. - }
  1655. -
  1656. - sign = (quantSpecCoef >= 0) ? 1 : -1;
  1657. -
  1658. - quantSpecCoef = sign * (((INT)1 << escapeOnesCounter) + escape_word);
  1659. -
  1660. - return quantSpecCoef;
  1661. -}
  1662. -
  1663. -/*---------------------------------------------------------------------------------------------
  1664. - description: Decodes the Signbits of a priority codeword (PCW) and writes
  1665. -out the resulting quantized spectral values into unsorted sections
  1666. ------------------------------------------------------------------------------------------------
  1667. - output: - two or four lines at position in corresponding section
  1668. -(which are not located at the desired position, i.e. they must be reordered in
  1669. -the last of eight function of HCR)
  1670. ------------------------------------------------------------------------------------------------
  1671. - return: - updated pQuantSpecCoef pointer (to next empty storage for a
  1672. -line)
  1673. ---------------------------------------------------------------------------------------------
  1674. -*/
  1675. -static int DecodePCW_Sign(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  1676. - UINT codebookDim, const SCHAR *pQuantVal,
  1677. - FIXP_DBL *pQuantSpecCoef, int *quantSpecCoefIdx,
  1678. - INT *pLeftStartOfSegment,
  1679. - SCHAR *pRemainingBitsInSegment,
  1680. - int *pNumDecodedBits) {
  1681. - UINT i;
  1682. - UINT carryBit;
  1683. - INT quantSpecCoef;
  1684. -
  1685. - for (i = codebookDim; i != 0; i--) {
  1686. - quantSpecCoef = *pQuantVal++;
  1687. - if (quantSpecCoef != 0) {
  1688. - carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment,
  1689. - pLeftStartOfSegment, /* dummy */
  1690. - FROM_LEFT_TO_RIGHT);
  1691. - *pRemainingBitsInSegment -= 1;
  1692. - *pNumDecodedBits += 1;
  1693. - if (*pRemainingBitsInSegment < 0 || *pNumDecodedBits >= (1024 >> 1)) {
  1694. - return -1;
  1695. - }
  1696. -
  1697. - /* adapt sign of values according to the decoded sign bit */
  1698. - if (carryBit != 0) {
  1699. - pQuantSpecCoef[*quantSpecCoefIdx] = -(FIXP_DBL)quantSpecCoef;
  1700. - } else {
  1701. - pQuantSpecCoef[*quantSpecCoefIdx] = (FIXP_DBL)quantSpecCoef;
  1702. - }
  1703. - } else {
  1704. - pQuantSpecCoef[*quantSpecCoefIdx] = FL2FXCONST_DBL(0.0f);
  1705. - }
  1706. - *quantSpecCoefIdx += 1;
  1707. - if (*quantSpecCoefIdx >= 1024) {
  1708. - return -1;
  1709. - }
  1710. - }
  1711. - return 0;
  1712. -}
  1713. -
  1714. -/*---------------------------------------------------------------------------------------------
  1715. - description: Mutes spectral lines which have been marked as erroneous
  1716. -(Q_VALUE_INVALID)
  1717. ---------------------------------------------------------------------------------------------
  1718. -*/
  1719. -void HcrMuteErroneousLines(H_HCR_INFO hHcr) {
  1720. - int c;
  1721. - FIXP_DBL *RESTRICT pLong =
  1722. - SPEC_LONG(hHcr->decInOut.pQuantizedSpectralCoefficientsBase);
  1723. -
  1724. - /* if there is a line with value Q_VALUE_INVALID mute it */
  1725. - for (c = 0; c < 1024; c++) {
  1726. - if (pLong[c] == (FIXP_DBL)Q_VALUE_INVALID) {
  1727. - pLong[c] = FL2FXCONST_DBL(0.0f); /* muting */
  1728. - }
  1729. - }
  1730. -}
  1731. --- a/libAACdec/src/aacdec_hcr.h
  1732. +++ /dev/null
  1733. @@ -1,128 +0,0 @@
  1734. -/* -----------------------------------------------------------------------------
  1735. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  1736. -
  1737. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  1738. -Forschung e.V. All rights reserved.
  1739. -
  1740. - 1. INTRODUCTION
  1741. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  1742. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  1743. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  1744. -a wide variety of Android devices.
  1745. -
  1746. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  1747. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  1748. -full-bandwidth communications codec by independent studies and is widely
  1749. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  1750. -specifications.
  1751. -
  1752. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  1753. -those of Fraunhofer) may be obtained through Via Licensing
  1754. -(www.vialicensing.com) or through the respective patent owners individually for
  1755. -the purpose of encoding or decoding bit streams in products that are compliant
  1756. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  1757. -Android devices already license these patent claims through Via Licensing or
  1758. -directly from the patent owners, and therefore FDK AAC Codec software may
  1759. -already be covered under those patent licenses when it is used for those
  1760. -licensed purposes only.
  1761. -
  1762. -Commercially-licensed AAC software libraries, including floating-point versions
  1763. -with enhanced sound quality, are also available from Fraunhofer. Users are
  1764. -encouraged to check the Fraunhofer website for additional applications
  1765. -information and documentation.
  1766. -
  1767. -2. COPYRIGHT LICENSE
  1768. -
  1769. -Redistribution and use in source and binary forms, with or without modification,
  1770. -are permitted without payment of copyright license fees provided that you
  1771. -satisfy the following conditions:
  1772. -
  1773. -You must retain the complete text of this software license in redistributions of
  1774. -the FDK AAC Codec or your modifications thereto in source code form.
  1775. -
  1776. -You must retain the complete text of this software license in the documentation
  1777. -and/or other materials provided with redistributions of the FDK AAC Codec or
  1778. -your modifications thereto in binary form. You must make available free of
  1779. -charge copies of the complete source code of the FDK AAC Codec and your
  1780. -modifications thereto to recipients of copies in binary form.
  1781. -
  1782. -The name of Fraunhofer may not be used to endorse or promote products derived
  1783. -from this library without prior written permission.
  1784. -
  1785. -You may not charge copyright license fees for anyone to use, copy or distribute
  1786. -the FDK AAC Codec software or your modifications thereto.
  1787. -
  1788. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  1789. -that you changed the software and the date of any change. For modified versions
  1790. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  1791. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  1792. -AAC Codec Library for Android."
  1793. -
  1794. -3. NO PATENT LICENSE
  1795. -
  1796. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  1797. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  1798. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  1799. -software.
  1800. -
  1801. -You may use this FDK AAC Codec software or modifications thereto only for
  1802. -purposes that are authorized by appropriate patent licenses.
  1803. -
  1804. -4. DISCLAIMER
  1805. -
  1806. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  1807. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  1808. -including but not limited to the implied warranties of merchantability and
  1809. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  1810. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  1811. -or consequential damages, including but not limited to procurement of substitute
  1812. -goods or services; loss of use, data, or profits, or business interruption,
  1813. -however caused and on any theory of liability, whether in contract, strict
  1814. -liability, or tort (including negligence), arising in any way out of the use of
  1815. -this software, even if advised of the possibility of such damage.
  1816. -
  1817. -5. CONTACT INFORMATION
  1818. -
  1819. -Fraunhofer Institute for Integrated Circuits IIS
  1820. -Attention: Audio and Multimedia Departments - FDK AAC LL
  1821. -Am Wolfsmantel 33
  1822. -91058 Erlangen, Germany
  1823. -
  1824. -www.iis.fraunhofer.de/amm
  1825. -amm-info@iis.fraunhofer.de
  1826. ------------------------------------------------------------------------------ */
  1827. -
  1828. -/**************************** AAC decoder library ******************************
  1829. -
  1830. - Author(s): Robert Weidner (DSP Solutions)
  1831. -
  1832. - Description: HCR Decoder: Interface function declaration; common defines
  1833. - and structures; defines for switching error-generator,
  1834. - -detector, and -concealment
  1835. -
  1836. -*******************************************************************************/
  1837. -
  1838. -#ifndef AACDEC_HCR_H
  1839. -#define AACDEC_HCR_H
  1840. -
  1841. -#include "channelinfo.h"
  1842. -#include "FDK_bitstream.h"
  1843. -
  1844. -UINT HcrInit(H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  1845. - const SamplingRateInfo *pSamplingRateInfo,
  1846. - HANDLE_FDK_BITSTREAM bs);
  1847. -UINT HcrDecoder(H_HCR_INFO hHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  1848. - const SamplingRateInfo *pSamplingRateInfo,
  1849. - HANDLE_FDK_BITSTREAM bs);
  1850. -void CarryBitToBranchValue(UCHAR carryBit, UINT treeNode, UINT *branchValue,
  1851. - UINT *branchNode);
  1852. -
  1853. -void CHcr_Read(HANDLE_FDK_BITSTREAM bs,
  1854. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  1855. - const MP4_ELEMENT_ID globalHcrType);
  1856. -void HcrMuteErroneousLines(H_HCR_INFO hHcr);
  1857. -
  1858. -void setHcrType(H_HCR_INFO hHcr, MP4_ELEMENT_ID type);
  1859. -INT getHcrType(H_HCR_INFO hHcr);
  1860. -
  1861. -#endif /* AACDEC_HCR_H */
  1862. --- a/libAACdec/src/aacdec_hcr_bit.cpp
  1863. +++ /dev/null
  1864. @@ -1,164 +0,0 @@
  1865. -/* -----------------------------------------------------------------------------
  1866. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  1867. -
  1868. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  1869. -Forschung e.V. All rights reserved.
  1870. -
  1871. - 1. INTRODUCTION
  1872. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  1873. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  1874. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  1875. -a wide variety of Android devices.
  1876. -
  1877. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  1878. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  1879. -full-bandwidth communications codec by independent studies and is widely
  1880. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  1881. -specifications.
  1882. -
  1883. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  1884. -those of Fraunhofer) may be obtained through Via Licensing
  1885. -(www.vialicensing.com) or through the respective patent owners individually for
  1886. -the purpose of encoding or decoding bit streams in products that are compliant
  1887. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  1888. -Android devices already license these patent claims through Via Licensing or
  1889. -directly from the patent owners, and therefore FDK AAC Codec software may
  1890. -already be covered under those patent licenses when it is used for those
  1891. -licensed purposes only.
  1892. -
  1893. -Commercially-licensed AAC software libraries, including floating-point versions
  1894. -with enhanced sound quality, are also available from Fraunhofer. Users are
  1895. -encouraged to check the Fraunhofer website for additional applications
  1896. -information and documentation.
  1897. -
  1898. -2. COPYRIGHT LICENSE
  1899. -
  1900. -Redistribution and use in source and binary forms, with or without modification,
  1901. -are permitted without payment of copyright license fees provided that you
  1902. -satisfy the following conditions:
  1903. -
  1904. -You must retain the complete text of this software license in redistributions of
  1905. -the FDK AAC Codec or your modifications thereto in source code form.
  1906. -
  1907. -You must retain the complete text of this software license in the documentation
  1908. -and/or other materials provided with redistributions of the FDK AAC Codec or
  1909. -your modifications thereto in binary form. You must make available free of
  1910. -charge copies of the complete source code of the FDK AAC Codec and your
  1911. -modifications thereto to recipients of copies in binary form.
  1912. -
  1913. -The name of Fraunhofer may not be used to endorse or promote products derived
  1914. -from this library without prior written permission.
  1915. -
  1916. -You may not charge copyright license fees for anyone to use, copy or distribute
  1917. -the FDK AAC Codec software or your modifications thereto.
  1918. -
  1919. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  1920. -that you changed the software and the date of any change. For modified versions
  1921. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  1922. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  1923. -AAC Codec Library for Android."
  1924. -
  1925. -3. NO PATENT LICENSE
  1926. -
  1927. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  1928. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  1929. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  1930. -software.
  1931. -
  1932. -You may use this FDK AAC Codec software or modifications thereto only for
  1933. -purposes that are authorized by appropriate patent licenses.
  1934. -
  1935. -4. DISCLAIMER
  1936. -
  1937. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  1938. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  1939. -including but not limited to the implied warranties of merchantability and
  1940. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  1941. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  1942. -or consequential damages, including but not limited to procurement of substitute
  1943. -goods or services; loss of use, data, or profits, or business interruption,
  1944. -however caused and on any theory of liability, whether in contract, strict
  1945. -liability, or tort (including negligence), arising in any way out of the use of
  1946. -this software, even if advised of the possibility of such damage.
  1947. -
  1948. -5. CONTACT INFORMATION
  1949. -
  1950. -Fraunhofer Institute for Integrated Circuits IIS
  1951. -Attention: Audio and Multimedia Departments - FDK AAC LL
  1952. -Am Wolfsmantel 33
  1953. -91058 Erlangen, Germany
  1954. -
  1955. -www.iis.fraunhofer.de/amm
  1956. -amm-info@iis.fraunhofer.de
  1957. ------------------------------------------------------------------------------ */
  1958. -
  1959. -/**************************** AAC decoder library ******************************
  1960. -
  1961. - Author(s): Robert Weidner (DSP Solutions)
  1962. -
  1963. - Description: HCR Decoder: Bitstream reading
  1964. -
  1965. -*******************************************************************************/
  1966. -
  1967. -#include "aacdec_hcr_bit.h"
  1968. -
  1969. -/*---------------------------------------------------------------------------------------------
  1970. - description: This function toggles the read direction.
  1971. ------------------------------------------------------------------------------------------------
  1972. - input: current read direction
  1973. ------------------------------------------------------------------------------------------------
  1974. - return: new read direction
  1975. ---------------------------------------------------------------------------------------------
  1976. -*/
  1977. -UCHAR ToggleReadDirection(UCHAR readDirection) {
  1978. - if (readDirection == FROM_LEFT_TO_RIGHT) {
  1979. - return FROM_RIGHT_TO_LEFT;
  1980. - } else {
  1981. - return FROM_LEFT_TO_RIGHT;
  1982. - }
  1983. -}
  1984. -
  1985. -/*---------------------------------------------------------------------------------------------
  1986. - description: This function returns a bit from the bitstream according to
  1987. -read direction. It is called very often, therefore it makes sense to inline it
  1988. -(runtime).
  1989. ------------------------------------------------------------------------------------------------
  1990. - input: - handle to FDK bitstream
  1991. - - reference value marking start of bitfield
  1992. - - pLeftStartOfSegment
  1993. - - pRightStartOfSegment
  1994. - - readDirection
  1995. ------------------------------------------------------------------------------------------------
  1996. - return: - bit from bitstream
  1997. ---------------------------------------------------------------------------------------------
  1998. -*/
  1999. -UINT HcrGetABitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  2000. - INT *pLeftStartOfSegment,
  2001. - INT *pRightStartOfSegment, UCHAR readDirection) {
  2002. - UINT bit;
  2003. - INT readBitOffset;
  2004. -
  2005. - if (readDirection == FROM_LEFT_TO_RIGHT) {
  2006. - readBitOffset = (INT)FDKgetValidBits(bs) - bsAnchor + *pLeftStartOfSegment;
  2007. - if (readBitOffset) {
  2008. - FDKpushBiDirectional(bs, readBitOffset);
  2009. - }
  2010. -
  2011. - bit = FDKreadBits(bs, 1);
  2012. -
  2013. - *pLeftStartOfSegment += 1;
  2014. - } else {
  2015. - readBitOffset = (INT)FDKgetValidBits(bs) - bsAnchor + *pRightStartOfSegment;
  2016. - if (readBitOffset) {
  2017. - FDKpushBiDirectional(bs, readBitOffset);
  2018. - }
  2019. -
  2020. - /* to be replaced with a brother function of FDKreadBits() */
  2021. - bit = FDKreadBits(bs, 1);
  2022. - FDKpushBack(bs, 2);
  2023. -
  2024. - *pRightStartOfSegment -= 1;
  2025. - }
  2026. -
  2027. - return (bit);
  2028. -}
  2029. --- a/libAACdec/src/aacdec_hcr_bit.h
  2030. +++ /dev/null
  2031. @@ -1,114 +0,0 @@
  2032. -/* -----------------------------------------------------------------------------
  2033. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  2034. -
  2035. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  2036. -Forschung e.V. All rights reserved.
  2037. -
  2038. - 1. INTRODUCTION
  2039. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  2040. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  2041. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  2042. -a wide variety of Android devices.
  2043. -
  2044. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  2045. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  2046. -full-bandwidth communications codec by independent studies and is widely
  2047. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  2048. -specifications.
  2049. -
  2050. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  2051. -those of Fraunhofer) may be obtained through Via Licensing
  2052. -(www.vialicensing.com) or through the respective patent owners individually for
  2053. -the purpose of encoding or decoding bit streams in products that are compliant
  2054. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  2055. -Android devices already license these patent claims through Via Licensing or
  2056. -directly from the patent owners, and therefore FDK AAC Codec software may
  2057. -already be covered under those patent licenses when it is used for those
  2058. -licensed purposes only.
  2059. -
  2060. -Commercially-licensed AAC software libraries, including floating-point versions
  2061. -with enhanced sound quality, are also available from Fraunhofer. Users are
  2062. -encouraged to check the Fraunhofer website for additional applications
  2063. -information and documentation.
  2064. -
  2065. -2. COPYRIGHT LICENSE
  2066. -
  2067. -Redistribution and use in source and binary forms, with or without modification,
  2068. -are permitted without payment of copyright license fees provided that you
  2069. -satisfy the following conditions:
  2070. -
  2071. -You must retain the complete text of this software license in redistributions of
  2072. -the FDK AAC Codec or your modifications thereto in source code form.
  2073. -
  2074. -You must retain the complete text of this software license in the documentation
  2075. -and/or other materials provided with redistributions of the FDK AAC Codec or
  2076. -your modifications thereto in binary form. You must make available free of
  2077. -charge copies of the complete source code of the FDK AAC Codec and your
  2078. -modifications thereto to recipients of copies in binary form.
  2079. -
  2080. -The name of Fraunhofer may not be used to endorse or promote products derived
  2081. -from this library without prior written permission.
  2082. -
  2083. -You may not charge copyright license fees for anyone to use, copy or distribute
  2084. -the FDK AAC Codec software or your modifications thereto.
  2085. -
  2086. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  2087. -that you changed the software and the date of any change. For modified versions
  2088. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  2089. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  2090. -AAC Codec Library for Android."
  2091. -
  2092. -3. NO PATENT LICENSE
  2093. -
  2094. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  2095. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  2096. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  2097. -software.
  2098. -
  2099. -You may use this FDK AAC Codec software or modifications thereto only for
  2100. -purposes that are authorized by appropriate patent licenses.
  2101. -
  2102. -4. DISCLAIMER
  2103. -
  2104. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  2105. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  2106. -including but not limited to the implied warranties of merchantability and
  2107. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  2108. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  2109. -or consequential damages, including but not limited to procurement of substitute
  2110. -goods or services; loss of use, data, or profits, or business interruption,
  2111. -however caused and on any theory of liability, whether in contract, strict
  2112. -liability, or tort (including negligence), arising in any way out of the use of
  2113. -this software, even if advised of the possibility of such damage.
  2114. -
  2115. -5. CONTACT INFORMATION
  2116. -
  2117. -Fraunhofer Institute for Integrated Circuits IIS
  2118. -Attention: Audio and Multimedia Departments - FDK AAC LL
  2119. -Am Wolfsmantel 33
  2120. -91058 Erlangen, Germany
  2121. -
  2122. -www.iis.fraunhofer.de/amm
  2123. -amm-info@iis.fraunhofer.de
  2124. ------------------------------------------------------------------------------ */
  2125. -
  2126. -/**************************** AAC decoder library ******************************
  2127. -
  2128. - Author(s): Robert Weidner (DSP Solutions)
  2129. -
  2130. - Description: HCR Decoder: Bitstream reading prototypes
  2131. -
  2132. -*******************************************************************************/
  2133. -
  2134. -#ifndef AACDEC_HCR_BIT_H
  2135. -#define AACDEC_HCR_BIT_H
  2136. -
  2137. -#include "aacdec_hcr.h"
  2138. -
  2139. -UCHAR ToggleReadDirection(UCHAR readDirection);
  2140. -
  2141. -UINT HcrGetABitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  2142. - INT *pLeftStartOfSegment,
  2143. - INT *pRightStartOfSegment, UCHAR readDirection);
  2144. -
  2145. -#endif /* AACDEC_HCR_BIT_H */
  2146. --- a/libAACdec/src/aacdec_hcr_types.h
  2147. +++ /dev/null
  2148. @@ -1,432 +0,0 @@
  2149. -/* -----------------------------------------------------------------------------
  2150. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  2151. -
  2152. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  2153. -Forschung e.V. All rights reserved.
  2154. -
  2155. - 1. INTRODUCTION
  2156. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  2157. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  2158. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  2159. -a wide variety of Android devices.
  2160. -
  2161. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  2162. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  2163. -full-bandwidth communications codec by independent studies and is widely
  2164. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  2165. -specifications.
  2166. -
  2167. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  2168. -those of Fraunhofer) may be obtained through Via Licensing
  2169. -(www.vialicensing.com) or through the respective patent owners individually for
  2170. -the purpose of encoding or decoding bit streams in products that are compliant
  2171. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  2172. -Android devices already license these patent claims through Via Licensing or
  2173. -directly from the patent owners, and therefore FDK AAC Codec software may
  2174. -already be covered under those patent licenses when it is used for those
  2175. -licensed purposes only.
  2176. -
  2177. -Commercially-licensed AAC software libraries, including floating-point versions
  2178. -with enhanced sound quality, are also available from Fraunhofer. Users are
  2179. -encouraged to check the Fraunhofer website for additional applications
  2180. -information and documentation.
  2181. -
  2182. -2. COPYRIGHT LICENSE
  2183. -
  2184. -Redistribution and use in source and binary forms, with or without modification,
  2185. -are permitted without payment of copyright license fees provided that you
  2186. -satisfy the following conditions:
  2187. -
  2188. -You must retain the complete text of this software license in redistributions of
  2189. -the FDK AAC Codec or your modifications thereto in source code form.
  2190. -
  2191. -You must retain the complete text of this software license in the documentation
  2192. -and/or other materials provided with redistributions of the FDK AAC Codec or
  2193. -your modifications thereto in binary form. You must make available free of
  2194. -charge copies of the complete source code of the FDK AAC Codec and your
  2195. -modifications thereto to recipients of copies in binary form.
  2196. -
  2197. -The name of Fraunhofer may not be used to endorse or promote products derived
  2198. -from this library without prior written permission.
  2199. -
  2200. -You may not charge copyright license fees for anyone to use, copy or distribute
  2201. -the FDK AAC Codec software or your modifications thereto.
  2202. -
  2203. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  2204. -that you changed the software and the date of any change. For modified versions
  2205. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  2206. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  2207. -AAC Codec Library for Android."
  2208. -
  2209. -3. NO PATENT LICENSE
  2210. -
  2211. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  2212. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  2213. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  2214. -software.
  2215. -
  2216. -You may use this FDK AAC Codec software or modifications thereto only for
  2217. -purposes that are authorized by appropriate patent licenses.
  2218. -
  2219. -4. DISCLAIMER
  2220. -
  2221. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  2222. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  2223. -including but not limited to the implied warranties of merchantability and
  2224. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  2225. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  2226. -or consequential damages, including but not limited to procurement of substitute
  2227. -goods or services; loss of use, data, or profits, or business interruption,
  2228. -however caused and on any theory of liability, whether in contract, strict
  2229. -liability, or tort (including negligence), arising in any way out of the use of
  2230. -this software, even if advised of the possibility of such damage.
  2231. -
  2232. -5. CONTACT INFORMATION
  2233. -
  2234. -Fraunhofer Institute for Integrated Circuits IIS
  2235. -Attention: Audio and Multimedia Departments - FDK AAC LL
  2236. -Am Wolfsmantel 33
  2237. -91058 Erlangen, Germany
  2238. -
  2239. -www.iis.fraunhofer.de/amm
  2240. -amm-info@iis.fraunhofer.de
  2241. ------------------------------------------------------------------------------ */
  2242. -
  2243. -/**************************** AAC decoder library ******************************
  2244. -
  2245. - Author(s): Robert Weidner (DSP Solutions)
  2246. -
  2247. - Description: HCR Decoder: Common defines and structures; defines for
  2248. - switching error-generator, -detector, and -concealment;
  2249. -
  2250. -*******************************************************************************/
  2251. -
  2252. -#ifndef AACDEC_HCR_TYPES_H
  2253. -#define AACDEC_HCR_TYPES_H
  2254. -
  2255. -#include "FDK_bitstream.h"
  2256. -#include "overlapadd.h"
  2257. -
  2258. -/* ------------------------------------------------ */
  2259. -/* ------------------------------------------------ */
  2260. -
  2261. -#define LINES_PER_UNIT 4
  2262. -
  2263. -/* ------------------------------------------------ */
  2264. -/* ------------------------------------------------ */
  2265. -/* ----------- basic HCR configuration ------------ */
  2266. -
  2267. -#define MAX_SFB_HCR \
  2268. - (((1024 / 8) / LINES_PER_UNIT) * 8) /* (8 * 16) is not enough because sfbs \
  2269. - are split in units for blocktype \
  2270. - short */
  2271. -#define NUMBER_OF_UNIT_GROUPS (LINES_PER_UNIT * 8)
  2272. -#define LINES_PER_UNIT_GROUP (1024 / NUMBER_OF_UNIT_GROUPS) /* 15 16 30 32 */
  2273. -
  2274. -/* ------------------------------------------------ */
  2275. -/* ------------------------------------------------ */
  2276. -/* ------------------------------------------------ */
  2277. -
  2278. -#define FROM_LEFT_TO_RIGHT 0
  2279. -#define FROM_RIGHT_TO_LEFT 1
  2280. -
  2281. -#define MAX_CB_PAIRS 23
  2282. -#define MAX_HCR_SETS 14
  2283. -
  2284. -#define ESCAPE_VALUE 16
  2285. -#define POSITION_OF_FLAG_A 21
  2286. -#define POSITION_OF_FLAG_B 20
  2287. -
  2288. -#define MAX_CB 32 /* last used CB is cb #31 when VCB11 is used */
  2289. -
  2290. -#define MAX_CB_CHECK \
  2291. - 32 /* support for VCB11 available -- is more general, could therefore used \
  2292. - in both cases */
  2293. -
  2294. -#define NUMBER_OF_BIT_IN_WORD 32
  2295. -
  2296. -/* log */
  2297. -#define THIRTYTWO_LOG_DIV_TWO_LOG 5
  2298. -#define EIGHT_LOG_DIV_TWO_LOG 3
  2299. -#define FOUR_LOG_DIV_TWO_LOG 2
  2300. -
  2301. -/* borders */
  2302. -#define CPE_TOP_LENGTH 12288
  2303. -#define SCE_TOP_LENGTH 6144
  2304. -#define LEN_OF_LONGEST_CW_TOP_LENGTH 49
  2305. -
  2306. -/* qsc's of high level */
  2307. -#define Q_VALUE_INVALID \
  2308. - 8192 /* mark a invalid line with this value (to be concealed later on) */
  2309. -#define HCR_DIRAC 500 /* a line of high level */
  2310. -
  2311. -/* masks */
  2312. -#define MASK_LEFT 0xFFF000
  2313. -#define MASK_RIGHT 0xFFF
  2314. -#define CLR_BIT_10 0x3FF
  2315. -#define TEST_BIT_10 0x400
  2316. -
  2317. -#define LEFT_OFFSET 12
  2318. -
  2319. -/* when set HCR is replaced by a dummy-module which just fills the outputbuffer
  2320. - * with a dirac sequence */
  2321. -/* use this if HCR is suspected to write in other modules -- if error is stell
  2322. - * there, HCR is innocent */
  2323. -
  2324. -/* ------------------------------ */
  2325. -/* - insert HCR errors - */
  2326. -/* ------------------------------ */
  2327. -
  2328. -/* modify input lengths -- high protected */
  2329. -#define ERROR_LORSD 0 /* offset: error if different from zero */
  2330. -#define ERROR_LOLC 0 /* offset: error if different from zero */
  2331. -
  2332. -/* segments are earlier empty as expected when decoding PCWs */
  2333. -#define ERROR_PCW_BODY \
  2334. - 0 /* set a positive values to trigger the error (make segments earlyer \
  2335. - appear to be empty) */
  2336. -#define ERROR_PCW_BODY_SIGN \
  2337. - 0 /* set a positive values to trigger the error (make segments earlyer \
  2338. - appear to be empty) */
  2339. -#define ERROR_PCW_BODY_SIGN_ESC \
  2340. - 0 /* set a positive values to trigger the error (make segments earlyer \
  2341. - appear to be empty) */
  2342. -
  2343. -/* pretend there are too many bits decoded (enlarge length of codeword) at PCWs
  2344. - * -- use a positive value */
  2345. -#define ERROR_PCW_BODY_ONLY_TOO_LONG \
  2346. - 0 /* set a positive values to trigger the error */
  2347. -#define ERROR_PCW_BODY_SIGN_TOO_LONG \
  2348. - 0 /* set a positive values to trigger the error */
  2349. -#define ERROR_PCW_BODY_SIGN_ESC_TOO_LONG \
  2350. - 0 /* set a positive values to trigger the error */
  2351. -
  2352. -/* modify HCR bitstream block */
  2353. -
  2354. -#define MODULO_DIVISOR_HCR 30
  2355. -
  2356. -/* ------------------------------ */
  2357. -/* - detect HCR errors - */
  2358. -/* ------------------------------ */
  2359. -/* check input data */
  2360. -
  2361. -/* during decoding */
  2362. -
  2363. -/* all the segments are checked -- therefore -- if this check passes, its a kind
  2364. - of evidence that the decoded PCWs and non-PCWs are fine */
  2365. -
  2366. -/* if a codeword is decoded there exists a border for the number of bits, which
  2367. - are allowed to read for this codeword. This border is the minimum of the
  2368. - length of the longest codeword (for the currently used codebook) and the
  2369. - separately transmitted 'lengthOfLongestCodeword' in this frame and channel.
  2370. - The number of decoded bits is counted (for PCWs only -- there it makes really
  2371. - sense in my opinion). If this number exceeds the border (derived as minimum
  2372. - -- see above), a error is detected. */
  2373. -
  2374. -/* -----------------------------------------------------------------------------------------------------
  2375. - This error check could be set to zero because due to a test within
  2376. - RVLC-Escape-huffman-Decoder a too long codeword could not be detected -- it
  2377. - seems that for RVLC-Escape-Codeword the coderoom is used to 100%. Therefore I
  2378. - assume that the coderoom is used to 100% also for the codebooks 1..11 used at
  2379. - HCR Therefore this test is deactivated pending further notice
  2380. - -----------------------------------------------------------------------------------------------------
  2381. - */
  2382. -
  2383. -/* test if the number of remaining bits in a segment is _below_ zero. If there
  2384. - are no errors the lowest allowed value for remainingBitsInSegment is zero.
  2385. - This check also could be set to zero (save runtime) */
  2386. -
  2387. -/* other */
  2388. -/* when set to '1', avoid setting the LAV-Flag in errorLog due to a
  2389. - previous-line-marking (at PCW decoder). A little more runtime is needed then
  2390. - when writing values out into output-buffer. */
  2391. -
  2392. -/* ------------------------------ */
  2393. -/* - conceal HCR errors - */
  2394. -/* ------------------------------ */
  2395. -
  2396. -#define HCR_ERROR_CONCEALMENT \
  2397. - 1 /* if set to '1', HCR _mutes_ the erred quantized spectral coefficients */
  2398. -
  2399. -// ------------------------------------------------------------------------------------------------------------------
  2400. -// errorLog: A word of 32 bits used for
  2401. -// logging possible errors within HCR
  2402. -// in case of distorted
  2403. -// bitstreams. Table of all
  2404. -// known errors:
  2405. -// ------------------------------------------------------------------------------------------------------------------------
  2406. -// bit fatal location meaning
  2407. -// ----+-----+-----------+--------------------------------------
  2408. -#define SEGMENT_OVERRIDE_ERR_PCW_BODY \
  2409. - 0x80000000 // 31 no PCW-Dec During PCW decoding it is checked after
  2410. - // every PCW if there are too many bits decoded (immediate
  2411. - // check).
  2412. -#define SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN \
  2413. - 0x40000000 // 30 no PCW-Dec During PCW decoding it is checked after
  2414. - // every PCW if there are too many bits decoded (immediate
  2415. - // check).
  2416. -#define SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN_ESC \
  2417. - 0x20000000 // 29 no PCW-Dec During PCW decoding it is checked after
  2418. - // every PCW if there are too many bits decoded (immediate
  2419. - // check).
  2420. -#define EXTENDED_SORTED_COUNTER_OVERFLOW \
  2421. - 0x10000000 // 28 yes Init-Dec Error during extending sideinfo
  2422. - // (neither a PCW nor a nonPCW was decoded so far)
  2423. - // 0x08000000 // 27 reserved
  2424. - // 0x04000000 // 26 reserved
  2425. - // 0x02000000 // 25 reserved
  2426. - // 0x01000000 // 24 reserved
  2427. - // 0x00800000 // 23 reserved
  2428. - // 0x00400000 // 22 reserved
  2429. - // 0x00200000 // 21 reserved
  2430. - // 0x00100000 // 20 reserved
  2431. -
  2432. -/* special errors */
  2433. -#define TOO_MANY_PCW_BODY_BITS_DECODED \
  2434. - 0x00080000 // 19 yes PCW-Dec During PCW-body-decoding too many bits
  2435. - // have been read from bitstream -- advice: skip non-PCW decoding
  2436. -#define TOO_MANY_PCW_BODY_SIGN_BITS_DECODED \
  2437. - 0x00040000 // 18 yes PCW-Dec During PCW-body-sign-decoding too many
  2438. - // bits have been read from bitstream -- advice: skip non-PCW
  2439. - // decoding
  2440. -#define TOO_MANY_PCW_BODY_SIGN_ESC_BITS_DECODED \
  2441. - 0x00020000 // 17 yes PCW-Dec During PCW-body-sign-esc-decoding too
  2442. - // many bits have been read from bitstream -- advice: skip
  2443. - // non-PCW decoding
  2444. -
  2445. -// 0x00010000 // 16 reserved
  2446. -#define STATE_ERROR_BODY_ONLY \
  2447. - 0x00008000 // 15 no NonPCW-Dec State machine returned with error
  2448. -#define STATE_ERROR_BODY_SIGN__BODY \
  2449. - 0x00004000 // 14 no NonPCW-Dec State machine returned with error
  2450. -#define STATE_ERROR_BODY_SIGN__SIGN \
  2451. - 0x00002000 // 13 no NonPCW-Dec State machine returned with error
  2452. -#define STATE_ERROR_BODY_SIGN_ESC__BODY \
  2453. - 0x00001000 // 12 no NonPCW-Dec State machine returned with error
  2454. -#define STATE_ERROR_BODY_SIGN_ESC__SIGN \
  2455. - 0x00000800 // 11 no NonPCW-Dec State machine returned with error
  2456. -#define STATE_ERROR_BODY_SIGN_ESC__ESC_PREFIX \
  2457. - 0x00000400 // 10 no NonPCW-Dec State machine returned with error
  2458. -#define STATE_ERROR_BODY_SIGN_ESC__ESC_WORD \
  2459. - 0x00000200 // 9 no NonPCW-Dec State machine returned with error
  2460. -#define HCR_SI_LENGTHS_FAILURE \
  2461. - 0x00000100 // 8 yes Init-Dec LengthOfLongestCodeword must not be
  2462. - // less than lenghtOfReorderedSpectralData
  2463. -#define NUM_SECT_OUT_OF_RANGE_SHORT_BLOCK \
  2464. - 0x00000080 // 7 yes Init-Dec The number of sections is not within
  2465. - // the allowed range (short block)
  2466. -#define NUM_SECT_OUT_OF_RANGE_LONG_BLOCK \
  2467. - 0x00000040 // 6 yes Init-Dec The number of sections is not within
  2468. - // the allowed range (long block)
  2469. -#define LINE_IN_SECT_OUT_OF_RANGE_SHORT_BLOCK \
  2470. - 0x00000020 // 5 yes Init-Dec The number of lines per section is not
  2471. - // within the allowed range (short block)
  2472. -#define CB_OUT_OF_RANGE_SHORT_BLOCK \
  2473. - 0x00000010 // 4 yes Init-Dec The codebook is not within the allowed
  2474. - // range (short block)
  2475. -#define LINE_IN_SECT_OUT_OF_RANGE_LONG_BLOCK \
  2476. - 0x00000008 // 3 yes Init-Dec The number of lines per section is not
  2477. - // within the allowed range (long block)
  2478. -#define CB_OUT_OF_RANGE_LONG_BLOCK \
  2479. - 0x00000004 // 2 yes Init-Dec The codebook is not within the allowed
  2480. - // range (long block)
  2481. -#define LAV_VIOLATION \
  2482. - 0x00000002 // 1 no Final The absolute value of at least one
  2483. - // decoded line was too high for the according codebook.
  2484. -#define BIT_IN_SEGMENTATION_ERROR \
  2485. - 0x00000001 // 0 no Final After PCW and non-PWC-decoding at least
  2486. - // one segment is not zero (global check).
  2487. -
  2488. -/*----------*/
  2489. -#define HCR_FATAL_PCW_ERROR_MASK 0x100E01FC
  2490. -
  2491. -typedef enum { PCW_BODY, PCW_BODY_SIGN, PCW_BODY_SIGN_ESC } PCW_TYPE;
  2492. -
  2493. -/* interface Decoder <---> HCR */
  2494. -typedef struct {
  2495. - UINT errorLog;
  2496. - SPECTRAL_PTR pQuantizedSpectralCoefficientsBase;
  2497. - int quantizedSpectralCoefficientsIdx;
  2498. - SHORT lengthOfReorderedSpectralData;
  2499. - SHORT numSection;
  2500. - SHORT *pNumLineInSect;
  2501. - INT bitstreamAnchor;
  2502. - SCHAR lengthOfLongestCodeword;
  2503. - UCHAR *pCodebook;
  2504. -} HCR_INPUT_OUTPUT;
  2505. -
  2506. -typedef struct {
  2507. - const UCHAR *pMinOfCbPair;
  2508. - const UCHAR *pMaxOfCbPair;
  2509. -} HCR_CB_PAIRS;
  2510. -
  2511. -typedef struct {
  2512. - const USHORT *pLargestAbsVal;
  2513. - const UCHAR *pMaxCwLength;
  2514. - const UCHAR *pCbDimension;
  2515. - const UCHAR *pCbDimShift;
  2516. - const UCHAR *pCbSign;
  2517. - const UCHAR *pCbPriority;
  2518. -} HCR_TABLE_INFO;
  2519. -
  2520. -typedef struct {
  2521. - UINT numSegment;
  2522. - UINT pSegmentBitfield[((1024 >> 1) / NUMBER_OF_BIT_IN_WORD + 1)];
  2523. - UINT pCodewordBitfield[((1024 >> 1) / NUMBER_OF_BIT_IN_WORD + 1)];
  2524. - UINT segmentOffset;
  2525. - INT pLeftStartOfSegment[1024 >> 1];
  2526. - INT pRightStartOfSegment[1024 >> 1];
  2527. - SCHAR pRemainingBitsInSegment[1024 >> 1];
  2528. - UCHAR readDirection;
  2529. - UCHAR numWordForBitfield;
  2530. - USHORT pNumBitValidInLastWord;
  2531. -} HCR_SEGMENT_INFO;
  2532. -
  2533. -typedef struct {
  2534. - UINT numCodeword;
  2535. - UINT numSortedSection;
  2536. - USHORT pNumCodewordInSection[MAX_SFB_HCR];
  2537. - USHORT pNumSortedCodewordInSection[MAX_SFB_HCR];
  2538. - USHORT pNumExtendedSortedCodewordInSection[MAX_SFB_HCR + MAX_HCR_SETS];
  2539. - int numExtendedSortedCodewordInSectionIdx;
  2540. - USHORT pNumExtendedSortedSectionsInSets[MAX_HCR_SETS];
  2541. - int numExtendedSortedSectionsInSetsIdx;
  2542. - USHORT pReorderOffset[MAX_SFB_HCR];
  2543. - UCHAR pSortedCodebook[MAX_SFB_HCR];
  2544. -
  2545. - UCHAR pExtendedSortedCodebook[MAX_SFB_HCR + MAX_HCR_SETS];
  2546. - int extendedSortedCodebookIdx;
  2547. - UCHAR pMaxLenOfCbInExtSrtSec[MAX_SFB_HCR + MAX_HCR_SETS];
  2548. - int maxLenOfCbInExtSrtSecIdx;
  2549. - UCHAR pCodebookSwitch[MAX_SFB_HCR];
  2550. -} HCR_SECTION_INFO;
  2551. -
  2552. -typedef UINT (*STATEFUNC)(HANDLE_FDK_BITSTREAM, void *);
  2553. -
  2554. -typedef struct {
  2555. - /* worst-case and 1024/4 non-PCWs exist in worst-case */
  2556. - FIXP_DBL
  2557. - *pResultBase; /* Base address for spectral data output target buffer */
  2558. - UINT iNode[1024 >> 2]; /* Helper indices for code books */
  2559. - USHORT
  2560. - iResultPointer[1024 >> 2]; /* Helper indices for accessing pResultBase */
  2561. - UINT pEscapeSequenceInfo[1024 >> 2];
  2562. - UINT codewordOffset;
  2563. - STATEFUNC pState;
  2564. - UCHAR pCodebook[1024 >> 2];
  2565. - UCHAR pCntSign[1024 >> 2];
  2566. - /* this array holds the states coded as integer values within the range
  2567. - * [0,1,..,7] */
  2568. - SCHAR pSta[1024 >> 2];
  2569. -} HCR_NON_PCW_SIDEINFO;
  2570. -
  2571. -typedef struct {
  2572. - HCR_INPUT_OUTPUT decInOut;
  2573. - HCR_SEGMENT_INFO segmentInfo;
  2574. - HCR_SECTION_INFO sectionInfo;
  2575. - HCR_NON_PCW_SIDEINFO nonPcwSideinfo;
  2576. -} CErHcrInfo;
  2577. -
  2578. -typedef CErHcrInfo *H_HCR_INFO;
  2579. -
  2580. -#endif /* AACDEC_HCR_TYPES_H */
  2581. --- a/libAACdec/src/aacdec_hcrs.cpp
  2582. +++ /dev/null
  2583. @@ -1,1551 +0,0 @@
  2584. -/* -----------------------------------------------------------------------------
  2585. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  2586. -
  2587. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  2588. -Forschung e.V. All rights reserved.
  2589. -
  2590. - 1. INTRODUCTION
  2591. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  2592. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  2593. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  2594. -a wide variety of Android devices.
  2595. -
  2596. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  2597. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  2598. -full-bandwidth communications codec by independent studies and is widely
  2599. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  2600. -specifications.
  2601. -
  2602. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  2603. -those of Fraunhofer) may be obtained through Via Licensing
  2604. -(www.vialicensing.com) or through the respective patent owners individually for
  2605. -the purpose of encoding or decoding bit streams in products that are compliant
  2606. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  2607. -Android devices already license these patent claims through Via Licensing or
  2608. -directly from the patent owners, and therefore FDK AAC Codec software may
  2609. -already be covered under those patent licenses when it is used for those
  2610. -licensed purposes only.
  2611. -
  2612. -Commercially-licensed AAC software libraries, including floating-point versions
  2613. -with enhanced sound quality, are also available from Fraunhofer. Users are
  2614. -encouraged to check the Fraunhofer website for additional applications
  2615. -information and documentation.
  2616. -
  2617. -2. COPYRIGHT LICENSE
  2618. -
  2619. -Redistribution and use in source and binary forms, with or without modification,
  2620. -are permitted without payment of copyright license fees provided that you
  2621. -satisfy the following conditions:
  2622. -
  2623. -You must retain the complete text of this software license in redistributions of
  2624. -the FDK AAC Codec or your modifications thereto in source code form.
  2625. -
  2626. -You must retain the complete text of this software license in the documentation
  2627. -and/or other materials provided with redistributions of the FDK AAC Codec or
  2628. -your modifications thereto in binary form. You must make available free of
  2629. -charge copies of the complete source code of the FDK AAC Codec and your
  2630. -modifications thereto to recipients of copies in binary form.
  2631. -
  2632. -The name of Fraunhofer may not be used to endorse or promote products derived
  2633. -from this library without prior written permission.
  2634. -
  2635. -You may not charge copyright license fees for anyone to use, copy or distribute
  2636. -the FDK AAC Codec software or your modifications thereto.
  2637. -
  2638. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  2639. -that you changed the software and the date of any change. For modified versions
  2640. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  2641. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  2642. -AAC Codec Library for Android."
  2643. -
  2644. -3. NO PATENT LICENSE
  2645. -
  2646. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  2647. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  2648. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  2649. -software.
  2650. -
  2651. -You may use this FDK AAC Codec software or modifications thereto only for
  2652. -purposes that are authorized by appropriate patent licenses.
  2653. -
  2654. -4. DISCLAIMER
  2655. -
  2656. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  2657. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  2658. -including but not limited to the implied warranties of merchantability and
  2659. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  2660. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  2661. -or consequential damages, including but not limited to procurement of substitute
  2662. -goods or services; loss of use, data, or profits, or business interruption,
  2663. -however caused and on any theory of liability, whether in contract, strict
  2664. -liability, or tort (including negligence), arising in any way out of the use of
  2665. -this software, even if advised of the possibility of such damage.
  2666. -
  2667. -5. CONTACT INFORMATION
  2668. -
  2669. -Fraunhofer Institute for Integrated Circuits IIS
  2670. -Attention: Audio and Multimedia Departments - FDK AAC LL
  2671. -Am Wolfsmantel 33
  2672. -91058 Erlangen, Germany
  2673. -
  2674. -www.iis.fraunhofer.de/amm
  2675. -amm-info@iis.fraunhofer.de
  2676. ------------------------------------------------------------------------------ */
  2677. -
  2678. -/**************************** AAC decoder library ******************************
  2679. -
  2680. - Author(s): Robert Weidner (DSP Solutions)
  2681. -
  2682. - Description: HCR Decoder: Prepare decoding of non-PCWs, segmentation- and
  2683. - bitfield-handling, HCR-Statemachine
  2684. -
  2685. -*******************************************************************************/
  2686. -
  2687. -#include "aacdec_hcrs.h"
  2688. -
  2689. -#include "aacdec_hcr.h"
  2690. -
  2691. -#include "aacdec_hcr_bit.h"
  2692. -#include "aac_rom.h"
  2693. -#include "aac_ram.h"
  2694. -
  2695. -static UINT InitSegmentBitfield(UINT *pNumSegment,
  2696. - SCHAR *pRemainingBitsInSegment,
  2697. - UINT *pSegmentBitfield,
  2698. - UCHAR *pNumWordForBitfield,
  2699. - USHORT *pNumBitValidInLastWord);
  2700. -
  2701. -static void InitNonPCWSideInformationForCurrentSet(H_HCR_INFO pHcr);
  2702. -
  2703. -static INT ModuloValue(INT input, INT bufferlength);
  2704. -
  2705. -static void ClearBitFromBitfield(STATEFUNC *ptrState, UINT offset,
  2706. - UINT *pBitfield);
  2707. -
  2708. -/*---------------------------------------------------------------------------------------------
  2709. - description: This function decodes all non-priority codewords (non-PCWs) by
  2710. -using a state-machine.
  2711. ---------------------------------------------------------------------------------------------
  2712. -*/
  2713. -void DecodeNonPCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO pHcr) {
  2714. - UINT numValidSegment;
  2715. - INT segmentOffset;
  2716. - INT codewordOffsetBase;
  2717. - INT codewordOffset;
  2718. - UINT trial;
  2719. -
  2720. - UINT *pNumSegment;
  2721. - SCHAR *pRemainingBitsInSegment;
  2722. - UINT *pSegmentBitfield;
  2723. - UCHAR *pNumWordForBitfield;
  2724. - USHORT *pNumBitValidInLastWord;
  2725. - UINT *pCodewordBitfield;
  2726. - INT bitfieldWord;
  2727. - INT bitInWord;
  2728. - UINT tempWord;
  2729. - UINT interMediateWord;
  2730. - INT tempBit;
  2731. - INT carry;
  2732. -
  2733. - UINT numCodeword;
  2734. - UCHAR numSet;
  2735. - UCHAR currentSet;
  2736. - UINT codewordInSet;
  2737. - UINT remainingCodewordsInSet;
  2738. - SCHAR *pSta;
  2739. - UINT ret;
  2740. -
  2741. - pNumSegment = &(pHcr->segmentInfo.numSegment);
  2742. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  2743. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  2744. - pNumWordForBitfield = &(pHcr->segmentInfo.numWordForBitfield);
  2745. - pNumBitValidInLastWord = &(pHcr->segmentInfo.pNumBitValidInLastWord);
  2746. - pSta = pHcr->nonPcwSideinfo.pSta;
  2747. -
  2748. - numValidSegment = InitSegmentBitfield(pNumSegment, pRemainingBitsInSegment,
  2749. - pSegmentBitfield, pNumWordForBitfield,
  2750. - pNumBitValidInLastWord);
  2751. -
  2752. - if (numValidSegment != 0) {
  2753. - numCodeword = pHcr->sectionInfo.numCodeword;
  2754. - numSet = ((numCodeword - 1) / *pNumSegment) + 1;
  2755. -
  2756. - pHcr->segmentInfo.readDirection = FROM_RIGHT_TO_LEFT;
  2757. -
  2758. - /* Process sets subsequently */
  2759. - for (currentSet = 1; currentSet < numSet; currentSet++) {
  2760. - /* step 1 */
  2761. - numCodeword -=
  2762. - *pNumSegment; /* number of remaining non PCWs [for all sets] */
  2763. - if (numCodeword < *pNumSegment) {
  2764. - codewordInSet = numCodeword; /* for last set */
  2765. - } else {
  2766. - codewordInSet = *pNumSegment; /* for all sets except last set */
  2767. - }
  2768. -
  2769. - /* step 2 */
  2770. - /* prepare array 'CodewordBitfield'; as much ones are written from left in
  2771. - * all words, as much decodedCodewordInSetCounter nonPCWs exist in this
  2772. - * set */
  2773. - tempWord = 0xFFFFFFFF;
  2774. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  2775. -
  2776. - for (bitfieldWord = *pNumWordForBitfield; bitfieldWord != 0;
  2777. - bitfieldWord--) { /* loop over all used words */
  2778. - if (codewordInSet > NUMBER_OF_BIT_IN_WORD) { /* more codewords than
  2779. - number of bits => fill
  2780. - ones */
  2781. - /* fill a whole word with ones */
  2782. - *pCodewordBitfield++ = tempWord;
  2783. - codewordInSet -= NUMBER_OF_BIT_IN_WORD; /* subtract number of bits */
  2784. - } else {
  2785. - /* prepare last tempWord */
  2786. - for (remainingCodewordsInSet = codewordInSet;
  2787. - remainingCodewordsInSet < NUMBER_OF_BIT_IN_WORD;
  2788. - remainingCodewordsInSet++) {
  2789. - tempWord =
  2790. - tempWord &
  2791. - ~(1
  2792. - << (NUMBER_OF_BIT_IN_WORD - 1 -
  2793. - remainingCodewordsInSet)); /* set a zero at bit number
  2794. - (NUMBER_OF_BIT_IN_WORD-1-i)
  2795. - in tempWord */
  2796. - }
  2797. - *pCodewordBitfield++ = tempWord;
  2798. - tempWord = 0x00000000;
  2799. - }
  2800. - }
  2801. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  2802. -
  2803. - /* step 3 */
  2804. - /* build non-PCW sideinfo for each non-PCW of the current set */
  2805. - InitNonPCWSideInformationForCurrentSet(pHcr);
  2806. -
  2807. - /* step 4 */
  2808. - /* decode all non-PCWs belonging to this set */
  2809. -
  2810. - /* loop over trials */
  2811. - codewordOffsetBase = 0;
  2812. - for (trial = *pNumSegment; trial > 0; trial--) {
  2813. - /* loop over number of words in bitfields */
  2814. - segmentOffset = 0; /* start at zero in every segment */
  2815. - pHcr->segmentInfo.segmentOffset =
  2816. - segmentOffset; /* store in structure for states */
  2817. - codewordOffset = codewordOffsetBase;
  2818. - pHcr->nonPcwSideinfo.codewordOffset =
  2819. - codewordOffset; /* store in structure for states */
  2820. -
  2821. - for (bitfieldWord = 0; bitfieldWord < *pNumWordForBitfield;
  2822. - bitfieldWord++) {
  2823. - /* derive tempWord with bitwise and */
  2824. - tempWord =
  2825. - pSegmentBitfield[bitfieldWord] & pCodewordBitfield[bitfieldWord];
  2826. -
  2827. - /* if tempWord is not zero, decode something */
  2828. - if (tempWord != 0) {
  2829. - /* loop over all bits in tempWord; start state machine if & is true
  2830. - */
  2831. - for (bitInWord = NUMBER_OF_BIT_IN_WORD; bitInWord > 0;
  2832. - bitInWord--) {
  2833. - interMediateWord = ((UINT)1 << (bitInWord - 1));
  2834. - if ((tempWord & interMediateWord) == interMediateWord) {
  2835. - /* get state and start state machine */
  2836. - pHcr->nonPcwSideinfo.pState =
  2837. - aStateConstant2State[pSta[codewordOffset]];
  2838. -
  2839. - while (pHcr->nonPcwSideinfo.pState) {
  2840. - ret = ((STATEFUNC)pHcr->nonPcwSideinfo.pState)(bs, pHcr);
  2841. - if (ret != 0) {
  2842. - return;
  2843. - }
  2844. - }
  2845. - }
  2846. -
  2847. - /* update both offsets */
  2848. - segmentOffset += 1; /* add NUMBER_OF_BIT_IN_WORD times one */
  2849. - pHcr->segmentInfo.segmentOffset = segmentOffset;
  2850. - codewordOffset += 1; /* add NUMBER_OF_BIT_IN_WORD times one */
  2851. - codewordOffset =
  2852. - ModuloValue(codewordOffset,
  2853. - *pNumSegment); /* index of the current codeword
  2854. - lies within modulo range */
  2855. - pHcr->nonPcwSideinfo.codewordOffset = codewordOffset;
  2856. - }
  2857. - } else {
  2858. - segmentOffset +=
  2859. - NUMBER_OF_BIT_IN_WORD; /* add NUMBER_OF_BIT_IN_WORD at once */
  2860. - pHcr->segmentInfo.segmentOffset = segmentOffset;
  2861. - codewordOffset +=
  2862. - NUMBER_OF_BIT_IN_WORD; /* add NUMBER_OF_BIT_IN_WORD at once */
  2863. - codewordOffset = ModuloValue(
  2864. - codewordOffset,
  2865. - *pNumSegment); /* index of the current codeword lies within
  2866. - modulo range */
  2867. - pHcr->nonPcwSideinfo.codewordOffset = codewordOffset;
  2868. - }
  2869. - } /* end of bitfield word loop */
  2870. -
  2871. - /* decrement codeword - pointer */
  2872. - codewordOffsetBase -= 1;
  2873. - codewordOffsetBase =
  2874. - ModuloValue(codewordOffsetBase, *pNumSegment); /* index of the
  2875. - current codeword
  2876. - base lies within
  2877. - modulo range */
  2878. -
  2879. - /* rotate numSegment bits in codewordBitfield */
  2880. - /* rotation of *numSegment bits in bitfield of codewords
  2881. - * (circle-rotation) */
  2882. - /* get last valid bit */
  2883. - tempBit = pCodewordBitfield[*pNumWordForBitfield - 1] &
  2884. - (1 << (NUMBER_OF_BIT_IN_WORD - *pNumBitValidInLastWord));
  2885. - tempBit = tempBit >> (NUMBER_OF_BIT_IN_WORD - *pNumBitValidInLastWord);
  2886. -
  2887. - /* write zero into place where tempBit was fetched from */
  2888. - pCodewordBitfield[*pNumWordForBitfield - 1] =
  2889. - pCodewordBitfield[*pNumWordForBitfield - 1] &
  2890. - ~(1 << (NUMBER_OF_BIT_IN_WORD - *pNumBitValidInLastWord));
  2891. -
  2892. - /* rotate last valid word */
  2893. - pCodewordBitfield[*pNumWordForBitfield - 1] =
  2894. - pCodewordBitfield[*pNumWordForBitfield - 1] >> 1;
  2895. -
  2896. - /* transfare carry bit 0 from current word into bitposition 31 from next
  2897. - * word and rotate current word */
  2898. - for (bitfieldWord = *pNumWordForBitfield - 2; bitfieldWord > -1;
  2899. - bitfieldWord--) {
  2900. - /* get carry (=bit at position 0) from current word */
  2901. - carry = pCodewordBitfield[bitfieldWord] & 1;
  2902. -
  2903. - /* put the carry bit at position 31 into word right from current word
  2904. - */
  2905. - pCodewordBitfield[bitfieldWord + 1] =
  2906. - pCodewordBitfield[bitfieldWord + 1] |
  2907. - (carry << (NUMBER_OF_BIT_IN_WORD - 1));
  2908. -
  2909. - /* shift current word */
  2910. - pCodewordBitfield[bitfieldWord] =
  2911. - pCodewordBitfield[bitfieldWord] >> 1;
  2912. - }
  2913. -
  2914. - /* put tempBit into free bit-position 31 from first word */
  2915. - pCodewordBitfield[0] =
  2916. - pCodewordBitfield[0] | (tempBit << (NUMBER_OF_BIT_IN_WORD - 1));
  2917. -
  2918. - } /* end of trial loop */
  2919. -
  2920. - /* toggle read direction */
  2921. - pHcr->segmentInfo.readDirection =
  2922. - ToggleReadDirection(pHcr->segmentInfo.readDirection);
  2923. - }
  2924. - /* end of set loop */
  2925. -
  2926. - /* all non-PCWs of this spectrum are decoded */
  2927. - }
  2928. -
  2929. - /* all PCWs and all non PCWs are decoded. They are unbacksorted in output
  2930. - * buffer. Here is the Interface with comparing QSCs to asm decoding */
  2931. -}
  2932. -
  2933. -/*---------------------------------------------------------------------------------------------
  2934. - description: This function prepares the bitfield used for the
  2935. - segments. The list is set up once to be used in all
  2936. -following sets. If a segment is decoded empty, the according bit from the
  2937. -Bitfield is removed.
  2938. ------------------------------------------------------------------------------------------------
  2939. - return: numValidSegment = the number of valid segments
  2940. ---------------------------------------------------------------------------------------------
  2941. -*/
  2942. -static UINT InitSegmentBitfield(UINT *pNumSegment,
  2943. - SCHAR *pRemainingBitsInSegment,
  2944. - UINT *pSegmentBitfield,
  2945. - UCHAR *pNumWordForBitfield,
  2946. - USHORT *pNumBitValidInLastWord) {
  2947. - SHORT i;
  2948. - USHORT r;
  2949. - UCHAR bitfieldWord;
  2950. - UINT tempWord;
  2951. - USHORT numValidSegment;
  2952. -
  2953. - *pNumWordForBitfield =
  2954. - (*pNumSegment == 0)
  2955. - ? 0
  2956. - : ((*pNumSegment - 1) >> THIRTYTWO_LOG_DIV_TWO_LOG) + 1;
  2957. -
  2958. - /* loop over all words, which are completely used or only partial */
  2959. - /* bit in pSegmentBitfield is zero if segment is empty; bit in
  2960. - * pSegmentBitfield is one if segment is not empty */
  2961. - numValidSegment = 0;
  2962. - *pNumBitValidInLastWord = *pNumSegment;
  2963. -
  2964. - /* loop over words */
  2965. - for (bitfieldWord = 0; bitfieldWord < *pNumWordForBitfield - 1;
  2966. - bitfieldWord++) {
  2967. - tempWord = 0xFFFFFFFF; /* set ones */
  2968. - r = bitfieldWord << THIRTYTWO_LOG_DIV_TWO_LOG;
  2969. - for (i = 0; i < NUMBER_OF_BIT_IN_WORD; i++) {
  2970. - if (pRemainingBitsInSegment[r + i] == 0) {
  2971. - tempWord = tempWord & ~(1 << (NUMBER_OF_BIT_IN_WORD - 1 -
  2972. - i)); /* set a zero at bit number
  2973. - (NUMBER_OF_BIT_IN_WORD-1-i) in
  2974. - tempWord */
  2975. - } else {
  2976. - numValidSegment += 1; /* count segments which are not empty */
  2977. - }
  2978. - }
  2979. - pSegmentBitfield[bitfieldWord] = tempWord; /* store result */
  2980. - *pNumBitValidInLastWord -= NUMBER_OF_BIT_IN_WORD; /* calculate number of
  2981. - zeros on LSB side in
  2982. - the last word */
  2983. - }
  2984. -
  2985. - /* calculate last word: prepare special tempWord */
  2986. - tempWord = 0xFFFFFFFF;
  2987. - for (i = 0; i < (NUMBER_OF_BIT_IN_WORD - *pNumBitValidInLastWord); i++) {
  2988. - tempWord = tempWord & ~(1 << i); /* clear bit i in tempWord */
  2989. - }
  2990. -
  2991. - /* calculate last word */
  2992. - r = bitfieldWord << THIRTYTWO_LOG_DIV_TWO_LOG;
  2993. - for (i = 0; i < *pNumBitValidInLastWord; i++) {
  2994. - if (pRemainingBitsInSegment[r + i] == 0) {
  2995. - tempWord = tempWord & ~(1 << (NUMBER_OF_BIT_IN_WORD - 1 -
  2996. - i)); /* set a zero at bit number
  2997. - (NUMBER_OF_BIT_IN_WORD-1-i) in
  2998. - tempWord */
  2999. - } else {
  3000. - numValidSegment += 1; /* count segments which are not empty */
  3001. - }
  3002. - }
  3003. - pSegmentBitfield[bitfieldWord] = tempWord; /* store result */
  3004. -
  3005. - return numValidSegment;
  3006. -}
  3007. -
  3008. -/*---------------------------------------------------------------------------------------------
  3009. - description: This function sets up sideinfo for the non-PCW decoder (for the
  3010. -current set).
  3011. ----------------------------------------------------------------------------------------------*/
  3012. -static void InitNonPCWSideInformationForCurrentSet(H_HCR_INFO pHcr) {
  3013. - USHORT i, k;
  3014. - UCHAR codebookDim;
  3015. - UINT startNode;
  3016. -
  3017. - UCHAR *pCodebook = pHcr->nonPcwSideinfo.pCodebook;
  3018. - UINT *iNode = pHcr->nonPcwSideinfo.iNode;
  3019. - UCHAR *pCntSign = pHcr->nonPcwSideinfo.pCntSign;
  3020. - USHORT *iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
  3021. - UINT *pEscapeSequenceInfo = pHcr->nonPcwSideinfo.pEscapeSequenceInfo;
  3022. - SCHAR *pSta = pHcr->nonPcwSideinfo.pSta;
  3023. - USHORT *pNumExtendedSortedCodewordInSection =
  3024. - pHcr->sectionInfo.pNumExtendedSortedCodewordInSection;
  3025. - int numExtendedSortedCodewordInSectionIdx =
  3026. - pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx;
  3027. - UCHAR *pExtendedSortedCodebook = pHcr->sectionInfo.pExtendedSortedCodebook;
  3028. - int extendedSortedCodebookIdx = pHcr->sectionInfo.extendedSortedCodebookIdx;
  3029. - USHORT *pNumExtendedSortedSectionsInSets =
  3030. - pHcr->sectionInfo.pNumExtendedSortedSectionsInSets;
  3031. - int numExtendedSortedSectionsInSetsIdx =
  3032. - pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx;
  3033. - int quantizedSpectralCoefficientsIdx =
  3034. - pHcr->decInOut.quantizedSpectralCoefficientsIdx;
  3035. - const UCHAR *pCbDimension = aDimCb;
  3036. - int iterationCounter = 0;
  3037. -
  3038. - /* loop over number of extended sorted sections in the current set so all
  3039. - * codewords sideinfo variables within this set can be prepared for decoding
  3040. - */
  3041. - for (i = pNumExtendedSortedSectionsInSets[numExtendedSortedSectionsInSetsIdx];
  3042. - i != 0; i--) {
  3043. - codebookDim =
  3044. - pCbDimension[pExtendedSortedCodebook[extendedSortedCodebookIdx]];
  3045. - startNode = *aHuffTable[pExtendedSortedCodebook[extendedSortedCodebookIdx]];
  3046. -
  3047. - for (k = pNumExtendedSortedCodewordInSection
  3048. - [numExtendedSortedCodewordInSectionIdx];
  3049. - k != 0; k--) {
  3050. - iterationCounter++;
  3051. - if (iterationCounter > (1024 >> 2)) {
  3052. - return;
  3053. - }
  3054. - *pSta++ = aCodebook2StartInt
  3055. - [pExtendedSortedCodebook[extendedSortedCodebookIdx]];
  3056. - *pCodebook++ = pExtendedSortedCodebook[extendedSortedCodebookIdx];
  3057. - *iNode++ = startNode;
  3058. - *pCntSign++ = 0;
  3059. - *iResultPointer++ = quantizedSpectralCoefficientsIdx;
  3060. - *pEscapeSequenceInfo++ = 0;
  3061. - quantizedSpectralCoefficientsIdx +=
  3062. - codebookDim; /* update pointer by codebookDim --> point to next
  3063. - starting value for writing out */
  3064. - if (quantizedSpectralCoefficientsIdx >= 1024) {
  3065. - return;
  3066. - }
  3067. - }
  3068. - numExtendedSortedCodewordInSectionIdx++; /* inc ptr for next ext sort sec in
  3069. - current set */
  3070. - extendedSortedCodebookIdx++; /* inc ptr for next ext sort sec in current set
  3071. - */
  3072. - if (numExtendedSortedCodewordInSectionIdx >= (MAX_SFB_HCR + MAX_HCR_SETS) ||
  3073. - extendedSortedCodebookIdx >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
  3074. - return;
  3075. - }
  3076. - }
  3077. - numExtendedSortedSectionsInSetsIdx++; /* inc ptr for next set of non-PCWs */
  3078. - if (numExtendedSortedCodewordInSectionIdx >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
  3079. - return;
  3080. - }
  3081. -
  3082. - /* Write back indexes */
  3083. - pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx =
  3084. - numExtendedSortedCodewordInSectionIdx;
  3085. - pHcr->sectionInfo.extendedSortedCodebookIdx = extendedSortedCodebookIdx;
  3086. - pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx =
  3087. - numExtendedSortedSectionsInSetsIdx;
  3088. - pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx =
  3089. - numExtendedSortedCodewordInSectionIdx;
  3090. - pHcr->decInOut.quantizedSpectralCoefficientsIdx =
  3091. - quantizedSpectralCoefficientsIdx;
  3092. -}
  3093. -
  3094. -/*---------------------------------------------------------------------------------------------
  3095. - description: This function returns the input value if the value is in the
  3096. - range of bufferlength. If <input> is smaller, one bufferlength
  3097. -is added, if <input> is bigger one bufferlength is subtracted.
  3098. ------------------------------------------------------------------------------------------------
  3099. - return: modulo result
  3100. ---------------------------------------------------------------------------------------------
  3101. -*/
  3102. -static INT ModuloValue(INT input, INT bufferlength) {
  3103. - if (input > (bufferlength - 1)) {
  3104. - return (input - bufferlength);
  3105. - }
  3106. - if (input < 0) {
  3107. - return (input + bufferlength);
  3108. - }
  3109. - return input;
  3110. -}
  3111. -
  3112. -/*---------------------------------------------------------------------------------------------
  3113. - description: This function clears a bit from current bitfield and
  3114. - switches off the statemachine.
  3115. -
  3116. - A bit is cleared in two cases:
  3117. - a) a codeword is decoded, then a bit is cleared in codeword
  3118. -bitfield b) a segment is decoded empty, then a bit is cleared in segment
  3119. -bitfield
  3120. ---------------------------------------------------------------------------------------------
  3121. -*/
  3122. -static void ClearBitFromBitfield(STATEFUNC *ptrState, UINT offset,
  3123. - UINT *pBitfield) {
  3124. - UINT numBitfieldWord;
  3125. - UINT numBitfieldBit;
  3126. -
  3127. - /* get both values needed for clearing the bit */
  3128. - numBitfieldWord = offset >> THIRTYTWO_LOG_DIV_TWO_LOG; /* int = wordNr */
  3129. - numBitfieldBit = offset - (numBitfieldWord
  3130. - << THIRTYTWO_LOG_DIV_TWO_LOG); /* fract = bitNr */
  3131. -
  3132. - /* clear a bit in bitfield */
  3133. - pBitfield[numBitfieldWord] =
  3134. - pBitfield[numBitfieldWord] &
  3135. - ~(1 << (NUMBER_OF_BIT_IN_WORD - 1 - numBitfieldBit));
  3136. -
  3137. - /* switch off state machine because codeword is decoded and/or because segment
  3138. - * is empty */
  3139. - *ptrState = NULL;
  3140. -}
  3141. -
  3142. -/* =========================================================================================
  3143. - the states of the statemachine
  3144. - =========================================================================================
  3145. - */
  3146. -
  3147. -/*---------------------------------------------------------------------------------------------
  3148. - description: Decodes the body of a codeword. This State is used for
  3149. -codebooks 1,2,5 and 6. No sign bits are decoded, because the table of the
  3150. -quantized spectral values has got a valid sign at the quantized spectral lines.
  3151. ------------------------------------------------------------------------------------------------
  3152. - output: Two or four quantizes spectral values written at position
  3153. -where pResultPointr points to
  3154. ------------------------------------------------------------------------------------------------
  3155. - return: 0
  3156. ---------------------------------------------------------------------------------------------
  3157. -*/
  3158. -UINT Hcr_State_BODY_ONLY(HANDLE_FDK_BITSTREAM bs, void *ptr) {
  3159. - H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
  3160. - UINT *pSegmentBitfield;
  3161. - UINT *pCodewordBitfield;
  3162. - UINT segmentOffset;
  3163. - FIXP_DBL *pResultBase;
  3164. - UINT *iNode;
  3165. - USHORT *iResultPointer;
  3166. - UINT codewordOffset;
  3167. - UINT branchNode;
  3168. - UINT branchValue;
  3169. - UINT iQSC;
  3170. - UINT treeNode;
  3171. - UCHAR carryBit;
  3172. - INT *pLeftStartOfSegment;
  3173. - INT *pRightStartOfSegment;
  3174. - SCHAR *pRemainingBitsInSegment;
  3175. - UCHAR readDirection;
  3176. - UCHAR *pCodebook;
  3177. - UCHAR dimCntr;
  3178. - const UINT *pCurrentTree;
  3179. - const UCHAR *pCbDimension;
  3180. - const SCHAR *pQuantVal;
  3181. - const SCHAR *pQuantValBase;
  3182. -
  3183. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  3184. - pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  3185. - pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  3186. - readDirection = pHcr->segmentInfo.readDirection;
  3187. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  3188. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  3189. - segmentOffset = pHcr->segmentInfo.segmentOffset;
  3190. -
  3191. - pCodebook = pHcr->nonPcwSideinfo.pCodebook;
  3192. - iNode = pHcr->nonPcwSideinfo.iNode;
  3193. - pResultBase = pHcr->nonPcwSideinfo.pResultBase;
  3194. - iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
  3195. - codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
  3196. -
  3197. - pCbDimension = aDimCb;
  3198. -
  3199. - treeNode = iNode[codewordOffset];
  3200. - pCurrentTree = aHuffTable[pCodebook[codewordOffset]];
  3201. -
  3202. - for (; pRemainingBitsInSegment[segmentOffset] > 0;
  3203. - pRemainingBitsInSegment[segmentOffset] -= 1) {
  3204. - carryBit = HcrGetABitFromBitstream(
  3205. - bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
  3206. - &pRightStartOfSegment[segmentOffset], readDirection);
  3207. -
  3208. - CarryBitToBranchValue(carryBit, /* make a step in decoding tree */
  3209. - treeNode, &branchValue, &branchNode);
  3210. -
  3211. - /* if end of branch reached write out lines and count bits needed for sign,
  3212. - * otherwise store node in codeword sideinfo */
  3213. - if ((branchNode & TEST_BIT_10) ==
  3214. - TEST_BIT_10) { /* test bit 10 ; ==> body is complete */
  3215. - pQuantValBase = aQuantTable[pCodebook[codewordOffset]]; /* get base
  3216. - address of
  3217. - quantized
  3218. - values
  3219. - belonging to
  3220. - current
  3221. - codebook */
  3222. - pQuantVal = pQuantValBase + branchValue; /* set pointer to first valid
  3223. - line [of 2 or 4 quantized
  3224. - values] */
  3225. -
  3226. - iQSC = iResultPointer[codewordOffset]; /* get position of first line for
  3227. - writing out result */
  3228. -
  3229. - for (dimCntr = pCbDimension[pCodebook[codewordOffset]]; dimCntr != 0;
  3230. - dimCntr--) {
  3231. - pResultBase[iQSC++] =
  3232. - (FIXP_DBL)*pQuantVal++; /* write out 2 or 4 lines into
  3233. - spectrum; no Sign bits
  3234. - available in this state */
  3235. - }
  3236. -
  3237. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3238. - pCodewordBitfield); /* clear a bit in bitfield and
  3239. - switch off statemachine */
  3240. - pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
  3241. - for loop counter (see
  3242. - above) is done here */
  3243. - break; /* end of branch in tree reached i.e. a whole nonPCW-Body is
  3244. - decoded */
  3245. - } else { /* body is not decoded completely: */
  3246. - treeNode = *(
  3247. - pCurrentTree +
  3248. - branchValue); /* update treeNode for further step in decoding tree */
  3249. - }
  3250. - }
  3251. - iNode[codewordOffset] = treeNode; /* store updated treeNode because maybe
  3252. - decoding of codeword body not finished
  3253. - yet */
  3254. -
  3255. - if (pRemainingBitsInSegment[segmentOffset] <= 0) {
  3256. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3257. - pSegmentBitfield); /* clear a bit in bitfield and
  3258. - switch off statemachine */
  3259. -
  3260. - if (pRemainingBitsInSegment[segmentOffset] < 0) {
  3261. - pHcr->decInOut.errorLog |= STATE_ERROR_BODY_ONLY;
  3262. - return BODY_ONLY;
  3263. - }
  3264. - }
  3265. -
  3266. - return STOP_THIS_STATE;
  3267. -}
  3268. -
  3269. -/*---------------------------------------------------------------------------------------------
  3270. - description: Decodes the codeword body, writes out result and counts the
  3271. -number of quantized spectral values, which are different form zero. For those
  3272. -values sign bits are needed.
  3273. -
  3274. - If sign bit counter cntSign is different from zero, switch to
  3275. -next state to decode sign Bits there. If sign bit counter cntSign is zero, no
  3276. -sign bits are needed and codeword is decoded.
  3277. ------------------------------------------------------------------------------------------------
  3278. - output: Two or four written quantizes spectral values written at
  3279. -position where pResultPointr points to. The signs of those lines may be wrong.
  3280. -If the signs [on just one signle sign] is wrong, the next state will correct it.
  3281. ------------------------------------------------------------------------------------------------
  3282. - return: 0
  3283. ---------------------------------------------------------------------------------------------
  3284. -*/
  3285. -UINT Hcr_State_BODY_SIGN__BODY(HANDLE_FDK_BITSTREAM bs, void *ptr) {
  3286. - H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
  3287. - SCHAR *pRemainingBitsInSegment;
  3288. - INT *pLeftStartOfSegment;
  3289. - INT *pRightStartOfSegment;
  3290. - UCHAR readDirection;
  3291. - UINT *pSegmentBitfield;
  3292. - UINT *pCodewordBitfield;
  3293. - UINT segmentOffset;
  3294. -
  3295. - UCHAR *pCodebook;
  3296. - UINT *iNode;
  3297. - UCHAR *pCntSign;
  3298. - FIXP_DBL *pResultBase;
  3299. - USHORT *iResultPointer;
  3300. - UINT codewordOffset;
  3301. -
  3302. - UINT iQSC;
  3303. - UINT cntSign;
  3304. - UCHAR dimCntr;
  3305. - UCHAR carryBit;
  3306. - SCHAR *pSta;
  3307. - UINT treeNode;
  3308. - UINT branchValue;
  3309. - UINT branchNode;
  3310. - const UCHAR *pCbDimension;
  3311. - const UINT *pCurrentTree;
  3312. - const SCHAR *pQuantValBase;
  3313. - const SCHAR *pQuantVal;
  3314. -
  3315. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  3316. - pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  3317. - pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  3318. - readDirection = pHcr->segmentInfo.readDirection;
  3319. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  3320. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  3321. - segmentOffset = pHcr->segmentInfo.segmentOffset;
  3322. -
  3323. - pCodebook = pHcr->nonPcwSideinfo.pCodebook;
  3324. - iNode = pHcr->nonPcwSideinfo.iNode;
  3325. - pCntSign = pHcr->nonPcwSideinfo.pCntSign;
  3326. - pResultBase = pHcr->nonPcwSideinfo.pResultBase;
  3327. - iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
  3328. - codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
  3329. - pSta = pHcr->nonPcwSideinfo.pSta;
  3330. -
  3331. - pCbDimension = aDimCb;
  3332. -
  3333. - treeNode = iNode[codewordOffset];
  3334. - pCurrentTree = aHuffTable[pCodebook[codewordOffset]];
  3335. -
  3336. - for (; pRemainingBitsInSegment[segmentOffset] > 0;
  3337. - pRemainingBitsInSegment[segmentOffset] -= 1) {
  3338. - carryBit = HcrGetABitFromBitstream(
  3339. - bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
  3340. - &pRightStartOfSegment[segmentOffset], readDirection);
  3341. -
  3342. - CarryBitToBranchValue(carryBit, /* make a step in decoding tree */
  3343. - treeNode, &branchValue, &branchNode);
  3344. -
  3345. - /* if end of branch reached write out lines and count bits needed for sign,
  3346. - * otherwise store node in codeword sideinfo */
  3347. - if ((branchNode & TEST_BIT_10) ==
  3348. - TEST_BIT_10) { /* test bit 10 ; if set body complete */
  3349. - /* body completely decoded; branchValue is valid, set pQuantVal to first
  3350. - * (of two or four) quantized spectral coefficients */
  3351. - pQuantValBase = aQuantTable[pCodebook[codewordOffset]]; /* get base
  3352. - address of
  3353. - quantized
  3354. - values
  3355. - belonging to
  3356. - current
  3357. - codebook */
  3358. - pQuantVal = pQuantValBase + branchValue; /* set pointer to first valid
  3359. - line [of 2 or 4 quantized
  3360. - values] */
  3361. -
  3362. - iQSC = iResultPointer[codewordOffset]; /* get position of first line for
  3363. - writing result */
  3364. -
  3365. - /* codeword decoding result is written out here: Write out 2 or 4
  3366. - * quantized spectral values with probably */
  3367. - /* wrong sign and count number of values which are different from zero for
  3368. - * sign bit decoding [which happens in next state] */
  3369. - cntSign = 0;
  3370. - for (dimCntr = pCbDimension[pCodebook[codewordOffset]]; dimCntr != 0;
  3371. - dimCntr--) {
  3372. - pResultBase[iQSC++] =
  3373. - (FIXP_DBL)*pQuantVal; /* write quant. spec. coef. into spectrum */
  3374. - if (*pQuantVal++ != 0) {
  3375. - cntSign += 1;
  3376. - }
  3377. - }
  3378. -
  3379. - if (cntSign == 0) {
  3380. - ClearBitFromBitfield(
  3381. - &(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3382. - pCodewordBitfield); /* clear a bit in bitfield and switch off
  3383. - statemachine */
  3384. - } else {
  3385. - pCntSign[codewordOffset] = cntSign; /* write sign count result into
  3386. - codewordsideinfo of current
  3387. - codeword */
  3388. - pSta[codewordOffset] = BODY_SIGN__SIGN; /* change state */
  3389. - pHcr->nonPcwSideinfo.pState =
  3390. - aStateConstant2State[pSta[codewordOffset]]; /* get state from
  3391. - separate array of
  3392. - cw-sideinfo */
  3393. - }
  3394. - pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
  3395. - for loop counter (see
  3396. - above) is done here */
  3397. - break; /* end of branch in tree reached i.e. a whole nonPCW-Body is
  3398. - decoded */
  3399. - } else { /* body is not decoded completely: */
  3400. - treeNode = *(
  3401. - pCurrentTree +
  3402. - branchValue); /* update treeNode for further step in decoding tree */
  3403. - }
  3404. - }
  3405. - iNode[codewordOffset] = treeNode; /* store updated treeNode because maybe
  3406. - decoding of codeword body not finished
  3407. - yet */
  3408. -
  3409. - if (pRemainingBitsInSegment[segmentOffset] <= 0) {
  3410. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3411. - pSegmentBitfield); /* clear a bit in bitfield and
  3412. - switch off statemachine */
  3413. -
  3414. - if (pRemainingBitsInSegment[segmentOffset] < 0) {
  3415. - pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN__BODY;
  3416. - return BODY_SIGN__BODY;
  3417. - }
  3418. - }
  3419. -
  3420. - return STOP_THIS_STATE;
  3421. -}
  3422. -
  3423. -/*---------------------------------------------------------------------------------------------
  3424. - description: This state decodes the sign bits belonging to a codeword. The
  3425. -state is called as often in different "trials" until pCntSgn[codewordOffset] is
  3426. -zero.
  3427. ------------------------------------------------------------------------------------------------
  3428. - output: The two or four quantizes spectral values (written in previous
  3429. -state) have now the correct sign.
  3430. ------------------------------------------------------------------------------------------------
  3431. - return: 0
  3432. ---------------------------------------------------------------------------------------------
  3433. -*/
  3434. -UINT Hcr_State_BODY_SIGN__SIGN(HANDLE_FDK_BITSTREAM bs, void *ptr) {
  3435. - H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
  3436. - SCHAR *pRemainingBitsInSegment;
  3437. - INT *pLeftStartOfSegment;
  3438. - INT *pRightStartOfSegment;
  3439. - UCHAR readDirection;
  3440. - UINT *pSegmentBitfield;
  3441. - UINT *pCodewordBitfield;
  3442. - UINT segmentOffset;
  3443. -
  3444. - UCHAR *pCntSign;
  3445. - FIXP_DBL *pResultBase;
  3446. - USHORT *iResultPointer;
  3447. - UINT codewordOffset;
  3448. -
  3449. - UCHAR carryBit;
  3450. - UINT iQSC;
  3451. - UCHAR cntSign;
  3452. -
  3453. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  3454. - pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  3455. - pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  3456. - readDirection = pHcr->segmentInfo.readDirection;
  3457. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  3458. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  3459. - segmentOffset = pHcr->segmentInfo.segmentOffset;
  3460. -
  3461. - /*pCodebook = */
  3462. - pCntSign = pHcr->nonPcwSideinfo.pCntSign;
  3463. - pResultBase = pHcr->nonPcwSideinfo.pResultBase;
  3464. - iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
  3465. - codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
  3466. -
  3467. - iQSC = iResultPointer[codewordOffset];
  3468. - cntSign = pCntSign[codewordOffset];
  3469. -
  3470. - /* loop for sign bit decoding */
  3471. - for (; pRemainingBitsInSegment[segmentOffset] > 0;
  3472. - pRemainingBitsInSegment[segmentOffset] -= 1) {
  3473. - carryBit = HcrGetABitFromBitstream(
  3474. - bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
  3475. - &pRightStartOfSegment[segmentOffset], readDirection);
  3476. - cntSign -=
  3477. - 1; /* decrement sign counter because one sign bit has been read */
  3478. -
  3479. - /* search for a line (which was decoded in previous state) which is not
  3480. - * zero. [This value will get a sign] */
  3481. - while (pResultBase[iQSC] == (FIXP_DBL)0) {
  3482. - if (++iQSC >= 1024) { /* points to current value different from zero */
  3483. - return BODY_SIGN__SIGN;
  3484. - }
  3485. - }
  3486. -
  3487. - /* put sign together with line; if carryBit is zero, the sign is ok already;
  3488. - * no write operation necessary in this case */
  3489. - if (carryBit != 0) {
  3490. - pResultBase[iQSC] = -pResultBase[iQSC]; /* carryBit = 1 --> minus */
  3491. - }
  3492. -
  3493. - iQSC++; /* update pointer to next (maybe valid) value */
  3494. -
  3495. - if (cntSign == 0) { /* if (cntSign==0) ==> set state CODEWORD_DECODED */
  3496. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3497. - pCodewordBitfield); /* clear a bit in bitfield and
  3498. - switch off statemachine */
  3499. - pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
  3500. - for loop counter (see
  3501. - above) is done here */
  3502. - break; /* whole nonPCW-Body and according sign bits are decoded */
  3503. - }
  3504. - }
  3505. - pCntSign[codewordOffset] = cntSign;
  3506. - iResultPointer[codewordOffset] = iQSC; /* store updated pResultPointer */
  3507. -
  3508. - if (pRemainingBitsInSegment[segmentOffset] <= 0) {
  3509. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3510. - pSegmentBitfield); /* clear a bit in bitfield and
  3511. - switch off statemachine */
  3512. -
  3513. - if (pRemainingBitsInSegment[segmentOffset] < 0) {
  3514. - pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN__SIGN;
  3515. - return BODY_SIGN__SIGN;
  3516. - }
  3517. - }
  3518. -
  3519. - return STOP_THIS_STATE;
  3520. -}
  3521. -
  3522. -/*---------------------------------------------------------------------------------------------
  3523. - description: Decodes the codeword body in case of codebook is 11. Writes
  3524. -out resulting two or four lines [with probably wrong sign] and counts the number
  3525. -of lines, which are different form zero. This information is needed in next
  3526. - state where sign bits will be decoded, if necessary.
  3527. - If sign bit counter cntSign is zero, no sign bits are needed
  3528. -and codeword is decoded completely.
  3529. ------------------------------------------------------------------------------------------------
  3530. - output: Two lines (quantizes spectral coefficients) which are probably
  3531. -wrong. The sign may be wrong and if one or two values is/are 16, the following
  3532. -states will decode the escape sequence to correct the values which are wirtten
  3533. -here.
  3534. ------------------------------------------------------------------------------------------------
  3535. - return: 0
  3536. ---------------------------------------------------------------------------------------------
  3537. -*/
  3538. -UINT Hcr_State_BODY_SIGN_ESC__BODY(HANDLE_FDK_BITSTREAM bs, void *ptr) {
  3539. - H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
  3540. - SCHAR *pRemainingBitsInSegment;
  3541. - INT *pLeftStartOfSegment;
  3542. - INT *pRightStartOfSegment;
  3543. - UCHAR readDirection;
  3544. - UINT *pSegmentBitfield;
  3545. - UINT *pCodewordBitfield;
  3546. - UINT segmentOffset;
  3547. -
  3548. - UINT *iNode;
  3549. - UCHAR *pCntSign;
  3550. - FIXP_DBL *pResultBase;
  3551. - USHORT *iResultPointer;
  3552. - UINT codewordOffset;
  3553. -
  3554. - UCHAR carryBit;
  3555. - UINT iQSC;
  3556. - UINT cntSign;
  3557. - UINT dimCntr;
  3558. - UINT treeNode;
  3559. - SCHAR *pSta;
  3560. - UINT branchNode;
  3561. - UINT branchValue;
  3562. - const UINT *pCurrentTree;
  3563. - const SCHAR *pQuantValBase;
  3564. - const SCHAR *pQuantVal;
  3565. -
  3566. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  3567. - pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  3568. - pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  3569. - readDirection = pHcr->segmentInfo.readDirection;
  3570. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  3571. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  3572. - segmentOffset = pHcr->segmentInfo.segmentOffset;
  3573. -
  3574. - iNode = pHcr->nonPcwSideinfo.iNode;
  3575. - pCntSign = pHcr->nonPcwSideinfo.pCntSign;
  3576. - pResultBase = pHcr->nonPcwSideinfo.pResultBase;
  3577. - iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
  3578. - codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
  3579. - pSta = pHcr->nonPcwSideinfo.pSta;
  3580. -
  3581. - treeNode = iNode[codewordOffset];
  3582. - pCurrentTree = aHuffTable[ESCAPE_CODEBOOK];
  3583. -
  3584. - for (; pRemainingBitsInSegment[segmentOffset] > 0;
  3585. - pRemainingBitsInSegment[segmentOffset] -= 1) {
  3586. - carryBit = HcrGetABitFromBitstream(
  3587. - bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
  3588. - &pRightStartOfSegment[segmentOffset], readDirection);
  3589. -
  3590. - /* make a step in tree */
  3591. - CarryBitToBranchValue(carryBit, treeNode, &branchValue, &branchNode);
  3592. -
  3593. - /* if end of branch reached write out lines and count bits needed for sign,
  3594. - * otherwise store node in codeword sideinfo */
  3595. - if ((branchNode & TEST_BIT_10) ==
  3596. - TEST_BIT_10) { /* test bit 10 ; if set body complete */
  3597. -
  3598. - /* body completely decoded; branchValue is valid */
  3599. - /* set pQuantVol to first (of two or four) quantized spectral coefficients
  3600. - */
  3601. - pQuantValBase = aQuantTable[ESCAPE_CODEBOOK]; /* get base address of
  3602. - quantized values
  3603. - belonging to current
  3604. - codebook */
  3605. - pQuantVal = pQuantValBase + branchValue; /* set pointer to first valid
  3606. - line [of 2 or 4 quantized
  3607. - values] */
  3608. -
  3609. - /* make backup from original resultPointer in node storage for state
  3610. - * BODY_SIGN_ESC__SIGN */
  3611. - iNode[codewordOffset] = iResultPointer[codewordOffset];
  3612. -
  3613. - /* get position of first line for writing result */
  3614. - iQSC = iResultPointer[codewordOffset];
  3615. -
  3616. - /* codeword decoding result is written out here: Write out 2 or 4
  3617. - * quantized spectral values with probably */
  3618. - /* wrong sign and count number of values which are different from zero for
  3619. - * sign bit decoding [which happens in next state] */
  3620. - cntSign = 0;
  3621. -
  3622. - for (dimCntr = DIMENSION_OF_ESCAPE_CODEBOOK; dimCntr != 0; dimCntr--) {
  3623. - pResultBase[iQSC++] =
  3624. - (FIXP_DBL)*pQuantVal; /* write quant. spec. coef. into spectrum */
  3625. - if (*pQuantVal++ != 0) {
  3626. - cntSign += 1;
  3627. - }
  3628. - }
  3629. -
  3630. - if (cntSign == 0) {
  3631. - ClearBitFromBitfield(
  3632. - &(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3633. - pCodewordBitfield); /* clear a bit in bitfield and switch off
  3634. - statemachine */
  3635. - /* codeword decoded */
  3636. - } else {
  3637. - /* write sign count result into codewordsideinfo of current codeword */
  3638. - pCntSign[codewordOffset] = cntSign;
  3639. - pSta[codewordOffset] = BODY_SIGN_ESC__SIGN; /* change state */
  3640. - pHcr->nonPcwSideinfo.pState =
  3641. - aStateConstant2State[pSta[codewordOffset]]; /* get state from
  3642. - separate array of
  3643. - cw-sideinfo */
  3644. - }
  3645. - pRemainingBitsInSegment[segmentOffset] -= 1; /* the last reinitialzation
  3646. - of for loop counter (see
  3647. - above) is done here */
  3648. - break; /* end of branch in tree reached i.e. a whole nonPCW-Body is
  3649. - decoded */
  3650. - } else { /* body is not decoded completely: */
  3651. - /* update treeNode for further step in decoding tree and store updated
  3652. - * treeNode because maybe no more bits left in segment */
  3653. - treeNode = *(pCurrentTree + branchValue);
  3654. - iNode[codewordOffset] = treeNode;
  3655. - }
  3656. - }
  3657. -
  3658. - if (pRemainingBitsInSegment[segmentOffset] <= 0) {
  3659. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3660. - pSegmentBitfield); /* clear a bit in bitfield and
  3661. - switch off statemachine */
  3662. -
  3663. - if (pRemainingBitsInSegment[segmentOffset] < 0) {
  3664. - pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN_ESC__BODY;
  3665. - return BODY_SIGN_ESC__BODY;
  3666. - }
  3667. - }
  3668. -
  3669. - return STOP_THIS_STATE;
  3670. -}
  3671. -
  3672. -/*---------------------------------------------------------------------------------------------
  3673. - description: This state decodes the sign bits, if a codeword of codebook 11
  3674. -needs some. A flag named 'flagB' in codeword sideinfo is set, if the second line
  3675. -of quantized spectral values is 16. The 'flagB' is used in case of decoding of a
  3676. -escape sequence is necessary as far as the second line is concerned.
  3677. -
  3678. - If only the first line needs an escape sequence, the flagB is
  3679. -cleared. If only the second line needs an escape sequence, the flagB is not
  3680. -used.
  3681. -
  3682. - For storing sideinfo in case of escape sequence decoding one
  3683. -single word can be used for both escape sequences because they are decoded not
  3684. -at the same time:
  3685. -
  3686. -
  3687. - bit 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5
  3688. -4 3 2 1 0
  3689. - ===== == == =========== ===========
  3690. -=================================== ^ ^ ^ ^ ^
  3691. -^ | | | | | | res. flagA flagB
  3692. -escapePrefixUp escapePrefixDown escapeWord
  3693. -
  3694. ------------------------------------------------------------------------------------------------
  3695. - output: Two lines with correct sign. If one or two values is/are 16,
  3696. -the lines are not valid, otherwise they are.
  3697. ------------------------------------------------------------------------------------------------
  3698. - return: 0
  3699. ---------------------------------------------------------------------------------------------
  3700. -*/
  3701. -UINT Hcr_State_BODY_SIGN_ESC__SIGN(HANDLE_FDK_BITSTREAM bs, void *ptr) {
  3702. - H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
  3703. - SCHAR *pRemainingBitsInSegment;
  3704. - INT *pLeftStartOfSegment;
  3705. - INT *pRightStartOfSegment;
  3706. - UCHAR readDirection;
  3707. - UINT *pSegmentBitfield;
  3708. - UINT *pCodewordBitfield;
  3709. - UINT segmentOffset;
  3710. -
  3711. - UINT *iNode;
  3712. - UCHAR *pCntSign;
  3713. - FIXP_DBL *pResultBase;
  3714. - USHORT *iResultPointer;
  3715. - UINT *pEscapeSequenceInfo;
  3716. - UINT codewordOffset;
  3717. -
  3718. - UINT iQSC;
  3719. - UCHAR cntSign;
  3720. - UINT flagA;
  3721. - UINT flagB;
  3722. - UINT flags;
  3723. - UCHAR carryBit;
  3724. - SCHAR *pSta;
  3725. -
  3726. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  3727. - pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  3728. - pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  3729. - readDirection = pHcr->segmentInfo.readDirection;
  3730. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  3731. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  3732. - segmentOffset = pHcr->segmentInfo.segmentOffset;
  3733. -
  3734. - iNode = pHcr->nonPcwSideinfo.iNode;
  3735. - pCntSign = pHcr->nonPcwSideinfo.pCntSign;
  3736. - pResultBase = pHcr->nonPcwSideinfo.pResultBase;
  3737. - iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
  3738. - pEscapeSequenceInfo = pHcr->nonPcwSideinfo.pEscapeSequenceInfo;
  3739. - codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
  3740. - pSta = pHcr->nonPcwSideinfo.pSta;
  3741. -
  3742. - iQSC = iResultPointer[codewordOffset];
  3743. - cntSign = pCntSign[codewordOffset];
  3744. -
  3745. - /* loop for sign bit decoding */
  3746. - for (; pRemainingBitsInSegment[segmentOffset] > 0;
  3747. - pRemainingBitsInSegment[segmentOffset] -= 1) {
  3748. - carryBit = HcrGetABitFromBitstream(
  3749. - bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
  3750. - &pRightStartOfSegment[segmentOffset], readDirection);
  3751. -
  3752. - /* decrement sign counter because one sign bit has been read */
  3753. - cntSign -= 1;
  3754. - pCntSign[codewordOffset] = cntSign;
  3755. -
  3756. - /* get a quantized spectral value (which was decoded in previous state)
  3757. - * which is not zero. [This value will get a sign] */
  3758. - while (pResultBase[iQSC] == (FIXP_DBL)0) {
  3759. - if (++iQSC >= 1024) {
  3760. - return BODY_SIGN_ESC__SIGN;
  3761. - }
  3762. - }
  3763. - iResultPointer[codewordOffset] = iQSC;
  3764. -
  3765. - /* put negative sign together with quantized spectral value; if carryBit is
  3766. - * zero, the sign is ok already; no write operation necessary in this case
  3767. - */
  3768. - if (carryBit != 0) {
  3769. - pResultBase[iQSC] = -pResultBase[iQSC]; /* carryBit = 1 --> minus */
  3770. - }
  3771. - iQSC++; /* update index to next (maybe valid) value */
  3772. - iResultPointer[codewordOffset] = iQSC;
  3773. -
  3774. - if (cntSign == 0) {
  3775. - /* all sign bits are decoded now */
  3776. - pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
  3777. - for loop counter (see
  3778. - above) is done here */
  3779. -
  3780. - /* check decoded values if codeword is decoded: Check if one or two escape
  3781. - * sequences 16 follow */
  3782. -
  3783. - /* step 0 */
  3784. - /* restore pointer to first decoded quantized value [ = original
  3785. - * pResultPointr] from index iNode prepared in State_BODY_SIGN_ESC__BODY
  3786. - */
  3787. - iQSC = iNode[codewordOffset];
  3788. -
  3789. - /* step 1 */
  3790. - /* test first value if escape sequence follows */
  3791. - flagA = 0; /* for first possible escape sequence */
  3792. - if (fixp_abs(pResultBase[iQSC++]) == (FIXP_DBL)ESCAPE_VALUE) {
  3793. - flagA = 1;
  3794. - }
  3795. -
  3796. - /* step 2 */
  3797. - /* test second value if escape sequence follows */
  3798. - flagB = 0; /* for second possible escape sequence */
  3799. - if (fixp_abs(pResultBase[iQSC]) == (FIXP_DBL)ESCAPE_VALUE) {
  3800. - flagB = 1;
  3801. - }
  3802. -
  3803. - /* step 3 */
  3804. - /* evaluate flag result and go on if necessary */
  3805. - if (!flagA && !flagB) {
  3806. - ClearBitFromBitfield(
  3807. - &(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3808. - pCodewordBitfield); /* clear a bit in bitfield and switch off
  3809. - statemachine */
  3810. - } else {
  3811. - /* at least one of two lines is 16 */
  3812. - /* store both flags at correct positions in non PCW codeword sideinfo
  3813. - * pEscapeSequenceInfo[codewordOffset] */
  3814. - flags = flagA << POSITION_OF_FLAG_A;
  3815. - flags |= (flagB << POSITION_OF_FLAG_B);
  3816. - pEscapeSequenceInfo[codewordOffset] = flags;
  3817. -
  3818. - /* set next state */
  3819. - pSta[codewordOffset] = BODY_SIGN_ESC__ESC_PREFIX;
  3820. - pHcr->nonPcwSideinfo.pState =
  3821. - aStateConstant2State[pSta[codewordOffset]]; /* get state from
  3822. - separate array of
  3823. - cw-sideinfo */
  3824. -
  3825. - /* set result pointer to the first line of the two decoded lines */
  3826. - iResultPointer[codewordOffset] = iNode[codewordOffset];
  3827. -
  3828. - if (!flagA && flagB) {
  3829. - /* update pResultPointr ==> state Stat_BODY_SIGN_ESC__ESC_WORD writes
  3830. - * to correct position. Second value is the one and only escape value
  3831. - */
  3832. - iQSC = iResultPointer[codewordOffset];
  3833. - iQSC++;
  3834. - iResultPointer[codewordOffset] = iQSC;
  3835. - }
  3836. -
  3837. - } /* at least one of two lines is 16 */
  3838. - break; /* nonPCW-Body at cb 11 and according sign bits are decoded */
  3839. -
  3840. - } /* if ( cntSign == 0 ) */
  3841. - } /* loop over remaining Bits in segment */
  3842. -
  3843. - if (pRemainingBitsInSegment[segmentOffset] <= 0) {
  3844. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3845. - pSegmentBitfield); /* clear a bit in bitfield and
  3846. - switch off statemachine */
  3847. -
  3848. - if (pRemainingBitsInSegment[segmentOffset] < 0) {
  3849. - pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN_ESC__SIGN;
  3850. - return BODY_SIGN_ESC__SIGN;
  3851. - }
  3852. - }
  3853. - return STOP_THIS_STATE;
  3854. -}
  3855. -
  3856. -/*---------------------------------------------------------------------------------------------
  3857. - description: Decode escape prefix of first or second escape sequence. The
  3858. -escape prefix consists of ones. The following zero is also decoded here.
  3859. ------------------------------------------------------------------------------------------------
  3860. - output: If the single separator-zero which follows the
  3861. -escape-prefix-ones is not yet decoded: The value 'escapePrefixUp' in word
  3862. -pEscapeSequenceInfo[codewordOffset] is updated.
  3863. -
  3864. - If the single separator-zero which follows the
  3865. -escape-prefix-ones is decoded: Two updated values 'escapePrefixUp' and
  3866. -'escapePrefixDown' in word pEscapeSequenceInfo[codewordOffset]. This State is
  3867. -finished. Switch to next state.
  3868. ------------------------------------------------------------------------------------------------
  3869. - return: 0
  3870. ---------------------------------------------------------------------------------------------
  3871. -*/
  3872. -UINT Hcr_State_BODY_SIGN_ESC__ESC_PREFIX(HANDLE_FDK_BITSTREAM bs, void *ptr) {
  3873. - H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
  3874. - SCHAR *pRemainingBitsInSegment;
  3875. - INT *pLeftStartOfSegment;
  3876. - INT *pRightStartOfSegment;
  3877. - UCHAR readDirection;
  3878. - UINT *pSegmentBitfield;
  3879. - UINT segmentOffset;
  3880. - UINT *pEscapeSequenceInfo;
  3881. - UINT codewordOffset;
  3882. - UCHAR carryBit;
  3883. - UINT escapePrefixUp;
  3884. - SCHAR *pSta;
  3885. -
  3886. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  3887. - pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  3888. - pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  3889. - readDirection = pHcr->segmentInfo.readDirection;
  3890. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  3891. - segmentOffset = pHcr->segmentInfo.segmentOffset;
  3892. - pEscapeSequenceInfo = pHcr->nonPcwSideinfo.pEscapeSequenceInfo;
  3893. - codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
  3894. - pSta = pHcr->nonPcwSideinfo.pSta;
  3895. -
  3896. - escapePrefixUp =
  3897. - (pEscapeSequenceInfo[codewordOffset] & MASK_ESCAPE_PREFIX_UP) >>
  3898. - LSB_ESCAPE_PREFIX_UP;
  3899. -
  3900. - /* decode escape prefix */
  3901. - for (; pRemainingBitsInSegment[segmentOffset] > 0;
  3902. - pRemainingBitsInSegment[segmentOffset] -= 1) {
  3903. - carryBit = HcrGetABitFromBitstream(
  3904. - bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
  3905. - &pRightStartOfSegment[segmentOffset], readDirection);
  3906. -
  3907. - /* count ones and store sum in escapePrefixUp */
  3908. - if (carryBit == 1) {
  3909. - escapePrefixUp += 1; /* update conter for ones */
  3910. -
  3911. - /* store updated counter in sideinfo of current codeword */
  3912. - pEscapeSequenceInfo[codewordOffset] &=
  3913. - ~MASK_ESCAPE_PREFIX_UP; /* delete old escapePrefixUp */
  3914. - escapePrefixUp <<= LSB_ESCAPE_PREFIX_UP; /* shift to correct position */
  3915. - pEscapeSequenceInfo[codewordOffset] |=
  3916. - escapePrefixUp; /* insert new escapePrefixUp */
  3917. - escapePrefixUp >>= LSB_ESCAPE_PREFIX_UP; /* shift back down */
  3918. - } else { /* separator [zero] reached */
  3919. - pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
  3920. - for loop counter (see
  3921. - above) is done here */
  3922. - escapePrefixUp +=
  3923. - 4; /* if escape_separator '0' appears, add 4 and ==> break */
  3924. -
  3925. - /* store escapePrefixUp in pEscapeSequenceInfo[codewordOffset] at bit
  3926. - * position escapePrefixUp */
  3927. - pEscapeSequenceInfo[codewordOffset] &=
  3928. - ~MASK_ESCAPE_PREFIX_UP; /* delete old escapePrefixUp */
  3929. - escapePrefixUp <<= LSB_ESCAPE_PREFIX_UP; /* shift to correct position */
  3930. - pEscapeSequenceInfo[codewordOffset] |=
  3931. - escapePrefixUp; /* insert new escapePrefixUp */
  3932. - escapePrefixUp >>= LSB_ESCAPE_PREFIX_UP; /* shift back down */
  3933. -
  3934. - /* store escapePrefixUp in pEscapeSequenceInfo[codewordOffset] at bit
  3935. - * position escapePrefixDown */
  3936. - pEscapeSequenceInfo[codewordOffset] &=
  3937. - ~MASK_ESCAPE_PREFIX_DOWN; /* delete old escapePrefixDown */
  3938. - escapePrefixUp <<= LSB_ESCAPE_PREFIX_DOWN; /* shift to correct position */
  3939. - pEscapeSequenceInfo[codewordOffset] |=
  3940. - escapePrefixUp; /* insert new escapePrefixDown */
  3941. -
  3942. - pSta[codewordOffset] = BODY_SIGN_ESC__ESC_WORD; /* set next state */
  3943. - pHcr->nonPcwSideinfo.pState =
  3944. - aStateConstant2State[pSta[codewordOffset]]; /* get state from separate
  3945. - array of cw-sideinfo */
  3946. - break;
  3947. - }
  3948. - }
  3949. -
  3950. - if (pRemainingBitsInSegment[segmentOffset] <= 0) {
  3951. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3952. - pSegmentBitfield); /* clear a bit in bitfield and
  3953. - switch off statemachine */
  3954. -
  3955. - if (pRemainingBitsInSegment[segmentOffset] < 0) {
  3956. - pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN_ESC__ESC_PREFIX;
  3957. - return BODY_SIGN_ESC__ESC_PREFIX;
  3958. - }
  3959. - }
  3960. -
  3961. - return STOP_THIS_STATE;
  3962. -}
  3963. -
  3964. -/*---------------------------------------------------------------------------------------------
  3965. - description: Decode escapeWord of escape sequence. If the escape sequence
  3966. -is decoded completely, assemble quantized-spectral-escape-coefficient and
  3967. -replace the previous decoded 16 by the new value. Test flagB. If flagB is set,
  3968. -the second escape sequence must be decoded. If flagB is not set, the codeword is
  3969. -decoded and the state machine is switched off.
  3970. ------------------------------------------------------------------------------------------------
  3971. - output: Two lines with valid sign. At least one of both lines has got
  3972. -the correct value.
  3973. ------------------------------------------------------------------------------------------------
  3974. - return: 0
  3975. ---------------------------------------------------------------------------------------------
  3976. -*/
  3977. -UINT Hcr_State_BODY_SIGN_ESC__ESC_WORD(HANDLE_FDK_BITSTREAM bs, void *ptr) {
  3978. - H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
  3979. - SCHAR *pRemainingBitsInSegment;
  3980. - INT *pLeftStartOfSegment;
  3981. - INT *pRightStartOfSegment;
  3982. - UCHAR readDirection;
  3983. - UINT *pSegmentBitfield;
  3984. - UINT *pCodewordBitfield;
  3985. - UINT segmentOffset;
  3986. -
  3987. - FIXP_DBL *pResultBase;
  3988. - USHORT *iResultPointer;
  3989. - UINT *pEscapeSequenceInfo;
  3990. - UINT codewordOffset;
  3991. -
  3992. - UINT escapeWord;
  3993. - UINT escapePrefixDown;
  3994. - UINT escapePrefixUp;
  3995. - UCHAR carryBit;
  3996. - UINT iQSC;
  3997. - INT sign;
  3998. - UINT flagA;
  3999. - UINT flagB;
  4000. - SCHAR *pSta;
  4001. -
  4002. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  4003. - pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  4004. - pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  4005. - readDirection = pHcr->segmentInfo.readDirection;
  4006. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  4007. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  4008. - segmentOffset = pHcr->segmentInfo.segmentOffset;
  4009. -
  4010. - pResultBase = pHcr->nonPcwSideinfo.pResultBase;
  4011. - iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
  4012. - pEscapeSequenceInfo = pHcr->nonPcwSideinfo.pEscapeSequenceInfo;
  4013. - codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
  4014. - pSta = pHcr->nonPcwSideinfo.pSta;
  4015. -
  4016. - escapeWord = pEscapeSequenceInfo[codewordOffset] & MASK_ESCAPE_WORD;
  4017. - escapePrefixDown =
  4018. - (pEscapeSequenceInfo[codewordOffset] & MASK_ESCAPE_PREFIX_DOWN) >>
  4019. - LSB_ESCAPE_PREFIX_DOWN;
  4020. -
  4021. - /* decode escape word */
  4022. - for (; pRemainingBitsInSegment[segmentOffset] > 0;
  4023. - pRemainingBitsInSegment[segmentOffset] -= 1) {
  4024. - carryBit = HcrGetABitFromBitstream(
  4025. - bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
  4026. - &pRightStartOfSegment[segmentOffset], readDirection);
  4027. -
  4028. - /* build escape word */
  4029. - escapeWord <<=
  4030. - 1; /* left shift previous decoded part of escapeWord by on bit */
  4031. - escapeWord = escapeWord | carryBit; /* assemble escape word by bitwise or */
  4032. -
  4033. - /* decrement counter for length of escape word because one more bit was
  4034. - * decoded */
  4035. - escapePrefixDown -= 1;
  4036. -
  4037. - /* store updated escapePrefixDown */
  4038. - pEscapeSequenceInfo[codewordOffset] &=
  4039. - ~MASK_ESCAPE_PREFIX_DOWN; /* delete old escapePrefixDown */
  4040. - escapePrefixDown <<= LSB_ESCAPE_PREFIX_DOWN; /* shift to correct position */
  4041. - pEscapeSequenceInfo[codewordOffset] |=
  4042. - escapePrefixDown; /* insert new escapePrefixDown */
  4043. - escapePrefixDown >>= LSB_ESCAPE_PREFIX_DOWN; /* shift back */
  4044. -
  4045. - /* store updated escapeWord */
  4046. - pEscapeSequenceInfo[codewordOffset] &=
  4047. - ~MASK_ESCAPE_WORD; /* delete old escapeWord */
  4048. - pEscapeSequenceInfo[codewordOffset] |=
  4049. - escapeWord; /* insert new escapeWord */
  4050. -
  4051. - if (escapePrefixDown == 0) {
  4052. - pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
  4053. - for loop counter (see
  4054. - above) is done here */
  4055. -
  4056. - /* escape sequence decoded. Assemble escape-line and replace original line
  4057. - */
  4058. -
  4059. - /* step 0 */
  4060. - /* derive sign */
  4061. - iQSC = iResultPointer[codewordOffset];
  4062. - sign = (pResultBase[iQSC] >= (FIXP_DBL)0)
  4063. - ? 1
  4064. - : -1; /* get sign of escape value 16 */
  4065. -
  4066. - /* step 1 */
  4067. - /* get escapePrefixUp */
  4068. - escapePrefixUp =
  4069. - (pEscapeSequenceInfo[codewordOffset] & MASK_ESCAPE_PREFIX_UP) >>
  4070. - LSB_ESCAPE_PREFIX_UP;
  4071. -
  4072. - /* step 2 */
  4073. - /* calculate escape value */
  4074. - pResultBase[iQSC] =
  4075. - (FIXP_DBL)(sign * (((INT)1 << escapePrefixUp) + (INT)escapeWord));
  4076. -
  4077. - /* get both flags from sideinfo (flags are not shifted to the
  4078. - * lsb-position) */
  4079. - flagA = pEscapeSequenceInfo[codewordOffset] & MASK_FLAG_A;
  4080. - flagB = pEscapeSequenceInfo[codewordOffset] & MASK_FLAG_B;
  4081. -
  4082. - /* step 3 */
  4083. - /* clear the whole escape sideinfo word */
  4084. - pEscapeSequenceInfo[codewordOffset] = 0;
  4085. -
  4086. - /* change state in dependence of flag flagB */
  4087. - if (flagA != 0) {
  4088. - /* first escape sequence decoded; previous decoded 16 has been replaced
  4089. - * by valid line */
  4090. -
  4091. - /* clear flagA in sideinfo word because this escape sequence has already
  4092. - * beed decoded */
  4093. - pEscapeSequenceInfo[codewordOffset] &= ~MASK_FLAG_A;
  4094. -
  4095. - if (flagB == 0) {
  4096. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  4097. - pCodewordBitfield); /* clear a bit in bitfield
  4098. - and switch off
  4099. - statemachine */
  4100. - } else {
  4101. - /* updated pointer to next and last 16 */
  4102. - iQSC++;
  4103. - iResultPointer[codewordOffset] = iQSC;
  4104. -
  4105. - /* change state */
  4106. - pSta[codewordOffset] = BODY_SIGN_ESC__ESC_PREFIX;
  4107. - pHcr->nonPcwSideinfo.pState =
  4108. - aStateConstant2State[pSta[codewordOffset]]; /* get state from
  4109. - separate array of
  4110. - cw-sideinfo */
  4111. - }
  4112. - } else {
  4113. - ClearBitFromBitfield(
  4114. - &(pHcr->nonPcwSideinfo.pState), segmentOffset,
  4115. - pCodewordBitfield); /* clear a bit in bitfield and switch off
  4116. - statemachine */
  4117. - }
  4118. - break;
  4119. - }
  4120. - }
  4121. -
  4122. - if (pRemainingBitsInSegment[segmentOffset] <= 0) {
  4123. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  4124. - pSegmentBitfield); /* clear a bit in bitfield and
  4125. - switch off statemachine */
  4126. -
  4127. - if (pRemainingBitsInSegment[segmentOffset] < 0) {
  4128. - pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN_ESC__ESC_WORD;
  4129. - return BODY_SIGN_ESC__ESC_WORD;
  4130. - }
  4131. - }
  4132. -
  4133. - return STOP_THIS_STATE;
  4134. -}
  4135. --- a/libAACdec/src/aacdec_hcrs.h
  4136. +++ /dev/null
  4137. @@ -1,176 +0,0 @@
  4138. -/* -----------------------------------------------------------------------------
  4139. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  4140. -
  4141. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  4142. -Forschung e.V. All rights reserved.
  4143. -
  4144. - 1. INTRODUCTION
  4145. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  4146. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  4147. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  4148. -a wide variety of Android devices.
  4149. -
  4150. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  4151. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  4152. -full-bandwidth communications codec by independent studies and is widely
  4153. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  4154. -specifications.
  4155. -
  4156. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  4157. -those of Fraunhofer) may be obtained through Via Licensing
  4158. -(www.vialicensing.com) or through the respective patent owners individually for
  4159. -the purpose of encoding or decoding bit streams in products that are compliant
  4160. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  4161. -Android devices already license these patent claims through Via Licensing or
  4162. -directly from the patent owners, and therefore FDK AAC Codec software may
  4163. -already be covered under those patent licenses when it is used for those
  4164. -licensed purposes only.
  4165. -
  4166. -Commercially-licensed AAC software libraries, including floating-point versions
  4167. -with enhanced sound quality, are also available from Fraunhofer. Users are
  4168. -encouraged to check the Fraunhofer website for additional applications
  4169. -information and documentation.
  4170. -
  4171. -2. COPYRIGHT LICENSE
  4172. -
  4173. -Redistribution and use in source and binary forms, with or without modification,
  4174. -are permitted without payment of copyright license fees provided that you
  4175. -satisfy the following conditions:
  4176. -
  4177. -You must retain the complete text of this software license in redistributions of
  4178. -the FDK AAC Codec or your modifications thereto in source code form.
  4179. -
  4180. -You must retain the complete text of this software license in the documentation
  4181. -and/or other materials provided with redistributions of the FDK AAC Codec or
  4182. -your modifications thereto in binary form. You must make available free of
  4183. -charge copies of the complete source code of the FDK AAC Codec and your
  4184. -modifications thereto to recipients of copies in binary form.
  4185. -
  4186. -The name of Fraunhofer may not be used to endorse or promote products derived
  4187. -from this library without prior written permission.
  4188. -
  4189. -You may not charge copyright license fees for anyone to use, copy or distribute
  4190. -the FDK AAC Codec software or your modifications thereto.
  4191. -
  4192. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  4193. -that you changed the software and the date of any change. For modified versions
  4194. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  4195. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  4196. -AAC Codec Library for Android."
  4197. -
  4198. -3. NO PATENT LICENSE
  4199. -
  4200. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  4201. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  4202. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  4203. -software.
  4204. -
  4205. -You may use this FDK AAC Codec software or modifications thereto only for
  4206. -purposes that are authorized by appropriate patent licenses.
  4207. -
  4208. -4. DISCLAIMER
  4209. -
  4210. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  4211. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  4212. -including but not limited to the implied warranties of merchantability and
  4213. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  4214. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  4215. -or consequential damages, including but not limited to procurement of substitute
  4216. -goods or services; loss of use, data, or profits, or business interruption,
  4217. -however caused and on any theory of liability, whether in contract, strict
  4218. -liability, or tort (including negligence), arising in any way out of the use of
  4219. -this software, even if advised of the possibility of such damage.
  4220. -
  4221. -5. CONTACT INFORMATION
  4222. -
  4223. -Fraunhofer Institute for Integrated Circuits IIS
  4224. -Attention: Audio and Multimedia Departments - FDK AAC LL
  4225. -Am Wolfsmantel 33
  4226. -91058 Erlangen, Germany
  4227. -
  4228. -www.iis.fraunhofer.de/amm
  4229. -amm-info@iis.fraunhofer.de
  4230. ------------------------------------------------------------------------------ */
  4231. -
  4232. -/**************************** AAC decoder library ******************************
  4233. -
  4234. - Author(s): Robert Weidner (DSP Solutions)
  4235. -
  4236. - Description: HCR Decoder: Defines of state-constants, masks and
  4237. - state-prototypes
  4238. -
  4239. -*******************************************************************************/
  4240. -
  4241. -#ifndef AACDEC_HCRS_H
  4242. -#define AACDEC_HCRS_H
  4243. -
  4244. -#include "FDK_bitstream.h"
  4245. -#include "aacdec_hcr_types.h"
  4246. -/* The four different kinds of types of states are: */
  4247. -/* different states are defined as constants */ /* start middle=self next
  4248. - stop */
  4249. -#define STOP_THIS_STATE \
  4250. - 0 /* */
  4251. -#define BODY_ONLY \
  4252. - 1 /* X X X */
  4253. -#define BODY_SIGN__BODY \
  4254. - 2 /* X X X X [stop if no sign] */
  4255. -#define BODY_SIGN__SIGN \
  4256. - 3 /* X X [stop if sign bits decoded] */
  4257. -#define BODY_SIGN_ESC__BODY \
  4258. - 4 /* X X X X [stop if no sign] */
  4259. -#define BODY_SIGN_ESC__SIGN \
  4260. - 5 /* X X X [stop if no escape sequence] */
  4261. -#define BODY_SIGN_ESC__ESC_PREFIX \
  4262. - 6 /* X X */
  4263. -#define BODY_SIGN_ESC__ESC_WORD \
  4264. - 7 /* X X X [stop if abs(second qsc) != 16] */
  4265. -
  4266. -/* examples: */
  4267. -
  4268. -/* BODY_ONLY means only the codeword body will be decoded; no
  4269. - * sign bits will follow and no escapesequence will follow */
  4270. -
  4271. -/* BODY_SIGN__BODY means that the codeword consists of two parts;
  4272. - * body and sign part. The part '__BODY' after the two underscores shows */
  4273. -/* that the bits which are currently decoded belong
  4274. - * to the '__BODY' of the codeword and not to the sign part. */
  4275. -
  4276. -/* BODY_SIGN_ESC__ESC_PB means that the codeword consists of three parts;
  4277. - * body, sign and (here: two) escape sequences; */
  4278. -/* P = Prefix = ones */
  4279. -/* W = Escape Word */
  4280. -/* A = first possible (of two) Escape sequeces */
  4281. -/* B = second possible (of two) Escape sequeces */
  4282. -/* The part after the two underscores shows that
  4283. - * the current bits which are decoded belong to the '__ESC_PB' - part of the */
  4284. -/* codeword. That means the body and the sign bits
  4285. - * are decoded completely and the bits which are decoded now belong to */
  4286. -/* the escape sequence [P = prefix; B=second
  4287. - * possible escape sequence] */
  4288. -
  4289. -#define MSB_31_MASK 0x80000000 /* masks MSB (= Bit 31) in a 32 bit word */
  4290. -#define DIMENSION_OF_ESCAPE_CODEBOOK 2 /* for cb >= 11 is dimension 2 */
  4291. -#define ESCAPE_CODEBOOK 11
  4292. -
  4293. -#define MASK_ESCAPE_PREFIX_UP 0x000F0000
  4294. -#define LSB_ESCAPE_PREFIX_UP 16
  4295. -
  4296. -#define MASK_ESCAPE_PREFIX_DOWN 0x0000F000
  4297. -#define LSB_ESCAPE_PREFIX_DOWN 12
  4298. -
  4299. -#define MASK_ESCAPE_WORD 0x00000FFF
  4300. -#define MASK_FLAG_A 0x00200000
  4301. -#define MASK_FLAG_B 0x00100000
  4302. -
  4303. -extern void DecodeNonPCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO hHcr);
  4304. -
  4305. -UINT Hcr_State_BODY_ONLY(HANDLE_FDK_BITSTREAM, void*);
  4306. -UINT Hcr_State_BODY_SIGN__BODY(HANDLE_FDK_BITSTREAM, void*);
  4307. -UINT Hcr_State_BODY_SIGN__SIGN(HANDLE_FDK_BITSTREAM, void*);
  4308. -UINT Hcr_State_BODY_SIGN_ESC__BODY(HANDLE_FDK_BITSTREAM, void*);
  4309. -UINT Hcr_State_BODY_SIGN_ESC__SIGN(HANDLE_FDK_BITSTREAM, void*);
  4310. -UINT Hcr_State_BODY_SIGN_ESC__ESC_PREFIX(HANDLE_FDK_BITSTREAM, void*);
  4311. -UINT Hcr_State_BODY_SIGN_ESC__ESC_WORD(HANDLE_FDK_BITSTREAM, void*);
  4312. -
  4313. -#endif /* AACDEC_HCRS_H */
  4314. --- a/libAACdec/src/aacdecoder.cpp
  4315. +++ b/libAACdec/src/aacdecoder.cpp
  4316. @@ -163,17 +163,12 @@ amm-info@iis.fraunhofer.de
  4317. #include "sac_dec_lib.h"
  4318. -#include "aacdec_hcr.h"
  4319. -#include "rvlc.h"
  4320. -
  4321. #include "usacdec_lpd.h"
  4322. #include "ac_arith_coder.h"
  4323. #include "tpdec_lib.h"
  4324. -#include "conceal.h"
  4325. -
  4326. #include "FDK_crc.h"
  4327. #define PS_IS_EXPLICITLY_DISABLED(aot, flags) \
  4328. (((aot) == AOT_DRM_AAC) && !(flags & AC_PS_PRESENT))
  4329. @@ -1191,10 +1186,6 @@ LINKSPEC_CPP HANDLE_AACDECODER CAacDecod
  4330. /* initialize progam config */
  4331. CProgramConfig_Init(&self->pce);
  4332. - /* initialize error concealment common data */
  4333. - CConcealment_InitCommonData(&self->concealCommonData);
  4334. - self->concealMethodUser = ConcealMethodNone; /* undefined -> auto mode */
  4335. -
  4336. self->hDrcInfo = GetDrcInfo();
  4337. if (self->hDrcInfo == NULL) {
  4338. goto bail;
  4339. @@ -1202,8 +1193,7 @@ LINKSPEC_CPP HANDLE_AACDECODER CAacDecod
  4340. /* Init common DRC structure */
  4341. aacDecoder_drcInit(self->hDrcInfo);
  4342. /* Set default frame delay */
  4343. - aacDecoder_drcSetParam(self->hDrcInfo, DRC_BS_DELAY,
  4344. - CConcealment_GetDelay(&self->concealCommonData));
  4345. + aacDecoder_drcSetParam(self->hDrcInfo, DRC_BS_DELAY, 0);
  4346. self->workBufferCore2 = GetWorkBufferCore2();
  4347. if (self->workBufferCore2 == NULL) goto bail;
  4348. @@ -2085,15 +2075,6 @@ CAacDecoder_Init(HANDLE_AACDECODER self,
  4349. if (self->pAacDecoderStaticChannelInfo[ch]->pCpeStaticData !=
  4350. NULL) {
  4351. self->pAacDecoderStaticChannelInfo[ch]
  4352. - ->pCpeStaticData->jointStereoPersistentData
  4353. - .spectralCoeffs[ch2] =
  4354. - self->pAacDecoderStaticChannelInfo[ch]
  4355. - ->concealmentInfo.spectralCoefficient;
  4356. - self->pAacDecoderStaticChannelInfo[ch]
  4357. - ->pCpeStaticData->jointStereoPersistentData.specScale[ch2] =
  4358. - self->pAacDecoderStaticChannelInfo[ch]
  4359. - ->concealmentInfo.specScale;
  4360. - self->pAacDecoderStaticChannelInfo[ch]
  4361. ->pCpeStaticData->jointStereoPersistentData.scratchBuffer =
  4362. (FIXP_DBL *)self->pTimeData2;
  4363. }
  4364. @@ -2193,12 +2174,6 @@ CAacDecoder_Init(HANDLE_AACDECODER self,
  4365. /* Delete mixdown metadata from the past */
  4366. pcmDmx_Reset(self->hPcmUtils, PCMDMX_RESET_BS_DATA);
  4367. - /* Reset concealment only if ASC changed. Otherwise it will be done with
  4368. - any config callback. E.g. every time the LATM SMC is present. */
  4369. - CConcealment_InitChannelData(
  4370. - &self->pAacDecoderStaticChannelInfo[ch]->concealmentInfo,
  4371. - &self->concealCommonData, initRenderMode,
  4372. - self->streamInfo.aacSamplesPerFrame);
  4373. ch++;
  4374. chIdx++;
  4375. }
  4376. @@ -2336,12 +2311,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecod
  4377. int ch;
  4378. /* Clear history */
  4379. for (ch = 0; ch < self->aacChannels; ch++) {
  4380. - /* Reset concealment */
  4381. - CConcealment_InitChannelData(
  4382. - &self->pAacDecoderStaticChannelInfo[ch]->concealmentInfo,
  4383. - &self->concealCommonData,
  4384. - self->pAacDecoderChannelInfo[0]->renderMode,
  4385. - self->streamInfo.aacSamplesPerFrame);
  4386. /* Clear overlap-add buffers to avoid clicks. */
  4387. FDKmemclear(self->pAacDecoderStaticChannelInfo[ch]->pOverlapBuffer,
  4388. OverlapBufferSize * sizeof(FIXP_DBL));
  4389. @@ -2403,15 +2372,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecod
  4390. if (ch >= self->aacChannels) {
  4391. return AAC_DEC_UNKNOWN;
  4392. }
  4393. -
  4394. - /* if last frame was broken and this frame is no independent frame,
  4395. - * correct decoding is impossible we need to trigger concealment */
  4396. - if ((CConcealment_GetLastFrameOk(
  4397. - &self->pAacDecoderStaticChannelInfo[ch]->concealmentInfo,
  4398. - 1) == 0) &&
  4399. - !(self->flags[streamIndex] & AC_INDEP)) {
  4400. - self->frameOK = 0;
  4401. - }
  4402. ch++;
  4403. }
  4404. }
  4405. @@ -3081,13 +3041,8 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecod
  4406. * following concealment method, mark the frame as erroneous */
  4407. {
  4408. CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
  4409. - CConcealmentInfo *hConcealmentInfo =
  4410. - &pAacDecoderStaticChannelInfo->concealmentInfo;
  4411. const int mute_release_active =
  4412. - (self->frameOK && !(flags & AACDEC_CONCEAL)) &&
  4413. - ((hConcealmentInfo->concealState >= ConcealState_Mute) &&
  4414. - (hConcealmentInfo->cntValidFrames + 1 <=
  4415. - hConcealmentInfo->pConcealParams->numMuteReleaseFrames));
  4416. + (self->frameOK && !(flags & AACDEC_CONCEAL));
  4417. const int icsIsInvalid = (GetScaleFactorBandsTransmitted(pIcsInfo) >
  4418. GetScaleFactorBandsTotal(pIcsInfo));
  4419. const int icsInfoUsedinFadeOut =
  4420. @@ -3098,29 +3053,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecod
  4421. }
  4422. }
  4423. - /*
  4424. - Conceal defective spectral data
  4425. - */
  4426. - {
  4427. - CAacDecoderChannelInfo **ppAacDecoderChannelInfo =
  4428. - &pAacDecoderChannelInfo;
  4429. - CAacDecoderStaticChannelInfo **ppAacDecoderStaticChannelInfo =
  4430. - &pAacDecoderStaticChannelInfo;
  4431. - {
  4432. - concealApplyReturnCode = CConcealment_Apply(
  4433. - &(*ppAacDecoderStaticChannelInfo)->concealmentInfo,
  4434. - *ppAacDecoderChannelInfo, *ppAacDecoderStaticChannelInfo,
  4435. - &self->samplingRateInfo[streamIndex],
  4436. - self->streamInfo.aacSamplesPerFrame,
  4437. - pAacDecoderStaticChannelInfo->last_lpd_mode,
  4438. - (self->frameOK && !(flags & AACDEC_CONCEAL)),
  4439. - self->flags[streamIndex]);
  4440. - }
  4441. - }
  4442. - if (concealApplyReturnCode == -1) {
  4443. - frameOk_butConceal = 1;
  4444. - }
  4445. -
  4446. if (flags & (AACDEC_INTR)) {
  4447. /* Reset DRC control data for this channel */
  4448. aacDecoder_drcInitChannelData(&pAacDecoderStaticChannelInfo->drcData);
  4449. @@ -3191,20 +3123,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecod
  4450. ErrorStatus = AAC_DEC_UNKNOWN;
  4451. break;
  4452. }
  4453. - /* TimeDomainFading */
  4454. - if (!CConceal_TDFading_Applied[c]) {
  4455. - CConceal_TDFading_Applied[c] = CConcealment_TDFading(
  4456. - self->streamInfo.aacSamplesPerFrame,
  4457. - &self->pAacDecoderStaticChannelInfo[c], pTimeData + offset, 0);
  4458. - if (c + 1 < (8) && c < aacChannels - 1) {
  4459. - /* update next TDNoise Seed to avoid muting in case of Parametric
  4460. - * Stereo */
  4461. - self->pAacDecoderStaticChannelInfo[c + 1]
  4462. - ->concealmentInfo.TDNoiseSeed =
  4463. - self->pAacDecoderStaticChannelInfo[c]
  4464. - ->concealmentInfo.TDNoiseSeed;
  4465. - }
  4466. - }
  4467. }
  4468. }
  4469. @@ -3249,11 +3167,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecod
  4470. }
  4471. }
  4472. - /* Add additional concealment delay */
  4473. - self->streamInfo.outputDelay +=
  4474. - CConcealment_GetDelay(&self->concealCommonData) *
  4475. - self->streamInfo.aacSamplesPerFrame;
  4476. -
  4477. /* Map DRC data to StreamInfo structure */
  4478. aacDecoder_drcGetInfo(self->hDrcInfo, &self->streamInfo.drcPresMode,
  4479. &self->streamInfo.drcProgRefLev);
  4480. --- a/libAACdec/src/aacdecoder.h
  4481. +++ b/libAACdec/src/aacdecoder.h
  4482. @@ -236,9 +236,6 @@ struct AAC_DECODER_INSTANCE {
  4483. 1)]; /*!< Pointer to persistent data shared by both channels of a CPE.
  4484. This structure is allocated once for each CPE. */
  4485. - CConcealParams concealCommonData;
  4486. - CConcealmentMethod concealMethodUser;
  4487. -
  4488. CUsacCoreExtensions usacCoreExt; /*!< Data and handles to extend USAC FD/LPD
  4489. core decoder (SBR, MPS, ...) */
  4490. UINT numUsacElements[(1 * 1)];
  4491. --- a/libAACdec/src/aacdecoder_lib.cpp
  4492. +++ b/libAACdec/src/aacdecoder_lib.cpp
  4493. @@ -107,8 +107,6 @@ amm-info@iis.fraunhofer.de
  4494. #include "tpdec_lib.h"
  4495. #include "FDK_core.h" /* FDK_tools version info */
  4496. -#include "conceal.h"
  4497. -
  4498. #include "aacdec_drc.h"
  4499. #include "sac_dec_lib.h"
  4500. @@ -280,26 +278,6 @@ static INT aacDecoder_ConfigCallback(voi
  4501. { err = aacDecoder_Config(self, pAscStruct, configMode, configChanged); }
  4502. }
  4503. if (err == AAC_DEC_OK) {
  4504. - /*
  4505. - revert concealment method if either
  4506. - - Interpolation concealment might not be meaningful
  4507. - - Interpolation concealment is not implemented
  4508. - */
  4509. - if ((self->flags[0] & (AC_LD | AC_ELD) &&
  4510. - (self->concealMethodUser == ConcealMethodNone) &&
  4511. - CConcealment_GetDelay(&self->concealCommonData) >
  4512. - 0) /* might not be meaningful but allow if user has set it
  4513. - expicitly */
  4514. - || (self->flags[0] & (AC_USAC | AC_RSVD50 | AC_RSV603DA) &&
  4515. - CConcealment_GetDelay(&self->concealCommonData) >
  4516. - 0) /* not implemented */
  4517. - ) {
  4518. - /* Revert to error concealment method Noise Substitution.
  4519. - Because interpolation is not implemented for USAC or
  4520. - the additional delay is unwanted for low delay codecs. */
  4521. - setConcealMethod(self, 1);
  4522. - }
  4523. - aacDecoder_setMetadataExpiry(self, self->metadataExpiry);
  4524. errTp = TRANSPORTDEC_OK;
  4525. } else {
  4526. if (err == AAC_DEC_NEED_TO_RESTART) {
  4527. @@ -529,17 +507,12 @@ static AAC_DECODER_ERROR setConcealMetho
  4528. const HANDLE_AACDECODER self, /*!< Handle of the decoder instance */
  4529. const INT method) {
  4530. AAC_DECODER_ERROR errorStatus = AAC_DEC_OK;
  4531. - CConcealParams *pConcealData = NULL;
  4532. int method_revert = 0;
  4533. HANDLE_AAC_DRC hDrcInfo = NULL;
  4534. HANDLE_PCM_DOWNMIX hPcmDmx = NULL;
  4535. - CConcealmentMethod backupMethod = ConcealMethodNone;
  4536. - int backupDelay = 0;
  4537. - int bsDelay = 0;
  4538. /* check decoder handle */
  4539. if (self != NULL) {
  4540. - pConcealData = &self->concealCommonData;
  4541. hDrcInfo = self->hDrcInfo;
  4542. hPcmDmx = self->hPcmUtils;
  4543. if (self->flags[0] & (AC_USAC | AC_RSVD50 | AC_RSV603DA) && method >= 2) {
  4544. @@ -555,33 +528,13 @@ static AAC_DECODER_ERROR setConcealMetho
  4545. }
  4546. }
  4547. - /* Get current method/delay */
  4548. - backupMethod = CConcealment_GetMethod(pConcealData);
  4549. - backupDelay = CConcealment_GetDelay(pConcealData);
  4550. -
  4551. - /* Be sure to set AAC and SBR concealment method simultaneously! */
  4552. - errorStatus = CConcealment_SetParams(
  4553. - pConcealData,
  4554. - (method_revert == 0) ? (int)method : (int)1, // concealMethod
  4555. - AACDEC_CONCEAL_PARAM_NOT_SPECIFIED, // concealFadeOutSlope
  4556. - AACDEC_CONCEAL_PARAM_NOT_SPECIFIED, // concealFadeInSlope
  4557. - AACDEC_CONCEAL_PARAM_NOT_SPECIFIED, // concealMuteRelease
  4558. - AACDEC_CONCEAL_PARAM_NOT_SPECIFIED // concealComfNoiseLevel
  4559. - );
  4560. - if ((errorStatus != AAC_DEC_OK) && (errorStatus != AAC_DEC_INVALID_HANDLE)) {
  4561. - goto bail;
  4562. - }
  4563. -
  4564. - /* Get new delay */
  4565. - bsDelay = CConcealment_GetDelay(pConcealData);
  4566. -
  4567. - errorStatus = aacDecoder_drcSetParam(hDrcInfo, DRC_BS_DELAY, bsDelay);
  4568. + errorStatus = aacDecoder_drcSetParam(hDrcInfo, DRC_BS_DELAY, 0);
  4569. if ((errorStatus != AAC_DEC_OK) && (errorStatus != AAC_DEC_INVALID_HANDLE)) {
  4570. goto bail;
  4571. }
  4572. if (errorStatus == AAC_DEC_OK) {
  4573. - PCMDMX_ERROR err = pcmDmx_SetParam(hPcmDmx, DMX_BS_DATA_DELAY, bsDelay);
  4574. + PCMDMX_ERROR err = pcmDmx_SetParam(hPcmDmx, DMX_BS_DATA_DELAY, 0);
  4575. switch (err) {
  4576. case PCMDMX_INVALID_HANDLE:
  4577. errorStatus = AAC_DEC_INVALID_HANDLE;
  4578. @@ -596,15 +549,10 @@ static AAC_DECODER_ERROR setConcealMetho
  4579. bail:
  4580. if ((errorStatus != AAC_DEC_OK) && (errorStatus != AAC_DEC_INVALID_HANDLE)) {
  4581. - /* Revert to the initial state */
  4582. - CConcealment_SetParams(
  4583. - pConcealData, (int)backupMethod, AACDEC_CONCEAL_PARAM_NOT_SPECIFIED,
  4584. - AACDEC_CONCEAL_PARAM_NOT_SPECIFIED, AACDEC_CONCEAL_PARAM_NOT_SPECIFIED,
  4585. - AACDEC_CONCEAL_PARAM_NOT_SPECIFIED);
  4586. /* Revert DRC bitstream delay */
  4587. - aacDecoder_drcSetParam(hDrcInfo, DRC_BS_DELAY, backupDelay);
  4588. + aacDecoder_drcSetParam(hDrcInfo, DRC_BS_DELAY, 0);
  4589. /* Revert PCM mixdown bitstream delay */
  4590. - pcmDmx_SetParam(hPcmDmx, DMX_BS_DATA_DELAY, backupDelay);
  4591. + pcmDmx_SetParam(hPcmDmx, DMX_BS_DATA_DELAY, 0);
  4592. }
  4593. return errorStatus;
  4594. @@ -834,9 +782,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR aacDecode
  4595. packed into a helper function which keeps all modules and libs in a
  4596. consistent state even in the case an error occures. */
  4597. errorStatus = setConcealMethod(self, value);
  4598. - if (errorStatus == AAC_DEC_OK) {
  4599. - self->concealMethodUser = (CConcealmentMethod)value;
  4600. - }
  4601. break;
  4602. default:
  4603. @@ -966,8 +911,7 @@ LINKSPEC_CPP HANDLE_AACDECODER aacDecode
  4604. aacDec->limiterEnableCurr = 0;
  4605. /* Assure that all modules have same delay */
  4606. - if (setConcealMethod(aacDec,
  4607. - CConcealment_GetMethod(&aacDec->concealCommonData))) {
  4608. + if (setConcealMethod(aacDec, 0)) {
  4609. err = -1;
  4610. goto bail;
  4611. }
  4612. @@ -1359,9 +1303,7 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER
  4613. break;
  4614. }
  4615. - if ((ErrorStatus != AAC_DEC_OK) || (flags & AACDEC_CONCEAL) ||
  4616. - self->pAacDecoderStaticChannelInfo[0]->concealmentInfo.concealState >
  4617. - ConcealState_FadeIn) {
  4618. + if ((ErrorStatus != AAC_DEC_OK) || (flags & AACDEC_CONCEAL)) {
  4619. self->frameOK = 0; /* if an error has occured do concealment in the SBR
  4620. decoder too */
  4621. }
  4622. @@ -1457,9 +1399,6 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER
  4623. domain signal before the QMF synthesis. Therefore the DRC gains
  4624. need to be delayed by the QMF synthesis delay. */
  4625. if (self->mpsEnableCurr) drcDelay = 257;
  4626. - /* Take into account concealment delay */
  4627. - drcDelay += CConcealment_GetDelay(&self->concealCommonData) *
  4628. - self->streamInfo.frameSize;
  4629. for (ch = 0; ch < self->streamInfo.numChannels; ch++) {
  4630. UCHAR mapValue = FDK_chMapDescr_getMapValue(
  4631. --- a/libAACdec/src/block.cpp
  4632. +++ b/libAACdec/src/block.cpp
  4633. @@ -114,9 +114,6 @@ amm-info@iis.fraunhofer.de
  4634. #include "ac_arith_coder.h"
  4635. -#include "aacdec_hcr.h"
  4636. -#include "rvlc.h"
  4637. -
  4638. #if defined(__arm__)
  4639. #include "arm/block_arm.cpp"
  4640. #endif
  4641. @@ -331,12 +328,7 @@ AAC_DECODER_ERROR CBlock_ReadSectionData
  4642. int group;
  4643. UCHAR sect_cb;
  4644. UCHAR *pCodeBook = pAacDecoderChannelInfo->pDynData->aCodeBook;
  4645. - /* HCR input (long) */
  4646. - SHORT *pNumLinesInSec =
  4647. - pAacDecoderChannelInfo->pDynData->specificTo.aac.aNumLineInSec4Hcr;
  4648. int numLinesInSecIdx = 0;
  4649. - UCHAR *pHcrCodeBook =
  4650. - pAacDecoderChannelInfo->pDynData->specificTo.aac.aCodeBooks4Hcr;
  4651. const SHORT *BandOffsets = GetScaleFactorBandOffsets(
  4652. &pAacDecoderChannelInfo->icsInfo, pSamplingRateInfo);
  4653. pAacDecoderChannelInfo->pDynData->specificTo.aac.numberSection = 0;
  4654. @@ -376,22 +368,8 @@ AAC_DECODER_ERROR CBlock_ReadSectionData
  4655. top = band + sect_len;
  4656. if (flags & AC_ER_HCR) {
  4657. - /* HCR input (long) -- collecting sideinfo (for HCR-_long_ only) */
  4658. - if (numLinesInSecIdx >= MAX_SFB_HCR) {
  4659. - return AAC_DEC_PARSE_ERROR;
  4660. - }
  4661. - if (top > (int)GetNumberOfScaleFactorBands(
  4662. - &pAacDecoderChannelInfo->icsInfo, pSamplingRateInfo)) {
  4663. - return AAC_DEC_PARSE_ERROR;
  4664. - }
  4665. - pNumLinesInSec[numLinesInSecIdx] = BandOffsets[top] - BandOffsets[band];
  4666. - numLinesInSecIdx++;
  4667. - if (sect_cb == BOOKSCL) {
  4668. - return AAC_DEC_INVALID_CODE_BOOK;
  4669. - } else {
  4670. - *pHcrCodeBook++ = sect_cb;
  4671. - }
  4672. - pAacDecoderChannelInfo->pDynData->specificTo.aac.numberSection++;
  4673. + /* HCR disabled */
  4674. + return AAC_DEC_PARSE_ERROR;
  4675. }
  4676. /* Check spectral line limits */
  4677. @@ -718,41 +696,12 @@ AAC_DECODER_ERROR CBlock_ReadSpectralDat
  4678. /* plain huffman decoding (short) finished */
  4679. }
  4680. - /* HCR - Huffman Codeword Reordering short */
  4681. else /* if ( flags & AC_ER_HCR ) */
  4682. {
  4683. - H_HCR_INFO hHcr = &pAacDecoderChannelInfo->pComData->overlay.aac.erHcrInfo;
  4684. -
  4685. - int hcrStatus = 0;
  4686. -
  4687. - /* advanced Huffman decoding starts here (HCR decoding :) */
  4688. - if (pAacDecoderChannelInfo->pDynData->specificTo.aac
  4689. - .lenOfReorderedSpectralData != 0) {
  4690. - /* HCR initialization short */
  4691. - hcrStatus = HcrInit(hHcr, pAacDecoderChannelInfo, pSamplingRateInfo, bs);
  4692. -
  4693. - if (hcrStatus != 0) {
  4694. - return AAC_DEC_DECODE_FRAME_ERROR;
  4695. - }
  4696. -
  4697. - /* HCR decoding short */
  4698. - hcrStatus =
  4699. - HcrDecoder(hHcr, pAacDecoderChannelInfo, pSamplingRateInfo, bs);
  4700. -
  4701. - if (hcrStatus != 0) {
  4702. -#if HCR_ERROR_CONCEALMENT
  4703. - HcrMuteErroneousLines(hHcr);
  4704. -#else
  4705. - return AAC_DEC_DECODE_FRAME_ERROR;
  4706. -#endif /* HCR_ERROR_CONCEALMENT */
  4707. - }
  4708. -
  4709. - FDKpushFor(bs, pAacDecoderChannelInfo->pDynData->specificTo.aac
  4710. - .lenOfReorderedSpectralData);
  4711. - }
  4712. + /* HCR - Huffman Codeword Reordering disabled */
  4713. + return AAC_DEC_DECODE_FRAME_ERROR;
  4714. }
  4715. - /* HCR - Huffman Codeword Reordering short finished */
  4716. if (IsLongBlock(&pAacDecoderChannelInfo->icsInfo) &&
  4717. !(flags & (AC_ELD | AC_SCALABLE))) {
  4718. --- a/libAACdec/src/channel.cpp
  4719. +++ b/libAACdec/src/channel.cpp
  4720. @@ -106,12 +106,6 @@ amm-info@iis.fraunhofer.de
  4721. #include "aacdec_tns.h"
  4722. #include "FDK_bitstream.h"
  4723. -#include "conceal.h"
  4724. -
  4725. -#include "rvlc.h"
  4726. -
  4727. -#include "aacdec_hcr.h"
  4728. -
  4729. #include "usacdec_lpd.h"
  4730. #include "usacdec_fac.h"
  4731. @@ -376,9 +370,6 @@ void CChannelElement_Decode(
  4732. ->pCpeStaticData->jointStereoPersistentData.clearSpectralCoeffs = 0;
  4733. }
  4734. }
  4735. -
  4736. - CRvlc_ElementCheck(pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo,
  4737. - flags, el_channels);
  4738. }
  4739. void CChannel_CodebookTableInit(
  4740. @@ -596,8 +587,8 @@ AAC_DECODER_ERROR CChannelElement_Read(
  4741. case scale_factor_data:
  4742. if (flags & AC_ER_RVLC) {
  4743. - /* read RVLC data from bitstream (error sens. cat. 1) */
  4744. - CRvlc_Read(pAacDecoderChannelInfo[ch], hBs);
  4745. + /* RVLC not supported */
  4746. + error = AAC_DEC_DECODE_FRAME_ERROR;
  4747. } else {
  4748. error = CBlock_ReadScaleFactorData(pAacDecoderChannelInfo[ch], hBs,
  4749. flags);
  4750. @@ -730,15 +721,13 @@ AAC_DECODER_ERROR CChannelElement_Read(
  4751. } break;
  4752. case esc2_rvlc:
  4753. if (flags & AC_ER_RVLC) {
  4754. - CRvlc_Decode(pAacDecoderChannelInfo[ch],
  4755. - pAacDecoderStaticChannelInfo[ch], hBs);
  4756. + error = AAC_DEC_UNSUPPORTED_FORMAT;
  4757. }
  4758. break;
  4759. case esc1_hcr:
  4760. if (flags & AC_ER_HCR) {
  4761. - CHcr_Read(hBs, pAacDecoderChannelInfo[ch],
  4762. - numberOfChannels == 2 ? ID_CPE : ID_SCE);
  4763. + error = AAC_DEC_UNSUPPORTED_FORMAT;
  4764. }
  4765. break;
  4766. --- a/libAACdec/src/channelinfo.h
  4767. +++ b/libAACdec/src/channelinfo.h
  4768. @@ -117,17 +117,12 @@ amm-info@iis.fraunhofer.de
  4769. #include "aacdec_pns.h"
  4770. -#include "aacdec_hcr_types.h"
  4771. -#include "rvlc_info.h"
  4772. -
  4773. #include "usacdec_acelp.h"
  4774. #include "usacdec_const.h"
  4775. #include "usacdec_rom.h"
  4776. #include "ac_arith_coder.h"
  4777. -#include "conceal_types.h"
  4778. -
  4779. #include "aacdec_drc_types.h"
  4780. #define WB_SECTION_SIZE (1024 * 2)
  4781. @@ -257,7 +252,6 @@ typedef struct {
  4782. ULONG nfRandomSeed; /* seed value for USAC noise filling random generator */
  4783. CDrcChannelData drcData;
  4784. - CConcealmentInfo concealmentInfo;
  4785. CpePersistentData *pCpeStaticData;
  4786. @@ -280,11 +274,6 @@ typedef struct {
  4787. shouldBeUnion {
  4788. struct {
  4789. CPulseData PulseData;
  4790. - SHORT aNumLineInSec4Hcr[MAX_SFB_HCR]; /* needed once for all channels
  4791. - except for Drm syntax */
  4792. - UCHAR
  4793. - aCodeBooks4Hcr[MAX_SFB_HCR]; /* needed once for all channels except for
  4794. - Drm syntax. Same as "aCodeBook" ? */
  4795. SHORT lenOfReorderedSpectralData;
  4796. SCHAR lenOfLongestCodeword;
  4797. SCHAR numberSection;
  4798. @@ -325,17 +314,6 @@ typedef struct {
  4799. CJointStereoData jointStereoData; /* One for one element */
  4800. - shouldBeUnion {
  4801. - struct {
  4802. - CErHcrInfo erHcrInfo;
  4803. - CErRvlcInfo erRvlcInfo;
  4804. - SHORT aRvlcScfEsc[RVLC_MAX_SFB]; /* needed once for all channels */
  4805. - SHORT aRvlcScfFwd[RVLC_MAX_SFB]; /* needed once for all channels */
  4806. - SHORT aRvlcScfBwd[RVLC_MAX_SFB]; /* needed once for all channels */
  4807. - } aac;
  4808. - }
  4809. - overlay;
  4810. -
  4811. } CAacDecoderCommonData;
  4812. typedef struct {
  4813. --- a/libAACdec/src/conceal.cpp
  4814. +++ /dev/null
  4815. @@ -1,2095 +0,0 @@
  4816. -/* -----------------------------------------------------------------------------
  4817. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  4818. -
  4819. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  4820. -Forschung e.V. All rights reserved.
  4821. -
  4822. - 1. INTRODUCTION
  4823. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  4824. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  4825. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  4826. -a wide variety of Android devices.
  4827. -
  4828. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  4829. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  4830. -full-bandwidth communications codec by independent studies and is widely
  4831. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  4832. -specifications.
  4833. -
  4834. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  4835. -those of Fraunhofer) may be obtained through Via Licensing
  4836. -(www.vialicensing.com) or through the respective patent owners individually for
  4837. -the purpose of encoding or decoding bit streams in products that are compliant
  4838. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  4839. -Android devices already license these patent claims through Via Licensing or
  4840. -directly from the patent owners, and therefore FDK AAC Codec software may
  4841. -already be covered under those patent licenses when it is used for those
  4842. -licensed purposes only.
  4843. -
  4844. -Commercially-licensed AAC software libraries, including floating-point versions
  4845. -with enhanced sound quality, are also available from Fraunhofer. Users are
  4846. -encouraged to check the Fraunhofer website for additional applications
  4847. -information and documentation.
  4848. -
  4849. -2. COPYRIGHT LICENSE
  4850. -
  4851. -Redistribution and use in source and binary forms, with or without modification,
  4852. -are permitted without payment of copyright license fees provided that you
  4853. -satisfy the following conditions:
  4854. -
  4855. -You must retain the complete text of this software license in redistributions of
  4856. -the FDK AAC Codec or your modifications thereto in source code form.
  4857. -
  4858. -You must retain the complete text of this software license in the documentation
  4859. -and/or other materials provided with redistributions of the FDK AAC Codec or
  4860. -your modifications thereto in binary form. You must make available free of
  4861. -charge copies of the complete source code of the FDK AAC Codec and your
  4862. -modifications thereto to recipients of copies in binary form.
  4863. -
  4864. -The name of Fraunhofer may not be used to endorse or promote products derived
  4865. -from this library without prior written permission.
  4866. -
  4867. -You may not charge copyright license fees for anyone to use, copy or distribute
  4868. -the FDK AAC Codec software or your modifications thereto.
  4869. -
  4870. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  4871. -that you changed the software and the date of any change. For modified versions
  4872. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  4873. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  4874. -AAC Codec Library for Android."
  4875. -
  4876. -3. NO PATENT LICENSE
  4877. -
  4878. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  4879. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  4880. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  4881. -software.
  4882. -
  4883. -You may use this FDK AAC Codec software or modifications thereto only for
  4884. -purposes that are authorized by appropriate patent licenses.
  4885. -
  4886. -4. DISCLAIMER
  4887. -
  4888. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  4889. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  4890. -including but not limited to the implied warranties of merchantability and
  4891. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  4892. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  4893. -or consequential damages, including but not limited to procurement of substitute
  4894. -goods or services; loss of use, data, or profits, or business interruption,
  4895. -however caused and on any theory of liability, whether in contract, strict
  4896. -liability, or tort (including negligence), arising in any way out of the use of
  4897. -this software, even if advised of the possibility of such damage.
  4898. -
  4899. -5. CONTACT INFORMATION
  4900. -
  4901. -Fraunhofer Institute for Integrated Circuits IIS
  4902. -Attention: Audio and Multimedia Departments - FDK AAC LL
  4903. -Am Wolfsmantel 33
  4904. -91058 Erlangen, Germany
  4905. -
  4906. -www.iis.fraunhofer.de/amm
  4907. -amm-info@iis.fraunhofer.de
  4908. ------------------------------------------------------------------------------ */
  4909. -
  4910. -/**************************** AAC decoder library ******************************
  4911. -
  4912. - Author(s): Josef Hoepfl
  4913. -
  4914. - Description: independent channel concealment
  4915. -
  4916. -*******************************************************************************/
  4917. -
  4918. -/*!
  4919. - \page concealment AAC core concealment
  4920. -
  4921. - This AAC core implementation includes a concealment function, which can be
  4922. - enabled using the several defines during compilation.
  4923. -
  4924. - There are various tests inside the core, starting with simple CRC tests and
  4925. - ending in a variety of plausibility checks. If such a check indicates an
  4926. - invalid bitstream, then concealment is applied.
  4927. -
  4928. - Concealment is also applied when the calling main program indicates a
  4929. - distorted or missing data frame using the frameOK flag. This is used for error
  4930. - detection on the transport layer. (See below)
  4931. -
  4932. - There are three concealment-modes:
  4933. -
  4934. - 1) Muting: The spectral data is simply set to zero in case of an detected
  4935. - error.
  4936. -
  4937. - 2) Noise substitution: In case of an detected error, concealment copies the
  4938. - last frame and adds attenuates the spectral data. For this mode you have to
  4939. - set the #CONCEAL_NOISE define. Noise substitution adds no additional delay.
  4940. -
  4941. - 3) Interpolation: The interpolation routine swaps the spectral data from the
  4942. - previous and the current frame just before the final frequency to time
  4943. - conversion. In case a single frame is corrupted, concealmant interpolates
  4944. - between the last good and the first good frame to create the spectral data for
  4945. - the missing frame. If multiple frames are corrupted, concealment implements
  4946. - first a fade out based on slightly modified spectral values from the last good
  4947. - frame. As soon as good frames are available, concealmant fades in the new
  4948. - spectral data. For this mode you have to set the #CONCEAL_INTER define. Note
  4949. - that in this case, you also need to set #SBR_BS_DELAY_ENABLE, which basically
  4950. - adds approriate delay in the SBR decoder. Note that the
  4951. - Interpolating-Concealment increases the delay of your decoder by one frame and
  4952. - that it does require additional resources such as memory and computational
  4953. - complexity.
  4954. -
  4955. - <h2>How concealment can be used with errors on the transport layer</h2>
  4956. -
  4957. - Many errors can or have to be detected on the transport layer. For example in
  4958. - IP based systems packet loss can occur. The transport protocol used should
  4959. - indicate such packet loss by inserting an empty frame with frameOK=0.
  4960. -*/
  4961. -
  4962. -#include "conceal.h"
  4963. -
  4964. -#include "aac_rom.h"
  4965. -#include "genericStds.h"
  4966. -
  4967. -/* PNS (of block) */
  4968. -#include "aacdec_pns.h"
  4969. -#include "block.h"
  4970. -
  4971. -#define CONCEAL_DFLT_COMF_NOISE_LEVEL (0x100000)
  4972. -
  4973. -#define CONCEAL_NOT_DEFINED ((UCHAR)-1)
  4974. -
  4975. -/* default settings */
  4976. -#define CONCEAL_DFLT_FADEOUT_FRAMES (6)
  4977. -#define CONCEAL_DFLT_FADEIN_FRAMES (5)
  4978. -#define CONCEAL_DFLT_MUTE_RELEASE_FRAMES (0)
  4979. -
  4980. -#define CONCEAL_DFLT_FADE_FACTOR (0.707106781186548f) /* 1/sqrt(2) */
  4981. -
  4982. -/* some often used constants: */
  4983. -#define FIXP_ZERO FL2FXCONST_DBL(0.0f)
  4984. -#define FIXP_ONE FL2FXCONST_DBL(1.0f)
  4985. -#define FIXP_FL_CORRECTION FL2FXCONST_DBL(0.53333333333333333f)
  4986. -
  4987. -/* For parameter conversion */
  4988. -#define CONCEAL_PARAMETER_BITS (8)
  4989. -#define CONCEAL_MAX_QUANT_FACTOR ((1 << CONCEAL_PARAMETER_BITS) - 1)
  4990. -/*#define CONCEAL_MIN_ATTENUATION_FACTOR_025 ( FL2FXCONST_DBL(0.971627951577106174) )*/ /* -0.25 dB */
  4991. -#define CONCEAL_MIN_ATTENUATION_FACTOR_025_LD \
  4992. - FL2FXCONST_DBL(-0.041524101186092029596853445212299)
  4993. -/*#define CONCEAL_MIN_ATTENUATION_FACTOR_050 ( FL2FXCONST_DBL(0.944060876285923380) )*/ /* -0.50 dB */
  4994. -#define CONCEAL_MIN_ATTENUATION_FACTOR_050_LD \
  4995. - FL2FXCONST_DBL(-0.083048202372184059253597008145293)
  4996. -
  4997. -typedef enum {
  4998. - CConcealment_NoExpand,
  4999. - CConcealment_Expand,
  5000. - CConcealment_Compress
  5001. -} CConcealmentExpandType;
  5002. -
  5003. -static const FIXP_SGL facMod4Table[4] = {
  5004. - FL2FXCONST_SGL(0.500000000f), /* FIXP_SGL(0x4000), 2^-(1-0,00) */
  5005. - FL2FXCONST_SGL(0.594603558f), /* FIXP_SGL(0x4c1b), 2^-(1-0,25) */
  5006. - FL2FXCONST_SGL(0.707106781f), /* FIXP_SGL(0x5a82), 2^-(1-0,50) */
  5007. - FL2FXCONST_SGL(0.840896415f) /* FIXP_SGL(0x6ba2) 2^-(1-0,75) */
  5008. -};
  5009. -
  5010. -static void CConcealment_CalcBandEnergy(
  5011. - FIXP_DBL *spectrum, const SamplingRateInfo *pSamplingRateInfo,
  5012. - const int blockType, CConcealmentExpandType ex, int *sfbEnergy);
  5013. -
  5014. -static void CConcealment_InterpolateBuffer(FIXP_DBL *spectrum,
  5015. - SHORT *pSpecScalePrev,
  5016. - SHORT *pSpecScaleAct,
  5017. - SHORT *pSpecScaleOut, int *enPrv,
  5018. - int *enAct, int sfbCnt,
  5019. - const SHORT *pSfbOffset);
  5020. -
  5021. -static int CConcealment_ApplyInter(
  5022. - CConcealmentInfo *pConcealmentInfo,
  5023. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  5024. - const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
  5025. - const int improveTonal, const int frameOk, const int mute_release_active);
  5026. -
  5027. -static int CConcealment_ApplyNoise(
  5028. - CConcealmentInfo *pConcealmentInfo,
  5029. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  5030. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  5031. - const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
  5032. - const UINT flags);
  5033. -
  5034. -static void CConcealment_UpdateState(
  5035. - CConcealmentInfo *pConcealmentInfo, int frameOk,
  5036. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  5037. - const int samplesPerFrame, CAacDecoderChannelInfo *pAacDecoderChannelInfo);
  5038. -
  5039. -static void CConcealment_ApplyRandomSign(int iRandomPhase, FIXP_DBL *spec,
  5040. - int samplesPerFrame);
  5041. -
  5042. -/* TimeDomainFading */
  5043. -static void CConcealment_TDFadePcmAtt(int start, int len, FIXP_DBL fadeStart,
  5044. - FIXP_DBL fadeStop, FIXP_PCM *pcmdata);
  5045. -static void CConcealment_TDFadeFillFadingStations(FIXP_DBL *fadingStations,
  5046. - int *fadingSteps,
  5047. - FIXP_DBL fadeStop,
  5048. - FIXP_DBL fadeStart,
  5049. - TDfadingType fadingType);
  5050. -static void CConcealment_TDFading_doLinearFadingSteps(int *fadingSteps);
  5051. -
  5052. -/* Streamline the state machine */
  5053. -static int CConcealment_ApplyFadeOut(
  5054. - int mode, CConcealmentInfo *pConcealmentInfo,
  5055. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  5056. - const int samplesPerFrame, CAacDecoderChannelInfo *pAacDecoderChannelInfo);
  5057. -
  5058. -static int CConcealment_TDNoise_Random(ULONG *seed);
  5059. -static void CConcealment_TDNoise_Apply(CConcealmentInfo *const pConcealmentInfo,
  5060. - const int len, FIXP_PCM *const pcmdata);
  5061. -
  5062. -static BLOCK_TYPE CConcealment_GetWinSeq(int prevWinSeq) {
  5063. - BLOCK_TYPE newWinSeq = BLOCK_LONG;
  5064. -
  5065. - /* Try to have only long blocks */
  5066. - if (prevWinSeq == BLOCK_START || prevWinSeq == BLOCK_SHORT) {
  5067. - newWinSeq = BLOCK_STOP;
  5068. - }
  5069. -
  5070. - return (newWinSeq);
  5071. -}
  5072. -
  5073. -/*!
  5074. - \brief Init common concealment information data
  5075. -
  5076. - \param pConcealCommonData Pointer to the concealment common data structure.
  5077. -*/
  5078. -void CConcealment_InitCommonData(CConcealParams *pConcealCommonData) {
  5079. - if (pConcealCommonData != NULL) {
  5080. - int i;
  5081. -
  5082. - /* Set default error concealment technique */
  5083. - pConcealCommonData->method = ConcealMethodInter;
  5084. -
  5085. - pConcealCommonData->numFadeOutFrames = CONCEAL_DFLT_FADEOUT_FRAMES;
  5086. - pConcealCommonData->numFadeInFrames = CONCEAL_DFLT_FADEIN_FRAMES;
  5087. - pConcealCommonData->numMuteReleaseFrames = CONCEAL_DFLT_MUTE_RELEASE_FRAMES;
  5088. -
  5089. - pConcealCommonData->comfortNoiseLevel =
  5090. - (FIXP_DBL)CONCEAL_DFLT_COMF_NOISE_LEVEL;
  5091. -
  5092. - /* Init fade factors (symetric) */
  5093. - pConcealCommonData->fadeOutFactor[0] =
  5094. - FL2FXCONST_SGL(CONCEAL_DFLT_FADE_FACTOR);
  5095. - pConcealCommonData->fadeInFactor[0] = pConcealCommonData->fadeOutFactor[0];
  5096. -
  5097. - for (i = 1; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
  5098. - pConcealCommonData->fadeOutFactor[i] =
  5099. - FX_DBL2FX_SGL(fMult(pConcealCommonData->fadeOutFactor[i - 1],
  5100. - FL2FXCONST_SGL(CONCEAL_DFLT_FADE_FACTOR)));
  5101. - pConcealCommonData->fadeInFactor[i] =
  5102. - pConcealCommonData->fadeOutFactor[i];
  5103. - }
  5104. - }
  5105. -}
  5106. -
  5107. -/*!
  5108. - \brief Get current concealment method.
  5109. -
  5110. - \param pConcealCommonData Pointer to common concealment data (for all
  5111. - channels)
  5112. -*/
  5113. -CConcealmentMethod CConcealment_GetMethod(CConcealParams *pConcealCommonData) {
  5114. - CConcealmentMethod method = ConcealMethodNone;
  5115. -
  5116. - if (pConcealCommonData != NULL) {
  5117. - method = pConcealCommonData->method;
  5118. - }
  5119. -
  5120. - return (method);
  5121. -}
  5122. -
  5123. -/*!
  5124. - \brief Init concealment information for each channel
  5125. -
  5126. - \param pConcealChannelInfo Pointer to the channel related concealment info
  5127. - structure to be initialized. \param pConcealCommonData Pointer to common
  5128. - concealment data (for all channels) \param initRenderMode Initial render
  5129. - mode to be set for the current channel. \param samplesPerFrame The number
  5130. - of samples per frame.
  5131. -*/
  5132. -void CConcealment_InitChannelData(CConcealmentInfo *pConcealChannelInfo,
  5133. - CConcealParams *pConcealCommonData,
  5134. - AACDEC_RENDER_MODE initRenderMode,
  5135. - int samplesPerFrame) {
  5136. - int i;
  5137. - pConcealChannelInfo->TDNoiseSeed = 0;
  5138. - FDKmemclear(pConcealChannelInfo->TDNoiseStates,
  5139. - sizeof(pConcealChannelInfo->TDNoiseStates));
  5140. - pConcealChannelInfo->TDNoiseCoef[0] = FL2FXCONST_SGL(0.05f);
  5141. - pConcealChannelInfo->TDNoiseCoef[1] = FL2FXCONST_SGL(0.5f);
  5142. - pConcealChannelInfo->TDNoiseCoef[2] = FL2FXCONST_SGL(0.45f);
  5143. -
  5144. - pConcealChannelInfo->pConcealParams = pConcealCommonData;
  5145. -
  5146. - pConcealChannelInfo->lastRenderMode = initRenderMode;
  5147. -
  5148. - pConcealChannelInfo->windowShape = CONCEAL_NOT_DEFINED;
  5149. - pConcealChannelInfo->windowSequence = BLOCK_LONG; /* default type */
  5150. - pConcealChannelInfo->lastWinGrpLen = 1;
  5151. -
  5152. - pConcealChannelInfo->concealState = ConcealState_Ok;
  5153. -
  5154. - FDKmemclear(pConcealChannelInfo->spectralCoefficient,
  5155. - 1024 * sizeof(FIXP_CNCL));
  5156. -
  5157. - for (i = 0; i < 8; i++) {
  5158. - pConcealChannelInfo->specScale[i] = 0;
  5159. - }
  5160. -
  5161. - pConcealChannelInfo->iRandomPhase = 0;
  5162. -
  5163. - pConcealChannelInfo->prevFrameOk[0] = 1;
  5164. - pConcealChannelInfo->prevFrameOk[1] = 1;
  5165. -
  5166. - pConcealChannelInfo->cntFadeFrames = 0;
  5167. - pConcealChannelInfo->cntValidFrames = 0;
  5168. - pConcealChannelInfo->fade_old = (FIXP_DBL)MAXVAL_DBL;
  5169. - pConcealChannelInfo->winGrpOffset[0] = 0;
  5170. - pConcealChannelInfo->winGrpOffset[1] = 0;
  5171. - pConcealChannelInfo->attGrpOffset[0] = 0;
  5172. - pConcealChannelInfo->attGrpOffset[1] = 0;
  5173. -}
  5174. -
  5175. -/*!
  5176. - \brief Set error concealment parameters
  5177. -
  5178. - \param concealParams
  5179. - \param method
  5180. - \param fadeOutSlope
  5181. - \param fadeInSlope
  5182. - \param muteRelease
  5183. - \param comfNoiseLevel
  5184. -*/
  5185. -AAC_DECODER_ERROR
  5186. -CConcealment_SetParams(CConcealParams *concealParams, int method,
  5187. - int fadeOutSlope, int fadeInSlope, int muteRelease,
  5188. - FIXP_DBL comfNoiseLevel) {
  5189. - /* set concealment technique */
  5190. - if (method != AACDEC_CONCEAL_PARAM_NOT_SPECIFIED) {
  5191. - switch ((CConcealmentMethod)method) {
  5192. - case ConcealMethodMute:
  5193. - case ConcealMethodNoise:
  5194. - case ConcealMethodInter:
  5195. - /* Be sure to enable delay adjustment of SBR decoder! */
  5196. - if (concealParams == NULL) {
  5197. - return AAC_DEC_INVALID_HANDLE;
  5198. - } else {
  5199. - /* set param */
  5200. - concealParams->method = (CConcealmentMethod)method;
  5201. - }
  5202. - break;
  5203. -
  5204. - default:
  5205. - return AAC_DEC_SET_PARAM_FAIL;
  5206. - }
  5207. - }
  5208. -
  5209. - /* set number of frames for fade-out slope */
  5210. - if (fadeOutSlope != AACDEC_CONCEAL_PARAM_NOT_SPECIFIED) {
  5211. - if ((fadeOutSlope < CONCEAL_MAX_NUM_FADE_FACTORS) && (fadeOutSlope >= 0)) {
  5212. - if (concealParams == NULL) {
  5213. - return AAC_DEC_INVALID_HANDLE;
  5214. - } else {
  5215. - /* set param */
  5216. - concealParams->numFadeOutFrames = fadeOutSlope;
  5217. - }
  5218. - } else {
  5219. - return AAC_DEC_SET_PARAM_FAIL;
  5220. - }
  5221. - }
  5222. -
  5223. - /* set number of frames for fade-in slope */
  5224. - if (fadeInSlope != AACDEC_CONCEAL_PARAM_NOT_SPECIFIED) {
  5225. - if ((fadeInSlope < CONCEAL_MAX_NUM_FADE_FACTORS) && (fadeInSlope >= 0)) {
  5226. - if (concealParams == NULL) {
  5227. - return AAC_DEC_INVALID_HANDLE;
  5228. - } else {
  5229. - /* set param */
  5230. - concealParams->numFadeInFrames = fadeInSlope;
  5231. - }
  5232. - } else {
  5233. - return AAC_DEC_SET_PARAM_FAIL;
  5234. - }
  5235. - }
  5236. -
  5237. - /* set number of error-free frames after which the muting will be released */
  5238. - if (muteRelease != AACDEC_CONCEAL_PARAM_NOT_SPECIFIED) {
  5239. - if ((muteRelease < (CONCEAL_MAX_NUM_FADE_FACTORS << 1)) &&
  5240. - (muteRelease >= 0)) {
  5241. - if (concealParams == NULL) {
  5242. - return AAC_DEC_INVALID_HANDLE;
  5243. - } else {
  5244. - /* set param */
  5245. - concealParams->numMuteReleaseFrames = muteRelease;
  5246. - }
  5247. - } else {
  5248. - return AAC_DEC_SET_PARAM_FAIL;
  5249. - }
  5250. - }
  5251. -
  5252. - /* set confort noise level which will be inserted while in state 'muting' */
  5253. - if (comfNoiseLevel != (FIXP_DBL)AACDEC_CONCEAL_PARAM_NOT_SPECIFIED) {
  5254. - if ((comfNoiseLevel < (FIXP_DBL)0) ||
  5255. - (comfNoiseLevel > (FIXP_DBL)MAXVAL_DBL)) {
  5256. - return AAC_DEC_SET_PARAM_FAIL;
  5257. - }
  5258. - if (concealParams == NULL) {
  5259. - return AAC_DEC_INVALID_HANDLE;
  5260. - } else {
  5261. - concealParams->comfortNoiseLevel = (FIXP_DBL)comfNoiseLevel;
  5262. - }
  5263. - }
  5264. -
  5265. - return (AAC_DEC_OK);
  5266. -}
  5267. -
  5268. -/*!
  5269. - \brief Set fade-out/in attenuation factor vectors
  5270. -
  5271. - \param concealParams
  5272. - \param fadeOutAttenuationVector
  5273. - \param fadeInAttenuationVector
  5274. -
  5275. - \return 0 if OK all other values indicate errors
  5276. -*/
  5277. -AAC_DECODER_ERROR
  5278. -CConcealment_SetAttenuation(CConcealParams *concealParams,
  5279. - const SHORT *fadeOutAttenuationVector,
  5280. - const SHORT *fadeInAttenuationVector) {
  5281. - if ((fadeOutAttenuationVector == NULL) && (fadeInAttenuationVector == NULL)) {
  5282. - return AAC_DEC_SET_PARAM_FAIL;
  5283. - }
  5284. -
  5285. - /* Fade-out factors */
  5286. - if (fadeOutAttenuationVector != NULL) {
  5287. - int i;
  5288. -
  5289. - /* check quantized factors first */
  5290. - for (i = 0; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
  5291. - if ((fadeOutAttenuationVector[i] < 0) ||
  5292. - (fadeOutAttenuationVector[i] > CONCEAL_MAX_QUANT_FACTOR)) {
  5293. - return AAC_DEC_SET_PARAM_FAIL;
  5294. - }
  5295. - }
  5296. - if (concealParams == NULL) {
  5297. - return AAC_DEC_INVALID_HANDLE;
  5298. - }
  5299. -
  5300. - /* now dequantize factors */
  5301. - for (i = 0; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
  5302. - concealParams->fadeOutFactor[i] =
  5303. - FX_DBL2FX_SGL(fLdPow(CONCEAL_MIN_ATTENUATION_FACTOR_025_LD, 0,
  5304. - (FIXP_DBL)((INT)(FL2FXCONST_DBL(1.0 / 2.0) >>
  5305. - (CONCEAL_PARAMETER_BITS - 1)) *
  5306. - (INT)fadeOutAttenuationVector[i]),
  5307. - CONCEAL_PARAMETER_BITS));
  5308. - }
  5309. - }
  5310. -
  5311. - /* Fade-in factors */
  5312. - if (fadeInAttenuationVector != NULL) {
  5313. - int i;
  5314. -
  5315. - /* check quantized factors first */
  5316. - for (i = 0; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
  5317. - if ((fadeInAttenuationVector[i] < 0) ||
  5318. - (fadeInAttenuationVector[i] > CONCEAL_MAX_QUANT_FACTOR)) {
  5319. - return AAC_DEC_SET_PARAM_FAIL;
  5320. - }
  5321. - }
  5322. - if (concealParams == NULL) {
  5323. - return AAC_DEC_INVALID_HANDLE;
  5324. - }
  5325. -
  5326. - /* now dequantize factors */
  5327. - for (i = 0; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
  5328. - concealParams->fadeInFactor[i] = FX_DBL2FX_SGL(
  5329. - fLdPow(CONCEAL_MIN_ATTENUATION_FACTOR_025_LD, 0,
  5330. - (FIXP_DBL)((INT)(FIXP_ONE >> CONCEAL_PARAMETER_BITS) *
  5331. - (INT)fadeInAttenuationVector[i]),
  5332. - CONCEAL_PARAMETER_BITS));
  5333. - }
  5334. - }
  5335. -
  5336. - return (AAC_DEC_OK);
  5337. -}
  5338. -
  5339. -/*!
  5340. - \brief Get state of concealment module.
  5341. -
  5342. - \param pConcealChannelInfo
  5343. -
  5344. - \return Concealment state.
  5345. -*/
  5346. -CConcealmentState CConcealment_GetState(CConcealmentInfo *pConcealChannelInfo) {
  5347. - CConcealmentState state = ConcealState_Ok;
  5348. -
  5349. - if (pConcealChannelInfo != NULL) {
  5350. - state = pConcealChannelInfo->concealState;
  5351. - }
  5352. -
  5353. - return (state);
  5354. -}
  5355. -
  5356. -/*!
  5357. - \brief Store data for concealment techniques applied later
  5358. -
  5359. - Interface function to store data for different concealment strategies
  5360. - */
  5361. -void CConcealment_Store(
  5362. - CConcealmentInfo *hConcealmentInfo,
  5363. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  5364. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
  5365. - UCHAR nbDiv = NB_DIV;
  5366. -
  5367. - if (!(pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_LPD &&
  5368. - pAacDecoderChannelInfo->data.usac.mod[nbDiv - 1] == 0))
  5369. -
  5370. - {
  5371. - FIXP_DBL *pSpectralCoefficient =
  5372. - SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
  5373. - SHORT *pSpecScale = pAacDecoderChannelInfo->specScale;
  5374. - CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
  5375. -
  5376. - SHORT tSpecScale[8];
  5377. - UCHAR tWindowShape;
  5378. - BLOCK_TYPE tWindowSequence;
  5379. -
  5380. - /* store old window infos for swapping */
  5381. - tWindowSequence = hConcealmentInfo->windowSequence;
  5382. - tWindowShape = hConcealmentInfo->windowShape;
  5383. -
  5384. - /* store old scale factors for swapping */
  5385. - FDKmemcpy(tSpecScale, hConcealmentInfo->specScale, 8 * sizeof(SHORT));
  5386. -
  5387. - /* store new window infos */
  5388. - hConcealmentInfo->windowSequence = GetWindowSequence(pIcsInfo);
  5389. - hConcealmentInfo->windowShape = GetWindowShape(pIcsInfo);
  5390. - hConcealmentInfo->lastWinGrpLen =
  5391. - *(GetWindowGroupLengthTable(pIcsInfo) + GetWindowGroups(pIcsInfo) - 1);
  5392. -
  5393. - /* store new scale factors */
  5394. - FDKmemcpy(hConcealmentInfo->specScale, pSpecScale, 8 * sizeof(SHORT));
  5395. -
  5396. - if (hConcealmentInfo->pConcealParams->method < ConcealMethodInter) {
  5397. - /* store new spectral bins */
  5398. -#if (CNCL_FRACT_BITS == DFRACT_BITS)
  5399. - FDKmemcpy(hConcealmentInfo->spectralCoefficient, pSpectralCoefficient,
  5400. - 1024 * sizeof(FIXP_CNCL));
  5401. -#else
  5402. - FIXP_CNCL *RESTRICT pCncl =
  5403. - &hConcealmentInfo->spectralCoefficient[1024 - 1];
  5404. - FIXP_DBL *RESTRICT pSpec = &pSpectralCoefficient[1024 - 1];
  5405. - int i;
  5406. - for (i = 1024; i != 0; i--) {
  5407. - *pCncl-- = FX_DBL2FX_CNCL(*pSpec--);
  5408. - }
  5409. -#endif
  5410. - } else {
  5411. - /* swap spectral data */
  5412. -#if (FIXP_CNCL == FIXP_DBL)
  5413. - C_ALLOC_SCRATCH_START(pSpecTmp, FIXP_DBL, 1024);
  5414. - FDKmemcpy(pSpecTmp, pSpectralCoefficient, 1024 * sizeof(FIXP_DBL));
  5415. - FDKmemcpy(pSpectralCoefficient, hConcealmentInfo->spectralCoefficient,
  5416. - 1024 * sizeof(FIXP_DBL));
  5417. - FDKmemcpy(hConcealmentInfo->spectralCoefficient, pSpecTmp,
  5418. - 1024 * sizeof(FIXP_DBL));
  5419. - C_ALLOC_SCRATCH_END(pSpecTmp, FIXP_DBL, 1024);
  5420. -#else
  5421. - FIXP_CNCL *RESTRICT pCncl =
  5422. - &hConcealmentInfo->spectralCoefficient[1024 - 1];
  5423. - FIXP_DBL *RESTRICT pSpec = &pSpectralCoefficient[1024 - 1];
  5424. - FIXP_DBL tSpec;
  5425. -
  5426. - for (int i = 1024; i != 0; i--) {
  5427. - tSpec = *pSpec;
  5428. - *pSpec-- = FX_CNCL2FX_DBL(*pCncl);
  5429. - *pCncl-- = FX_DBL2FX_CNCL(tSpec);
  5430. - }
  5431. -#endif
  5432. -
  5433. - /* complete swapping of window infos */
  5434. - pIcsInfo->WindowSequence = tWindowSequence;
  5435. - pIcsInfo->WindowShape = tWindowShape;
  5436. -
  5437. - /* complete swapping of scale factors */
  5438. - FDKmemcpy(pSpecScale, tSpecScale, 8 * sizeof(SHORT));
  5439. - }
  5440. - }
  5441. -
  5442. - if (pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_LPD) {
  5443. - /* Store LSF4 */
  5444. - FDKmemcpy(hConcealmentInfo->lsf4, pAacDecoderStaticChannelInfo->lpc4_lsf,
  5445. - sizeof(hConcealmentInfo->lsf4));
  5446. - /* Store TCX gain */
  5447. - hConcealmentInfo->last_tcx_gain =
  5448. - pAacDecoderStaticChannelInfo->last_tcx_gain;
  5449. - hConcealmentInfo->last_tcx_gain_e =
  5450. - pAacDecoderStaticChannelInfo->last_tcx_gain_e;
  5451. - }
  5452. -}
  5453. -
  5454. -/*!
  5455. - \brief Apply concealment
  5456. -
  5457. - Interface function to different concealment strategies
  5458. - */
  5459. -int CConcealment_Apply(
  5460. - CConcealmentInfo *hConcealmentInfo,
  5461. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  5462. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  5463. - const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
  5464. - const UCHAR lastLpdMode, const int frameOk, const UINT flags) {
  5465. - int appliedProcessing = 0;
  5466. - const int mute_release_active =
  5467. - frameOk && (hConcealmentInfo->concealState >= ConcealState_Mute) &&
  5468. - (hConcealmentInfo->cntValidFrames + 1 <=
  5469. - hConcealmentInfo->pConcealParams->numMuteReleaseFrames);
  5470. -
  5471. - if (hConcealmentInfo->windowShape == CONCEAL_NOT_DEFINED) {
  5472. - /* Initialize window_shape with same value as in the current (parsed) frame.
  5473. - Because section 4.6.11.3.2 (Windowing and block switching) of ISO/IEC
  5474. - 14496-3:2009 says: For the first raw_data_block() to be decoded the
  5475. - window_shape of the left and right half of the window are identical. */
  5476. - hConcealmentInfo->windowShape = pAacDecoderChannelInfo->icsInfo.WindowShape;
  5477. - }
  5478. -
  5479. - if (frameOk && !mute_release_active) {
  5480. - /* Update render mode if frameOk except for ongoing mute release state. */
  5481. - hConcealmentInfo->lastRenderMode =
  5482. - (SCHAR)pAacDecoderChannelInfo->renderMode;
  5483. -
  5484. - /* Rescue current data for concealment in future frames */
  5485. - CConcealment_Store(hConcealmentInfo, pAacDecoderChannelInfo,
  5486. - pAacDecoderStaticChannelInfo);
  5487. - /* Reset index to random sign vector to make sign calculation frame agnostic
  5488. - (only depends on number of subsequently concealed spectral blocks) */
  5489. - hConcealmentInfo->iRandomPhase = 0;
  5490. - } else {
  5491. - if (hConcealmentInfo->lastRenderMode == AACDEC_RENDER_INVALID) {
  5492. - hConcealmentInfo->lastRenderMode = AACDEC_RENDER_IMDCT;
  5493. - }
  5494. - pAacDecoderChannelInfo->renderMode =
  5495. - (AACDEC_RENDER_MODE)hConcealmentInfo->lastRenderMode;
  5496. - }
  5497. -
  5498. - /* hand current frame status to the state machine */
  5499. - CConcealment_UpdateState(hConcealmentInfo, frameOk,
  5500. - pAacDecoderStaticChannelInfo, samplesPerFrame,
  5501. - pAacDecoderChannelInfo);
  5502. -
  5503. - {
  5504. - if (!frameOk && pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_IMDCT) {
  5505. - /* LPC extrapolation */
  5506. - CLpc_Conceal(pAacDecoderChannelInfo->data.usac.lsp_coeff,
  5507. - pAacDecoderStaticChannelInfo->lpc4_lsf,
  5508. - pAacDecoderStaticChannelInfo->lsf_adaptive_mean,
  5509. - hConcealmentInfo->lastRenderMode == AACDEC_RENDER_IMDCT);
  5510. - FDKmemcpy(hConcealmentInfo->lsf4, pAacDecoderStaticChannelInfo->lpc4_lsf,
  5511. - sizeof(pAacDecoderStaticChannelInfo->lpc4_lsf));
  5512. - }
  5513. -
  5514. - /* Create data for signal rendering according to the selected concealment
  5515. - * method and decoder operating mode. */
  5516. -
  5517. - if ((!frameOk || mute_release_active) &&
  5518. - (pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_LPD)) {
  5519. - /* Restore old LSF4 */
  5520. - FDKmemcpy(pAacDecoderStaticChannelInfo->lpc4_lsf, hConcealmentInfo->lsf4,
  5521. - sizeof(pAacDecoderStaticChannelInfo->lpc4_lsf));
  5522. - /* Restore old TCX gain */
  5523. - pAacDecoderStaticChannelInfo->last_tcx_gain =
  5524. - hConcealmentInfo->last_tcx_gain;
  5525. - pAacDecoderStaticChannelInfo->last_tcx_gain_e =
  5526. - hConcealmentInfo->last_tcx_gain_e;
  5527. - }
  5528. -
  5529. - if (!(pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_LPD &&
  5530. - pAacDecoderStaticChannelInfo->last_lpd_mode == 0)) {
  5531. - switch (hConcealmentInfo->pConcealParams->method) {
  5532. - default:
  5533. - case ConcealMethodMute:
  5534. - if (!frameOk) {
  5535. - /* Mute spectral data in case of errors */
  5536. - FDKmemclear(pAacDecoderChannelInfo->pSpectralCoefficient,
  5537. - samplesPerFrame * sizeof(FIXP_DBL));
  5538. - /* Set last window shape */
  5539. - pAacDecoderChannelInfo->icsInfo.WindowShape =
  5540. - hConcealmentInfo->windowShape;
  5541. - appliedProcessing = 1;
  5542. - }
  5543. - break;
  5544. -
  5545. - case ConcealMethodNoise:
  5546. - /* Noise substitution error concealment technique */
  5547. - appliedProcessing = CConcealment_ApplyNoise(
  5548. - hConcealmentInfo, pAacDecoderChannelInfo,
  5549. - pAacDecoderStaticChannelInfo, pSamplingRateInfo, samplesPerFrame,
  5550. - flags);
  5551. - break;
  5552. -
  5553. - case ConcealMethodInter:
  5554. - /* Energy interpolation concealment based on 3GPP */
  5555. - appliedProcessing = CConcealment_ApplyInter(
  5556. - hConcealmentInfo, pAacDecoderChannelInfo, pSamplingRateInfo,
  5557. - samplesPerFrame, 0, /* don't use tonal improvement */
  5558. - frameOk, mute_release_active);
  5559. - break;
  5560. - }
  5561. - } else if (!frameOk || mute_release_active) {
  5562. - /* simply restore the buffer */
  5563. - FIXP_DBL *pSpectralCoefficient =
  5564. - SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
  5565. - SHORT *pSpecScale = pAacDecoderChannelInfo->specScale;
  5566. - CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
  5567. -#if (CNCL_FRACT_BITS != DFRACT_BITS)
  5568. - FIXP_CNCL *RESTRICT pCncl =
  5569. - &hConcealmentInfo->spectralCoefficient[1024 - 1];
  5570. - FIXP_DBL *RESTRICT pSpec = &pSpectralCoefficient[1024 - 1];
  5571. - int i;
  5572. -#endif
  5573. -
  5574. - /* restore window infos (gri) do we need that? */
  5575. - pIcsInfo->WindowSequence = hConcealmentInfo->windowSequence;
  5576. - pIcsInfo->WindowShape = hConcealmentInfo->windowShape;
  5577. -
  5578. - if (hConcealmentInfo->concealState != ConcealState_Mute) {
  5579. - /* restore scale factors */
  5580. - FDKmemcpy(pSpecScale, hConcealmentInfo->specScale, 8 * sizeof(SHORT));
  5581. -
  5582. - /* restore spectral bins */
  5583. -#if (CNCL_FRACT_BITS == DFRACT_BITS)
  5584. - FDKmemcpy(pSpectralCoefficient, hConcealmentInfo->spectralCoefficient,
  5585. - 1024 * sizeof(FIXP_DBL));
  5586. -#else
  5587. - for (i = 1024; i != 0; i--) {
  5588. - *pSpec-- = FX_CNCL2FX_DBL(*pCncl--);
  5589. - }
  5590. -#endif
  5591. - } else {
  5592. - /* clear scale factors */
  5593. - FDKmemclear(pSpecScale, 8 * sizeof(SHORT));
  5594. -
  5595. - /* clear buffer */
  5596. - FDKmemclear(pSpectralCoefficient, 1024 * sizeof(FIXP_CNCL));
  5597. - }
  5598. - }
  5599. - }
  5600. - /* update history */
  5601. - hConcealmentInfo->prevFrameOk[0] = hConcealmentInfo->prevFrameOk[1];
  5602. - hConcealmentInfo->prevFrameOk[1] = frameOk;
  5603. -
  5604. - return mute_release_active ? -1 : appliedProcessing;
  5605. -}
  5606. -
  5607. -/*!
  5608. -\brief Apply concealment noise substitution
  5609. -
  5610. - In case of frame lost this function produces a noisy frame with respect to the
  5611. - energies values of past frame.
  5612. - */
  5613. -static int CConcealment_ApplyNoise(
  5614. - CConcealmentInfo *pConcealmentInfo,
  5615. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  5616. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  5617. - const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
  5618. - const UINT flags) {
  5619. - FIXP_DBL *pSpectralCoefficient =
  5620. - SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
  5621. - CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
  5622. -
  5623. - int appliedProcessing = 0;
  5624. -
  5625. - FDK_ASSERT(pConcealmentInfo != NULL);
  5626. - FDK_ASSERT((samplesPerFrame >= 120) && (samplesPerFrame <= 1024));
  5627. -
  5628. - switch (pConcealmentInfo->concealState) {
  5629. - case ConcealState_Ok:
  5630. - /* Nothing to do here! */
  5631. - break;
  5632. -
  5633. - case ConcealState_Single:
  5634. - case ConcealState_FadeOut:
  5635. - appliedProcessing = CConcealment_ApplyFadeOut(
  5636. - /*mode =*/1, pConcealmentInfo, pAacDecoderStaticChannelInfo,
  5637. - samplesPerFrame, pAacDecoderChannelInfo);
  5638. - break;
  5639. -
  5640. - case ConcealState_Mute: {
  5641. - /* set dummy window parameters */
  5642. - pIcsInfo->Valid = 0; /* Trigger the generation of a consitent IcsInfo */
  5643. - pIcsInfo->WindowShape =
  5644. - pConcealmentInfo->windowShape; /* Prevent an invalid WindowShape
  5645. - (required for F/T transform) */
  5646. - pIcsInfo->WindowSequence =
  5647. - CConcealment_GetWinSeq(pConcealmentInfo->windowSequence);
  5648. - pConcealmentInfo->windowSequence =
  5649. - pIcsInfo->WindowSequence; /* Store for next frame
  5650. - (spectrum in concealment
  5651. - buffer can't be used at
  5652. - all) */
  5653. -
  5654. - /* mute spectral data */
  5655. - FDKmemclear(pSpectralCoefficient, samplesPerFrame * sizeof(FIXP_DBL));
  5656. - FDKmemclear(pConcealmentInfo->spectralCoefficient,
  5657. - samplesPerFrame * sizeof(FIXP_DBL));
  5658. -
  5659. - appliedProcessing = 1;
  5660. - } break;
  5661. -
  5662. - case ConcealState_FadeIn: {
  5663. - /* TimeDomainFading: */
  5664. - /* Attenuation of signal is done in CConcealment_TDFading() */
  5665. -
  5666. - appliedProcessing = 1;
  5667. - } break;
  5668. -
  5669. - default:
  5670. - /* we shouldn't come here anyway */
  5671. - FDK_ASSERT(0);
  5672. - break;
  5673. - }
  5674. -
  5675. - return appliedProcessing;
  5676. -}
  5677. -
  5678. -/*!
  5679. - \brief Apply concealment interpolation
  5680. -
  5681. - The function swaps the data from the current and the previous frame. If an
  5682. - error has occured, frame interpolation is performed to restore the missing
  5683. - frame. In case of multiple faulty frames, fade-in and fade-out is applied.
  5684. -*/
  5685. -static int CConcealment_ApplyInter(
  5686. - CConcealmentInfo *pConcealmentInfo,
  5687. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  5688. - const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
  5689. - const int improveTonal, const int frameOk, const int mute_release_active) {
  5690. -#if defined(FDK_ASSERT_ENABLE)
  5691. - CConcealParams *pConcealCommonData = pConcealmentInfo->pConcealParams;
  5692. -#endif
  5693. -
  5694. - FIXP_DBL *pSpectralCoefficient =
  5695. - SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
  5696. - CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
  5697. - SHORT *pSpecScale = pAacDecoderChannelInfo->specScale;
  5698. -
  5699. - int sfbEnergyPrev[64];
  5700. - int sfbEnergyAct[64];
  5701. -
  5702. - int i, appliedProcessing = 0;
  5703. -
  5704. - /* clear/init */
  5705. - FDKmemclear(sfbEnergyPrev, 64 * sizeof(int));
  5706. - FDKmemclear(sfbEnergyAct, 64 * sizeof(int));
  5707. -
  5708. - if (!frameOk || mute_release_active) {
  5709. - /* Restore last frame from concealment buffer */
  5710. - pIcsInfo->WindowShape = pConcealmentInfo->windowShape;
  5711. - pIcsInfo->WindowSequence = pConcealmentInfo->windowSequence;
  5712. -
  5713. - /* Restore spectral data */
  5714. - for (i = 0; i < samplesPerFrame; i++) {
  5715. - pSpectralCoefficient[i] =
  5716. - FX_CNCL2FX_DBL(pConcealmentInfo->spectralCoefficient[i]);
  5717. - }
  5718. -
  5719. - /* Restore scale factors */
  5720. - FDKmemcpy(pSpecScale, pConcealmentInfo->specScale, 8 * sizeof(SHORT));
  5721. - }
  5722. -
  5723. - /* if previous frame was not ok */
  5724. - if (!pConcealmentInfo->prevFrameOk[1] || mute_release_active) {
  5725. - /* if current frame (f_n) is ok and the last but one frame (f_(n-2))
  5726. - was ok, too, then interpolate both frames in order to generate
  5727. - the current output frame (f_(n-1)). Otherwise, use the last stored
  5728. - frame (f_(n-2) or f_(n-3) or ...). */
  5729. - if (frameOk && pConcealmentInfo->prevFrameOk[0] && !mute_release_active) {
  5730. - appliedProcessing = 1;
  5731. -
  5732. - /* Interpolate both frames in order to generate the current output frame
  5733. - * (f_(n-1)). */
  5734. - if (pIcsInfo->WindowSequence == BLOCK_SHORT) {
  5735. - /* f_(n-2) == BLOCK_SHORT */
  5736. - /* short--??????--short, short--??????--long interpolation */
  5737. - /* short--short---short, short---long---long interpolation */
  5738. -
  5739. - int wnd;
  5740. -
  5741. - if (pConcealmentInfo->windowSequence ==
  5742. - BLOCK_SHORT) { /* f_n == BLOCK_SHORT */
  5743. - /* short--short---short interpolation */
  5744. -
  5745. - int scaleFactorBandsTotal =
  5746. - pSamplingRateInfo->NumberOfScaleFactorBands_Short;
  5747. - const SHORT *pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Short;
  5748. - pIcsInfo->WindowShape = (samplesPerFrame <= 512) ? 2 : 1;
  5749. - pIcsInfo->WindowSequence = BLOCK_SHORT;
  5750. -
  5751. - for (wnd = 0; wnd < 8; wnd++) {
  5752. - CConcealment_CalcBandEnergy(
  5753. - &pSpectralCoefficient[wnd *
  5754. - (samplesPerFrame / 8)], /* spec_(n-2) */
  5755. - pSamplingRateInfo, BLOCK_SHORT, CConcealment_NoExpand,
  5756. - sfbEnergyPrev);
  5757. -
  5758. - CConcealment_CalcBandEnergy(
  5759. - &pConcealmentInfo->spectralCoefficient[wnd * (samplesPerFrame /
  5760. - 8)], /* spec_n */
  5761. - pSamplingRateInfo, BLOCK_SHORT, CConcealment_NoExpand,
  5762. - sfbEnergyAct);
  5763. -
  5764. - CConcealment_InterpolateBuffer(
  5765. - &pSpectralCoefficient[wnd *
  5766. - (samplesPerFrame / 8)], /* spec_(n-1) */
  5767. - &pSpecScale[wnd], &pConcealmentInfo->specScale[wnd],
  5768. - &pSpecScale[wnd], sfbEnergyPrev, sfbEnergyAct,
  5769. - scaleFactorBandsTotal, pSfbOffset);
  5770. - }
  5771. - } else { /* f_n != BLOCK_SHORT */
  5772. - /* short---long---long interpolation */
  5773. -
  5774. - int scaleFactorBandsTotal =
  5775. - pSamplingRateInfo->NumberOfScaleFactorBands_Long;
  5776. - const SHORT *pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Long;
  5777. - SHORT specScaleOut;
  5778. -
  5779. - CConcealment_CalcBandEnergy(
  5780. - &pSpectralCoefficient[samplesPerFrame -
  5781. - (samplesPerFrame /
  5782. - 8)], /* [wnd] spec_(n-2) */
  5783. - pSamplingRateInfo, BLOCK_SHORT, CConcealment_Expand,
  5784. - sfbEnergyAct);
  5785. -
  5786. - CConcealment_CalcBandEnergy(
  5787. - pConcealmentInfo->spectralCoefficient, /* spec_n */
  5788. - pSamplingRateInfo, BLOCK_LONG, CConcealment_NoExpand,
  5789. - sfbEnergyPrev);
  5790. -
  5791. - pIcsInfo->WindowShape = 0;
  5792. - pIcsInfo->WindowSequence = BLOCK_STOP;
  5793. -
  5794. - for (i = 0; i < samplesPerFrame; i++) {
  5795. - pSpectralCoefficient[i] =
  5796. - pConcealmentInfo->spectralCoefficient[i]; /* spec_n */
  5797. - }
  5798. -
  5799. - for (i = 0; i < 8; i++) { /* search for max(specScale) */
  5800. - if (pSpecScale[i] > pSpecScale[0]) {
  5801. - pSpecScale[0] = pSpecScale[i];
  5802. - }
  5803. - }
  5804. -
  5805. - CConcealment_InterpolateBuffer(
  5806. - pSpectralCoefficient, /* spec_(n-1) */
  5807. - &pConcealmentInfo->specScale[0], &pSpecScale[0], &specScaleOut,
  5808. - sfbEnergyPrev, sfbEnergyAct, scaleFactorBandsTotal, pSfbOffset);
  5809. -
  5810. - pSpecScale[0] = specScaleOut;
  5811. - }
  5812. - } else {
  5813. - /* long--??????--short, long--??????--long interpolation */
  5814. - /* long---long---short, long---long---long interpolation */
  5815. -
  5816. - int scaleFactorBandsTotal =
  5817. - pSamplingRateInfo->NumberOfScaleFactorBands_Long;
  5818. - const SHORT *pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Long;
  5819. - SHORT specScaleAct = pConcealmentInfo->specScale[0];
  5820. -
  5821. - CConcealment_CalcBandEnergy(pSpectralCoefficient, /* spec_(n-2) */
  5822. - pSamplingRateInfo, BLOCK_LONG,
  5823. - CConcealment_NoExpand, sfbEnergyPrev);
  5824. -
  5825. - if (pConcealmentInfo->windowSequence ==
  5826. - BLOCK_SHORT) { /* f_n == BLOCK_SHORT */
  5827. - /* long---long---short interpolation */
  5828. -
  5829. - pIcsInfo->WindowShape = (samplesPerFrame <= 512) ? 2 : 1;
  5830. - pIcsInfo->WindowSequence = BLOCK_START;
  5831. -
  5832. - for (i = 1; i < 8; i++) { /* search for max(specScale) */
  5833. - if (pConcealmentInfo->specScale[i] > specScaleAct) {
  5834. - specScaleAct = pConcealmentInfo->specScale[i];
  5835. - }
  5836. - }
  5837. -
  5838. - /* Expand first short spectrum */
  5839. - CConcealment_CalcBandEnergy(
  5840. - pConcealmentInfo->spectralCoefficient, /* spec_n */
  5841. - pSamplingRateInfo, BLOCK_SHORT, CConcealment_Expand, /* !!! */
  5842. - sfbEnergyAct);
  5843. - } else {
  5844. - /* long---long---long interpolation */
  5845. -
  5846. - pIcsInfo->WindowShape = 0;
  5847. - pIcsInfo->WindowSequence = BLOCK_LONG;
  5848. -
  5849. - CConcealment_CalcBandEnergy(
  5850. - pConcealmentInfo->spectralCoefficient, /* spec_n */
  5851. - pSamplingRateInfo, BLOCK_LONG, CConcealment_NoExpand,
  5852. - sfbEnergyAct);
  5853. - }
  5854. -
  5855. - CConcealment_InterpolateBuffer(
  5856. - pSpectralCoefficient, /* spec_(n-1) */
  5857. - &pSpecScale[0], &specScaleAct, &pSpecScale[0], sfbEnergyPrev,
  5858. - sfbEnergyAct, scaleFactorBandsTotal, pSfbOffset);
  5859. - }
  5860. - }
  5861. -
  5862. - /* Noise substitution of sign of the output spectral coefficients */
  5863. - CConcealment_ApplyRandomSign(pConcealmentInfo->iRandomPhase,
  5864. - pSpectralCoefficient, samplesPerFrame);
  5865. - /* Increment random phase index to avoid repetition artifacts. */
  5866. - pConcealmentInfo->iRandomPhase =
  5867. - (pConcealmentInfo->iRandomPhase + 1) & (AAC_NF_NO_RANDOM_VAL - 1);
  5868. - }
  5869. -
  5870. - /* scale spectrum according to concealment state */
  5871. - switch (pConcealmentInfo->concealState) {
  5872. - case ConcealState_Single:
  5873. - appliedProcessing = 1;
  5874. - break;
  5875. -
  5876. - case ConcealState_FadeOut: {
  5877. - FDK_ASSERT(pConcealmentInfo->cntFadeFrames >= 0);
  5878. - FDK_ASSERT(pConcealmentInfo->cntFadeFrames <
  5879. - CONCEAL_MAX_NUM_FADE_FACTORS);
  5880. - FDK_ASSERT(pConcealmentInfo->cntFadeFrames <
  5881. - pConcealCommonData->numFadeOutFrames);
  5882. -
  5883. - /* TimeDomainFading: */
  5884. - /* Attenuation of signal is done in CConcealment_TDFading() */
  5885. -
  5886. - appliedProcessing = 1;
  5887. - } break;
  5888. -
  5889. - case ConcealState_FadeIn: {
  5890. - FDK_ASSERT(pConcealmentInfo->cntFadeFrames >= 0);
  5891. - FDK_ASSERT(pConcealmentInfo->cntFadeFrames <
  5892. - CONCEAL_MAX_NUM_FADE_FACTORS);
  5893. - FDK_ASSERT(pConcealmentInfo->cntFadeFrames <
  5894. - pConcealCommonData->numFadeInFrames);
  5895. -
  5896. - /* TimeDomainFading: */
  5897. - /* Attenuation of signal is done in CConcealment_TDFading() */
  5898. -
  5899. - appliedProcessing = 1;
  5900. - } break;
  5901. -
  5902. - case ConcealState_Mute: {
  5903. - /* set dummy window parameters */
  5904. - pIcsInfo->Valid = 0; /* Trigger the generation of a consitent IcsInfo */
  5905. - pIcsInfo->WindowShape =
  5906. - pConcealmentInfo->windowShape; /* Prevent an invalid WindowShape
  5907. - (required for F/T transform) */
  5908. - pIcsInfo->WindowSequence =
  5909. - CConcealment_GetWinSeq(pConcealmentInfo->windowSequence);
  5910. - pConcealmentInfo->windowSequence =
  5911. - pIcsInfo->WindowSequence; /* Store for next frame
  5912. - (spectrum in concealment
  5913. - buffer can't be used at
  5914. - all) */
  5915. -
  5916. - /* mute spectral data */
  5917. - FDKmemclear(pSpectralCoefficient, samplesPerFrame * sizeof(FIXP_DBL));
  5918. -
  5919. - appliedProcessing = 1;
  5920. - } break;
  5921. -
  5922. - default:
  5923. - /* nothing to do here */
  5924. - break;
  5925. - }
  5926. -
  5927. - return appliedProcessing;
  5928. -}
  5929. -
  5930. -/*!
  5931. - \brief Calculate the spectral energy
  5932. -
  5933. - The function calculates band-wise the spectral energy. This is used for
  5934. - frame interpolation.
  5935. -*/
  5936. -static void CConcealment_CalcBandEnergy(
  5937. - FIXP_DBL *spectrum, const SamplingRateInfo *pSamplingRateInfo,
  5938. - const int blockType, CConcealmentExpandType expandType, int *sfbEnergy) {
  5939. - const SHORT *pSfbOffset;
  5940. - int line, sfb, scaleFactorBandsTotal = 0;
  5941. -
  5942. - /* In the following calculations, enAccu is initialized with LSB-value in
  5943. - * order to avoid zero energy-level */
  5944. -
  5945. - line = 0;
  5946. -
  5947. - switch (blockType) {
  5948. - case BLOCK_LONG:
  5949. - case BLOCK_START:
  5950. - case BLOCK_STOP:
  5951. -
  5952. - if (expandType == CConcealment_NoExpand) {
  5953. - /* standard long calculation */
  5954. - scaleFactorBandsTotal =
  5955. - pSamplingRateInfo->NumberOfScaleFactorBands_Long;
  5956. - pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Long;
  5957. -
  5958. - for (sfb = 0; sfb < scaleFactorBandsTotal; sfb++) {
  5959. - FIXP_DBL enAccu = (FIXP_DBL)(LONG)1;
  5960. - int sfbScale =
  5961. - (sizeof(LONG) << 3) -
  5962. - CntLeadingZeros(pSfbOffset[sfb + 1] - pSfbOffset[sfb]) - 1;
  5963. - /* scaling depends on sfb width. */
  5964. - for (; line < pSfbOffset[sfb + 1]; line++) {
  5965. - enAccu += fPow2Div2(*(spectrum + line)) >> sfbScale;
  5966. - }
  5967. - *(sfbEnergy + sfb) = CntLeadingZeros(enAccu) - 1;
  5968. - }
  5969. - } else {
  5970. - /* compress long to short */
  5971. - scaleFactorBandsTotal =
  5972. - pSamplingRateInfo->NumberOfScaleFactorBands_Short;
  5973. - pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Short;
  5974. -
  5975. - for (sfb = 0; sfb < scaleFactorBandsTotal; sfb++) {
  5976. - FIXP_DBL enAccu = (FIXP_DBL)(LONG)1;
  5977. - int sfbScale =
  5978. - (sizeof(LONG) << 3) -
  5979. - CntLeadingZeros(pSfbOffset[sfb + 1] - pSfbOffset[sfb]) - 1;
  5980. - /* scaling depends on sfb width. */
  5981. - for (; line < pSfbOffset[sfb + 1] << 3; line++) {
  5982. - enAccu +=
  5983. - (enAccu + (fPow2Div2(*(spectrum + line)) >> sfbScale)) >> 3;
  5984. - }
  5985. - *(sfbEnergy + sfb) = CntLeadingZeros(enAccu) - 1;
  5986. - }
  5987. - }
  5988. - break;
  5989. -
  5990. - case BLOCK_SHORT:
  5991. -
  5992. - if (expandType == CConcealment_NoExpand) {
  5993. - /* standard short calculation */
  5994. - scaleFactorBandsTotal =
  5995. - pSamplingRateInfo->NumberOfScaleFactorBands_Short;
  5996. - pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Short;
  5997. -
  5998. - for (sfb = 0; sfb < scaleFactorBandsTotal; sfb++) {
  5999. - FIXP_DBL enAccu = (FIXP_DBL)(LONG)1;
  6000. - int sfbScale =
  6001. - (sizeof(LONG) << 3) -
  6002. - CntLeadingZeros(pSfbOffset[sfb + 1] - pSfbOffset[sfb]) - 1;
  6003. - /* scaling depends on sfb width. */
  6004. - for (; line < pSfbOffset[sfb + 1]; line++) {
  6005. - enAccu += fPow2Div2(*(spectrum + line)) >> sfbScale;
  6006. - }
  6007. - *(sfbEnergy + sfb) = CntLeadingZeros(enAccu) - 1;
  6008. - }
  6009. - } else {
  6010. - /* expand short to long spectrum */
  6011. - scaleFactorBandsTotal =
  6012. - pSamplingRateInfo->NumberOfScaleFactorBands_Long;
  6013. - pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Long;
  6014. -
  6015. - for (sfb = 0; sfb < scaleFactorBandsTotal; sfb++) {
  6016. - FIXP_DBL enAccu = (FIXP_DBL)(LONG)1;
  6017. - int sfbScale =
  6018. - (sizeof(LONG) << 3) -
  6019. - CntLeadingZeros(pSfbOffset[sfb + 1] - pSfbOffset[sfb]) - 1;
  6020. - /* scaling depends on sfb width. */
  6021. - for (; line < pSfbOffset[sfb + 1]; line++) {
  6022. - enAccu += fPow2Div2(*(spectrum + (line >> 3))) >> sfbScale;
  6023. - }
  6024. - *(sfbEnergy + sfb) = CntLeadingZeros(enAccu) - 1;
  6025. - }
  6026. - }
  6027. - break;
  6028. - }
  6029. -}
  6030. -
  6031. -/*!
  6032. - \brief Interpolate buffer
  6033. -
  6034. - The function creates the interpolated spectral data according to the
  6035. - energy of the last good frame and the current (good) frame.
  6036. -*/
  6037. -static void CConcealment_InterpolateBuffer(FIXP_DBL *spectrum,
  6038. - SHORT *pSpecScalePrv,
  6039. - SHORT *pSpecScaleAct,
  6040. - SHORT *pSpecScaleOut, int *enPrv,
  6041. - int *enAct, int sfbCnt,
  6042. - const SHORT *pSfbOffset) {
  6043. - int sfb, line = 0;
  6044. - int fac_shift;
  6045. - int fac_mod;
  6046. - FIXP_DBL accu;
  6047. -
  6048. - for (sfb = 0; sfb < sfbCnt; sfb++) {
  6049. - fac_shift =
  6050. - enPrv[sfb] - enAct[sfb] + ((*pSpecScaleAct - *pSpecScalePrv) << 1);
  6051. - fac_mod = fac_shift & 3;
  6052. - fac_shift = (fac_shift >> 2) + 1;
  6053. - fac_shift += *pSpecScalePrv - fixMax(*pSpecScalePrv, *pSpecScaleAct);
  6054. -
  6055. - for (; line < pSfbOffset[sfb + 1]; line++) {
  6056. - accu = fMult(*(spectrum + line), facMod4Table[fac_mod]);
  6057. - if (fac_shift < 0) {
  6058. - accu >>= -fac_shift;
  6059. - } else {
  6060. - accu <<= fac_shift;
  6061. - }
  6062. - *(spectrum + line) = accu;
  6063. - }
  6064. - }
  6065. - *pSpecScaleOut = fixMax(*pSpecScalePrv, *pSpecScaleAct);
  6066. -}
  6067. -
  6068. -/*!
  6069. - \brief Find next fading frame in case of changing fading direction
  6070. -
  6071. - \param pConcealCommonData Pointer to the concealment common data structure.
  6072. - \param actFadeIndex Last index used for fading
  6073. - \param direction Direction of change: 0 : change from FADE-OUT to FADE-IN, 1
  6074. - : change from FADE-IN to FADE-OUT
  6075. -
  6076. - This function determines the next fading index to be used for the fading
  6077. - direction to be changed to.
  6078. -*/
  6079. -
  6080. -static INT findEquiFadeFrame(CConcealParams *pConcealCommonData,
  6081. - INT actFadeIndex, int direction) {
  6082. - FIXP_SGL *pFactor;
  6083. - FIXP_SGL referenceVal;
  6084. - FIXP_SGL minDiff = (FIXP_SGL)MAXVAL_SGL;
  6085. -
  6086. - INT nextFadeIndex = 0;
  6087. -
  6088. - int i;
  6089. -
  6090. - /* init depending on direction */
  6091. - if (direction == 0) { /* FADE-OUT => FADE-IN */
  6092. - if (actFadeIndex < 0) {
  6093. - referenceVal = (FIXP_SGL)MAXVAL_SGL;
  6094. - } else {
  6095. - referenceVal = pConcealCommonData->fadeOutFactor[actFadeIndex] >> 1;
  6096. - }
  6097. - pFactor = pConcealCommonData->fadeInFactor;
  6098. - } else { /* FADE-IN => FADE-OUT */
  6099. - if (actFadeIndex < 0) {
  6100. - referenceVal = (FIXP_SGL)MAXVAL_SGL;
  6101. - } else {
  6102. - referenceVal = pConcealCommonData->fadeInFactor[actFadeIndex] >> 1;
  6103. - }
  6104. - pFactor = pConcealCommonData->fadeOutFactor;
  6105. - }
  6106. -
  6107. - /* search for minimum difference */
  6108. - for (i = 0; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
  6109. - FIXP_SGL diff = fixp_abs((pFactor[i] >> 1) - referenceVal);
  6110. - if (diff < minDiff) {
  6111. - minDiff = diff;
  6112. - nextFadeIndex = i;
  6113. - }
  6114. - }
  6115. -
  6116. - /* check and adjust depending on direction */
  6117. - if (direction == 0) { /* FADE-OUT => FADE-IN */
  6118. - if (nextFadeIndex > pConcealCommonData->numFadeInFrames) {
  6119. - nextFadeIndex = fMax(pConcealCommonData->numFadeInFrames - 1, 0);
  6120. - }
  6121. - if (((pFactor[nextFadeIndex] >> 1) <= referenceVal) &&
  6122. - (nextFadeIndex > 0)) {
  6123. - nextFadeIndex -= 1;
  6124. - }
  6125. - } else { /* FADE-IN => FADE-OUT */
  6126. - if (((pFactor[nextFadeIndex] >> 1) >= referenceVal) &&
  6127. - (nextFadeIndex < CONCEAL_MAX_NUM_FADE_FACTORS - 1)) {
  6128. - nextFadeIndex += 1;
  6129. - }
  6130. - }
  6131. -
  6132. - return (nextFadeIndex);
  6133. -}
  6134. -
  6135. -/*!
  6136. - \brief Update the concealment state
  6137. -
  6138. - The function updates the state of the concealment state-machine. The
  6139. - states are: mute, fade-in, fade-out, interpolate and frame-ok.
  6140. -*/
  6141. -static void CConcealment_UpdateState(
  6142. - CConcealmentInfo *pConcealmentInfo, int frameOk,
  6143. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  6144. - const int samplesPerFrame, CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
  6145. - CConcealParams *pConcealCommonData = pConcealmentInfo->pConcealParams;
  6146. -
  6147. - switch (pConcealCommonData->method) {
  6148. - case ConcealMethodNoise: {
  6149. - if (pConcealmentInfo->concealState != ConcealState_Ok) {
  6150. - /* count the valid frames during concealment process */
  6151. - if (frameOk) {
  6152. - pConcealmentInfo->cntValidFrames += 1;
  6153. - } else {
  6154. - pConcealmentInfo->cntValidFrames = 0;
  6155. - }
  6156. - }
  6157. -
  6158. - /* -- STATE MACHINE for Noise Substitution -- */
  6159. - switch (pConcealmentInfo->concealState) {
  6160. - case ConcealState_Ok:
  6161. - if (!frameOk) {
  6162. - pConcealmentInfo->cntFadeFrames = 0;
  6163. - pConcealmentInfo->cntValidFrames = 0;
  6164. - pConcealmentInfo->attGrpOffset[0] = 0;
  6165. - pConcealmentInfo->attGrpOffset[1] = 0;
  6166. - pConcealmentInfo->winGrpOffset[0] = 0;
  6167. - pConcealmentInfo->winGrpOffset[1] = 0;
  6168. - if (pConcealCommonData->numFadeOutFrames > 0) {
  6169. - /* change to state SINGLE-FRAME-LOSS */
  6170. - pConcealmentInfo->concealState = ConcealState_Single;
  6171. - /* mode 0 just updates the Fading counter */
  6172. - CConcealment_ApplyFadeOut(
  6173. - /*mode =*/0, pConcealmentInfo, pAacDecoderStaticChannelInfo,
  6174. - samplesPerFrame, pAacDecoderChannelInfo);
  6175. -
  6176. - } else {
  6177. - /* change to state MUTE */
  6178. - pConcealmentInfo->concealState = ConcealState_Mute;
  6179. - }
  6180. - }
  6181. - break;
  6182. -
  6183. - case ConcealState_Single: /* Just a pre-stage before fade-out begins.
  6184. - Stay here only one frame! */
  6185. - if (frameOk) {
  6186. - /* change to state OK */
  6187. - pConcealmentInfo->concealState = ConcealState_Ok;
  6188. - } else {
  6189. - if (pConcealmentInfo->cntFadeFrames >=
  6190. - pConcealCommonData->numFadeOutFrames) {
  6191. - /* change to state MUTE */
  6192. - pConcealmentInfo->concealState = ConcealState_Mute;
  6193. - } else {
  6194. - /* change to state FADE-OUT */
  6195. - pConcealmentInfo->concealState = ConcealState_FadeOut;
  6196. - /* mode 0 just updates the Fading counter */
  6197. - CConcealment_ApplyFadeOut(
  6198. - /*mode =*/0, pConcealmentInfo, pAacDecoderStaticChannelInfo,
  6199. - samplesPerFrame, pAacDecoderChannelInfo);
  6200. - }
  6201. - }
  6202. - break;
  6203. -
  6204. - case ConcealState_FadeOut:
  6205. - if (pConcealmentInfo->cntValidFrames >
  6206. - pConcealCommonData->numMuteReleaseFrames) {
  6207. - if (pConcealCommonData->numFadeInFrames > 0) {
  6208. - /* change to state FADE-IN */
  6209. - pConcealmentInfo->concealState = ConcealState_FadeIn;
  6210. - pConcealmentInfo->cntFadeFrames = findEquiFadeFrame(
  6211. - pConcealCommonData, pConcealmentInfo->cntFadeFrames,
  6212. - 0 /* FadeOut -> FadeIn */);
  6213. - } else {
  6214. - /* change to state OK */
  6215. - pConcealmentInfo->concealState = ConcealState_Ok;
  6216. - }
  6217. - } else {
  6218. - if (frameOk) {
  6219. - /* we have good frame information but stay fully in concealment -
  6220. - * reset winGrpOffset/attGrpOffset */
  6221. - pConcealmentInfo->winGrpOffset[0] = 0;
  6222. - pConcealmentInfo->winGrpOffset[1] = 0;
  6223. - pConcealmentInfo->attGrpOffset[0] = 0;
  6224. - pConcealmentInfo->attGrpOffset[1] = 0;
  6225. - }
  6226. - if (pConcealmentInfo->cntFadeFrames >=
  6227. - pConcealCommonData->numFadeOutFrames) {
  6228. - /* change to state MUTE */
  6229. - pConcealmentInfo->concealState = ConcealState_Mute;
  6230. - } else /* Stay in FADE-OUT */
  6231. - {
  6232. - /* mode 0 just updates the Fading counter */
  6233. - CConcealment_ApplyFadeOut(
  6234. - /*mode =*/0, pConcealmentInfo, pAacDecoderStaticChannelInfo,
  6235. - samplesPerFrame, pAacDecoderChannelInfo);
  6236. - }
  6237. - }
  6238. - break;
  6239. -
  6240. - case ConcealState_Mute:
  6241. - if (pConcealmentInfo->cntValidFrames >
  6242. - pConcealCommonData->numMuteReleaseFrames) {
  6243. - if (pConcealCommonData->numFadeInFrames > 0) {
  6244. - /* change to state FADE-IN */
  6245. - pConcealmentInfo->concealState = ConcealState_FadeIn;
  6246. - pConcealmentInfo->cntFadeFrames =
  6247. - pConcealCommonData->numFadeInFrames - 1;
  6248. - } else {
  6249. - /* change to state OK */
  6250. - pConcealmentInfo->concealState = ConcealState_Ok;
  6251. - }
  6252. - } else {
  6253. - if (frameOk) {
  6254. - /* we have good frame information but stay fully in concealment -
  6255. - * reset winGrpOffset/attGrpOffset */
  6256. - pConcealmentInfo->winGrpOffset[0] = 0;
  6257. - pConcealmentInfo->winGrpOffset[1] = 0;
  6258. - pConcealmentInfo->attGrpOffset[0] = 0;
  6259. - pConcealmentInfo->attGrpOffset[1] = 0;
  6260. - }
  6261. - }
  6262. - break;
  6263. -
  6264. - case ConcealState_FadeIn:
  6265. - pConcealmentInfo->cntFadeFrames -= 1;
  6266. - if (frameOk) {
  6267. - if (pConcealmentInfo->cntFadeFrames < 0) {
  6268. - /* change to state OK */
  6269. - pConcealmentInfo->concealState = ConcealState_Ok;
  6270. - }
  6271. - } else {
  6272. - if (pConcealCommonData->numFadeOutFrames > 0) {
  6273. - /* change to state FADE-OUT */
  6274. - pConcealmentInfo->concealState = ConcealState_FadeOut;
  6275. - pConcealmentInfo->cntFadeFrames = findEquiFadeFrame(
  6276. - pConcealCommonData, pConcealmentInfo->cntFadeFrames + 1,
  6277. - 1 /* FadeIn -> FadeOut */);
  6278. - pConcealmentInfo->winGrpOffset[0] = 0;
  6279. - pConcealmentInfo->winGrpOffset[1] = 0;
  6280. - pConcealmentInfo->attGrpOffset[0] = 0;
  6281. - pConcealmentInfo->attGrpOffset[1] = 0;
  6282. -
  6283. - pConcealmentInfo
  6284. - ->cntFadeFrames--; /* decrease because
  6285. - CConcealment_ApplyFadeOut() will
  6286. - increase, accordingly */
  6287. - /* mode 0 just updates the Fading counter */
  6288. - CConcealment_ApplyFadeOut(
  6289. - /*mode =*/0, pConcealmentInfo, pAacDecoderStaticChannelInfo,
  6290. - samplesPerFrame, pAacDecoderChannelInfo);
  6291. - } else {
  6292. - /* change to state MUTE */
  6293. - pConcealmentInfo->concealState = ConcealState_Mute;
  6294. - }
  6295. - }
  6296. - break;
  6297. -
  6298. - default:
  6299. - FDK_ASSERT(0);
  6300. - break;
  6301. - }
  6302. - } break;
  6303. -
  6304. - case ConcealMethodInter:
  6305. - case ConcealMethodTonal: {
  6306. - if (pConcealmentInfo->concealState != ConcealState_Ok) {
  6307. - /* count the valid frames during concealment process */
  6308. - if (pConcealmentInfo->prevFrameOk[1] ||
  6309. - (pConcealmentInfo->prevFrameOk[0] &&
  6310. - !pConcealmentInfo->prevFrameOk[1] && frameOk)) {
  6311. - /* The frame is OK even if it can be estimated by the energy
  6312. - * interpolation algorithm */
  6313. - pConcealmentInfo->cntValidFrames += 1;
  6314. - } else {
  6315. - pConcealmentInfo->cntValidFrames = 0;
  6316. - }
  6317. - }
  6318. -
  6319. - /* -- STATE MACHINE for energy interpolation -- */
  6320. - switch (pConcealmentInfo->concealState) {
  6321. - case ConcealState_Ok:
  6322. - if (!(pConcealmentInfo->prevFrameOk[1] ||
  6323. - (pConcealmentInfo->prevFrameOk[0] &&
  6324. - !pConcealmentInfo->prevFrameOk[1] && frameOk))) {
  6325. - if (pConcealCommonData->numFadeOutFrames > 0) {
  6326. - /* Fade out only if the energy interpolation algorithm can not be
  6327. - * applied! */
  6328. - pConcealmentInfo->concealState = ConcealState_FadeOut;
  6329. - } else {
  6330. - /* change to state MUTE */
  6331. - pConcealmentInfo->concealState = ConcealState_Mute;
  6332. - }
  6333. - pConcealmentInfo->cntFadeFrames = 0;
  6334. - pConcealmentInfo->cntValidFrames = 0;
  6335. - }
  6336. - break;
  6337. -
  6338. - case ConcealState_Single:
  6339. - pConcealmentInfo->concealState = ConcealState_Ok;
  6340. - break;
  6341. -
  6342. - case ConcealState_FadeOut:
  6343. - pConcealmentInfo->cntFadeFrames += 1;
  6344. -
  6345. - if (pConcealmentInfo->cntValidFrames >
  6346. - pConcealCommonData->numMuteReleaseFrames) {
  6347. - if (pConcealCommonData->numFadeInFrames > 0) {
  6348. - /* change to state FADE-IN */
  6349. - pConcealmentInfo->concealState = ConcealState_FadeIn;
  6350. - pConcealmentInfo->cntFadeFrames = findEquiFadeFrame(
  6351. - pConcealCommonData, pConcealmentInfo->cntFadeFrames - 1,
  6352. - 0 /* FadeOut -> FadeIn */);
  6353. - } else {
  6354. - /* change to state OK */
  6355. - pConcealmentInfo->concealState = ConcealState_Ok;
  6356. - }
  6357. - } else {
  6358. - if (pConcealmentInfo->cntFadeFrames >=
  6359. - pConcealCommonData->numFadeOutFrames) {
  6360. - /* change to state MUTE */
  6361. - pConcealmentInfo->concealState = ConcealState_Mute;
  6362. - }
  6363. - }
  6364. - break;
  6365. -
  6366. - case ConcealState_Mute:
  6367. - if (pConcealmentInfo->cntValidFrames >
  6368. - pConcealCommonData->numMuteReleaseFrames) {
  6369. - if (pConcealCommonData->numFadeInFrames > 0) {
  6370. - /* change to state FADE-IN */
  6371. - pConcealmentInfo->concealState = ConcealState_FadeIn;
  6372. - pConcealmentInfo->cntFadeFrames =
  6373. - pConcealCommonData->numFadeInFrames - 1;
  6374. - } else {
  6375. - /* change to state OK */
  6376. - pConcealmentInfo->concealState = ConcealState_Ok;
  6377. - }
  6378. - }
  6379. - break;
  6380. -
  6381. - case ConcealState_FadeIn:
  6382. - pConcealmentInfo->cntFadeFrames -=
  6383. - 1; /* used to address the fade-in factors */
  6384. -
  6385. - if (frameOk || pConcealmentInfo->prevFrameOk[1]) {
  6386. - if (pConcealmentInfo->cntFadeFrames < 0) {
  6387. - /* change to state OK */
  6388. - pConcealmentInfo->concealState = ConcealState_Ok;
  6389. - }
  6390. - } else {
  6391. - if (pConcealCommonData->numFadeOutFrames > 0) {
  6392. - /* change to state FADE-OUT */
  6393. - pConcealmentInfo->concealState = ConcealState_FadeOut;
  6394. - pConcealmentInfo->cntFadeFrames = findEquiFadeFrame(
  6395. - pConcealCommonData, pConcealmentInfo->cntFadeFrames + 1,
  6396. - 1 /* FadeIn -> FadeOut */);
  6397. - } else {
  6398. - /* change to state MUTE */
  6399. - pConcealmentInfo->concealState = ConcealState_Mute;
  6400. - }
  6401. - }
  6402. - break;
  6403. - } /* End switch(pConcealmentInfo->concealState) */
  6404. - } break;
  6405. -
  6406. - default:
  6407. - /* Don't need a state machine for other concealment methods. */
  6408. - break;
  6409. - }
  6410. -}
  6411. -
  6412. -/*!
  6413. -\brief Randomizes the sign of the spectral data
  6414. -
  6415. - The function toggles the sign of the spectral data randomly. This is
  6416. - useful to ensure the quality of the concealed frames.
  6417. - */
  6418. -static void CConcealment_ApplyRandomSign(int randomPhase, FIXP_DBL *spec,
  6419. - int samplesPerFrame) {
  6420. - int i;
  6421. - USHORT packedSign = 0;
  6422. -
  6423. - /* random table 512x16bit has been reduced to 512 packed sign bits = 32x16 bit
  6424. - */
  6425. -
  6426. - /* read current packed sign word */
  6427. - packedSign = AacDec_randomSign[randomPhase >> 4];
  6428. - packedSign >>= (randomPhase & 0xf);
  6429. -
  6430. - for (i = 0; i < samplesPerFrame; i++) {
  6431. - if ((randomPhase & 0xf) == 0) {
  6432. - packedSign = AacDec_randomSign[randomPhase >> 4];
  6433. - }
  6434. -
  6435. - if (packedSign & 0x1) {
  6436. - spec[i] = -spec[i];
  6437. - }
  6438. - packedSign >>= 1;
  6439. -
  6440. - randomPhase = (randomPhase + 1) & (AAC_NF_NO_RANDOM_VAL - 1);
  6441. - }
  6442. -}
  6443. -
  6444. -/*!
  6445. - \brief Get fadeing factor for current concealment state.
  6446. -
  6447. - The function returns the state (ok or not) of the previous frame.
  6448. - If called before the function CConcealment_Apply() set the fBeforeApply
  6449. - flag to get the correct value.
  6450. -
  6451. - \return Frame OK flag of previous frame.
  6452. - */
  6453. -int CConcealment_GetLastFrameOk(CConcealmentInfo *hConcealmentInfo,
  6454. - const int fBeforeApply) {
  6455. - int prevFrameOk = 1;
  6456. -
  6457. - if (hConcealmentInfo != NULL) {
  6458. - prevFrameOk = hConcealmentInfo->prevFrameOk[fBeforeApply & 0x1];
  6459. - }
  6460. -
  6461. - return prevFrameOk;
  6462. -}
  6463. -
  6464. -/*!
  6465. - \brief Get the number of delay frames introduced by concealment technique.
  6466. -
  6467. - \return Number of delay frames.
  6468. - */
  6469. -UINT CConcealment_GetDelay(CConcealParams *pConcealCommonData) {
  6470. - UINT frameDelay = 0;
  6471. -
  6472. - if (pConcealCommonData != NULL) {
  6473. - switch (pConcealCommonData->method) {
  6474. - case ConcealMethodTonal:
  6475. - case ConcealMethodInter:
  6476. - frameDelay = 1;
  6477. - break;
  6478. - default:
  6479. - break;
  6480. - }
  6481. - }
  6482. -
  6483. - return frameDelay;
  6484. -}
  6485. -
  6486. -static int CConcealment_ApplyFadeOut(
  6487. - int mode, CConcealmentInfo *pConcealmentInfo,
  6488. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  6489. - const int samplesPerFrame, CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
  6490. - /* mode 1 = apply RandomSign and mute spectral coefficients if necessary, *
  6491. - * mode 0 = Update cntFadeFrames */
  6492. -
  6493. - /* restore frequency coefficients from buffer with a specific muting */
  6494. - int srcWin, dstWin, numWindows = 1;
  6495. - int windowLen = samplesPerFrame;
  6496. - int srcGrpStart = 0;
  6497. - int winIdxStride = 1;
  6498. - int numWinGrpPerFac, attIdx, attIdxStride;
  6499. - int i;
  6500. - int appliedProcessing = 0;
  6501. -
  6502. - CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
  6503. - FIXP_DBL *pSpectralCoefficient =
  6504. - SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
  6505. - SHORT *pSpecScale = pAacDecoderChannelInfo->specScale;
  6506. -
  6507. - /* set old window parameters */
  6508. - if (pConcealmentInfo->lastRenderMode == AACDEC_RENDER_LPD) {
  6509. - switch (pAacDecoderStaticChannelInfo->last_lpd_mode) {
  6510. - case 1:
  6511. - numWindows = 4;
  6512. - srcGrpStart = 3;
  6513. - windowLen = samplesPerFrame >> 2;
  6514. - break;
  6515. - case 2:
  6516. - numWindows = 2;
  6517. - srcGrpStart = 1;
  6518. - windowLen = samplesPerFrame >> 1;
  6519. - winIdxStride = 2;
  6520. - break;
  6521. - case 3:
  6522. - numWindows = 1;
  6523. - srcGrpStart = 0;
  6524. - windowLen = samplesPerFrame;
  6525. - winIdxStride = 4;
  6526. - break;
  6527. - }
  6528. - pConcealmentInfo->lastWinGrpLen = 1;
  6529. - } else {
  6530. - pIcsInfo->WindowShape = pConcealmentInfo->windowShape;
  6531. - pIcsInfo->WindowSequence = pConcealmentInfo->windowSequence;
  6532. -
  6533. - if (pConcealmentInfo->windowSequence == BLOCK_SHORT) {
  6534. - /* short block handling */
  6535. - numWindows = 8;
  6536. - windowLen = samplesPerFrame >> 3;
  6537. - srcGrpStart = numWindows - pConcealmentInfo->lastWinGrpLen;
  6538. - }
  6539. - }
  6540. -
  6541. - attIdxStride =
  6542. - fMax(1, (int)(numWindows / (pConcealmentInfo->lastWinGrpLen + 1)));
  6543. -
  6544. - /* load last state */
  6545. - attIdx = pConcealmentInfo->cntFadeFrames;
  6546. - numWinGrpPerFac = pConcealmentInfo->attGrpOffset[mode];
  6547. - srcWin = srcGrpStart + pConcealmentInfo->winGrpOffset[mode];
  6548. -
  6549. - FDK_ASSERT((srcGrpStart * windowLen + windowLen) <= samplesPerFrame);
  6550. - FDK_ASSERT((srcWin * windowLen + windowLen) <= 1024);
  6551. -
  6552. - for (dstWin = 0; dstWin < numWindows; dstWin += 1) {
  6553. - FIXP_CNCL *pCncl =
  6554. - pConcealmentInfo->spectralCoefficient + (srcWin * windowLen);
  6555. - FIXP_DBL *pOut = pSpectralCoefficient + (dstWin * windowLen);
  6556. -
  6557. - if (mode == 1) {
  6558. - /* mute if attIdx gets large enaugh */
  6559. - if (attIdx > pConcealmentInfo->pConcealParams->numFadeOutFrames) {
  6560. - FDKmemclear(pCncl, sizeof(FIXP_DBL) * windowLen);
  6561. - }
  6562. -
  6563. - /* restore frequency coefficients from buffer - attenuation is done later
  6564. - */
  6565. - for (i = 0; i < windowLen; i++) {
  6566. - pOut[i] = pCncl[i];
  6567. - }
  6568. -
  6569. - /* apply random change of sign for spectral coefficients */
  6570. - CConcealment_ApplyRandomSign(pConcealmentInfo->iRandomPhase, pOut,
  6571. - windowLen);
  6572. -
  6573. - /* Increment random phase index to avoid repetition artifacts. */
  6574. - pConcealmentInfo->iRandomPhase =
  6575. - (pConcealmentInfo->iRandomPhase + 1) & (AAC_NF_NO_RANDOM_VAL - 1);
  6576. -
  6577. - /* set old scale factors */
  6578. - pSpecScale[dstWin * winIdxStride] =
  6579. - pConcealmentInfo->specScale[srcWin * winIdxStride];
  6580. - }
  6581. -
  6582. - srcWin += 1;
  6583. -
  6584. - if (srcWin >= numWindows) {
  6585. - /* end of sequence -> rewind to first window of group */
  6586. - srcWin = srcGrpStart;
  6587. - numWinGrpPerFac += 1;
  6588. - if (numWinGrpPerFac >= attIdxStride) {
  6589. - numWinGrpPerFac = 0;
  6590. - attIdx += 1;
  6591. - }
  6592. - }
  6593. - }
  6594. -
  6595. - /* store current state */
  6596. -
  6597. - pConcealmentInfo->winGrpOffset[mode] = srcWin - srcGrpStart;
  6598. - FDK_ASSERT((pConcealmentInfo->winGrpOffset[mode] >= 0) &&
  6599. - (pConcealmentInfo->winGrpOffset[mode] < 8));
  6600. - pConcealmentInfo->attGrpOffset[mode] = numWinGrpPerFac;
  6601. - FDK_ASSERT((pConcealmentInfo->attGrpOffset[mode] >= 0) &&
  6602. - (pConcealmentInfo->attGrpOffset[mode] < attIdxStride));
  6603. -
  6604. - if (mode == 0) {
  6605. - pConcealmentInfo->cntFadeFrames = attIdx;
  6606. - }
  6607. -
  6608. - appliedProcessing = 1;
  6609. -
  6610. - return appliedProcessing;
  6611. -}
  6612. -
  6613. -/*!
  6614. - \brief Do Time domain fading (TDFading) in concealment case
  6615. -
  6616. - In case of concealment, this function takes care of the fading, after time
  6617. -domain signal has been rendered by the respective signal rendering functions.
  6618. - The fading out in case of ACELP decoding is not done by this function but by
  6619. -the ACELP decoder for the first concealed frame if CONCEAL_CORE_IGNORANT_FADE is
  6620. -not set.
  6621. -
  6622. - TimeDomain fading never creates jumps in energy / discontinuities, it always
  6623. -does a continuous fading. To achieve this, fading is always done from a starting
  6624. -point to a target point, while the starting point is always determined to be the
  6625. -last target point. By varying the target point of a fading, the fading slope can
  6626. -be controlled.
  6627. -
  6628. - This principle is applied to the fading within a frame and the fading from
  6629. -frame to frame.
  6630. -
  6631. - One frame is divided into 8 subframes to obtain 8 parts of fading slopes
  6632. -within a frame, each maybe with its own gradient.
  6633. -
  6634. - Workflow:
  6635. - 1.) Determine Fading behavior and end-of-frame target fading level, based on
  6636. -concealmentState (determined by CConcealment_UpdateState()) and the core mode.
  6637. - - By _DEFAULT_,
  6638. - The target fading level is determined by fadeOutFactor[cntFadeFrames]
  6639. -in case of fadeOut, or fadeInFactor[cntFadeFrames] in case of fadeIn.
  6640. - --> fading type is FADE_TIMEDOMAIN in this case. Target fading level
  6641. -is determined by fading index cntFadeFrames.
  6642. -
  6643. - - If concealmentState is signalling a _MUTED SIGNAL_,
  6644. - TDFading decays to 0 within 1/8th of a frame if numFadeOutFrames == 0.
  6645. - --> fading type is FADE_TIMEDOMAIN_TOSPECTRALMUTE in this case.
  6646. -
  6647. - - If concealmentState is signalling the _END OF MUTING_,
  6648. - TDFading fades to target fading level within 1/8th of a frame if
  6649. -numFadeInFrames == 0.
  6650. - --> fading type is FADE_TIMEDOMAIN_FROMSPECTRALMUTE in this case.
  6651. -Target fading level is determined by fading index cntFadeFrames.
  6652. -
  6653. -#ifndef CONCEAL_CORE_IGNORANT_FADE
  6654. - - In case of an _ACELP FADEOUT_,
  6655. - TDFading leaves fading control to ACELP decoder for 1/2 frame.
  6656. - --> fading type is FADE_ACELPDOMAIN in this case.
  6657. -#endif
  6658. -
  6659. - 2.) Render fading levels within current frame and do the final fading:
  6660. - Map Fading slopes to fading levels and apply to time domain signal.
  6661. -
  6662. -
  6663. -*/
  6664. -
  6665. -INT CConcealment_TDFading(
  6666. - int len, CAacDecoderStaticChannelInfo **ppAacDecoderStaticChannelInfo,
  6667. - FIXP_PCM *pcmdata, FIXP_PCM *pcmdata_1) {
  6668. - /*
  6669. - Do the fading in Time domain based on concealment states and core mode
  6670. - */
  6671. - FIXP_DBL fadeStop, attMute = (FIXP_DBL)0;
  6672. - int idx = 0, ii;
  6673. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo =
  6674. - *ppAacDecoderStaticChannelInfo;
  6675. - CConcealmentInfo *pConcealmentInfo =
  6676. - &pAacDecoderStaticChannelInfo->concealmentInfo;
  6677. - CConcealParams *pConcealParams = pConcealmentInfo->pConcealParams;
  6678. - const CConcealmentState concealState = pConcealmentInfo->concealState;
  6679. - TDfadingType fadingType;
  6680. - FIXP_DBL fadingStations[9] = {0};
  6681. - int fadingSteps[8] = {0};
  6682. - const FIXP_DBL fadeStart =
  6683. - pConcealmentInfo
  6684. - ->fade_old; /* start fading at last end-of-frame attenuation */
  6685. - FIXP_SGL *fadeFactor = pConcealParams->fadeOutFactor;
  6686. - const INT cntFadeFrames = pConcealmentInfo->cntFadeFrames;
  6687. - int TDFadeOutStopBeforeMute = 1;
  6688. - int TDFadeInStopBeforeFullLevel = 1;
  6689. -
  6690. - /*
  6691. - determine Fading behaviour (end-of-frame attenuation and fading type) (1.)
  6692. - */
  6693. -
  6694. - switch (concealState) {
  6695. - case ConcealState_Single:
  6696. - case ConcealState_Mute:
  6697. - case ConcealState_FadeOut:
  6698. - idx = (pConcealParams->method == ConcealMethodNoise) ? cntFadeFrames - 1
  6699. - : cntFadeFrames;
  6700. - fadingType = FADE_TIMEDOMAIN;
  6701. -
  6702. - if (concealState == ConcealState_Mute ||
  6703. - (cntFadeFrames + TDFadeOutStopBeforeMute) >
  6704. - pConcealmentInfo->pConcealParams->numFadeOutFrames) {
  6705. - fadingType = FADE_TIMEDOMAIN_TOSPECTRALMUTE;
  6706. - }
  6707. -
  6708. - break;
  6709. - case ConcealState_FadeIn:
  6710. - idx = cntFadeFrames;
  6711. - idx -= TDFadeInStopBeforeFullLevel;
  6712. - FDK_FALLTHROUGH;
  6713. - case ConcealState_Ok:
  6714. - fadeFactor = pConcealParams->fadeInFactor;
  6715. - idx = (concealState == ConcealState_Ok) ? -1 : idx;
  6716. - fadingType = (pConcealmentInfo->concealState_old == ConcealState_Mute)
  6717. - ? FADE_TIMEDOMAIN_FROMSPECTRALMUTE
  6718. - : FADE_TIMEDOMAIN;
  6719. - break;
  6720. - default:
  6721. - FDK_ASSERT(0);
  6722. - fadingType = FADE_TIMEDOMAIN_TOSPECTRALMUTE;
  6723. - break;
  6724. - }
  6725. -
  6726. - /* determine Target end-of-frame fading level and fading slope */
  6727. - switch (fadingType) {
  6728. - case FADE_TIMEDOMAIN_FROMSPECTRALMUTE:
  6729. - fadeStop =
  6730. - (idx < 0) ? (FIXP_DBL)MAXVAL_DBL : FX_SGL2FX_DBL(fadeFactor[idx]);
  6731. - if (pConcealmentInfo->pConcealParams->numFadeInFrames == 0) {
  6732. - /* do step as fast as possible */
  6733. - fadingSteps[0] = 1;
  6734. - break;
  6735. - }
  6736. - CConcealment_TDFading_doLinearFadingSteps(&fadingSteps[0]);
  6737. - break;
  6738. - case FADE_TIMEDOMAIN:
  6739. - fadeStop =
  6740. - (idx < 0) ? (FIXP_DBL)MAXVAL_DBL : FX_SGL2FX_DBL(fadeFactor[idx]);
  6741. - CConcealment_TDFading_doLinearFadingSteps(&fadingSteps[0]);
  6742. - break;
  6743. - case FADE_TIMEDOMAIN_TOSPECTRALMUTE:
  6744. - fadeStop = attMute;
  6745. - if (pConcealmentInfo->pConcealParams->numFadeOutFrames == 0) {
  6746. - /* do step as fast as possible */
  6747. - fadingSteps[0] = 1;
  6748. - break;
  6749. - }
  6750. - CConcealment_TDFading_doLinearFadingSteps(&fadingSteps[0]);
  6751. - break;
  6752. - }
  6753. -
  6754. - /*
  6755. - Render fading levels within current frame and do the final fading (2.)
  6756. - */
  6757. -
  6758. - len >>= 3;
  6759. - CConcealment_TDFadeFillFadingStations(fadingStations, fadingSteps, fadeStop,
  6760. - fadeStart, fadingType);
  6761. -
  6762. - if ((fadingStations[8] != (FIXP_DBL)MAXVAL_DBL) ||
  6763. - (fadingStations[7] != (FIXP_DBL)MAXVAL_DBL) ||
  6764. - (fadingStations[6] != (FIXP_DBL)MAXVAL_DBL) ||
  6765. - (fadingStations[5] != (FIXP_DBL)MAXVAL_DBL) ||
  6766. - (fadingStations[4] != (FIXP_DBL)MAXVAL_DBL) ||
  6767. - (fadingStations[3] != (FIXP_DBL)MAXVAL_DBL) ||
  6768. - (fadingStations[2] != (FIXP_DBL)MAXVAL_DBL) ||
  6769. - (fadingStations[1] != (FIXP_DBL)MAXVAL_DBL) ||
  6770. - (fadingStations[0] !=
  6771. - (FIXP_DBL)MAXVAL_DBL)) /* if there's something to fade */
  6772. - {
  6773. - int start = 0;
  6774. - for (ii = 0; ii < 8; ii++) {
  6775. - CConcealment_TDFadePcmAtt(start, len, fadingStations[ii],
  6776. - fadingStations[ii + 1], pcmdata);
  6777. - start += len;
  6778. - }
  6779. - }
  6780. - CConcealment_TDNoise_Apply(pConcealmentInfo, len, pcmdata);
  6781. -
  6782. - /* Save end-of-frame attenuation and fading type */
  6783. - pConcealmentInfo->lastFadingType = fadingType;
  6784. - pConcealmentInfo->fade_old = fadeStop;
  6785. - pConcealmentInfo->concealState_old = concealState;
  6786. -
  6787. - return 1;
  6788. -}
  6789. -
  6790. -/* attenuate pcmdata in Time Domain Fading process */
  6791. -static void CConcealment_TDFadePcmAtt(int start, int len, FIXP_DBL fadeStart,
  6792. - FIXP_DBL fadeStop, FIXP_PCM *pcmdata) {
  6793. - int i;
  6794. - FIXP_DBL dStep;
  6795. - FIXP_DBL dGain;
  6796. - FIXP_DBL dGain_apply;
  6797. - int bitshift = (DFRACT_BITS - SAMPLE_BITS);
  6798. -
  6799. - /* set start energy */
  6800. - dGain = fadeStart;
  6801. - /* determine energy steps from sample to sample */
  6802. - dStep = (FIXP_DBL)((int)((fadeStart >> 1) - (fadeStop >> 1)) / len) << 1;
  6803. -
  6804. - for (i = start; i < (start + len); i++) {
  6805. - dGain -= dStep;
  6806. - /* prevent gain from getting negative due to possible fixpoint inaccuracies
  6807. - */
  6808. - dGain_apply = fMax((FIXP_DBL)0, dGain);
  6809. - /* finally, attenuate samples */
  6810. - pcmdata[i] = (FIXP_PCM)((fMult(pcmdata[i], (dGain_apply))) >> bitshift);
  6811. - }
  6812. -}
  6813. -
  6814. -/*
  6815. -\brief Fill FadingStations
  6816. -
  6817. -The fadingstations are the attenuation factors, being applied to its dedicated
  6818. -portions of pcm data. They are calculated using the fadingsteps. One fadingstep
  6819. -is the weighted contribution to the fading slope within its dedicated portion of
  6820. -pcm data.
  6821. -
  6822. -*Fadingsteps : 0 0 0 1 0 1 2 0
  6823. -
  6824. - |<- 1 Frame pcm data ->|
  6825. - fadeStart-->|__________ |
  6826. - ^ ^ ^ ^ \____ |
  6827. - Attenuation : | | | | ^ ^\__ |
  6828. - | | | | | | ^\ |
  6829. - | | | | | | | \___|<-- fadeStop
  6830. - | | | | | | | ^ ^
  6831. - | | | | | | | | |
  6832. -Fadingstations: [0][1][2][3][4][5][6][7][8]
  6833. -
  6834. -(Fadingstations "[0]" is "[8] from previous frame", therefore its not meaningful
  6835. -to be edited)
  6836. -
  6837. -*/
  6838. -static void CConcealment_TDFadeFillFadingStations(FIXP_DBL *fadingStations,
  6839. - int *fadingSteps,
  6840. - FIXP_DBL fadeStop,
  6841. - FIXP_DBL fadeStart,
  6842. - TDfadingType fadingType) {
  6843. - int i;
  6844. - INT fadingSteps_sum = 0;
  6845. - INT fadeDiff;
  6846. -
  6847. - fadingSteps_sum = fadingSteps[0] + fadingSteps[1] + fadingSteps[2] +
  6848. - fadingSteps[3] + fadingSteps[4] + fadingSteps[5] +
  6849. - fadingSteps[6] + fadingSteps[7];
  6850. - fadeDiff = ((INT)(fadeStop - fadeStart) / fMax(fadingSteps_sum, (INT)1));
  6851. - fadingStations[0] = fadeStart;
  6852. - for (i = 1; i < 8; i++) {
  6853. - fadingStations[i] =
  6854. - fadingStations[i - 1] + (FIXP_DBL)(fadeDiff * fadingSteps[i - 1]);
  6855. - }
  6856. - fadingStations[8] = fadeStop;
  6857. -}
  6858. -
  6859. -static void CConcealment_TDFading_doLinearFadingSteps(int *fadingSteps) {
  6860. - fadingSteps[0] = fadingSteps[1] = fadingSteps[2] = fadingSteps[3] =
  6861. - fadingSteps[4] = fadingSteps[5] = fadingSteps[6] = fadingSteps[7] = 1;
  6862. -}
  6863. -
  6864. -/* end of TimeDomainFading functions */
  6865. -
  6866. -/* derived from int UsacRandomSign() */
  6867. -static int CConcealment_TDNoise_Random(ULONG *seed) {
  6868. - *seed = (ULONG)(((UINT64)(*seed) * 69069) + 5);
  6869. - return (int)(*seed);
  6870. -}
  6871. -
  6872. -static void CConcealment_TDNoise_Apply(CConcealmentInfo *const pConcealmentInfo,
  6873. - const int len, FIXP_PCM *const pcmdata) {
  6874. - FIXP_PCM *states = pConcealmentInfo->TDNoiseStates;
  6875. - FIXP_PCM noiseVal;
  6876. - FIXP_DBL noiseValLong;
  6877. - FIXP_SGL *coef = pConcealmentInfo->TDNoiseCoef;
  6878. - FIXP_DBL TDNoiseAtt;
  6879. - ULONG seed = pConcealmentInfo->TDNoiseSeed =
  6880. - (ULONG)CConcealment_TDNoise_Random(&pConcealmentInfo->TDNoiseSeed) + 1;
  6881. -
  6882. - TDNoiseAtt = pConcealmentInfo->pConcealParams->comfortNoiseLevel;
  6883. -
  6884. - int ii;
  6885. -
  6886. - if ((pConcealmentInfo->concealState != ConcealState_Ok ||
  6887. - pConcealmentInfo->concealState_old != ConcealState_Ok) &&
  6888. - TDNoiseAtt != (FIXP_DBL)0) {
  6889. - for (ii = 0; ii < (len << 3); ii++) {
  6890. - /* create filtered noise */
  6891. - states[2] = states[1];
  6892. - states[1] = states[0];
  6893. - states[0] = ((FIXP_PCM)CConcealment_TDNoise_Random(&seed));
  6894. - noiseValLong = fMult(states[0], coef[0]) + fMult(states[1], coef[1]) +
  6895. - fMult(states[2], coef[2]);
  6896. - noiseVal = FX_DBL2FX_PCM(fMult(noiseValLong, TDNoiseAtt));
  6897. -
  6898. - /* add filtered noise - check for clipping, before */
  6899. - if (noiseVal > (FIXP_PCM)0 &&
  6900. - pcmdata[ii] > (FIXP_PCM)MAXVAL_FIXP_PCM - noiseVal) {
  6901. - noiseVal = noiseVal * (FIXP_PCM)-1;
  6902. - } else if (noiseVal < (FIXP_PCM)0 &&
  6903. - pcmdata[ii] < (FIXP_PCM)MINVAL_FIXP_PCM - noiseVal) {
  6904. - noiseVal = noiseVal * (FIXP_PCM)-1;
  6905. - }
  6906. -
  6907. - pcmdata[ii] += noiseVal;
  6908. - }
  6909. - }
  6910. -}
  6911. --- a/libAACdec/src/conceal.h
  6912. +++ /dev/null
  6913. @@ -1,152 +0,0 @@
  6914. -/* -----------------------------------------------------------------------------
  6915. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  6916. -
  6917. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  6918. -Forschung e.V. All rights reserved.
  6919. -
  6920. - 1. INTRODUCTION
  6921. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  6922. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  6923. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  6924. -a wide variety of Android devices.
  6925. -
  6926. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  6927. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  6928. -full-bandwidth communications codec by independent studies and is widely
  6929. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  6930. -specifications.
  6931. -
  6932. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  6933. -those of Fraunhofer) may be obtained through Via Licensing
  6934. -(www.vialicensing.com) or through the respective patent owners individually for
  6935. -the purpose of encoding or decoding bit streams in products that are compliant
  6936. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  6937. -Android devices already license these patent claims through Via Licensing or
  6938. -directly from the patent owners, and therefore FDK AAC Codec software may
  6939. -already be covered under those patent licenses when it is used for those
  6940. -licensed purposes only.
  6941. -
  6942. -Commercially-licensed AAC software libraries, including floating-point versions
  6943. -with enhanced sound quality, are also available from Fraunhofer. Users are
  6944. -encouraged to check the Fraunhofer website for additional applications
  6945. -information and documentation.
  6946. -
  6947. -2. COPYRIGHT LICENSE
  6948. -
  6949. -Redistribution and use in source and binary forms, with or without modification,
  6950. -are permitted without payment of copyright license fees provided that you
  6951. -satisfy the following conditions:
  6952. -
  6953. -You must retain the complete text of this software license in redistributions of
  6954. -the FDK AAC Codec or your modifications thereto in source code form.
  6955. -
  6956. -You must retain the complete text of this software license in the documentation
  6957. -and/or other materials provided with redistributions of the FDK AAC Codec or
  6958. -your modifications thereto in binary form. You must make available free of
  6959. -charge copies of the complete source code of the FDK AAC Codec and your
  6960. -modifications thereto to recipients of copies in binary form.
  6961. -
  6962. -The name of Fraunhofer may not be used to endorse or promote products derived
  6963. -from this library without prior written permission.
  6964. -
  6965. -You may not charge copyright license fees for anyone to use, copy or distribute
  6966. -the FDK AAC Codec software or your modifications thereto.
  6967. -
  6968. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  6969. -that you changed the software and the date of any change. For modified versions
  6970. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  6971. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  6972. -AAC Codec Library for Android."
  6973. -
  6974. -3. NO PATENT LICENSE
  6975. -
  6976. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  6977. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  6978. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  6979. -software.
  6980. -
  6981. -You may use this FDK AAC Codec software or modifications thereto only for
  6982. -purposes that are authorized by appropriate patent licenses.
  6983. -
  6984. -4. DISCLAIMER
  6985. -
  6986. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  6987. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  6988. -including but not limited to the implied warranties of merchantability and
  6989. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  6990. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  6991. -or consequential damages, including but not limited to procurement of substitute
  6992. -goods or services; loss of use, data, or profits, or business interruption,
  6993. -however caused and on any theory of liability, whether in contract, strict
  6994. -liability, or tort (including negligence), arising in any way out of the use of
  6995. -this software, even if advised of the possibility of such damage.
  6996. -
  6997. -5. CONTACT INFORMATION
  6998. -
  6999. -Fraunhofer Institute for Integrated Circuits IIS
  7000. -Attention: Audio and Multimedia Departments - FDK AAC LL
  7001. -Am Wolfsmantel 33
  7002. -91058 Erlangen, Germany
  7003. -
  7004. -www.iis.fraunhofer.de/amm
  7005. -amm-info@iis.fraunhofer.de
  7006. ------------------------------------------------------------------------------ */
  7007. -
  7008. -/**************************** AAC decoder library ******************************
  7009. -
  7010. - Author(s): Josef Hoepfl
  7011. -
  7012. - Description: independent channel concealment
  7013. -
  7014. -*******************************************************************************/
  7015. -
  7016. -#ifndef CONCEAL_H
  7017. -#define CONCEAL_H
  7018. -
  7019. -#include "channelinfo.h"
  7020. -
  7021. -#define AACDEC_CONCEAL_PARAM_NOT_SPECIFIED (0xFFFE)
  7022. -
  7023. -void CConcealment_InitCommonData(CConcealParams *pConcealCommonData);
  7024. -
  7025. -void CConcealment_InitChannelData(CConcealmentInfo *hConcealmentInfo,
  7026. - CConcealParams *pConcealCommonData,
  7027. - AACDEC_RENDER_MODE initRenderMode,
  7028. - int samplesPerFrame);
  7029. -
  7030. -CConcealmentMethod CConcealment_GetMethod(CConcealParams *pConcealCommonData);
  7031. -
  7032. -UINT CConcealment_GetDelay(CConcealParams *pConcealCommonData);
  7033. -
  7034. -AAC_DECODER_ERROR
  7035. -CConcealment_SetParams(CConcealParams *concealParams, int method,
  7036. - int fadeOutSlope, int fadeInSlope, int muteRelease,
  7037. - FIXP_DBL comfNoiseLevel);
  7038. -
  7039. -CConcealmentState CConcealment_GetState(CConcealmentInfo *hConcealmentInfo);
  7040. -
  7041. -AAC_DECODER_ERROR
  7042. -CConcealment_SetAttenuation(CConcealParams *concealParams,
  7043. - const SHORT *fadeOutAttenuationVector,
  7044. - const SHORT *fadeInAttenuationVector);
  7045. -
  7046. -void CConcealment_Store(
  7047. - CConcealmentInfo *hConcealmentInfo,
  7048. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  7049. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo);
  7050. -
  7051. -int CConcealment_Apply(
  7052. - CConcealmentInfo *hConcealmentInfo,
  7053. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  7054. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  7055. - const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
  7056. - const UCHAR lastLpdMode, const int FrameOk, const UINT flags);
  7057. -
  7058. -int CConcealment_GetLastFrameOk(CConcealmentInfo *hConcealmentInfo,
  7059. - const int fBeforeApply);
  7060. -
  7061. -INT CConcealment_TDFading(
  7062. - int len, CAacDecoderStaticChannelInfo **ppAacDecoderStaticChannelInfo,
  7063. - FIXP_PCM *pcmdata, FIXP_PCM *pcmdata_1);
  7064. -
  7065. -#endif /* #ifndef CONCEAL_H */
  7066. --- a/libAACdec/src/conceal_types.h
  7067. +++ /dev/null
  7068. @@ -1,203 +0,0 @@
  7069. -/* -----------------------------------------------------------------------------
  7070. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  7071. -
  7072. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  7073. -Forschung e.V. All rights reserved.
  7074. -
  7075. - 1. INTRODUCTION
  7076. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  7077. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  7078. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  7079. -a wide variety of Android devices.
  7080. -
  7081. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  7082. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  7083. -full-bandwidth communications codec by independent studies and is widely
  7084. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  7085. -specifications.
  7086. -
  7087. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  7088. -those of Fraunhofer) may be obtained through Via Licensing
  7089. -(www.vialicensing.com) or through the respective patent owners individually for
  7090. -the purpose of encoding or decoding bit streams in products that are compliant
  7091. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  7092. -Android devices already license these patent claims through Via Licensing or
  7093. -directly from the patent owners, and therefore FDK AAC Codec software may
  7094. -already be covered under those patent licenses when it is used for those
  7095. -licensed purposes only.
  7096. -
  7097. -Commercially-licensed AAC software libraries, including floating-point versions
  7098. -with enhanced sound quality, are also available from Fraunhofer. Users are
  7099. -encouraged to check the Fraunhofer website for additional applications
  7100. -information and documentation.
  7101. -
  7102. -2. COPYRIGHT LICENSE
  7103. -
  7104. -Redistribution and use in source and binary forms, with or without modification,
  7105. -are permitted without payment of copyright license fees provided that you
  7106. -satisfy the following conditions:
  7107. -
  7108. -You must retain the complete text of this software license in redistributions of
  7109. -the FDK AAC Codec or your modifications thereto in source code form.
  7110. -
  7111. -You must retain the complete text of this software license in the documentation
  7112. -and/or other materials provided with redistributions of the FDK AAC Codec or
  7113. -your modifications thereto in binary form. You must make available free of
  7114. -charge copies of the complete source code of the FDK AAC Codec and your
  7115. -modifications thereto to recipients of copies in binary form.
  7116. -
  7117. -The name of Fraunhofer may not be used to endorse or promote products derived
  7118. -from this library without prior written permission.
  7119. -
  7120. -You may not charge copyright license fees for anyone to use, copy or distribute
  7121. -the FDK AAC Codec software or your modifications thereto.
  7122. -
  7123. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  7124. -that you changed the software and the date of any change. For modified versions
  7125. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  7126. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  7127. -AAC Codec Library for Android."
  7128. -
  7129. -3. NO PATENT LICENSE
  7130. -
  7131. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  7132. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  7133. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  7134. -software.
  7135. -
  7136. -You may use this FDK AAC Codec software or modifications thereto only for
  7137. -purposes that are authorized by appropriate patent licenses.
  7138. -
  7139. -4. DISCLAIMER
  7140. -
  7141. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  7142. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  7143. -including but not limited to the implied warranties of merchantability and
  7144. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  7145. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  7146. -or consequential damages, including but not limited to procurement of substitute
  7147. -goods or services; loss of use, data, or profits, or business interruption,
  7148. -however caused and on any theory of liability, whether in contract, strict
  7149. -liability, or tort (including negligence), arising in any way out of the use of
  7150. -this software, even if advised of the possibility of such damage.
  7151. -
  7152. -5. CONTACT INFORMATION
  7153. -
  7154. -Fraunhofer Institute for Integrated Circuits IIS
  7155. -Attention: Audio and Multimedia Departments - FDK AAC LL
  7156. -Am Wolfsmantel 33
  7157. -91058 Erlangen, Germany
  7158. -
  7159. -www.iis.fraunhofer.de/amm
  7160. -amm-info@iis.fraunhofer.de
  7161. ------------------------------------------------------------------------------ */
  7162. -
  7163. -/**************************** AAC decoder library ******************************
  7164. -
  7165. - Author(s): Christian Griebel
  7166. -
  7167. - Description: Error concealment structs and types
  7168. -
  7169. -*******************************************************************************/
  7170. -
  7171. -#ifndef CONCEAL_TYPES_H
  7172. -#define CONCEAL_TYPES_H
  7173. -
  7174. -#include "machine_type.h"
  7175. -#include "common_fix.h"
  7176. -
  7177. -#include "rvlc_info.h"
  7178. -
  7179. -#include "usacdec_lpc.h"
  7180. -
  7181. -#define CONCEAL_MAX_NUM_FADE_FACTORS (32)
  7182. -
  7183. -#define FIXP_CNCL FIXP_DBL
  7184. -#define FL2FXCONST_CNCL FL2FXCONST_DBL
  7185. -#define FX_DBL2FX_CNCL
  7186. -#define FX_CNCL2FX_DBL
  7187. -#define CNCL_FRACT_BITS DFRACT_BITS
  7188. -
  7189. -/* Warning: Do not ever change these values. */
  7190. -typedef enum {
  7191. - ConcealMethodNone = -1,
  7192. - ConcealMethodMute = 0,
  7193. - ConcealMethodNoise = 1,
  7194. - ConcealMethodInter = 2,
  7195. - ConcealMethodTonal = 3
  7196. -
  7197. -} CConcealmentMethod;
  7198. -
  7199. -typedef enum {
  7200. - ConcealState_Ok,
  7201. - ConcealState_Single,
  7202. - ConcealState_FadeIn,
  7203. - ConcealState_Mute,
  7204. - ConcealState_FadeOut
  7205. -
  7206. -} CConcealmentState;
  7207. -
  7208. -typedef struct {
  7209. - FIXP_SGL fadeOutFactor[CONCEAL_MAX_NUM_FADE_FACTORS];
  7210. - FIXP_SGL fadeInFactor[CONCEAL_MAX_NUM_FADE_FACTORS];
  7211. -
  7212. - CConcealmentMethod method;
  7213. -
  7214. - int numFadeOutFrames;
  7215. - int numFadeInFrames;
  7216. - int numMuteReleaseFrames;
  7217. - FIXP_DBL comfortNoiseLevel;
  7218. -
  7219. -} CConcealParams;
  7220. -
  7221. -typedef enum {
  7222. - FADE_TIMEDOMAIN_TOSPECTRALMUTE = 1,
  7223. - FADE_TIMEDOMAIN_FROMSPECTRALMUTE,
  7224. - FADE_TIMEDOMAIN
  7225. -} TDfadingType;
  7226. -
  7227. -typedef struct {
  7228. - CConcealParams *pConcealParams;
  7229. -
  7230. - FIXP_CNCL spectralCoefficient[1024];
  7231. - SHORT specScale[8];
  7232. -
  7233. - INT iRandomPhase;
  7234. - INT prevFrameOk[2];
  7235. - INT cntValidFrames;
  7236. - INT cntFadeFrames; /* State for signal fade-in/out */
  7237. - /* States for signal fade-out of frames with more than one window/subframe -
  7238. - [0] used by Update CntFadeFrames mode of CConcealment_ApplyFadeOut, [1] used
  7239. - by FadeOut mode */
  7240. - int winGrpOffset[2]; /* State for signal fade-out of frames with more than one
  7241. - window/subframe */
  7242. - int attGrpOffset[2]; /* State for faster signal fade-out of frames with
  7243. - transient signal parts */
  7244. -
  7245. - SCHAR lastRenderMode;
  7246. -
  7247. - UCHAR windowShape;
  7248. - BLOCK_TYPE windowSequence;
  7249. - UCHAR lastWinGrpLen;
  7250. -
  7251. - CConcealmentState concealState;
  7252. - CConcealmentState concealState_old;
  7253. - FIXP_DBL fade_old; /* last fading factor */
  7254. - TDfadingType lastFadingType; /* last fading type */
  7255. -
  7256. - SHORT aRvlcPreviousScaleFactor[RVLC_MAX_SFB]; /* needed once per channel */
  7257. - UCHAR aRvlcPreviousCodebook[RVLC_MAX_SFB]; /* needed once per channel */
  7258. - SCHAR rvlcPreviousScaleFactorOK;
  7259. - SCHAR rvlcPreviousBlockType;
  7260. -
  7261. - FIXP_LPC lsf4[M_LP_FILTER_ORDER];
  7262. - FIXP_DBL last_tcx_gain;
  7263. - INT last_tcx_gain_e;
  7264. - ULONG TDNoiseSeed;
  7265. - FIXP_PCM TDNoiseStates[3];
  7266. - FIXP_SGL TDNoiseCoef[3];
  7267. - FIXP_SGL TDNoiseAtt;
  7268. -
  7269. -} CConcealmentInfo;
  7270. -
  7271. -#endif /* #ifndef CONCEAL_TYPES_H */
  7272. --- a/libAACdec/src/rvlc.cpp
  7273. +++ /dev/null
  7274. @@ -1,1217 +0,0 @@
  7275. -/* -----------------------------------------------------------------------------
  7276. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  7277. -
  7278. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  7279. -Forschung e.V. All rights reserved.
  7280. -
  7281. - 1. INTRODUCTION
  7282. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  7283. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  7284. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  7285. -a wide variety of Android devices.
  7286. -
  7287. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  7288. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  7289. -full-bandwidth communications codec by independent studies and is widely
  7290. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  7291. -specifications.
  7292. -
  7293. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  7294. -those of Fraunhofer) may be obtained through Via Licensing
  7295. -(www.vialicensing.com) or through the respective patent owners individually for
  7296. -the purpose of encoding or decoding bit streams in products that are compliant
  7297. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  7298. -Android devices already license these patent claims through Via Licensing or
  7299. -directly from the patent owners, and therefore FDK AAC Codec software may
  7300. -already be covered under those patent licenses when it is used for those
  7301. -licensed purposes only.
  7302. -
  7303. -Commercially-licensed AAC software libraries, including floating-point versions
  7304. -with enhanced sound quality, are also available from Fraunhofer. Users are
  7305. -encouraged to check the Fraunhofer website for additional applications
  7306. -information and documentation.
  7307. -
  7308. -2. COPYRIGHT LICENSE
  7309. -
  7310. -Redistribution and use in source and binary forms, with or without modification,
  7311. -are permitted without payment of copyright license fees provided that you
  7312. -satisfy the following conditions:
  7313. -
  7314. -You must retain the complete text of this software license in redistributions of
  7315. -the FDK AAC Codec or your modifications thereto in source code form.
  7316. -
  7317. -You must retain the complete text of this software license in the documentation
  7318. -and/or other materials provided with redistributions of the FDK AAC Codec or
  7319. -your modifications thereto in binary form. You must make available free of
  7320. -charge copies of the complete source code of the FDK AAC Codec and your
  7321. -modifications thereto to recipients of copies in binary form.
  7322. -
  7323. -The name of Fraunhofer may not be used to endorse or promote products derived
  7324. -from this library without prior written permission.
  7325. -
  7326. -You may not charge copyright license fees for anyone to use, copy or distribute
  7327. -the FDK AAC Codec software or your modifications thereto.
  7328. -
  7329. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  7330. -that you changed the software and the date of any change. For modified versions
  7331. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  7332. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  7333. -AAC Codec Library for Android."
  7334. -
  7335. -3. NO PATENT LICENSE
  7336. -
  7337. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  7338. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  7339. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  7340. -software.
  7341. -
  7342. -You may use this FDK AAC Codec software or modifications thereto only for
  7343. -purposes that are authorized by appropriate patent licenses.
  7344. -
  7345. -4. DISCLAIMER
  7346. -
  7347. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  7348. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  7349. -including but not limited to the implied warranties of merchantability and
  7350. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  7351. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  7352. -or consequential damages, including but not limited to procurement of substitute
  7353. -goods or services; loss of use, data, or profits, or business interruption,
  7354. -however caused and on any theory of liability, whether in contract, strict
  7355. -liability, or tort (including negligence), arising in any way out of the use of
  7356. -this software, even if advised of the possibility of such damage.
  7357. -
  7358. -5. CONTACT INFORMATION
  7359. -
  7360. -Fraunhofer Institute for Integrated Circuits IIS
  7361. -Attention: Audio and Multimedia Departments - FDK AAC LL
  7362. -Am Wolfsmantel 33
  7363. -91058 Erlangen, Germany
  7364. -
  7365. -www.iis.fraunhofer.de/amm
  7366. -amm-info@iis.fraunhofer.de
  7367. ------------------------------------------------------------------------------ */
  7368. -
  7369. -/**************************** AAC decoder library ******************************
  7370. -
  7371. - Author(s):
  7372. -
  7373. - Description:
  7374. -
  7375. -*******************************************************************************/
  7376. -
  7377. -/*!
  7378. - \file
  7379. - \brief RVLC Decoder
  7380. - \author Robert Weidner
  7381. -*/
  7382. -
  7383. -#include "rvlc.h"
  7384. -
  7385. -#include "block.h"
  7386. -
  7387. -#include "aac_rom.h"
  7388. -#include "rvlcbit.h"
  7389. -#include "rvlcconceal.h"
  7390. -#include "aacdec_hcr.h"
  7391. -
  7392. -/*---------------------------------------------------------------------------------------------
  7393. - function: rvlcInit
  7394. -
  7395. - description: init RVLC by data from channelinfo, which was decoded
  7396. -previously and set up pointers
  7397. ------------------------------------------------------------------------------------------------
  7398. - input: - pointer rvlc structure
  7399. - - pointer channel info structure
  7400. - - pointer bitstream structure
  7401. ------------------------------------------------------------------------------------------------
  7402. - return: -
  7403. ---------------------------------------------------------------------------------------------
  7404. -*/
  7405. -
  7406. -static void rvlcInit(CErRvlcInfo *pRvlc,
  7407. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  7408. - HANDLE_FDK_BITSTREAM bs) {
  7409. - /* RVLC common initialization part 2 of 2 */
  7410. - SHORT *pScfEsc = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfEsc;
  7411. - SHORT *pScfFwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd;
  7412. - SHORT *pScfBwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd;
  7413. - SHORT *pScaleFactor = pAacDecoderChannelInfo->pDynData->aScaleFactor;
  7414. - int bnds;
  7415. -
  7416. - pAacDecoderChannelInfo->pDynData->specificTo.aac.rvlcIntensityUsed = 0;
  7417. -
  7418. - pRvlc->numDecodedEscapeWordsEsc = 0;
  7419. - pRvlc->numDecodedEscapeWordsFwd = 0;
  7420. - pRvlc->numDecodedEscapeWordsBwd = 0;
  7421. -
  7422. - pRvlc->intensity_used = 0;
  7423. - pRvlc->errorLogRvlc = 0;
  7424. -
  7425. - pRvlc->conceal_max = CONCEAL_MAX_INIT;
  7426. - pRvlc->conceal_min = CONCEAL_MIN_INIT;
  7427. -
  7428. - pRvlc->conceal_max_esc = CONCEAL_MAX_INIT;
  7429. - pRvlc->conceal_min_esc = CONCEAL_MIN_INIT;
  7430. -
  7431. - pRvlc->pHuffTreeRvlcEscape = aHuffTreeRvlcEscape;
  7432. - pRvlc->pHuffTreeRvlCodewds = aHuffTreeRvlCodewds;
  7433. -
  7434. - /* init scf arrays (for savety (in case of there are only zero codebooks)) */
  7435. - for (bnds = 0; bnds < RVLC_MAX_SFB; bnds++) {
  7436. - pScfFwd[bnds] = 0;
  7437. - pScfBwd[bnds] = 0;
  7438. - pScfEsc[bnds] = 0;
  7439. - pScaleFactor[bnds] = 0;
  7440. - }
  7441. -
  7442. - /* set base bitstream ptr to the RVL-coded part (start of RVLC data (ESC 2))
  7443. - */
  7444. - FDKsyncCache(bs);
  7445. - pRvlc->bsAnchor = (INT)FDKgetValidBits(bs);
  7446. -
  7447. - pRvlc->bitstreamIndexRvlFwd =
  7448. - 0; /* first bit within RVL coded block as start address for forward
  7449. - decoding */
  7450. - pRvlc->bitstreamIndexRvlBwd =
  7451. - pRvlc->length_of_rvlc_sf - 1; /* last bit within RVL coded block as start
  7452. - address for backward decoding */
  7453. -
  7454. - /* skip RVLC-bitstream-part -- pointing now to escapes (if present) or to TNS
  7455. - * data (if present) */
  7456. - FDKpushFor(bs, pRvlc->length_of_rvlc_sf);
  7457. -
  7458. - if (pRvlc->sf_escapes_present != 0) {
  7459. - /* locate internal bitstream ptr at escapes (which is the second part) */
  7460. - FDKsyncCache(bs);
  7461. - pRvlc->bitstreamIndexEsc = pRvlc->bsAnchor - (INT)FDKgetValidBits(bs);
  7462. -
  7463. - /* skip escapeRVLC-bitstream-part -- pointing to TNS data (if present) to
  7464. - * make decoder continue */
  7465. - /* decoding of RVLC should work despite this second pushFor during
  7466. - * initialization because */
  7467. - /* bitstream initialization is valid for both ESC2 data parts (RVL-coded
  7468. - * values and ESC-coded values) */
  7469. - FDKpushFor(bs, pRvlc->length_of_rvlc_escapes);
  7470. - }
  7471. -}
  7472. -
  7473. -/*---------------------------------------------------------------------------------------------
  7474. - function: rvlcCheckIntensityCb
  7475. -
  7476. - description: Check if a intensity codebook is used in the current channel.
  7477. ------------------------------------------------------------------------------------------------
  7478. - input: - pointer rvlc structure
  7479. - - pointer channel info structure
  7480. ------------------------------------------------------------------------------------------------
  7481. - output: - intensity_used: 0 no intensity codebook is used
  7482. - 1 intensity codebook is used
  7483. ------------------------------------------------------------------------------------------------
  7484. - return: -
  7485. ---------------------------------------------------------------------------------------------
  7486. -*/
  7487. -
  7488. -static void rvlcCheckIntensityCb(
  7489. - CErRvlcInfo *pRvlc, CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
  7490. - int group, band, bnds;
  7491. -
  7492. - pRvlc->intensity_used = 0;
  7493. -
  7494. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  7495. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  7496. - bnds = 16 * group + band;
  7497. - if ((pAacDecoderChannelInfo->pDynData->aCodeBook[bnds] ==
  7498. - INTENSITY_HCB) ||
  7499. - (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds] ==
  7500. - INTENSITY_HCB2)) {
  7501. - pRvlc->intensity_used = 1;
  7502. - break;
  7503. - }
  7504. - }
  7505. - }
  7506. -}
  7507. -
  7508. -/*---------------------------------------------------------------------------------------------
  7509. - function: rvlcDecodeEscapeWord
  7510. -
  7511. - description: Decode a huffman coded RVLC Escape-word. This value is part
  7512. -of a DPCM coded scalefactor.
  7513. ------------------------------------------------------------------------------------------------
  7514. - input: - pointer rvlc structure
  7515. ------------------------------------------------------------------------------------------------
  7516. - return: - a single RVLC-Escape value which had to be applied to a
  7517. -DPCM value (which has a absolute value of 7)
  7518. ---------------------------------------------------------------------------------------------
  7519. -*/
  7520. -
  7521. -static SCHAR rvlcDecodeEscapeWord(CErRvlcInfo *pRvlc, HANDLE_FDK_BITSTREAM bs) {
  7522. - int i;
  7523. - SCHAR value;
  7524. - UCHAR carryBit;
  7525. - UINT treeNode;
  7526. - UINT branchValue;
  7527. - UINT branchNode;
  7528. -
  7529. - INT *pBitstreamIndexEsc;
  7530. - const UINT *pEscTree;
  7531. -
  7532. - pEscTree = pRvlc->pHuffTreeRvlcEscape;
  7533. - pBitstreamIndexEsc = &(pRvlc->bitstreamIndexEsc);
  7534. - treeNode = *pEscTree; /* init at starting node */
  7535. -
  7536. - for (i = MAX_LEN_RVLC_ESCAPE_WORD - 1; i >= 0; i--) {
  7537. - carryBit =
  7538. - rvlcReadBitFromBitstream(bs, /* get next bit */
  7539. - pRvlc->bsAnchor, pBitstreamIndexEsc, FWD);
  7540. -
  7541. - CarryBitToBranchValue(carryBit, /* huffman decoding, do a single step in
  7542. - huffman decoding tree */
  7543. - treeNode, &branchValue, &branchNode);
  7544. -
  7545. - if ((branchNode & TEST_BIT_10) ==
  7546. - TEST_BIT_10) { /* test bit 10 ; if set --> a RVLC-escape-word is
  7547. - completely decoded */
  7548. - value = (SCHAR)branchNode & CLR_BIT_10;
  7549. - pRvlc->length_of_rvlc_escapes -= (MAX_LEN_RVLC_ESCAPE_WORD - i);
  7550. -
  7551. - if (pRvlc->length_of_rvlc_escapes < 0) {
  7552. - pRvlc->errorLogRvlc |= RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID;
  7553. - value = -1;
  7554. - }
  7555. -
  7556. - return value;
  7557. - } else {
  7558. - treeNode = *(
  7559. - pEscTree +
  7560. - branchValue); /* update treeNode for further step in decoding tree */
  7561. - }
  7562. - }
  7563. -
  7564. - pRvlc->errorLogRvlc |= RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID;
  7565. -
  7566. - return -1; /* should not be reached */
  7567. -}
  7568. -
  7569. -/*---------------------------------------------------------------------------------------------
  7570. - function: rvlcDecodeEscapes
  7571. -
  7572. - description: Decodes all huffman coded RVLC Escape Words.
  7573. - Here a difference to the pseudo-code-implementation from
  7574. -standard can be found. A while loop (and not two nested for loops) is used for
  7575. -two reasons:
  7576. -
  7577. - 1. The plain huffman encoded escapes are decoded before the
  7578. -RVL-coded scalefactors. Therefore the escapes are present in the second step
  7579. - when decoding the RVL-coded-scalefactor values in forward
  7580. -and backward direction.
  7581. -
  7582. - When the RVL-coded scalefactors are decoded and there a
  7583. -escape is needed, then it is just taken out of the array in ascending order.
  7584. -
  7585. - 2. It's faster.
  7586. ------------------------------------------------------------------------------------------------
  7587. - input: - pointer rvlc structure
  7588. - - handle to FDK bitstream
  7589. ------------------------------------------------------------------------------------------------
  7590. - return: - 0 ok the decoded escapes seem to be valid
  7591. - - 1 error there was a error detected during decoding escapes
  7592. - --> all escapes are invalid
  7593. ---------------------------------------------------------------------------------------------
  7594. -*/
  7595. -
  7596. -static void rvlcDecodeEscapes(CErRvlcInfo *pRvlc, SHORT *pEsc,
  7597. - HANDLE_FDK_BITSTREAM bs) {
  7598. - SCHAR escWord;
  7599. - SCHAR escCnt = 0;
  7600. - SHORT *pEscBitCntSum;
  7601. -
  7602. - pEscBitCntSum = &(pRvlc->length_of_rvlc_escapes);
  7603. -
  7604. - /* Decode all RVLC-Escape words with a plain Huffman-Decoder */
  7605. - while (*pEscBitCntSum > 0) {
  7606. - escWord = rvlcDecodeEscapeWord(pRvlc, bs);
  7607. -
  7608. - if (escWord >= 0) {
  7609. - pEsc[escCnt] = escWord;
  7610. - escCnt++;
  7611. - } else {
  7612. - pRvlc->errorLogRvlc |= RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID;
  7613. - pRvlc->numDecodedEscapeWordsEsc = escCnt;
  7614. -
  7615. - return;
  7616. - }
  7617. - } /* all RVLC escapes decoded */
  7618. -
  7619. - pRvlc->numDecodedEscapeWordsEsc = escCnt;
  7620. -}
  7621. -
  7622. -/*---------------------------------------------------------------------------------------------
  7623. - function: decodeRVLCodeword
  7624. -
  7625. - description: Decodes a RVL-coded dpcm-word (-part).
  7626. ------------------------------------------------------------------------------------------------
  7627. - input: - FDK bitstream handle
  7628. - - pointer rvlc structure
  7629. ------------------------------------------------------------------------------------------------
  7630. - return: - a dpcm value which is within range [0,1,..,14] in case of
  7631. -no errors. The offset of 7 must be subtracted to get a valid dpcm scalefactor
  7632. -value. In case of errors a forbidden codeword is detected --> returning -1
  7633. ---------------------------------------------------------------------------------------------
  7634. -*/
  7635. -
  7636. -SCHAR decodeRVLCodeword(HANDLE_FDK_BITSTREAM bs, CErRvlcInfo *pRvlc) {
  7637. - int i;
  7638. - SCHAR value;
  7639. - UCHAR carryBit;
  7640. - UINT branchValue;
  7641. - UINT branchNode;
  7642. -
  7643. - const UINT *pRvlCodeTree = pRvlc->pHuffTreeRvlCodewds;
  7644. - UCHAR direction = pRvlc->direction;
  7645. - INT *pBitstrIndxRvl = pRvlc->pBitstrIndxRvl_RVL;
  7646. - UINT treeNode = *pRvlCodeTree;
  7647. -
  7648. - for (i = MAX_LEN_RVLC_CODE_WORD - 1; i >= 0; i--) {
  7649. - carryBit =
  7650. - rvlcReadBitFromBitstream(bs, /* get next bit */
  7651. - pRvlc->bsAnchor, pBitstrIndxRvl, direction);
  7652. -
  7653. - CarryBitToBranchValue(carryBit, /* huffman decoding, do a single step in
  7654. - huffman decoding tree */
  7655. - treeNode, &branchValue, &branchNode);
  7656. -
  7657. - if ((branchNode & TEST_BIT_10) ==
  7658. - TEST_BIT_10) { /* test bit 10 ; if set --> a
  7659. - RVLC-codeword is completely decoded
  7660. - */
  7661. - value = (SCHAR)(branchNode & CLR_BIT_10);
  7662. - *pRvlc->pRvlBitCnt_RVL -= (MAX_LEN_RVLC_CODE_WORD - i);
  7663. -
  7664. - /* check available bits for decoding */
  7665. - if (*pRvlc->pRvlBitCnt_RVL < 0) {
  7666. - if (direction == FWD) {
  7667. - pRvlc->errorLogRvlc |= RVLC_ERROR_RVL_SUM_BIT_COUNTER_BELOW_ZERO_FWD;
  7668. - } else {
  7669. - pRvlc->errorLogRvlc |= RVLC_ERROR_RVL_SUM_BIT_COUNTER_BELOW_ZERO_BWD;
  7670. - }
  7671. - value = -1; /* signalize an error in return value, because too many bits
  7672. - was decoded */
  7673. - }
  7674. -
  7675. - /* check max value of dpcm value */
  7676. - if (value > MAX_ALLOWED_DPCM_INDEX) {
  7677. - if (direction == FWD) {
  7678. - pRvlc->errorLogRvlc |= RVLC_ERROR_FORBIDDEN_CW_DETECTED_FWD;
  7679. - } else {
  7680. - pRvlc->errorLogRvlc |= RVLC_ERROR_FORBIDDEN_CW_DETECTED_BWD;
  7681. - }
  7682. - value = -1; /* signalize an error in return value, because a forbidden
  7683. - cw was detected*/
  7684. - }
  7685. -
  7686. - return value; /* return a dpcm value with offset +7 or an error status */
  7687. - } else {
  7688. - treeNode = *(
  7689. - pRvlCodeTree +
  7690. - branchValue); /* update treeNode for further step in decoding tree */
  7691. - }
  7692. - }
  7693. -
  7694. - return -1;
  7695. -}
  7696. -
  7697. -/*---------------------------------------------------------------------------------------------
  7698. - function: rvlcDecodeForward
  7699. -
  7700. - description: Decode RVL-coded codewords in forward direction.
  7701. ------------------------------------------------------------------------------------------------
  7702. - input: - pointer rvlc structure
  7703. - - pointer channel info structure
  7704. - - handle to FDK bitstream
  7705. ------------------------------------------------------------------------------------------------
  7706. - return: -
  7707. ---------------------------------------------------------------------------------------------
  7708. -*/
  7709. -
  7710. -static void rvlcDecodeForward(CErRvlcInfo *pRvlc,
  7711. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  7712. - HANDLE_FDK_BITSTREAM bs) {
  7713. - int band = 0;
  7714. - int group = 0;
  7715. - int bnds = 0;
  7716. -
  7717. - SHORT dpcm;
  7718. -
  7719. - SHORT factor =
  7720. - pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET;
  7721. - SHORT position = -SF_OFFSET;
  7722. - SHORT noisenrg = pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain -
  7723. - SF_OFFSET - 90 - 256;
  7724. -
  7725. - SHORT *pScfFwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd;
  7726. - SHORT *pScfEsc = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfEsc;
  7727. - UCHAR *pEscFwdCnt = &(pRvlc->numDecodedEscapeWordsFwd);
  7728. -
  7729. - pRvlc->pRvlBitCnt_RVL = &(pRvlc->length_of_rvlc_sf_fwd);
  7730. - pRvlc->pBitstrIndxRvl_RVL = &(pRvlc->bitstreamIndexRvlFwd);
  7731. -
  7732. - *pEscFwdCnt = 0;
  7733. - pRvlc->direction = FWD;
  7734. - pRvlc->noise_used = 0;
  7735. - pRvlc->sf_used = 0;
  7736. - pRvlc->lastScf = 0;
  7737. - pRvlc->lastNrg = 0;
  7738. - pRvlc->lastIs = 0;
  7739. -
  7740. - rvlcCheckIntensityCb(pRvlc, pAacDecoderChannelInfo);
  7741. -
  7742. - /* main loop fwd long */
  7743. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  7744. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  7745. - bnds = 16 * group + band;
  7746. -
  7747. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  7748. - case ZERO_HCB:
  7749. - pScfFwd[bnds] = 0;
  7750. - break;
  7751. -
  7752. - case INTENSITY_HCB2:
  7753. - case INTENSITY_HCB:
  7754. - /* store dpcm_is_position */
  7755. - dpcm = decodeRVLCodeword(bs, pRvlc);
  7756. - if (dpcm < 0) {
  7757. - pRvlc->conceal_max = bnds;
  7758. - return;
  7759. - }
  7760. - dpcm -= TABLE_OFFSET;
  7761. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  7762. - if (pRvlc->length_of_rvlc_escapes) {
  7763. - pRvlc->conceal_max = bnds;
  7764. - return;
  7765. - } else {
  7766. - if (dpcm == MIN_RVL) {
  7767. - dpcm -= *pScfEsc++;
  7768. - } else {
  7769. - dpcm += *pScfEsc++;
  7770. - }
  7771. - (*pEscFwdCnt)++;
  7772. - if (pRvlc->conceal_max_esc == CONCEAL_MAX_INIT) {
  7773. - pRvlc->conceal_max_esc = bnds;
  7774. - }
  7775. - }
  7776. - }
  7777. - position += dpcm;
  7778. - pScfFwd[bnds] = position;
  7779. - pRvlc->lastIs = position;
  7780. - break;
  7781. -
  7782. - case NOISE_HCB:
  7783. - if (pRvlc->noise_used == 0) {
  7784. - pRvlc->noise_used = 1;
  7785. - pRvlc->first_noise_band = bnds;
  7786. - noisenrg += pRvlc->dpcm_noise_nrg;
  7787. - pScfFwd[bnds] = 100 + noisenrg;
  7788. - pRvlc->lastNrg = noisenrg;
  7789. - } else {
  7790. - dpcm = decodeRVLCodeword(bs, pRvlc);
  7791. - if (dpcm < 0) {
  7792. - pRvlc->conceal_max = bnds;
  7793. - return;
  7794. - }
  7795. - dpcm -= TABLE_OFFSET;
  7796. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  7797. - if (pRvlc->length_of_rvlc_escapes) {
  7798. - pRvlc->conceal_max = bnds;
  7799. - return;
  7800. - } else {
  7801. - if (dpcm == MIN_RVL) {
  7802. - dpcm -= *pScfEsc++;
  7803. - } else {
  7804. - dpcm += *pScfEsc++;
  7805. - }
  7806. - (*pEscFwdCnt)++;
  7807. - if (pRvlc->conceal_max_esc == CONCEAL_MAX_INIT) {
  7808. - pRvlc->conceal_max_esc = bnds;
  7809. - }
  7810. - }
  7811. - }
  7812. - noisenrg += dpcm;
  7813. - pScfFwd[bnds] = 100 + noisenrg;
  7814. - pRvlc->lastNrg = noisenrg;
  7815. - }
  7816. - pAacDecoderChannelInfo->data.aac.PnsData.pnsUsed[bnds] = 1;
  7817. - break;
  7818. -
  7819. - default:
  7820. - pRvlc->sf_used = 1;
  7821. - dpcm = decodeRVLCodeword(bs, pRvlc);
  7822. - if (dpcm < 0) {
  7823. - pRvlc->conceal_max = bnds;
  7824. - return;
  7825. - }
  7826. - dpcm -= TABLE_OFFSET;
  7827. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  7828. - if (pRvlc->length_of_rvlc_escapes) {
  7829. - pRvlc->conceal_max = bnds;
  7830. - return;
  7831. - } else {
  7832. - if (dpcm == MIN_RVL) {
  7833. - dpcm -= *pScfEsc++;
  7834. - } else {
  7835. - dpcm += *pScfEsc++;
  7836. - }
  7837. - (*pEscFwdCnt)++;
  7838. - if (pRvlc->conceal_max_esc == CONCEAL_MAX_INIT) {
  7839. - pRvlc->conceal_max_esc = bnds;
  7840. - }
  7841. - }
  7842. - }
  7843. - factor += dpcm;
  7844. - pScfFwd[bnds] = factor;
  7845. - pRvlc->lastScf = factor;
  7846. - break;
  7847. - }
  7848. - }
  7849. - }
  7850. -
  7851. - /* postfetch fwd long */
  7852. - if (pRvlc->intensity_used) {
  7853. - dpcm = decodeRVLCodeword(bs, pRvlc); /* dpcm_is_last_position */
  7854. - if (dpcm < 0) {
  7855. - pRvlc->conceal_max = bnds;
  7856. - return;
  7857. - }
  7858. - dpcm -= TABLE_OFFSET;
  7859. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  7860. - if (pRvlc->length_of_rvlc_escapes) {
  7861. - pRvlc->conceal_max = bnds;
  7862. - return;
  7863. - } else {
  7864. - if (dpcm == MIN_RVL) {
  7865. - dpcm -= *pScfEsc++;
  7866. - } else {
  7867. - dpcm += *pScfEsc++;
  7868. - }
  7869. - (*pEscFwdCnt)++;
  7870. - if (pRvlc->conceal_max_esc == CONCEAL_MAX_INIT) {
  7871. - pRvlc->conceal_max_esc = bnds;
  7872. - }
  7873. - }
  7874. - }
  7875. - pRvlc->dpcm_is_last_position = dpcm;
  7876. - }
  7877. -}
  7878. -
  7879. -/*---------------------------------------------------------------------------------------------
  7880. - function: rvlcDecodeBackward
  7881. -
  7882. - description: Decode RVL-coded codewords in backward direction.
  7883. ------------------------------------------------------------------------------------------------
  7884. - input: - pointer rvlc structure
  7885. - - pointer channel info structure
  7886. - - handle FDK bitstream
  7887. ------------------------------------------------------------------------------------------------
  7888. - return: -
  7889. ---------------------------------------------------------------------------------------------
  7890. -*/
  7891. -
  7892. -static void rvlcDecodeBackward(CErRvlcInfo *pRvlc,
  7893. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  7894. - HANDLE_FDK_BITSTREAM bs) {
  7895. - SHORT band, group, dpcm, offset;
  7896. - SHORT bnds = pRvlc->maxSfbTransmitted - 1;
  7897. -
  7898. - SHORT factor = pRvlc->rev_global_gain - SF_OFFSET;
  7899. - SHORT position = pRvlc->dpcm_is_last_position - SF_OFFSET;
  7900. - SHORT noisenrg = pRvlc->rev_global_gain + pRvlc->dpcm_noise_last_position -
  7901. - SF_OFFSET - 90 - 256;
  7902. -
  7903. - SHORT *pScfBwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd;
  7904. - SHORT *pScfEsc = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfEsc;
  7905. - UCHAR *pEscEscCnt = &(pRvlc->numDecodedEscapeWordsEsc);
  7906. - UCHAR *pEscBwdCnt = &(pRvlc->numDecodedEscapeWordsBwd);
  7907. -
  7908. - pRvlc->pRvlBitCnt_RVL = &(pRvlc->length_of_rvlc_sf_bwd);
  7909. - pRvlc->pBitstrIndxRvl_RVL = &(pRvlc->bitstreamIndexRvlBwd);
  7910. -
  7911. - *pEscBwdCnt = 0;
  7912. - pRvlc->direction = BWD;
  7913. - pScfEsc += *pEscEscCnt - 1; /* set pScfEsc to last entry */
  7914. - pRvlc->firstScf = 0;
  7915. - pRvlc->firstNrg = 0;
  7916. - pRvlc->firstIs = 0;
  7917. -
  7918. - /* prefetch long BWD */
  7919. - if (pRvlc->intensity_used) {
  7920. - dpcm = decodeRVLCodeword(bs, pRvlc); /* dpcm_is_last_position */
  7921. - if (dpcm < 0) {
  7922. - pRvlc->dpcm_is_last_position = 0;
  7923. - pRvlc->conceal_min = bnds;
  7924. - return;
  7925. - }
  7926. - dpcm -= TABLE_OFFSET;
  7927. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  7928. - if (pRvlc->length_of_rvlc_escapes) {
  7929. - pRvlc->conceal_min = bnds;
  7930. - return;
  7931. - } else {
  7932. - if (dpcm == MIN_RVL) {
  7933. - dpcm -= *pScfEsc--;
  7934. - } else {
  7935. - dpcm += *pScfEsc--;
  7936. - }
  7937. - (*pEscBwdCnt)++;
  7938. - if (pRvlc->conceal_min_esc == CONCEAL_MIN_INIT) {
  7939. - pRvlc->conceal_min_esc = bnds;
  7940. - }
  7941. - }
  7942. - }
  7943. - pRvlc->dpcm_is_last_position = dpcm;
  7944. - }
  7945. -
  7946. - /* main loop long BWD */
  7947. - for (group = pRvlc->numWindowGroups - 1; group >= 0; group--) {
  7948. - for (band = pRvlc->maxSfbTransmitted - 1; band >= 0; band--) {
  7949. - bnds = 16 * group + band;
  7950. - if ((band == 0) && (pRvlc->numWindowGroups != 1))
  7951. - offset = 16 - pRvlc->maxSfbTransmitted + 1;
  7952. - else
  7953. - offset = 1;
  7954. -
  7955. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  7956. - case ZERO_HCB:
  7957. - pScfBwd[bnds] = 0;
  7958. - break;
  7959. -
  7960. - case INTENSITY_HCB2:
  7961. - case INTENSITY_HCB:
  7962. - /* store dpcm_is_position */
  7963. - dpcm = decodeRVLCodeword(bs, pRvlc);
  7964. - if (dpcm < 0) {
  7965. - pScfBwd[bnds] = position;
  7966. - pRvlc->conceal_min = fMax(0, bnds - offset);
  7967. - return;
  7968. - }
  7969. - dpcm -= TABLE_OFFSET;
  7970. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  7971. - if (pRvlc->length_of_rvlc_escapes) {
  7972. - pScfBwd[bnds] = position;
  7973. - pRvlc->conceal_min = fMax(0, bnds - offset);
  7974. - return;
  7975. - } else {
  7976. - if (dpcm == MIN_RVL) {
  7977. - dpcm -= *pScfEsc--;
  7978. - } else {
  7979. - dpcm += *pScfEsc--;
  7980. - }
  7981. - (*pEscBwdCnt)++;
  7982. - if (pRvlc->conceal_min_esc == CONCEAL_MIN_INIT) {
  7983. - pRvlc->conceal_min_esc = fMax(0, bnds - offset);
  7984. - }
  7985. - }
  7986. - }
  7987. - pScfBwd[bnds] = position;
  7988. - position -= dpcm;
  7989. - pRvlc->firstIs = position;
  7990. - break;
  7991. -
  7992. - case NOISE_HCB:
  7993. - if (bnds == pRvlc->first_noise_band) {
  7994. - pScfBwd[bnds] =
  7995. - pRvlc->dpcm_noise_nrg +
  7996. - pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain -
  7997. - SF_OFFSET - 90 - 256;
  7998. - pRvlc->firstNrg = pScfBwd[bnds];
  7999. - } else {
  8000. - dpcm = decodeRVLCodeword(bs, pRvlc);
  8001. - if (dpcm < 0) {
  8002. - pScfBwd[bnds] = noisenrg;
  8003. - pRvlc->conceal_min = fMax(0, bnds - offset);
  8004. - return;
  8005. - }
  8006. - dpcm -= TABLE_OFFSET;
  8007. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  8008. - if (pRvlc->length_of_rvlc_escapes) {
  8009. - pScfBwd[bnds] = noisenrg;
  8010. - pRvlc->conceal_min = fMax(0, bnds - offset);
  8011. - return;
  8012. - } else {
  8013. - if (dpcm == MIN_RVL) {
  8014. - dpcm -= *pScfEsc--;
  8015. - } else {
  8016. - dpcm += *pScfEsc--;
  8017. - }
  8018. - (*pEscBwdCnt)++;
  8019. - if (pRvlc->conceal_min_esc == CONCEAL_MIN_INIT) {
  8020. - pRvlc->conceal_min_esc = fMax(0, bnds - offset);
  8021. - }
  8022. - }
  8023. - }
  8024. - pScfBwd[bnds] = noisenrg;
  8025. - noisenrg -= dpcm;
  8026. - pRvlc->firstNrg = noisenrg;
  8027. - }
  8028. - break;
  8029. -
  8030. - default:
  8031. - dpcm = decodeRVLCodeword(bs, pRvlc);
  8032. - if (dpcm < 0) {
  8033. - pScfBwd[bnds] = factor;
  8034. - pRvlc->conceal_min = fMax(0, bnds - offset);
  8035. - return;
  8036. - }
  8037. - dpcm -= TABLE_OFFSET;
  8038. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  8039. - if (pRvlc->length_of_rvlc_escapes) {
  8040. - pScfBwd[bnds] = factor;
  8041. - pRvlc->conceal_min = fMax(0, bnds - offset);
  8042. - return;
  8043. - } else {
  8044. - if (dpcm == MIN_RVL) {
  8045. - dpcm -= *pScfEsc--;
  8046. - } else {
  8047. - dpcm += *pScfEsc--;
  8048. - }
  8049. - (*pEscBwdCnt)++;
  8050. - if (pRvlc->conceal_min_esc == CONCEAL_MIN_INIT) {
  8051. - pRvlc->conceal_min_esc = fMax(0, bnds - offset);
  8052. - }
  8053. - }
  8054. - }
  8055. - pScfBwd[bnds] = factor;
  8056. - factor -= dpcm;
  8057. - pRvlc->firstScf = factor;
  8058. - break;
  8059. - }
  8060. - }
  8061. - }
  8062. -}
  8063. -
  8064. -/*---------------------------------------------------------------------------------------------
  8065. - function: rvlcFinalErrorDetection
  8066. -
  8067. - description: Call RVLC concealment if error was detected in decoding
  8068. -process
  8069. ------------------------------------------------------------------------------------------------
  8070. - input: - pointer rvlc structure
  8071. - - pointer channel info structure
  8072. ------------------------------------------------------------------------------------------------
  8073. - return: -
  8074. ---------------------------------------------------------------------------------------------
  8075. -*/
  8076. -
  8077. -static void rvlcFinalErrorDetection(
  8078. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  8079. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
  8080. - CErRvlcInfo *pRvlc =
  8081. - &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
  8082. - UCHAR ErrorStatusComplete = 0;
  8083. - UCHAR ErrorStatusLengthFwd = 0;
  8084. - UCHAR ErrorStatusLengthBwd = 0;
  8085. - UCHAR ErrorStatusLengthEscapes = 0;
  8086. - UCHAR ErrorStatusFirstScf = 0;
  8087. - UCHAR ErrorStatusLastScf = 0;
  8088. - UCHAR ErrorStatusFirstNrg = 0;
  8089. - UCHAR ErrorStatusLastNrg = 0;
  8090. - UCHAR ErrorStatusFirstIs = 0;
  8091. - UCHAR ErrorStatusLastIs = 0;
  8092. - UCHAR ErrorStatusForbiddenCwFwd = 0;
  8093. - UCHAR ErrorStatusForbiddenCwBwd = 0;
  8094. - UCHAR ErrorStatusNumEscapesFwd = 0;
  8095. - UCHAR ErrorStatusNumEscapesBwd = 0;
  8096. - UCHAR ConcealStatus = 1;
  8097. - UCHAR currentBlockType; /* short: 0, not short: 1*/
  8098. -
  8099. - pAacDecoderChannelInfo->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK = 1;
  8100. -
  8101. - /* invalid escape words, bit counter unequal zero, forbidden codeword detected
  8102. - */
  8103. - if (pRvlc->errorLogRvlc & RVLC_ERROR_FORBIDDEN_CW_DETECTED_FWD)
  8104. - ErrorStatusForbiddenCwFwd = 1;
  8105. -
  8106. - if (pRvlc->errorLogRvlc & RVLC_ERROR_FORBIDDEN_CW_DETECTED_BWD)
  8107. - ErrorStatusForbiddenCwBwd = 1;
  8108. -
  8109. - /* bit counter forward unequal zero */
  8110. - if (pRvlc->length_of_rvlc_sf_fwd) ErrorStatusLengthFwd = 1;
  8111. -
  8112. - /* bit counter backward unequal zero */
  8113. - if (pRvlc->length_of_rvlc_sf_bwd) ErrorStatusLengthBwd = 1;
  8114. -
  8115. - /* bit counter escape sequences unequal zero */
  8116. - if (pRvlc->sf_escapes_present)
  8117. - if (pRvlc->length_of_rvlc_escapes) ErrorStatusLengthEscapes = 1;
  8118. -
  8119. - if (pRvlc->sf_used) {
  8120. - /* first decoded scf does not match to global gain in backward direction */
  8121. - if (pRvlc->firstScf !=
  8122. - (pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET))
  8123. - ErrorStatusFirstScf = 1;
  8124. -
  8125. - /* last decoded scf does not match to rev global gain in forward direction
  8126. - */
  8127. - if (pRvlc->lastScf != (pRvlc->rev_global_gain - SF_OFFSET))
  8128. - ErrorStatusLastScf = 1;
  8129. - }
  8130. -
  8131. - if (pRvlc->noise_used) {
  8132. - /* first decoded nrg does not match to dpcm_noise_nrg in backward direction
  8133. - */
  8134. - if (pRvlc->firstNrg !=
  8135. - (pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain +
  8136. - pRvlc->dpcm_noise_nrg - SF_OFFSET - 90 - 256))
  8137. - ErrorStatusFirstNrg = 1;
  8138. -
  8139. - /* last decoded nrg does not match to dpcm_noise_last_position in forward
  8140. - * direction */
  8141. - if (pRvlc->lastNrg !=
  8142. - (pRvlc->rev_global_gain + pRvlc->dpcm_noise_last_position - SF_OFFSET -
  8143. - 90 - 256))
  8144. - ErrorStatusLastNrg = 1;
  8145. - }
  8146. -
  8147. - if (pRvlc->intensity_used) {
  8148. - /* first decoded is position does not match in backward direction */
  8149. - if (pRvlc->firstIs != (-SF_OFFSET)) ErrorStatusFirstIs = 1;
  8150. -
  8151. - /* last decoded is position does not match in forward direction */
  8152. - if (pRvlc->lastIs != (pRvlc->dpcm_is_last_position - SF_OFFSET))
  8153. - ErrorStatusLastIs = 1;
  8154. - }
  8155. -
  8156. - /* decoded escapes and used escapes in forward direction do not fit */
  8157. - if ((pRvlc->numDecodedEscapeWordsFwd != pRvlc->numDecodedEscapeWordsEsc) &&
  8158. - (pRvlc->conceal_max == CONCEAL_MAX_INIT)) {
  8159. - ErrorStatusNumEscapesFwd = 1;
  8160. - }
  8161. -
  8162. - /* decoded escapes and used escapes in backward direction do not fit */
  8163. - if ((pRvlc->numDecodedEscapeWordsBwd != pRvlc->numDecodedEscapeWordsEsc) &&
  8164. - (pRvlc->conceal_min == CONCEAL_MIN_INIT)) {
  8165. - ErrorStatusNumEscapesBwd = 1;
  8166. - }
  8167. -
  8168. - if (ErrorStatusLengthEscapes ||
  8169. - (((pRvlc->conceal_max == CONCEAL_MAX_INIT) &&
  8170. - (pRvlc->numDecodedEscapeWordsFwd != pRvlc->numDecodedEscapeWordsEsc) &&
  8171. - (ErrorStatusLastScf || ErrorStatusLastNrg || ErrorStatusLastIs))
  8172. -
  8173. - &&
  8174. -
  8175. - ((pRvlc->conceal_min == CONCEAL_MIN_INIT) &&
  8176. - (pRvlc->numDecodedEscapeWordsBwd != pRvlc->numDecodedEscapeWordsEsc) &&
  8177. - (ErrorStatusFirstScf || ErrorStatusFirstNrg || ErrorStatusFirstIs))) ||
  8178. - ((pRvlc->conceal_max == CONCEAL_MAX_INIT) &&
  8179. - ((pRvlc->rev_global_gain - SF_OFFSET - pRvlc->lastScf) < -15)) ||
  8180. - ((pRvlc->conceal_min == CONCEAL_MIN_INIT) &&
  8181. - ((pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET -
  8182. - pRvlc->firstScf) < -15))) {
  8183. - if ((pRvlc->conceal_max == CONCEAL_MAX_INIT) ||
  8184. - (pRvlc->conceal_min == CONCEAL_MIN_INIT)) {
  8185. - pRvlc->conceal_max = 0;
  8186. - pRvlc->conceal_min = fMax(
  8187. - 0, (pRvlc->numWindowGroups - 1) * 16 + pRvlc->maxSfbTransmitted - 1);
  8188. - } else {
  8189. - pRvlc->conceal_max = fMin(pRvlc->conceal_max, pRvlc->conceal_max_esc);
  8190. - pRvlc->conceal_min = fMax(pRvlc->conceal_min, pRvlc->conceal_min_esc);
  8191. - }
  8192. - }
  8193. -
  8194. - ErrorStatusComplete = ErrorStatusLastScf || ErrorStatusFirstScf ||
  8195. - ErrorStatusLastNrg || ErrorStatusFirstNrg ||
  8196. - ErrorStatusLastIs || ErrorStatusFirstIs ||
  8197. - ErrorStatusForbiddenCwFwd ||
  8198. - ErrorStatusForbiddenCwBwd || ErrorStatusLengthFwd ||
  8199. - ErrorStatusLengthBwd || ErrorStatusLengthEscapes ||
  8200. - ErrorStatusNumEscapesFwd || ErrorStatusNumEscapesBwd;
  8201. -
  8202. - currentBlockType =
  8203. - (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) ? 0
  8204. - : 1;
  8205. -
  8206. - if (!ErrorStatusComplete) {
  8207. - int band;
  8208. - int group;
  8209. - int bnds;
  8210. - int lastSfbIndex;
  8211. -
  8212. - lastSfbIndex = (pRvlc->numWindowGroups > 1) ? 16 : 64;
  8213. -
  8214. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  8215. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  8216. - bnds = 16 * group + band;
  8217. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  8218. - pAacDecoderStaticChannelInfo->concealmentInfo
  8219. - .aRvlcPreviousScaleFactor[bnds] =
  8220. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  8221. - }
  8222. - }
  8223. -
  8224. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  8225. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  8226. - bnds = 16 * group + band;
  8227. - pAacDecoderStaticChannelInfo->concealmentInfo
  8228. - .aRvlcPreviousCodebook[bnds] =
  8229. - pAacDecoderChannelInfo->pDynData->aCodeBook[bnds];
  8230. - }
  8231. - for (; band < lastSfbIndex; band++) {
  8232. - bnds = 16 * group + band;
  8233. - FDK_ASSERT(bnds >= 0 && bnds < RVLC_MAX_SFB);
  8234. - pAacDecoderStaticChannelInfo->concealmentInfo
  8235. - .aRvlcPreviousCodebook[bnds] = ZERO_HCB;
  8236. - }
  8237. - }
  8238. - } else {
  8239. - int band;
  8240. - int group;
  8241. -
  8242. - /* A single bit error was detected in decoding of dpcm values. It also could
  8243. - be an error with more bits in decoding of escapes and dpcm values whereby
  8244. - an illegal codeword followed not directly after the corrupted bits but
  8245. - just after decoding some more (wrong) scalefactors. Use the smaller
  8246. - scalefactor from forward decoding, backward decoding and previous frame.
  8247. - */
  8248. - if (((pRvlc->conceal_min != CONCEAL_MIN_INIT) ||
  8249. - (pRvlc->conceal_max != CONCEAL_MAX_INIT)) &&
  8250. - (pRvlc->conceal_min <= pRvlc->conceal_max) &&
  8251. - (pAacDecoderStaticChannelInfo->concealmentInfo.rvlcPreviousBlockType ==
  8252. - currentBlockType) &&
  8253. - pAacDecoderStaticChannelInfo->concealmentInfo
  8254. - .rvlcPreviousScaleFactorOK &&
  8255. - pRvlc->sf_concealment && ConcealStatus) {
  8256. - BidirectionalEstimation_UseScfOfPrevFrameAsReference(
  8257. - pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo);
  8258. - ConcealStatus = 0;
  8259. - }
  8260. -
  8261. - /* A single bit error was detected in decoding of dpcm values. It also could
  8262. - be an error with more bits in decoding of escapes and dpcm values whereby
  8263. - an illegal codeword followed not directly after the corrupted bits but
  8264. - just after decoding some more (wrong) scalefactors. Use the smaller
  8265. - scalefactor from forward and backward decoding. */
  8266. - if ((pRvlc->conceal_min <= pRvlc->conceal_max) &&
  8267. - ((pRvlc->conceal_min != CONCEAL_MIN_INIT) ||
  8268. - (pRvlc->conceal_max != CONCEAL_MAX_INIT)) &&
  8269. - !(pAacDecoderStaticChannelInfo->concealmentInfo
  8270. - .rvlcPreviousScaleFactorOK &&
  8271. - pRvlc->sf_concealment &&
  8272. - (pAacDecoderStaticChannelInfo->concealmentInfo
  8273. - .rvlcPreviousBlockType == currentBlockType)) &&
  8274. - ConcealStatus) {
  8275. - BidirectionalEstimation_UseLowerScfOfCurrentFrame(pAacDecoderChannelInfo);
  8276. - ConcealStatus = 0;
  8277. - }
  8278. -
  8279. - /* No errors were detected in decoding of escapes and dpcm values however
  8280. - the first and last value of a group (is,nrg,sf) is incorrect */
  8281. - if ((pRvlc->conceal_min <= pRvlc->conceal_max) &&
  8282. - ((ErrorStatusLastScf && ErrorStatusFirstScf) ||
  8283. - (ErrorStatusLastNrg && ErrorStatusFirstNrg) ||
  8284. - (ErrorStatusLastIs && ErrorStatusFirstIs)) &&
  8285. - !(ErrorStatusForbiddenCwFwd || ErrorStatusForbiddenCwBwd ||
  8286. - ErrorStatusLengthEscapes) &&
  8287. - ConcealStatus) {
  8288. - StatisticalEstimation(pAacDecoderChannelInfo);
  8289. - ConcealStatus = 0;
  8290. - }
  8291. -
  8292. - /* A error with more bits in decoding of escapes and dpcm values was
  8293. - detected. Use the smaller scalefactor from forward decoding, backward
  8294. - decoding and previous frame. */
  8295. - if ((pRvlc->conceal_min <= pRvlc->conceal_max) &&
  8296. - pAacDecoderStaticChannelInfo->concealmentInfo
  8297. - .rvlcPreviousScaleFactorOK &&
  8298. - pRvlc->sf_concealment &&
  8299. - (pAacDecoderStaticChannelInfo->concealmentInfo.rvlcPreviousBlockType ==
  8300. - currentBlockType) &&
  8301. - ConcealStatus) {
  8302. - PredictiveInterpolation(pAacDecoderChannelInfo,
  8303. - pAacDecoderStaticChannelInfo);
  8304. - ConcealStatus = 0;
  8305. - }
  8306. -
  8307. - /* Call frame concealment, because no better strategy was found. Setting the
  8308. - scalefactors to zero is done for debugging purposes */
  8309. - if (ConcealStatus) {
  8310. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  8311. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  8312. - pAacDecoderChannelInfo->pDynData->aScaleFactor[16 * group + band] = 0;
  8313. - }
  8314. - }
  8315. - pAacDecoderChannelInfo->pDynData->specificTo.aac
  8316. - .rvlcCurrentScaleFactorOK = 0;
  8317. - }
  8318. - }
  8319. -}
  8320. -
  8321. -/*---------------------------------------------------------------------------------------------
  8322. - function: CRvlc_Read
  8323. -
  8324. - description: Read RVLC ESC1 data (side info) from bitstream.
  8325. ------------------------------------------------------------------------------------------------
  8326. - input: - pointer rvlc structure
  8327. - - pointer channel info structure
  8328. - - pointer bitstream structure
  8329. ------------------------------------------------------------------------------------------------
  8330. - return: -
  8331. ---------------------------------------------------------------------------------------------
  8332. -*/
  8333. -
  8334. -void CRvlc_Read(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  8335. - HANDLE_FDK_BITSTREAM bs) {
  8336. - CErRvlcInfo *pRvlc =
  8337. - &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
  8338. -
  8339. - int group, band;
  8340. -
  8341. - /* RVLC long specific initialization Init part 1 of 2 */
  8342. - pRvlc->numWindowGroups = GetWindowGroups(&pAacDecoderChannelInfo->icsInfo);
  8343. - pRvlc->maxSfbTransmitted =
  8344. - GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->icsInfo);
  8345. - pRvlc->noise_used = 0; /* noise detection */
  8346. - pRvlc->dpcm_noise_nrg = 0; /* only for debugging */
  8347. - pRvlc->dpcm_noise_last_position = 0; /* only for debugging */
  8348. - pRvlc->length_of_rvlc_escapes =
  8349. - -1; /* default value is used for error detection and concealment */
  8350. -
  8351. - /* read only error sensitivity class 1 data (ESC 1 - data) */
  8352. - pRvlc->sf_concealment = FDKreadBits(bs, 1); /* #1 */
  8353. - pRvlc->rev_global_gain = FDKreadBits(bs, 8); /* #2 */
  8354. -
  8355. - if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) {
  8356. - pRvlc->length_of_rvlc_sf = FDKreadBits(bs, 11); /* #3 */
  8357. - } else {
  8358. - pRvlc->length_of_rvlc_sf = FDKreadBits(bs, 9); /* #3 */
  8359. - }
  8360. -
  8361. - /* check if noise codebook is used */
  8362. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  8363. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  8364. - if (pAacDecoderChannelInfo->pDynData->aCodeBook[16 * group + band] ==
  8365. - NOISE_HCB) {
  8366. - pRvlc->noise_used = 1;
  8367. - break;
  8368. - }
  8369. - }
  8370. - }
  8371. -
  8372. - if (pRvlc->noise_used)
  8373. - pRvlc->dpcm_noise_nrg = FDKreadBits(bs, 9); /* #4 PNS */
  8374. -
  8375. - pRvlc->sf_escapes_present = FDKreadBits(bs, 1); /* #5 */
  8376. -
  8377. - if (pRvlc->sf_escapes_present) {
  8378. - pRvlc->length_of_rvlc_escapes = FDKreadBits(bs, 8); /* #6 */
  8379. - }
  8380. -
  8381. - if (pRvlc->noise_used) {
  8382. - pRvlc->dpcm_noise_last_position = FDKreadBits(bs, 9); /* #7 PNS */
  8383. - pRvlc->length_of_rvlc_sf -= 9;
  8384. - }
  8385. -
  8386. - pRvlc->length_of_rvlc_sf_fwd = pRvlc->length_of_rvlc_sf;
  8387. - pRvlc->length_of_rvlc_sf_bwd = pRvlc->length_of_rvlc_sf;
  8388. -}
  8389. -
  8390. -/*---------------------------------------------------------------------------------------------
  8391. - function: CRvlc_Decode
  8392. -
  8393. - description: Decode rvlc data
  8394. - The function reads both the escape sequences and the
  8395. -scalefactors in forward and backward direction. If an error occured during
  8396. -decoding process which can not be concealed with the rvlc concealment frame
  8397. -concealment will be initiated. Then the element "rvlcCurrentScaleFactorOK" in
  8398. -the decoder channel info is set to 0 otherwise it is set to 1.
  8399. ------------------------------------------------------------------------------------------------
  8400. - input: - pointer rvlc structure
  8401. - - pointer channel info structure
  8402. - - pointer to persistent channel info structure
  8403. - - pointer bitstream structure
  8404. ------------------------------------------------------------------------------------------------
  8405. - return: ErrorStatus = AAC_DEC_OK
  8406. ---------------------------------------------------------------------------------------------
  8407. -*/
  8408. -
  8409. -void CRvlc_Decode(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  8410. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  8411. - HANDLE_FDK_BITSTREAM bs) {
  8412. - CErRvlcInfo *pRvlc =
  8413. - &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
  8414. - INT bitCntOffst;
  8415. - INT saveBitCnt;
  8416. -
  8417. - rvlcInit(pRvlc, pAacDecoderChannelInfo, bs);
  8418. -
  8419. - /* save bitstream position */
  8420. - saveBitCnt = (INT)FDKgetValidBits(bs);
  8421. -
  8422. - if (pRvlc->sf_escapes_present)
  8423. - rvlcDecodeEscapes(
  8424. - pRvlc, pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfEsc, bs);
  8425. -
  8426. - rvlcDecodeForward(pRvlc, pAacDecoderChannelInfo, bs);
  8427. - rvlcDecodeBackward(pRvlc, pAacDecoderChannelInfo, bs);
  8428. - rvlcFinalErrorDetection(pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo);
  8429. -
  8430. - pAacDecoderChannelInfo->pDynData->specificTo.aac.rvlcIntensityUsed =
  8431. - pRvlc->intensity_used;
  8432. - pAacDecoderChannelInfo->data.aac.PnsData.PnsActive = pRvlc->noise_used;
  8433. -
  8434. - /* restore bitstream position */
  8435. - bitCntOffst = (INT)FDKgetValidBits(bs) - saveBitCnt;
  8436. - if (bitCntOffst) {
  8437. - FDKpushBiDirectional(bs, bitCntOffst);
  8438. - }
  8439. -}
  8440. -
  8441. -void CRvlc_ElementCheck(
  8442. - CAacDecoderChannelInfo *pAacDecoderChannelInfo[],
  8443. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo[],
  8444. - const UINT flags, const INT elChannels) {
  8445. - int ch;
  8446. -
  8447. - /* Required for MPS residuals. */
  8448. - if (pAacDecoderStaticChannelInfo == NULL) {
  8449. - return;
  8450. - }
  8451. -
  8452. - /* RVLC specific sanity checks */
  8453. - if ((flags & AC_ER_RVLC) && (elChannels == 2)) { /* to be reviewed */
  8454. - if (((pAacDecoderChannelInfo[0]
  8455. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK == 0) ||
  8456. - (pAacDecoderChannelInfo[1]
  8457. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK == 0)) &&
  8458. - pAacDecoderChannelInfo[0]->pComData->jointStereoData.MsMaskPresent) {
  8459. - pAacDecoderChannelInfo[0]
  8460. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK = 0;
  8461. - pAacDecoderChannelInfo[1]
  8462. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK = 0;
  8463. - }
  8464. -
  8465. - if ((pAacDecoderChannelInfo[0]
  8466. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK == 0) &&
  8467. - (pAacDecoderChannelInfo[1]
  8468. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK == 1) &&
  8469. - (pAacDecoderChannelInfo[1]
  8470. - ->pDynData->specificTo.aac.rvlcIntensityUsed == 1)) {
  8471. - pAacDecoderChannelInfo[1]
  8472. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK = 0;
  8473. - }
  8474. - }
  8475. -
  8476. - for (ch = 0; ch < elChannels; ch++) {
  8477. - pAacDecoderStaticChannelInfo[ch]->concealmentInfo.rvlcPreviousBlockType =
  8478. - (GetWindowSequence(&pAacDecoderChannelInfo[ch]->icsInfo) == BLOCK_SHORT)
  8479. - ? 0
  8480. - : 1;
  8481. - if (flags & AC_ER_RVLC) {
  8482. - pAacDecoderStaticChannelInfo[ch]
  8483. - ->concealmentInfo.rvlcPreviousScaleFactorOK =
  8484. - pAacDecoderChannelInfo[ch]
  8485. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK;
  8486. - } else {
  8487. - pAacDecoderStaticChannelInfo[ch]
  8488. - ->concealmentInfo.rvlcPreviousScaleFactorOK = 0;
  8489. - }
  8490. - }
  8491. -}
  8492. --- a/libAACdec/src/rvlc.h
  8493. +++ /dev/null
  8494. @@ -1,153 +0,0 @@
  8495. -/* -----------------------------------------------------------------------------
  8496. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  8497. -
  8498. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  8499. -Forschung e.V. All rights reserved.
  8500. -
  8501. - 1. INTRODUCTION
  8502. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  8503. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  8504. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  8505. -a wide variety of Android devices.
  8506. -
  8507. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  8508. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  8509. -full-bandwidth communications codec by independent studies and is widely
  8510. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  8511. -specifications.
  8512. -
  8513. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  8514. -those of Fraunhofer) may be obtained through Via Licensing
  8515. -(www.vialicensing.com) or through the respective patent owners individually for
  8516. -the purpose of encoding or decoding bit streams in products that are compliant
  8517. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  8518. -Android devices already license these patent claims through Via Licensing or
  8519. -directly from the patent owners, and therefore FDK AAC Codec software may
  8520. -already be covered under those patent licenses when it is used for those
  8521. -licensed purposes only.
  8522. -
  8523. -Commercially-licensed AAC software libraries, including floating-point versions
  8524. -with enhanced sound quality, are also available from Fraunhofer. Users are
  8525. -encouraged to check the Fraunhofer website for additional applications
  8526. -information and documentation.
  8527. -
  8528. -2. COPYRIGHT LICENSE
  8529. -
  8530. -Redistribution and use in source and binary forms, with or without modification,
  8531. -are permitted without payment of copyright license fees provided that you
  8532. -satisfy the following conditions:
  8533. -
  8534. -You must retain the complete text of this software license in redistributions of
  8535. -the FDK AAC Codec or your modifications thereto in source code form.
  8536. -
  8537. -You must retain the complete text of this software license in the documentation
  8538. -and/or other materials provided with redistributions of the FDK AAC Codec or
  8539. -your modifications thereto in binary form. You must make available free of
  8540. -charge copies of the complete source code of the FDK AAC Codec and your
  8541. -modifications thereto to recipients of copies in binary form.
  8542. -
  8543. -The name of Fraunhofer may not be used to endorse or promote products derived
  8544. -from this library without prior written permission.
  8545. -
  8546. -You may not charge copyright license fees for anyone to use, copy or distribute
  8547. -the FDK AAC Codec software or your modifications thereto.
  8548. -
  8549. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  8550. -that you changed the software and the date of any change. For modified versions
  8551. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  8552. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  8553. -AAC Codec Library for Android."
  8554. -
  8555. -3. NO PATENT LICENSE
  8556. -
  8557. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  8558. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  8559. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  8560. -software.
  8561. -
  8562. -You may use this FDK AAC Codec software or modifications thereto only for
  8563. -purposes that are authorized by appropriate patent licenses.
  8564. -
  8565. -4. DISCLAIMER
  8566. -
  8567. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  8568. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  8569. -including but not limited to the implied warranties of merchantability and
  8570. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  8571. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  8572. -or consequential damages, including but not limited to procurement of substitute
  8573. -goods or services; loss of use, data, or profits, or business interruption,
  8574. -however caused and on any theory of liability, whether in contract, strict
  8575. -liability, or tort (including negligence), arising in any way out of the use of
  8576. -this software, even if advised of the possibility of such damage.
  8577. -
  8578. -5. CONTACT INFORMATION
  8579. -
  8580. -Fraunhofer Institute for Integrated Circuits IIS
  8581. -Attention: Audio and Multimedia Departments - FDK AAC LL
  8582. -Am Wolfsmantel 33
  8583. -91058 Erlangen, Germany
  8584. -
  8585. -www.iis.fraunhofer.de/amm
  8586. -amm-info@iis.fraunhofer.de
  8587. ------------------------------------------------------------------------------ */
  8588. -
  8589. -/**************************** AAC decoder library ******************************
  8590. -
  8591. - Author(s):
  8592. -
  8593. - Description:
  8594. -
  8595. -*******************************************************************************/
  8596. -
  8597. -/*!
  8598. - \file
  8599. - \brief Defines structures and prototypes for RVLC
  8600. - \author Robert Weidner
  8601. -*/
  8602. -
  8603. -#ifndef RVLC_H
  8604. -#define RVLC_H
  8605. -
  8606. -#include "aacdecoder.h"
  8607. -#include "channel.h"
  8608. -#include "rvlc_info.h"
  8609. -
  8610. -/* ------------------------------------------------------------------- */
  8611. -/* errorLogRvlc: A word of 32 bits used for logging possible errors */
  8612. -/* within RVLC in case of distorted bitstreams. */
  8613. -/* ------------------------------------------------------------------- */
  8614. -#define RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID \
  8615. - 0x80000000 /* ESC-Dec During RVLC-Escape-decoding there have been more \
  8616. - bits decoded as there are available */
  8617. -#define RVLC_ERROR_RVL_SUM_BIT_COUNTER_BELOW_ZERO_FWD \
  8618. - 0x40000000 /* RVL-Dec negative sum-bitcounter during RVL-fwd-decoding \
  8619. - (long+shrt) */
  8620. -#define RVLC_ERROR_RVL_SUM_BIT_COUNTER_BELOW_ZERO_BWD \
  8621. - 0x20000000 /* RVL-Dec negative sum-bitcounter during RVL-fwd-decoding \
  8622. - (long+shrt) */
  8623. -#define RVLC_ERROR_FORBIDDEN_CW_DETECTED_FWD \
  8624. - 0x08000000 /* RVL-Dec forbidden codeword detected fwd (long+shrt) */
  8625. -#define RVLC_ERROR_FORBIDDEN_CW_DETECTED_BWD \
  8626. - 0x04000000 /* RVL-Dec forbidden codeword detected bwd (long+shrt) */
  8627. -
  8628. -void CRvlc_Read(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  8629. - HANDLE_FDK_BITSTREAM bs);
  8630. -
  8631. -void CRvlc_Decode(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  8632. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  8633. - HANDLE_FDK_BITSTREAM bs);
  8634. -
  8635. -/**
  8636. - * \brief performe sanity checks to the channel data corresponding to one
  8637. - * channel element.
  8638. - * \param pAacDecoderChannelInfo
  8639. - * \param pAacDecoderStaticChannelInfo
  8640. - * \param elChannels amount of channels of the channel element.
  8641. - */
  8642. -void CRvlc_ElementCheck(
  8643. - CAacDecoderChannelInfo *pAacDecoderChannelInfo[],
  8644. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo[],
  8645. - const UINT flags, const INT elChannels);
  8646. -
  8647. -#endif /* RVLC_H */
  8648. --- a/libAACdec/src/rvlc_info.h
  8649. +++ /dev/null
  8650. @@ -1,204 +0,0 @@
  8651. -/* -----------------------------------------------------------------------------
  8652. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  8653. -
  8654. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  8655. -Forschung e.V. All rights reserved.
  8656. -
  8657. - 1. INTRODUCTION
  8658. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  8659. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  8660. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  8661. -a wide variety of Android devices.
  8662. -
  8663. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  8664. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  8665. -full-bandwidth communications codec by independent studies and is widely
  8666. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  8667. -specifications.
  8668. -
  8669. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  8670. -those of Fraunhofer) may be obtained through Via Licensing
  8671. -(www.vialicensing.com) or through the respective patent owners individually for
  8672. -the purpose of encoding or decoding bit streams in products that are compliant
  8673. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  8674. -Android devices already license these patent claims through Via Licensing or
  8675. -directly from the patent owners, and therefore FDK AAC Codec software may
  8676. -already be covered under those patent licenses when it is used for those
  8677. -licensed purposes only.
  8678. -
  8679. -Commercially-licensed AAC software libraries, including floating-point versions
  8680. -with enhanced sound quality, are also available from Fraunhofer. Users are
  8681. -encouraged to check the Fraunhofer website for additional applications
  8682. -information and documentation.
  8683. -
  8684. -2. COPYRIGHT LICENSE
  8685. -
  8686. -Redistribution and use in source and binary forms, with or without modification,
  8687. -are permitted without payment of copyright license fees provided that you
  8688. -satisfy the following conditions:
  8689. -
  8690. -You must retain the complete text of this software license in redistributions of
  8691. -the FDK AAC Codec or your modifications thereto in source code form.
  8692. -
  8693. -You must retain the complete text of this software license in the documentation
  8694. -and/or other materials provided with redistributions of the FDK AAC Codec or
  8695. -your modifications thereto in binary form. You must make available free of
  8696. -charge copies of the complete source code of the FDK AAC Codec and your
  8697. -modifications thereto to recipients of copies in binary form.
  8698. -
  8699. -The name of Fraunhofer may not be used to endorse or promote products derived
  8700. -from this library without prior written permission.
  8701. -
  8702. -You may not charge copyright license fees for anyone to use, copy or distribute
  8703. -the FDK AAC Codec software or your modifications thereto.
  8704. -
  8705. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  8706. -that you changed the software and the date of any change. For modified versions
  8707. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  8708. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  8709. -AAC Codec Library for Android."
  8710. -
  8711. -3. NO PATENT LICENSE
  8712. -
  8713. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  8714. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  8715. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  8716. -software.
  8717. -
  8718. -You may use this FDK AAC Codec software or modifications thereto only for
  8719. -purposes that are authorized by appropriate patent licenses.
  8720. -
  8721. -4. DISCLAIMER
  8722. -
  8723. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  8724. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  8725. -including but not limited to the implied warranties of merchantability and
  8726. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  8727. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  8728. -or consequential damages, including but not limited to procurement of substitute
  8729. -goods or services; loss of use, data, or profits, or business interruption,
  8730. -however caused and on any theory of liability, whether in contract, strict
  8731. -liability, or tort (including negligence), arising in any way out of the use of
  8732. -this software, even if advised of the possibility of such damage.
  8733. -
  8734. -5. CONTACT INFORMATION
  8735. -
  8736. -Fraunhofer Institute for Integrated Circuits IIS
  8737. -Attention: Audio and Multimedia Departments - FDK AAC LL
  8738. -Am Wolfsmantel 33
  8739. -91058 Erlangen, Germany
  8740. -
  8741. -www.iis.fraunhofer.de/amm
  8742. -amm-info@iis.fraunhofer.de
  8743. ------------------------------------------------------------------------------ */
  8744. -
  8745. -/**************************** AAC decoder library ******************************
  8746. -
  8747. - Author(s):
  8748. -
  8749. - Description:
  8750. -
  8751. -*******************************************************************************/
  8752. -
  8753. -/*!
  8754. - \file
  8755. - \brief Defines structures for RVLC
  8756. - \author Robert Weidner
  8757. -*/
  8758. -#ifndef RVLC_INFO_H
  8759. -#define RVLC_INFO_H
  8760. -
  8761. -#define FWD 0 /* bitstream decoding direction forward (RVL coded part) */
  8762. -#define BWD 1 /* bitstream decoding direction backward (RVL coded part) */
  8763. -
  8764. -#define MAX_RVL 7 /* positive RVLC escape */
  8765. -#define MIN_RVL -7 /* negative RVLC escape */
  8766. -#define MAX_ALLOWED_DPCM_INDEX \
  8767. - 14 /* the maximum allowed index of a decoded dpcm value (offset \
  8768. - 'TABLE_OFFSET' incl --> must be subtracted) */
  8769. -#define TABLE_OFFSET \
  8770. - 7 /* dpcm offset of valid output values of rvl table decoding, the rvl table \
  8771. - ouly returns positive values, therefore the offset */
  8772. -#define MAX_LEN_RVLC_CODE_WORD 9 /* max length of a RVL codeword in bits */
  8773. -#define MAX_LEN_RVLC_ESCAPE_WORD \
  8774. - 20 /* max length of huffman coded RVLC escape word in bits */
  8775. -
  8776. -#define DPCM_NOISE_NRG_BITS 9
  8777. -#define SF_OFFSET 100 /* offset for correcting scf value */
  8778. -
  8779. -#define CONCEAL_MAX_INIT 1311 /* arbitrary value */
  8780. -#define CONCEAL_MIN_INIT -1311 /* arbitrary value */
  8781. -
  8782. -#define RVLC_MAX_SFB ((8) * (16))
  8783. -
  8784. -/* sideinfo of RVLC */
  8785. -typedef struct {
  8786. - /* ------- ESC 1 Data: --------- */ /* order of RVLC-bitstream components in
  8787. - bitstream (RVLC-initialization), every
  8788. - component appears only once in
  8789. - bitstream */
  8790. - INT sf_concealment; /* 1 */
  8791. - INT rev_global_gain; /* 2 */
  8792. - SHORT length_of_rvlc_sf; /* 3 */ /* original value, gets modified
  8793. - (subtract 9) in case of noise
  8794. - (PNS); is kept for later use */
  8795. - INT dpcm_noise_nrg; /* 4 optional */
  8796. - INT sf_escapes_present; /* 5 */
  8797. - SHORT length_of_rvlc_escapes; /* 6 optional */
  8798. - INT dpcm_noise_last_position; /* 7 optional */
  8799. -
  8800. - INT dpcm_is_last_position;
  8801. -
  8802. - SHORT length_of_rvlc_sf_fwd; /* length_of_rvlc_sf used for forward decoding */
  8803. - SHORT
  8804. - length_of_rvlc_sf_bwd; /* length_of_rvlc_sf used for backward decoding */
  8805. -
  8806. - /* for RVL-Codeword decoder to distinguish between fwd and bwd decoding */
  8807. - SHORT *pRvlBitCnt_RVL;
  8808. - INT *pBitstrIndxRvl_RVL;
  8809. -
  8810. - UCHAR numWindowGroups;
  8811. - UCHAR maxSfbTransmitted;
  8812. - UCHAR first_noise_group;
  8813. - UCHAR first_noise_band;
  8814. - UCHAR direction;
  8815. -
  8816. - /* bitstream indices */
  8817. - INT bsAnchor; /* hcr bit buffer reference index */
  8818. - INT bitstreamIndexRvlFwd; /* base address of RVL-coded-scalefactor data (ESC
  8819. - 2) for forward decoding */
  8820. - INT bitstreamIndexRvlBwd; /* base address of RVL-coded-scalefactor data (ESC
  8821. - 2) for backward decoding */
  8822. - INT bitstreamIndexEsc; /* base address where RVLC-escapes start (ESC 2) */
  8823. -
  8824. - /* decoding trees */
  8825. - const UINT *pHuffTreeRvlCodewds;
  8826. - const UINT *pHuffTreeRvlcEscape;
  8827. -
  8828. - /* escape counters */
  8829. - UCHAR numDecodedEscapeWordsFwd; /* when decoding RVL-codes forward */
  8830. - UCHAR numDecodedEscapeWordsBwd; /* when decoding RVL-codes backward */
  8831. - UCHAR numDecodedEscapeWordsEsc; /* when decoding the escape-Words */
  8832. -
  8833. - SCHAR noise_used;
  8834. - SCHAR intensity_used;
  8835. - SCHAR sf_used;
  8836. -
  8837. - SHORT firstScf;
  8838. - SHORT lastScf;
  8839. - SHORT firstNrg;
  8840. - SHORT lastNrg;
  8841. - SHORT firstIs;
  8842. - SHORT lastIs;
  8843. -
  8844. - /* ------ RVLC error detection ------ */
  8845. - UINT errorLogRvlc; /* store RVLC errors */
  8846. - SHORT conceal_min; /* is set at backward decoding */
  8847. - SHORT conceal_max; /* is set at forward decoding */
  8848. - SHORT conceal_min_esc; /* is set at backward decoding */
  8849. - SHORT conceal_max_esc; /* is set at forward decoding */
  8850. -} CErRvlcInfo;
  8851. -
  8852. -typedef CErRvlcInfo RVLC_INFO; /* temp */
  8853. -
  8854. -#endif /* RVLC_INFO_H */
  8855. --- a/libAACdec/src/rvlcbit.cpp
  8856. +++ /dev/null
  8857. @@ -1,148 +0,0 @@
  8858. -/* -----------------------------------------------------------------------------
  8859. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  8860. -
  8861. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  8862. -Forschung e.V. All rights reserved.
  8863. -
  8864. - 1. INTRODUCTION
  8865. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  8866. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  8867. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  8868. -a wide variety of Android devices.
  8869. -
  8870. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  8871. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  8872. -full-bandwidth communications codec by independent studies and is widely
  8873. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  8874. -specifications.
  8875. -
  8876. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  8877. -those of Fraunhofer) may be obtained through Via Licensing
  8878. -(www.vialicensing.com) or through the respective patent owners individually for
  8879. -the purpose of encoding or decoding bit streams in products that are compliant
  8880. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  8881. -Android devices already license these patent claims through Via Licensing or
  8882. -directly from the patent owners, and therefore FDK AAC Codec software may
  8883. -already be covered under those patent licenses when it is used for those
  8884. -licensed purposes only.
  8885. -
  8886. -Commercially-licensed AAC software libraries, including floating-point versions
  8887. -with enhanced sound quality, are also available from Fraunhofer. Users are
  8888. -encouraged to check the Fraunhofer website for additional applications
  8889. -information and documentation.
  8890. -
  8891. -2. COPYRIGHT LICENSE
  8892. -
  8893. -Redistribution and use in source and binary forms, with or without modification,
  8894. -are permitted without payment of copyright license fees provided that you
  8895. -satisfy the following conditions:
  8896. -
  8897. -You must retain the complete text of this software license in redistributions of
  8898. -the FDK AAC Codec or your modifications thereto in source code form.
  8899. -
  8900. -You must retain the complete text of this software license in the documentation
  8901. -and/or other materials provided with redistributions of the FDK AAC Codec or
  8902. -your modifications thereto in binary form. You must make available free of
  8903. -charge copies of the complete source code of the FDK AAC Codec and your
  8904. -modifications thereto to recipients of copies in binary form.
  8905. -
  8906. -The name of Fraunhofer may not be used to endorse or promote products derived
  8907. -from this library without prior written permission.
  8908. -
  8909. -You may not charge copyright license fees for anyone to use, copy or distribute
  8910. -the FDK AAC Codec software or your modifications thereto.
  8911. -
  8912. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  8913. -that you changed the software and the date of any change. For modified versions
  8914. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  8915. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  8916. -AAC Codec Library for Android."
  8917. -
  8918. -3. NO PATENT LICENSE
  8919. -
  8920. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  8921. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  8922. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  8923. -software.
  8924. -
  8925. -You may use this FDK AAC Codec software or modifications thereto only for
  8926. -purposes that are authorized by appropriate patent licenses.
  8927. -
  8928. -4. DISCLAIMER
  8929. -
  8930. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  8931. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  8932. -including but not limited to the implied warranties of merchantability and
  8933. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  8934. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  8935. -or consequential damages, including but not limited to procurement of substitute
  8936. -goods or services; loss of use, data, or profits, or business interruption,
  8937. -however caused and on any theory of liability, whether in contract, strict
  8938. -liability, or tort (including negligence), arising in any way out of the use of
  8939. -this software, even if advised of the possibility of such damage.
  8940. -
  8941. -5. CONTACT INFORMATION
  8942. -
  8943. -Fraunhofer Institute for Integrated Circuits IIS
  8944. -Attention: Audio and Multimedia Departments - FDK AAC LL
  8945. -Am Wolfsmantel 33
  8946. -91058 Erlangen, Germany
  8947. -
  8948. -www.iis.fraunhofer.de/amm
  8949. -amm-info@iis.fraunhofer.de
  8950. ------------------------------------------------------------------------------ */
  8951. -
  8952. -/**************************** AAC decoder library ******************************
  8953. -
  8954. - Author(s):
  8955. -
  8956. - Description:
  8957. -
  8958. -*******************************************************************************/
  8959. -
  8960. -/*!
  8961. - \file
  8962. - \brief RVLC bitstream reading
  8963. - \author Robert Weidner
  8964. -*/
  8965. -
  8966. -#include "rvlcbit.h"
  8967. -
  8968. -/*---------------------------------------------------------------------------------------------
  8969. - function: rvlcReadBitFromBitstream
  8970. -
  8971. - description: This function returns a bit from the bitstream according to
  8972. -read direction. It is called very often, therefore it makes sense to inline it
  8973. -(runtime).
  8974. ------------------------------------------------------------------------------------------------
  8975. - input: - bitstream
  8976. - - pPosition
  8977. - - readDirection
  8978. ------------------------------------------------------------------------------------------------
  8979. - return: - bit from bitstream
  8980. ---------------------------------------------------------------------------------------------
  8981. -*/
  8982. -
  8983. -UCHAR rvlcReadBitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  8984. - INT *pPosition, UCHAR readDirection) {
  8985. - UINT bit;
  8986. - INT readBitOffset = (INT)FDKgetValidBits(bs) - bsAnchor + *pPosition;
  8987. -
  8988. - if (readBitOffset) {
  8989. - FDKpushBiDirectional(bs, readBitOffset);
  8990. - }
  8991. -
  8992. - if (readDirection == FWD) {
  8993. - bit = FDKreadBits(bs, 1);
  8994. -
  8995. - *pPosition += 1;
  8996. - } else {
  8997. - /* to be replaced with a brother function of FDKreadBits() */
  8998. - bit = FDKreadBits(bs, 1);
  8999. - FDKpushBack(bs, 2);
  9000. -
  9001. - *pPosition -= 1;
  9002. - }
  9003. -
  9004. - return (bit);
  9005. -}
  9006. --- a/libAACdec/src/rvlcbit.h
  9007. +++ /dev/null
  9008. @@ -1,111 +0,0 @@
  9009. -/* -----------------------------------------------------------------------------
  9010. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  9011. -
  9012. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  9013. -Forschung e.V. All rights reserved.
  9014. -
  9015. - 1. INTRODUCTION
  9016. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  9017. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  9018. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  9019. -a wide variety of Android devices.
  9020. -
  9021. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  9022. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  9023. -full-bandwidth communications codec by independent studies and is widely
  9024. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  9025. -specifications.
  9026. -
  9027. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  9028. -those of Fraunhofer) may be obtained through Via Licensing
  9029. -(www.vialicensing.com) or through the respective patent owners individually for
  9030. -the purpose of encoding or decoding bit streams in products that are compliant
  9031. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  9032. -Android devices already license these patent claims through Via Licensing or
  9033. -directly from the patent owners, and therefore FDK AAC Codec software may
  9034. -already be covered under those patent licenses when it is used for those
  9035. -licensed purposes only.
  9036. -
  9037. -Commercially-licensed AAC software libraries, including floating-point versions
  9038. -with enhanced sound quality, are also available from Fraunhofer. Users are
  9039. -encouraged to check the Fraunhofer website for additional applications
  9040. -information and documentation.
  9041. -
  9042. -2. COPYRIGHT LICENSE
  9043. -
  9044. -Redistribution and use in source and binary forms, with or without modification,
  9045. -are permitted without payment of copyright license fees provided that you
  9046. -satisfy the following conditions:
  9047. -
  9048. -You must retain the complete text of this software license in redistributions of
  9049. -the FDK AAC Codec or your modifications thereto in source code form.
  9050. -
  9051. -You must retain the complete text of this software license in the documentation
  9052. -and/or other materials provided with redistributions of the FDK AAC Codec or
  9053. -your modifications thereto in binary form. You must make available free of
  9054. -charge copies of the complete source code of the FDK AAC Codec and your
  9055. -modifications thereto to recipients of copies in binary form.
  9056. -
  9057. -The name of Fraunhofer may not be used to endorse or promote products derived
  9058. -from this library without prior written permission.
  9059. -
  9060. -You may not charge copyright license fees for anyone to use, copy or distribute
  9061. -the FDK AAC Codec software or your modifications thereto.
  9062. -
  9063. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  9064. -that you changed the software and the date of any change. For modified versions
  9065. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  9066. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  9067. -AAC Codec Library for Android."
  9068. -
  9069. -3. NO PATENT LICENSE
  9070. -
  9071. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  9072. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  9073. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  9074. -software.
  9075. -
  9076. -You may use this FDK AAC Codec software or modifications thereto only for
  9077. -purposes that are authorized by appropriate patent licenses.
  9078. -
  9079. -4. DISCLAIMER
  9080. -
  9081. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  9082. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  9083. -including but not limited to the implied warranties of merchantability and
  9084. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  9085. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  9086. -or consequential damages, including but not limited to procurement of substitute
  9087. -goods or services; loss of use, data, or profits, or business interruption,
  9088. -however caused and on any theory of liability, whether in contract, strict
  9089. -liability, or tort (including negligence), arising in any way out of the use of
  9090. -this software, even if advised of the possibility of such damage.
  9091. -
  9092. -5. CONTACT INFORMATION
  9093. -
  9094. -Fraunhofer Institute for Integrated Circuits IIS
  9095. -Attention: Audio and Multimedia Departments - FDK AAC LL
  9096. -Am Wolfsmantel 33
  9097. -91058 Erlangen, Germany
  9098. -
  9099. -www.iis.fraunhofer.de/amm
  9100. -amm-info@iis.fraunhofer.de
  9101. ------------------------------------------------------------------------------ */
  9102. -
  9103. -/**************************** AAC decoder library ******************************
  9104. -
  9105. - Author(s): Robert Weidner (DSP Solutions)
  9106. -
  9107. - Description: RVLC Decoder: Bitstream reading
  9108. -
  9109. -*******************************************************************************/
  9110. -
  9111. -#ifndef RVLCBIT_H
  9112. -#define RVLCBIT_H
  9113. -
  9114. -#include "rvlc.h"
  9115. -
  9116. -UCHAR rvlcReadBitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  9117. - INT *pPosition, UCHAR readDirection);
  9118. -
  9119. -#endif /* RVLCBIT_H */
  9120. --- a/libAACdec/src/rvlcconceal.cpp
  9121. +++ /dev/null
  9122. @@ -1,787 +0,0 @@
  9123. -/* -----------------------------------------------------------------------------
  9124. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  9125. -
  9126. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  9127. -Forschung e.V. All rights reserved.
  9128. -
  9129. - 1. INTRODUCTION
  9130. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  9131. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  9132. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  9133. -a wide variety of Android devices.
  9134. -
  9135. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  9136. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  9137. -full-bandwidth communications codec by independent studies and is widely
  9138. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  9139. -specifications.
  9140. -
  9141. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  9142. -those of Fraunhofer) may be obtained through Via Licensing
  9143. -(www.vialicensing.com) or through the respective patent owners individually for
  9144. -the purpose of encoding or decoding bit streams in products that are compliant
  9145. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  9146. -Android devices already license these patent claims through Via Licensing or
  9147. -directly from the patent owners, and therefore FDK AAC Codec software may
  9148. -already be covered under those patent licenses when it is used for those
  9149. -licensed purposes only.
  9150. -
  9151. -Commercially-licensed AAC software libraries, including floating-point versions
  9152. -with enhanced sound quality, are also available from Fraunhofer. Users are
  9153. -encouraged to check the Fraunhofer website for additional applications
  9154. -information and documentation.
  9155. -
  9156. -2. COPYRIGHT LICENSE
  9157. -
  9158. -Redistribution and use in source and binary forms, with or without modification,
  9159. -are permitted without payment of copyright license fees provided that you
  9160. -satisfy the following conditions:
  9161. -
  9162. -You must retain the complete text of this software license in redistributions of
  9163. -the FDK AAC Codec or your modifications thereto in source code form.
  9164. -
  9165. -You must retain the complete text of this software license in the documentation
  9166. -and/or other materials provided with redistributions of the FDK AAC Codec or
  9167. -your modifications thereto in binary form. You must make available free of
  9168. -charge copies of the complete source code of the FDK AAC Codec and your
  9169. -modifications thereto to recipients of copies in binary form.
  9170. -
  9171. -The name of Fraunhofer may not be used to endorse or promote products derived
  9172. -from this library without prior written permission.
  9173. -
  9174. -You may not charge copyright license fees for anyone to use, copy or distribute
  9175. -the FDK AAC Codec software or your modifications thereto.
  9176. -
  9177. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  9178. -that you changed the software and the date of any change. For modified versions
  9179. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  9180. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  9181. -AAC Codec Library for Android."
  9182. -
  9183. -3. NO PATENT LICENSE
  9184. -
  9185. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  9186. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  9187. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  9188. -software.
  9189. -
  9190. -You may use this FDK AAC Codec software or modifications thereto only for
  9191. -purposes that are authorized by appropriate patent licenses.
  9192. -
  9193. -4. DISCLAIMER
  9194. -
  9195. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  9196. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  9197. -including but not limited to the implied warranties of merchantability and
  9198. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  9199. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  9200. -or consequential damages, including but not limited to procurement of substitute
  9201. -goods or services; loss of use, data, or profits, or business interruption,
  9202. -however caused and on any theory of liability, whether in contract, strict
  9203. -liability, or tort (including negligence), arising in any way out of the use of
  9204. -this software, even if advised of the possibility of such damage.
  9205. -
  9206. -5. CONTACT INFORMATION
  9207. -
  9208. -Fraunhofer Institute for Integrated Circuits IIS
  9209. -Attention: Audio and Multimedia Departments - FDK AAC LL
  9210. -Am Wolfsmantel 33
  9211. -91058 Erlangen, Germany
  9212. -
  9213. -www.iis.fraunhofer.de/amm
  9214. -amm-info@iis.fraunhofer.de
  9215. ------------------------------------------------------------------------------ */
  9216. -
  9217. -/**************************** AAC decoder library ******************************
  9218. -
  9219. - Author(s):
  9220. -
  9221. - Description:
  9222. -
  9223. -*******************************************************************************/
  9224. -
  9225. -/*!
  9226. - \file
  9227. - \brief rvlc concealment
  9228. - \author Josef Hoepfl
  9229. -*/
  9230. -
  9231. -#include "rvlcconceal.h"
  9232. -
  9233. -#include "block.h"
  9234. -#include "rvlc.h"
  9235. -
  9236. -/*---------------------------------------------------------------------------------------------
  9237. - function: calcRefValFwd
  9238. -
  9239. - description: The function determines the scalefactor which is closed to the
  9240. -scalefactorband conceal_min. The same is done for intensity data and noise
  9241. -energies.
  9242. ------------------------------------------------------------------------------------------------
  9243. - output: - reference value scf
  9244. - - reference value internsity data
  9245. - - reference value noise energy
  9246. ------------------------------------------------------------------------------------------------
  9247. - return: -
  9248. ---------------------------------------------------------------------------------------------
  9249. -*/
  9250. -
  9251. -static void calcRefValFwd(CErRvlcInfo *pRvlc,
  9252. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  9253. - int *refIsFwd, int *refNrgFwd, int *refScfFwd) {
  9254. - int band, bnds, group, startBand;
  9255. - int idIs, idNrg, idScf;
  9256. - int conceal_min, conceal_group_min;
  9257. - int MaximumScaleFactorBands;
  9258. -
  9259. - if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT)
  9260. - MaximumScaleFactorBands = 16;
  9261. - else
  9262. - MaximumScaleFactorBands = 64;
  9263. -
  9264. - conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
  9265. - conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
  9266. -
  9267. - /* calculate first reference value for approach in forward direction */
  9268. - idIs = idNrg = idScf = 1;
  9269. -
  9270. - /* set reference values */
  9271. - *refIsFwd = -SF_OFFSET;
  9272. - *refNrgFwd = pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain -
  9273. - SF_OFFSET - 90 - 256;
  9274. - *refScfFwd =
  9275. - pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET;
  9276. -
  9277. - startBand = conceal_min - 1;
  9278. - for (group = conceal_group_min; group >= 0; group--) {
  9279. - for (band = startBand; band >= 0; band--) {
  9280. - bnds = 16 * group + band;
  9281. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  9282. - case ZERO_HCB:
  9283. - break;
  9284. - case INTENSITY_HCB:
  9285. - case INTENSITY_HCB2:
  9286. - if (idIs) {
  9287. - *refIsFwd =
  9288. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9289. - idIs = 0; /* reference value has been set */
  9290. - }
  9291. - break;
  9292. - case NOISE_HCB:
  9293. - if (idNrg) {
  9294. - *refNrgFwd =
  9295. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9296. - idNrg = 0; /* reference value has been set */
  9297. - }
  9298. - break;
  9299. - default:
  9300. - if (idScf) {
  9301. - *refScfFwd =
  9302. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9303. - idScf = 0; /* reference value has been set */
  9304. - }
  9305. - break;
  9306. - }
  9307. - }
  9308. - startBand = pRvlc->maxSfbTransmitted - 1;
  9309. - }
  9310. -}
  9311. -
  9312. -/*---------------------------------------------------------------------------------------------
  9313. - function: calcRefValBwd
  9314. -
  9315. - description: The function determines the scalefactor which is closed to the
  9316. -scalefactorband conceal_max. The same is done for intensity data and noise
  9317. -energies.
  9318. ------------------------------------------------------------------------------------------------
  9319. - output: - reference value scf
  9320. - - reference value internsity data
  9321. - - reference value noise energy
  9322. ------------------------------------------------------------------------------------------------
  9323. - return: -
  9324. ---------------------------------------------------------------------------------------------
  9325. -*/
  9326. -
  9327. -static void calcRefValBwd(CErRvlcInfo *pRvlc,
  9328. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  9329. - int *refIsBwd, int *refNrgBwd, int *refScfBwd) {
  9330. - int band, bnds, group, startBand;
  9331. - int idIs, idNrg, idScf;
  9332. - int conceal_max, conceal_group_max;
  9333. - int MaximumScaleFactorBands;
  9334. -
  9335. - if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT)
  9336. - MaximumScaleFactorBands = 16;
  9337. - else
  9338. - MaximumScaleFactorBands = 64;
  9339. -
  9340. - conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
  9341. - conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
  9342. -
  9343. - /* calculate first reference value for approach in backward direction */
  9344. - idIs = idNrg = idScf = 1;
  9345. -
  9346. - /* set reference values */
  9347. - *refIsBwd = pRvlc->dpcm_is_last_position - SF_OFFSET;
  9348. - *refNrgBwd = pRvlc->rev_global_gain + pRvlc->dpcm_noise_last_position -
  9349. - SF_OFFSET - 90 - 256 + pRvlc->dpcm_noise_nrg;
  9350. - *refScfBwd = pRvlc->rev_global_gain - SF_OFFSET;
  9351. -
  9352. - startBand = conceal_max + 1;
  9353. -
  9354. - /* if needed, re-set reference values */
  9355. - for (group = conceal_group_max; group < pRvlc->numWindowGroups; group++) {
  9356. - for (band = startBand; band < pRvlc->maxSfbTransmitted; band++) {
  9357. - bnds = 16 * group + band;
  9358. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  9359. - case ZERO_HCB:
  9360. - break;
  9361. - case INTENSITY_HCB:
  9362. - case INTENSITY_HCB2:
  9363. - if (idIs) {
  9364. - *refIsBwd =
  9365. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9366. - idIs = 0; /* reference value has been set */
  9367. - }
  9368. - break;
  9369. - case NOISE_HCB:
  9370. - if (idNrg) {
  9371. - *refNrgBwd =
  9372. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9373. - idNrg = 0; /* reference value has been set */
  9374. - }
  9375. - break;
  9376. - default:
  9377. - if (idScf) {
  9378. - *refScfBwd =
  9379. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9380. - idScf = 0; /* reference value has been set */
  9381. - }
  9382. - break;
  9383. - }
  9384. - }
  9385. - startBand = 0;
  9386. - }
  9387. -}
  9388. -
  9389. -/*---------------------------------------------------------------------------------------------
  9390. - function: BidirectionalEstimation_UseLowerScfOfCurrentFrame
  9391. -
  9392. - description: This approach by means of bidirectional estimation is generally
  9393. -performed when a single bit error has been detected, the bit error can be
  9394. -isolated between 'conceal_min' and 'conceal_max' and the 'sf_concealment' flag
  9395. -is not set. The sets of scalefactors decoded in forward and backward direction
  9396. -are compared with each other. The smaller scalefactor will be considered as the
  9397. -correct one respectively. The reconstruction of the scalefactors with this
  9398. -approach archieve good results in audio quality. The strategy must be applied to
  9399. -scalefactors, intensity data and noise energy seperately.
  9400. ------------------------------------------------------------------------------------------------
  9401. - output: Concealed scalefactor, noise energy and intensity data between
  9402. -conceal_min and conceal_max
  9403. ------------------------------------------------------------------------------------------------
  9404. - return: -
  9405. ---------------------------------------------------------------------------------------------
  9406. -*/
  9407. -
  9408. -void BidirectionalEstimation_UseLowerScfOfCurrentFrame(
  9409. - CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
  9410. - CErRvlcInfo *pRvlc =
  9411. - &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
  9412. - int band, bnds, startBand, endBand, group;
  9413. - int conceal_min, conceal_max;
  9414. - int conceal_group_min, conceal_group_max;
  9415. - int MaximumScaleFactorBands;
  9416. -
  9417. - if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) {
  9418. - MaximumScaleFactorBands = 16;
  9419. - } else {
  9420. - MaximumScaleFactorBands = 64;
  9421. - }
  9422. -
  9423. - /* If an error was detected just in forward or backward direction, set the
  9424. - corresponding border for concealment to a appropriate scalefactor band. The
  9425. - border is set to first or last sfb respectively, because the error will
  9426. - possibly not follow directly after the corrupt bit but just after decoding
  9427. - some more (wrong) scalefactors. */
  9428. - if (pRvlc->conceal_min == CONCEAL_MIN_INIT) pRvlc->conceal_min = 0;
  9429. -
  9430. - if (pRvlc->conceal_max == CONCEAL_MAX_INIT)
  9431. - pRvlc->conceal_max =
  9432. - (pRvlc->numWindowGroups - 1) * 16 + pRvlc->maxSfbTransmitted - 1;
  9433. -
  9434. - conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
  9435. - conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
  9436. - conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
  9437. - conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
  9438. -
  9439. - if (pRvlc->conceal_min == pRvlc->conceal_max) {
  9440. - int refIsFwd, refNrgFwd, refScfFwd;
  9441. - int refIsBwd, refNrgBwd, refScfBwd;
  9442. -
  9443. - bnds = pRvlc->conceal_min;
  9444. - calcRefValFwd(pRvlc, pAacDecoderChannelInfo, &refIsFwd, &refNrgFwd,
  9445. - &refScfFwd);
  9446. - calcRefValBwd(pRvlc, pAacDecoderChannelInfo, &refIsBwd, &refNrgBwd,
  9447. - &refScfBwd);
  9448. -
  9449. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  9450. - case ZERO_HCB:
  9451. - break;
  9452. - case INTENSITY_HCB:
  9453. - case INTENSITY_HCB2:
  9454. - if (refIsFwd < refIsBwd)
  9455. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refIsFwd;
  9456. - else
  9457. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refIsBwd;
  9458. - break;
  9459. - case NOISE_HCB:
  9460. - if (refNrgFwd < refNrgBwd)
  9461. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refNrgFwd;
  9462. - else
  9463. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refNrgBwd;
  9464. - break;
  9465. - default:
  9466. - if (refScfFwd < refScfBwd)
  9467. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refScfFwd;
  9468. - else
  9469. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refScfBwd;
  9470. - break;
  9471. - }
  9472. - } else {
  9473. - pAacDecoderChannelInfo->pComData->overlay.aac
  9474. - .aRvlcScfFwd[pRvlc->conceal_max] =
  9475. - pAacDecoderChannelInfo->pComData->overlay.aac
  9476. - .aRvlcScfBwd[pRvlc->conceal_max];
  9477. - pAacDecoderChannelInfo->pComData->overlay.aac
  9478. - .aRvlcScfBwd[pRvlc->conceal_min] =
  9479. - pAacDecoderChannelInfo->pComData->overlay.aac
  9480. - .aRvlcScfFwd[pRvlc->conceal_min];
  9481. -
  9482. - /* consider the smaller of the forward and backward decoded value as the
  9483. - * correct one */
  9484. - startBand = conceal_min;
  9485. - if (conceal_group_min == conceal_group_max)
  9486. - endBand = conceal_max;
  9487. - else
  9488. - endBand = pRvlc->maxSfbTransmitted - 1;
  9489. -
  9490. - for (group = conceal_group_min; group <= conceal_group_max; group++) {
  9491. - for (band = startBand; band <= endBand; band++) {
  9492. - bnds = 16 * group + band;
  9493. - if (pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds] <
  9494. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds])
  9495. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9496. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9497. - else
  9498. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9499. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9500. - }
  9501. - startBand = 0;
  9502. - if ((group + 1) == conceal_group_max) endBand = conceal_max;
  9503. - }
  9504. - }
  9505. -
  9506. - /* now copy all data to the output buffer which needs not to be concealed */
  9507. - if (conceal_group_min == 0)
  9508. - endBand = conceal_min;
  9509. - else
  9510. - endBand = pRvlc->maxSfbTransmitted;
  9511. - for (group = 0; group <= conceal_group_min; group++) {
  9512. - for (band = 0; band < endBand; band++) {
  9513. - bnds = 16 * group + band;
  9514. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9515. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9516. - }
  9517. - if ((group + 1) == conceal_group_min) endBand = conceal_min;
  9518. - }
  9519. -
  9520. - startBand = conceal_max + 1;
  9521. - for (group = conceal_group_max; group < pRvlc->numWindowGroups; group++) {
  9522. - for (band = startBand; band < pRvlc->maxSfbTransmitted; band++) {
  9523. - bnds = 16 * group + band;
  9524. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9525. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9526. - }
  9527. - startBand = 0;
  9528. - }
  9529. -}
  9530. -
  9531. -/*---------------------------------------------------------------------------------------------
  9532. - function: BidirectionalEstimation_UseScfOfPrevFrameAsReference
  9533. -
  9534. - description: This approach by means of bidirectional estimation is generally
  9535. -performed when a single bit error has been detected, the bit error can be
  9536. -isolated between 'conceal_min' and 'conceal_max', the 'sf_concealment' flag is
  9537. -set and the previous frame has the same block type as the current frame. The
  9538. -scalefactor decoded in forward and backward direction and the scalefactor of the
  9539. -previous frame are compared with each other. The smaller scalefactor will be
  9540. -considered as the correct one. At this the codebook of the previous and current
  9541. -frame must be of the same set (scf, nrg, is) in each scalefactorband. Otherwise
  9542. -the scalefactor of the previous frame is not considered in the minimum
  9543. -calculation. The reconstruction of the scalefactors with this approach archieve
  9544. -good results in audio quality. The strategy must be applied to scalefactors,
  9545. -intensity data and noise energy seperately.
  9546. ------------------------------------------------------------------------------------------------
  9547. - output: Concealed scalefactor, noise energy and intensity data between
  9548. -conceal_min and conceal_max
  9549. ------------------------------------------------------------------------------------------------
  9550. - return: -
  9551. ---------------------------------------------------------------------------------------------
  9552. -*/
  9553. -
  9554. -void BidirectionalEstimation_UseScfOfPrevFrameAsReference(
  9555. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  9556. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
  9557. - CErRvlcInfo *pRvlc =
  9558. - &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
  9559. - int band, bnds, startBand, endBand, group;
  9560. - int conceal_min, conceal_max;
  9561. - int conceal_group_min, conceal_group_max;
  9562. - int MaximumScaleFactorBands;
  9563. - SHORT commonMin;
  9564. -
  9565. - if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) {
  9566. - MaximumScaleFactorBands = 16;
  9567. - } else {
  9568. - MaximumScaleFactorBands = 64;
  9569. - }
  9570. -
  9571. - /* If an error was detected just in forward or backward direction, set the
  9572. - corresponding border for concealment to a appropriate scalefactor band. The
  9573. - border is set to first or last sfb respectively, because the error will
  9574. - possibly not follow directly after the corrupt bit but just after decoding
  9575. - some more (wrong) scalefactors. */
  9576. - if (pRvlc->conceal_min == CONCEAL_MIN_INIT) pRvlc->conceal_min = 0;
  9577. -
  9578. - if (pRvlc->conceal_max == CONCEAL_MAX_INIT)
  9579. - pRvlc->conceal_max =
  9580. - (pRvlc->numWindowGroups - 1) * 16 + pRvlc->maxSfbTransmitted - 1;
  9581. -
  9582. - conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
  9583. - conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
  9584. - conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
  9585. - conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
  9586. -
  9587. - pAacDecoderChannelInfo->pComData->overlay.aac
  9588. - .aRvlcScfFwd[pRvlc->conceal_max] =
  9589. - pAacDecoderChannelInfo->pComData->overlay.aac
  9590. - .aRvlcScfBwd[pRvlc->conceal_max];
  9591. - pAacDecoderChannelInfo->pComData->overlay.aac
  9592. - .aRvlcScfBwd[pRvlc->conceal_min] =
  9593. - pAacDecoderChannelInfo->pComData->overlay.aac
  9594. - .aRvlcScfFwd[pRvlc->conceal_min];
  9595. -
  9596. - /* consider the smaller of the forward and backward decoded value as the
  9597. - * correct one */
  9598. - startBand = conceal_min;
  9599. - if (conceal_group_min == conceal_group_max)
  9600. - endBand = conceal_max;
  9601. - else
  9602. - endBand = pRvlc->maxSfbTransmitted - 1;
  9603. -
  9604. - for (group = conceal_group_min; group <= conceal_group_max; group++) {
  9605. - for (band = startBand; band <= endBand; band++) {
  9606. - bnds = 16 * group + band;
  9607. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  9608. - case ZERO_HCB:
  9609. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
  9610. - break;
  9611. -
  9612. - case INTENSITY_HCB:
  9613. - case INTENSITY_HCB2:
  9614. - if ((pAacDecoderStaticChannelInfo->concealmentInfo
  9615. - .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB) ||
  9616. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9617. - .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB2)) {
  9618. - commonMin = fMin(
  9619. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9620. - pAacDecoderChannelInfo->pComData->overlay.aac
  9621. - .aRvlcScfBwd[bnds]);
  9622. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9623. - fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
  9624. - .aRvlcPreviousScaleFactor[bnds]);
  9625. - } else {
  9626. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = fMin(
  9627. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9628. - pAacDecoderChannelInfo->pComData->overlay.aac
  9629. - .aRvlcScfBwd[bnds]);
  9630. - }
  9631. - break;
  9632. -
  9633. - case NOISE_HCB:
  9634. - if (pAacDecoderStaticChannelInfo->concealmentInfo
  9635. - .aRvlcPreviousCodebook[bnds] == NOISE_HCB) {
  9636. - commonMin = fMin(
  9637. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9638. - pAacDecoderChannelInfo->pComData->overlay.aac
  9639. - .aRvlcScfBwd[bnds]);
  9640. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9641. - fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
  9642. - .aRvlcPreviousScaleFactor[bnds]);
  9643. - } else {
  9644. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = fMin(
  9645. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9646. - pAacDecoderChannelInfo->pComData->overlay.aac
  9647. - .aRvlcScfBwd[bnds]);
  9648. - }
  9649. - break;
  9650. -
  9651. - default:
  9652. - if ((pAacDecoderStaticChannelInfo->concealmentInfo
  9653. - .aRvlcPreviousCodebook[bnds] != ZERO_HCB) &&
  9654. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9655. - .aRvlcPreviousCodebook[bnds] != NOISE_HCB) &&
  9656. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9657. - .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB) &&
  9658. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9659. - .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB2)) {
  9660. - commonMin = fMin(
  9661. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9662. - pAacDecoderChannelInfo->pComData->overlay.aac
  9663. - .aRvlcScfBwd[bnds]);
  9664. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9665. - fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
  9666. - .aRvlcPreviousScaleFactor[bnds]);
  9667. - } else {
  9668. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = fMin(
  9669. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9670. - pAacDecoderChannelInfo->pComData->overlay.aac
  9671. - .aRvlcScfBwd[bnds]);
  9672. - }
  9673. - break;
  9674. - }
  9675. - }
  9676. - startBand = 0;
  9677. - if ((group + 1) == conceal_group_max) endBand = conceal_max;
  9678. - }
  9679. -
  9680. - /* now copy all data to the output buffer which needs not to be concealed */
  9681. - if (conceal_group_min == 0)
  9682. - endBand = conceal_min;
  9683. - else
  9684. - endBand = pRvlc->maxSfbTransmitted;
  9685. - for (group = 0; group <= conceal_group_min; group++) {
  9686. - for (band = 0; band < endBand; band++) {
  9687. - bnds = 16 * group + band;
  9688. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9689. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9690. - }
  9691. - if ((group + 1) == conceal_group_min) endBand = conceal_min;
  9692. - }
  9693. -
  9694. - startBand = conceal_max + 1;
  9695. - for (group = conceal_group_max; group < pRvlc->numWindowGroups; group++) {
  9696. - for (band = startBand; band < pRvlc->maxSfbTransmitted; band++) {
  9697. - bnds = 16 * group + band;
  9698. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9699. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9700. - }
  9701. - startBand = 0;
  9702. - }
  9703. -}
  9704. -
  9705. -/*---------------------------------------------------------------------------------------------
  9706. - function: StatisticalEstimation
  9707. -
  9708. - description: This approach by means of statistical estimation is generally
  9709. -performed when both the start value and the end value are different and no
  9710. -further errors have been detected. Considering the forward and backward decoded
  9711. -scalefactors, the set with the lower scalefactors in sum will be considered as
  9712. -the correct one. The scalefactors are differentially encoded. Normally it would
  9713. -reach to compare one pair of the forward and backward decoded scalefactors to
  9714. -specify the lower set. But having detected no further errors does not
  9715. -necessarily mean the absence of errors. Therefore all scalefactors decoded in
  9716. -forward and backward direction are summed up seperately. The set with the lower
  9717. -sum will be used. The strategy must be applied to scalefactors, intensity data
  9718. -and noise energy seperately.
  9719. ------------------------------------------------------------------------------------------------
  9720. - output: Concealed scalefactor, noise energy and intensity data
  9721. ------------------------------------------------------------------------------------------------
  9722. - return: -
  9723. ---------------------------------------------------------------------------------------------
  9724. -*/
  9725. -
  9726. -void StatisticalEstimation(CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
  9727. - CErRvlcInfo *pRvlc =
  9728. - &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
  9729. - int band, bnds, group;
  9730. - int sumIsFwd, sumIsBwd; /* sum of intensity data forward/backward */
  9731. - int sumNrgFwd, sumNrgBwd; /* sum of noise energy data forward/backward */
  9732. - int sumScfFwd, sumScfBwd; /* sum of scalefactor data forward/backward */
  9733. - int useIsFwd, useNrgFwd, useScfFwd; /* the flags signals the elements which
  9734. - are used for the final result */
  9735. -
  9736. - sumIsFwd = sumIsBwd = sumNrgFwd = sumNrgBwd = sumScfFwd = sumScfBwd = 0;
  9737. - useIsFwd = useNrgFwd = useScfFwd = 0;
  9738. -
  9739. - /* calculate sum of each group (scf,nrg,is) of forward and backward direction
  9740. - */
  9741. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  9742. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  9743. - bnds = 16 * group + band;
  9744. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  9745. - case ZERO_HCB:
  9746. - break;
  9747. -
  9748. - case INTENSITY_HCB:
  9749. - case INTENSITY_HCB2:
  9750. - sumIsFwd +=
  9751. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9752. - sumIsBwd +=
  9753. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9754. - break;
  9755. -
  9756. - case NOISE_HCB:
  9757. - sumNrgFwd +=
  9758. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9759. - sumNrgBwd +=
  9760. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9761. - break;
  9762. -
  9763. - default:
  9764. - sumScfFwd +=
  9765. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9766. - sumScfBwd +=
  9767. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9768. - break;
  9769. - }
  9770. - }
  9771. - }
  9772. -
  9773. - /* find for each group (scf,nrg,is) the correct direction */
  9774. - if (sumIsFwd < sumIsBwd) useIsFwd = 1;
  9775. -
  9776. - if (sumNrgFwd < sumNrgBwd) useNrgFwd = 1;
  9777. -
  9778. - if (sumScfFwd < sumScfBwd) useScfFwd = 1;
  9779. -
  9780. - /* conceal each group (scf,nrg,is) */
  9781. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  9782. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  9783. - bnds = 16 * group + band;
  9784. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  9785. - case ZERO_HCB:
  9786. - break;
  9787. -
  9788. - case INTENSITY_HCB:
  9789. - case INTENSITY_HCB2:
  9790. - if (useIsFwd)
  9791. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9792. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9793. - else
  9794. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9795. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9796. - break;
  9797. -
  9798. - case NOISE_HCB:
  9799. - if (useNrgFwd)
  9800. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9801. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9802. - else
  9803. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9804. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9805. - break;
  9806. -
  9807. - default:
  9808. - if (useScfFwd)
  9809. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9810. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9811. - else
  9812. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9813. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9814. - break;
  9815. - }
  9816. - }
  9817. - }
  9818. -}
  9819. -
  9820. -/*---------------------------------------------------------------------------------------------
  9821. - description: Approach by means of predictive interpolation
  9822. - This approach by means of predictive estimation is generally
  9823. -performed when the error cannot be isolated between 'conceal_min' and
  9824. -'conceal_max', the 'sf_concealment' flag is set and the previous frame has the
  9825. -same block type as the current frame. Check for each scalefactorband if the same
  9826. -type of data (scalefactor, internsity data, noise energies) is transmitted. If
  9827. -so use the scalefactor (intensity data, noise energy) in the current frame.
  9828. -Otherwise set the scalefactor (intensity data, noise energy) for this
  9829. -scalefactorband to zero.
  9830. ------------------------------------------------------------------------------------------------
  9831. - output: Concealed scalefactor, noise energy and intensity data
  9832. ------------------------------------------------------------------------------------------------
  9833. - return: -
  9834. ---------------------------------------------------------------------------------------------
  9835. -*/
  9836. -
  9837. -void PredictiveInterpolation(
  9838. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  9839. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
  9840. - CErRvlcInfo *pRvlc =
  9841. - &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
  9842. - int band, bnds, group;
  9843. - SHORT commonMin;
  9844. -
  9845. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  9846. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  9847. - bnds = 16 * group + band;
  9848. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  9849. - case ZERO_HCB:
  9850. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
  9851. - break;
  9852. -
  9853. - case INTENSITY_HCB:
  9854. - case INTENSITY_HCB2:
  9855. - if ((pAacDecoderStaticChannelInfo->concealmentInfo
  9856. - .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB) ||
  9857. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9858. - .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB2)) {
  9859. - commonMin = fMin(
  9860. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9861. - pAacDecoderChannelInfo->pComData->overlay.aac
  9862. - .aRvlcScfBwd[bnds]);
  9863. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9864. - fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
  9865. - .aRvlcPreviousScaleFactor[bnds]);
  9866. - } else {
  9867. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = -110;
  9868. - }
  9869. - break;
  9870. -
  9871. - case NOISE_HCB:
  9872. - if (pAacDecoderStaticChannelInfo->concealmentInfo
  9873. - .aRvlcPreviousCodebook[bnds] == NOISE_HCB) {
  9874. - commonMin = fMin(
  9875. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9876. - pAacDecoderChannelInfo->pComData->overlay.aac
  9877. - .aRvlcScfBwd[bnds]);
  9878. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9879. - fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
  9880. - .aRvlcPreviousScaleFactor[bnds]);
  9881. - } else {
  9882. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = -110;
  9883. - }
  9884. - break;
  9885. -
  9886. - default:
  9887. - if ((pAacDecoderStaticChannelInfo->concealmentInfo
  9888. - .aRvlcPreviousCodebook[bnds] != ZERO_HCB) &&
  9889. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9890. - .aRvlcPreviousCodebook[bnds] != NOISE_HCB) &&
  9891. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9892. - .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB) &&
  9893. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9894. - .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB2)) {
  9895. - commonMin = fMin(
  9896. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9897. - pAacDecoderChannelInfo->pComData->overlay.aac
  9898. - .aRvlcScfBwd[bnds]);
  9899. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9900. - fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
  9901. - .aRvlcPreviousScaleFactor[bnds]);
  9902. - } else {
  9903. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
  9904. - }
  9905. - break;
  9906. - }
  9907. - }
  9908. - }
  9909. -}
  9910. --- a/libAACdec/src/rvlcconceal.h
  9911. +++ /dev/null
  9912. @@ -1,127 +0,0 @@
  9913. -/* -----------------------------------------------------------------------------
  9914. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  9915. -
  9916. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  9917. -Forschung e.V. All rights reserved.
  9918. -
  9919. - 1. INTRODUCTION
  9920. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  9921. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  9922. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  9923. -a wide variety of Android devices.
  9924. -
  9925. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  9926. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  9927. -full-bandwidth communications codec by independent studies and is widely
  9928. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  9929. -specifications.
  9930. -
  9931. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  9932. -those of Fraunhofer) may be obtained through Via Licensing
  9933. -(www.vialicensing.com) or through the respective patent owners individually for
  9934. -the purpose of encoding or decoding bit streams in products that are compliant
  9935. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  9936. -Android devices already license these patent claims through Via Licensing or
  9937. -directly from the patent owners, and therefore FDK AAC Codec software may
  9938. -already be covered under those patent licenses when it is used for those
  9939. -licensed purposes only.
  9940. -
  9941. -Commercially-licensed AAC software libraries, including floating-point versions
  9942. -with enhanced sound quality, are also available from Fraunhofer. Users are
  9943. -encouraged to check the Fraunhofer website for additional applications
  9944. -information and documentation.
  9945. -
  9946. -2. COPYRIGHT LICENSE
  9947. -
  9948. -Redistribution and use in source and binary forms, with or without modification,
  9949. -are permitted without payment of copyright license fees provided that you
  9950. -satisfy the following conditions:
  9951. -
  9952. -You must retain the complete text of this software license in redistributions of
  9953. -the FDK AAC Codec or your modifications thereto in source code form.
  9954. -
  9955. -You must retain the complete text of this software license in the documentation
  9956. -and/or other materials provided with redistributions of the FDK AAC Codec or
  9957. -your modifications thereto in binary form. You must make available free of
  9958. -charge copies of the complete source code of the FDK AAC Codec and your
  9959. -modifications thereto to recipients of copies in binary form.
  9960. -
  9961. -The name of Fraunhofer may not be used to endorse or promote products derived
  9962. -from this library without prior written permission.
  9963. -
  9964. -You may not charge copyright license fees for anyone to use, copy or distribute
  9965. -the FDK AAC Codec software or your modifications thereto.
  9966. -
  9967. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  9968. -that you changed the software and the date of any change. For modified versions
  9969. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  9970. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  9971. -AAC Codec Library for Android."
  9972. -
  9973. -3. NO PATENT LICENSE
  9974. -
  9975. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  9976. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  9977. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  9978. -software.
  9979. -
  9980. -You may use this FDK AAC Codec software or modifications thereto only for
  9981. -purposes that are authorized by appropriate patent licenses.
  9982. -
  9983. -4. DISCLAIMER
  9984. -
  9985. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  9986. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  9987. -including but not limited to the implied warranties of merchantability and
  9988. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  9989. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  9990. -or consequential damages, including but not limited to procurement of substitute
  9991. -goods or services; loss of use, data, or profits, or business interruption,
  9992. -however caused and on any theory of liability, whether in contract, strict
  9993. -liability, or tort (including negligence), arising in any way out of the use of
  9994. -this software, even if advised of the possibility of such damage.
  9995. -
  9996. -5. CONTACT INFORMATION
  9997. -
  9998. -Fraunhofer Institute for Integrated Circuits IIS
  9999. -Attention: Audio and Multimedia Departments - FDK AAC LL
  10000. -Am Wolfsmantel 33
  10001. -91058 Erlangen, Germany
  10002. -
  10003. -www.iis.fraunhofer.de/amm
  10004. -amm-info@iis.fraunhofer.de
  10005. ------------------------------------------------------------------------------ */
  10006. -
  10007. -/**************************** AAC decoder library ******************************
  10008. -
  10009. - Author(s):
  10010. -
  10011. - Description:
  10012. -
  10013. -*******************************************************************************/
  10014. -
  10015. -/*!
  10016. - \file
  10017. - \brief rvlc concealment
  10018. - \author Josef Hoepfl
  10019. -*/
  10020. -
  10021. -#ifndef RVLCCONCEAL_H
  10022. -#define RVLCCONCEAL_H
  10023. -
  10024. -#include "rvlc.h"
  10025. -
  10026. -void BidirectionalEstimation_UseLowerScfOfCurrentFrame(
  10027. - CAacDecoderChannelInfo *pAacDecoderChannelInfo);
  10028. -
  10029. -void BidirectionalEstimation_UseScfOfPrevFrameAsReference(
  10030. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  10031. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo);
  10032. -
  10033. -void StatisticalEstimation(CAacDecoderChannelInfo *pAacDecoderChannelInfo);
  10034. -
  10035. -void PredictiveInterpolation(
  10036. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  10037. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo);
  10038. -
  10039. -#endif /* RVLCCONCEAL_H */
  10040. --- a/libAACdec/src/usacdec_lpd.cpp
  10041. +++ b/libAACdec/src/usacdec_lpd.cpp
  10042. @@ -111,8 +111,6 @@ amm-info@iis.fraunhofer.de
  10043. #include "usacdec_acelp.h"
  10044. #include "overlapadd.h"
  10045. -#include "conceal.h"
  10046. -
  10047. #include "block.h"
  10048. #define SF_PITCH_TRACK 6
  10049. @@ -1210,8 +1208,7 @@ AAC_DECODER_ERROR CLpdChannelStream_Read
  10050. : &lg_table_ccfl[1][lg_table_offset];
  10051. int last_lpc_lost = pAacDecoderStaticChannelInfo->last_lpc_lost;
  10052. - int last_frame_ok = CConcealment_GetLastFrameOk(
  10053. - &pAacDecoderStaticChannelInfo->concealmentInfo, 1);
  10054. + int last_frame_ok = 1;
  10055. INT i_offset;
  10056. UINT samplingRate;
  10057. @@ -1392,13 +1389,7 @@ AAC_DECODER_ERROR CLpdChannelStream_Read
  10058. }
  10059. }
  10060. - if (!CConcealment_GetLastFrameOk(
  10061. - &pAacDecoderStaticChannelInfo->concealmentInfo, 1)) {
  10062. - E_LPC_f_lsp_a_conversion(
  10063. - pAacDecoderChannelInfo->data.usac.lsp_coeff[0],
  10064. - pAacDecoderChannelInfo->data.usac.lp_coeff[0],
  10065. - &pAacDecoderChannelInfo->data.usac.lp_coeff_exp[0]);
  10066. - } else if (pAacDecoderStaticChannelInfo->last_lpd_mode != 0) {
  10067. + if (pAacDecoderStaticChannelInfo->last_lpd_mode != 0) {
  10068. if (pAacDecoderStaticChannelInfo->last_lpd_mode == 255) {
  10069. /* We need it for TCX decoding or ACELP excitation update */
  10070. E_LPC_f_lsp_a_conversion(
  10071. @@ -1426,9 +1417,7 @@ AAC_DECODER_ERROR CLpdChannelStream_Read
  10072. FD_SHORT;
  10073. pAacDecoderChannelInfo->data.usac.lpd_mode_last = 255;
  10074. - if ((pAacDecoderStaticChannelInfo->last_core_mode != FD_SHORT) &&
  10075. - CConcealment_GetLastFrameOk(
  10076. - &pAacDecoderStaticChannelInfo->concealmentInfo, 1)) {
  10077. + if ((pAacDecoderStaticChannelInfo->last_core_mode != FD_SHORT)) {
  10078. /* USAC Conformance document:
  10079. short_fac_flag shall be encoded with a value of 1 if the
  10080. window_sequence of the previous frame was 2 (EIGHT_SHORT_SEQUENCE).
  10081. @@ -1604,8 +1593,7 @@ AAC_DECODER_ERROR CLpd_RenderTimeSignal(
  10082. return AAC_DEC_UNKNOWN;
  10083. }
  10084. - last_frame_lost = !CConcealment_GetLastFrameOk(
  10085. - &pAacDecoderStaticChannelInfo->concealmentInfo, 0);
  10086. + last_frame_lost = 0;
  10087. /* Maintain LPD mode from previous frame */
  10088. if ((pAacDecoderStaticChannelInfo->last_core_mode == FD_LONG) ||