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.

10233 lines
414 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. diff --git a/Makefile.am b/Makefile.am
  54. index 79e0677..16b21e1 100644
  55. --- a/Makefile.am
  56. +++ b/Makefile.am
  57. @@ -50,9 +50,6 @@ AACDEC_SRC = \
  58. libAACdec/src/aac_ram.cpp \
  59. libAACdec/src/aac_rom.cpp \
  60. libAACdec/src/aacdec_drc.cpp \
  61. - libAACdec/src/aacdec_hcr.cpp \
  62. - libAACdec/src/aacdec_hcr_bit.cpp \
  63. - libAACdec/src/aacdec_hcrs.cpp \
  64. libAACdec/src/aacdec_pns.cpp \
  65. libAACdec/src/aacdec_tns.cpp \
  66. libAACdec/src/aacdecoder.cpp \
  67. @@ -60,12 +57,8 @@ AACDEC_SRC = \
  68. libAACdec/src/block.cpp \
  69. libAACdec/src/channel.cpp \
  70. libAACdec/src/channelinfo.cpp \
  71. - libAACdec/src/conceal.cpp \
  72. libAACdec/src/ldfiltbank.cpp \
  73. libAACdec/src/pulsedata.cpp \
  74. - libAACdec/src/rvlc.cpp \
  75. - libAACdec/src/rvlcbit.cpp \
  76. - libAACdec/src/rvlcconceal.cpp \
  77. libAACdec/src/stereo.cpp \
  78. libAACdec/src/usacdec_ace_d4t64.cpp \
  79. libAACdec/src/usacdec_ace_ltp.cpp \
  80. diff --git a/Makefile.vc b/Makefile.vc
  81. index ac3c097..97a0615 100644
  82. --- a/Makefile.vc
  83. +++ b/Makefile.vc
  84. @@ -34,9 +34,6 @@ AACDEC_SRC = \
  85. libAACdec/src/aac_ram.cpp \
  86. libAACdec/src/aac_rom.cpp \
  87. libAACdec/src/aacdec_drc.cpp \
  88. - libAACdec/src/aacdec_hcr.cpp \
  89. - libAACdec/src/aacdec_hcr_bit.cpp \
  90. - libAACdec/src/aacdec_hcrs.cpp \
  91. libAACdec/src/aacdec_pns.cpp \
  92. libAACdec/src/aacdec_tns.cpp \
  93. libAACdec/src/aacdecoder.cpp \
  94. @@ -44,12 +41,8 @@ AACDEC_SRC = \
  95. libAACdec/src/block.cpp \
  96. libAACdec/src/channel.cpp \
  97. libAACdec/src/channelinfo.cpp \
  98. - libAACdec/src/conceal.cpp \
  99. libAACdec/src/ldfiltbank.cpp \
  100. libAACdec/src/pulsedata.cpp \
  101. - libAACdec/src/rvlc.cpp \
  102. - libAACdec/src/rvlcbit.cpp \
  103. - libAACdec/src/rvlcconceal.cpp \
  104. libAACdec/src/stereo.cpp \
  105. libAACdec/src/usacdec_ace_d4t64.cpp \
  106. libAACdec/src/usacdec_ace_ltp.cpp \
  107. diff --git a/libAACdec/src/aac_ram.h b/libAACdec/src/aac_ram.h
  108. index a861e25..7ee8d26 100644
  109. --- a/libAACdec/src/aac_ram.h
  110. +++ b/libAACdec/src/aac_ram.h
  111. @@ -111,9 +111,6 @@ amm-info@iis.fraunhofer.de
  112. #include "ac_arith_coder.h"
  113. -#include "aacdec_hcr_types.h"
  114. -#include "aacdec_hcr.h"
  115. -
  116. /* End of formal fix.h */
  117. #define MAX_SYNCHS 10
  118. diff --git a/libAACdec/src/aac_rom.cpp b/libAACdec/src/aac_rom.cpp
  119. index cbdffc4..2c3c1b1 100644
  120. --- a/libAACdec/src/aac_rom.cpp
  121. +++ b/libAACdec/src/aac_rom.cpp
  122. @@ -1583,102 +1583,6 @@ const SCHAR *aQuantTable[] = {
  123. aValTab24, /* 30 6 */
  124. aValTab24}; /* 31 6 */
  125. -/* arrays for HCR_TABLE_INFO structures */
  126. -/* maximum length of codeword in each codebook */
  127. -/* codebook: 0,1, 2,3, 4, 5, 6, 7, 8, 9,
  128. - * 10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 */
  129. -const UCHAR aMaxCwLen[MAX_CB] = {0, 11, 9, 20, 16, 13, 11, 14, 12, 17, 14,
  130. - 49, 0, 0, 0, 0, 14, 17, 21, 21, 25, 25,
  131. - 29, 29, 29, 29, 33, 33, 33, 37, 37, 41};
  132. -
  133. -/* 11 13 15 17 19
  134. - * 21 23 25 27 39 31 */
  135. -/* CB: 0 1 2 3 4 5 6 7 8 9 10 12 14 16 18 20
  136. - * 22 24 26 28 30 */
  137. -const UCHAR aDimCb[MAX_CB] = {
  138. - 2, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2,
  139. - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; /* codebook dimension -
  140. - zero cb got a
  141. - dimension of 2 */
  142. -
  143. -/* 11 13 15 17 19
  144. - * 21 23 25 27 39 31 */
  145. -/* CB: 0 1 2 3 4 5 6 7 8 9 10 12 14 16 18 20
  146. - * 22 24 26 28 30 */
  147. -const UCHAR aDimCbShift[MAX_CB] = {
  148. - 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,
  149. - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; /* codebook dimension */
  150. -
  151. -/* 1 -> decode sign bits */
  152. -/* 0 -> decode no sign bits 11 13 15 17 19 21
  153. - * 23 25 27 39 31 */
  154. -/* CB: 0 1 2 3 4 5 6 7 8 9 10 12 14 16 18 20 22
  155. - * 24 26 28 30 */
  156. -const UCHAR aSignCb[MAX_CB] = {0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0,
  157. - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
  158. -
  159. -/* arrays for HCR_CB_PAIRS structures */
  160. -const UCHAR aMinOfCbPair[MAX_CB_PAIRS] = {0, 1, 3, 5, 7, 9, 16, 17,
  161. - 18, 19, 20, 21, 22, 23, 24, 25,
  162. - 26, 27, 28, 29, 30, 31, 11};
  163. -const UCHAR aMaxOfCbPair[MAX_CB_PAIRS] = {0, 2, 4, 6, 8, 10, 16, 17,
  164. - 18, 19, 20, 21, 22, 23, 24, 25,
  165. - 26, 27, 28, 29, 30, 31, 11};
  166. -
  167. -/* priorities of codebooks */
  168. -const UCHAR aCbPriority[MAX_CB] = {0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
  169. - 22, 0, 0, 0, 0, 6, 7, 8, 9, 10, 11,
  170. - 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
  171. -
  172. -const SCHAR aCodebook2StartInt[] = {STOP_THIS_STATE, /* cb 0 */
  173. - BODY_ONLY, /* cb 1 */
  174. - BODY_ONLY, /* cb 2 */
  175. - BODY_SIGN__BODY, /* cb 3 */
  176. - BODY_SIGN__BODY, /* cb 4 */
  177. - BODY_ONLY, /* cb 5 */
  178. - BODY_ONLY, /* cb 6 */
  179. - BODY_SIGN__BODY, /* cb 7 */
  180. - BODY_SIGN__BODY, /* cb 8 */
  181. - BODY_SIGN__BODY, /* cb 9 */
  182. - BODY_SIGN__BODY, /* cb 10 */
  183. - BODY_SIGN_ESC__BODY, /* cb 11 */
  184. - STOP_THIS_STATE, /* cb 12 */
  185. - STOP_THIS_STATE, /* cb 13 */
  186. - STOP_THIS_STATE, /* cb 14 */
  187. - STOP_THIS_STATE, /* cb 15 */
  188. - BODY_SIGN_ESC__BODY, /* cb 16 */
  189. - BODY_SIGN_ESC__BODY, /* cb 17 */
  190. - BODY_SIGN_ESC__BODY, /* cb 18 */
  191. - BODY_SIGN_ESC__BODY, /* cb 19 */
  192. - BODY_SIGN_ESC__BODY, /* cb 20 */
  193. - BODY_SIGN_ESC__BODY, /* cb 21 */
  194. - BODY_SIGN_ESC__BODY, /* cb 22 */
  195. - BODY_SIGN_ESC__BODY, /* cb 23 */
  196. - BODY_SIGN_ESC__BODY, /* cb 24 */
  197. - BODY_SIGN_ESC__BODY, /* cb 25 */
  198. - BODY_SIGN_ESC__BODY, /* cb 26 */
  199. - BODY_SIGN_ESC__BODY, /* cb 27 */
  200. - BODY_SIGN_ESC__BODY, /* cb 28 */
  201. - BODY_SIGN_ESC__BODY, /* cb 29 */
  202. - BODY_SIGN_ESC__BODY, /* cb 30 */
  203. - BODY_SIGN_ESC__BODY}; /* cb 31 */
  204. -
  205. -const STATEFUNC aStateConstant2State[] = {
  206. - NULL, /* 0 = STOP_THIS_STATE */
  207. - Hcr_State_BODY_ONLY, /* 1 = BODY_ONLY */
  208. - Hcr_State_BODY_SIGN__BODY, /* 2 = BODY_SIGN__BODY */
  209. - Hcr_State_BODY_SIGN__SIGN, /* 3 = BODY_SIGN__SIGN */
  210. - Hcr_State_BODY_SIGN_ESC__BODY, /* 4 = BODY_SIGN_ESC__BODY */
  211. - Hcr_State_BODY_SIGN_ESC__SIGN, /* 5 = BODY_SIGN_ESC__SIGN */
  212. - Hcr_State_BODY_SIGN_ESC__ESC_PREFIX, /* 6 = BODY_SIGN_ESC__ESC_PREFIX */
  213. - Hcr_State_BODY_SIGN_ESC__ESC_WORD}; /* 7 = BODY_SIGN_ESC__ESC_WORD */
  214. -
  215. -/* CB: 0 1 2 3 4 5 6 7 8 9 10 12
  216. - * 14 16 18 20 22 24 26 28 30 */
  217. -const USHORT aLargestAbsoluteValue[MAX_CB] = {
  218. - 0, 1, 1, 2, 2, 4, 4, 7, 7, 12, 12,
  219. - 8191, 0, 0, 0, 0, 15, 31, 47, 63, 95, 127,
  220. - 159, 191, 223, 255, 319, 383, 511, 767, 1023, 2047}; /* lav */
  221. /* CB: 11 13
  222. * 15 17 19 21 23 25 27 39 31 */
  223. diff --git a/libAACdec/src/aac_rom.h b/libAACdec/src/aac_rom.h
  224. index ffaf951..503e459 100644
  225. --- a/libAACdec/src/aac_rom.h
  226. +++ b/libAACdec/src/aac_rom.h
  227. @@ -105,8 +105,6 @@ amm-info@iis.fraunhofer.de
  228. #include "common_fix.h"
  229. #include "FDK_audio.h"
  230. -#include "aacdec_hcr_types.h"
  231. -#include "aacdec_hcrs.h"
  232. #define PCM_DEC FIXP_DBL
  233. #define MAXVAL_PCM_DEC MAXVAL_DBL
  234. @@ -165,7 +163,7 @@ typedef struct {
  235. extern const CodeBookDescription AACcodeBookDescriptionTable[13];
  236. extern const CodeBookDescription AACcodeBookDescriptionSCL;
  237. -extern const STATEFUNC aStateConstant2State[];
  238. +#define MAX_CB 32 /* last used CB is cb #31 when VCB11 is used */
  239. extern const SCHAR aCodebook2StartInt[];
  240. diff --git a/libAACdec/src/aacdec_hcr.cpp b/libAACdec/src/aacdec_hcr.cpp
  241. deleted file mode 100644
  242. index 6114756..0000000
  243. --- a/libAACdec/src/aacdec_hcr.cpp
  244. +++ /dev/null
  245. @@ -1,1498 +0,0 @@
  246. -/* -----------------------------------------------------------------------------
  247. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  248. -
  249. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  250. -Forschung e.V. All rights reserved.
  251. -
  252. - 1. INTRODUCTION
  253. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  254. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  255. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  256. -a wide variety of Android devices.
  257. -
  258. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  259. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  260. -full-bandwidth communications codec by independent studies and is widely
  261. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  262. -specifications.
  263. -
  264. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  265. -those of Fraunhofer) may be obtained through Via Licensing
  266. -(www.vialicensing.com) or through the respective patent owners individually for
  267. -the purpose of encoding or decoding bit streams in products that are compliant
  268. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  269. -Android devices already license these patent claims through Via Licensing or
  270. -directly from the patent owners, and therefore FDK AAC Codec software may
  271. -already be covered under those patent licenses when it is used for those
  272. -licensed purposes only.
  273. -
  274. -Commercially-licensed AAC software libraries, including floating-point versions
  275. -with enhanced sound quality, are also available from Fraunhofer. Users are
  276. -encouraged to check the Fraunhofer website for additional applications
  277. -information and documentation.
  278. -
  279. -2. COPYRIGHT LICENSE
  280. -
  281. -Redistribution and use in source and binary forms, with or without modification,
  282. -are permitted without payment of copyright license fees provided that you
  283. -satisfy the following conditions:
  284. -
  285. -You must retain the complete text of this software license in redistributions of
  286. -the FDK AAC Codec or your modifications thereto in source code form.
  287. -
  288. -You must retain the complete text of this software license in the documentation
  289. -and/or other materials provided with redistributions of the FDK AAC Codec or
  290. -your modifications thereto in binary form. You must make available free of
  291. -charge copies of the complete source code of the FDK AAC Codec and your
  292. -modifications thereto to recipients of copies in binary form.
  293. -
  294. -The name of Fraunhofer may not be used to endorse or promote products derived
  295. -from this library without prior written permission.
  296. -
  297. -You may not charge copyright license fees for anyone to use, copy or distribute
  298. -the FDK AAC Codec software or your modifications thereto.
  299. -
  300. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  301. -that you changed the software and the date of any change. For modified versions
  302. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  303. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  304. -AAC Codec Library for Android."
  305. -
  306. -3. NO PATENT LICENSE
  307. -
  308. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  309. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  310. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  311. -software.
  312. -
  313. -You may use this FDK AAC Codec software or modifications thereto only for
  314. -purposes that are authorized by appropriate patent licenses.
  315. -
  316. -4. DISCLAIMER
  317. -
  318. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  319. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  320. -including but not limited to the implied warranties of merchantability and
  321. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  322. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  323. -or consequential damages, including but not limited to procurement of substitute
  324. -goods or services; loss of use, data, or profits, or business interruption,
  325. -however caused and on any theory of liability, whether in contract, strict
  326. -liability, or tort (including negligence), arising in any way out of the use of
  327. -this software, even if advised of the possibility of such damage.
  328. -
  329. -5. CONTACT INFORMATION
  330. -
  331. -Fraunhofer Institute for Integrated Circuits IIS
  332. -Attention: Audio and Multimedia Departments - FDK AAC LL
  333. -Am Wolfsmantel 33
  334. -91058 Erlangen, Germany
  335. -
  336. -www.iis.fraunhofer.de/amm
  337. -amm-info@iis.fraunhofer.de
  338. ------------------------------------------------------------------------------ */
  339. -
  340. -/**************************** AAC decoder library ******************************
  341. -
  342. - Author(s): Robert Weidner (DSP Solutions)
  343. -
  344. - Description: HCR Decoder: HCR initialization, preprocess HCR sideinfo,
  345. - decode priority codewords (PCWs)
  346. -
  347. -*******************************************************************************/
  348. -
  349. -#include "aacdec_hcr.h"
  350. -
  351. -#include "aacdec_hcr_types.h"
  352. -#include "aacdec_hcr_bit.h"
  353. -#include "aacdec_hcrs.h"
  354. -#include "aac_ram.h"
  355. -#include "aac_rom.h"
  356. -#include "channel.h"
  357. -#include "block.h"
  358. -
  359. -#include "aacdecoder.h" /* for ID_CPE, ID_SCE ... */
  360. -#include "FDK_bitstream.h"
  361. -
  362. -extern int mlFileChCurr;
  363. -
  364. -static void errDetectorInHcrSideinfoShrt(SCHAR cb, SHORT numLine,
  365. - UINT *errorWord);
  366. -
  367. -static void errDetectorInHcrLengths(SCHAR lengthOfLongestCodeword,
  368. - SHORT lengthOfReorderedSpectralData,
  369. - UINT *errorWord);
  370. -
  371. -static void HcrCalcNumCodeword(H_HCR_INFO pHcr);
  372. -static void HcrSortCodebookAndNumCodewordInSection(H_HCR_INFO pHcr);
  373. -static void HcrPrepareSegmentationGrid(H_HCR_INFO pHcr);
  374. -static void HcrExtendedSectionInfo(H_HCR_INFO pHcr);
  375. -
  376. -static void DeriveNumberOfExtendedSortedSectionsInSets(
  377. - UINT numSegment, USHORT *pNumExtendedSortedCodewordInSection,
  378. - int numExtendedSortedCodewordInSectionIdx,
  379. - USHORT *pNumExtendedSortedSectionsInSets,
  380. - int numExtendedSortedSectionsInSetsIdx);
  381. -
  382. -static INT DecodeEscapeSequence(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  383. - INT quantSpecCoef, INT *pLeftStartOfSegment,
  384. - SCHAR *pRemainingBitsInSegment,
  385. - int *pNumDecodedBits);
  386. -
  387. -static int DecodePCW_Sign(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  388. - UINT codebookDim, const SCHAR *pQuantVal,
  389. - FIXP_DBL *pQuantSpecCoef, int *quantSpecCoefIdx,
  390. - INT *pLeftStartOfSegment,
  391. - SCHAR *pRemainingBitsInSegment, int *pNumDecodedBits);
  392. -
  393. -static const SCHAR *DecodePCW_Body(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  394. - const UINT *pCurrentTree,
  395. - const SCHAR *pQuantValBase,
  396. - INT *pLeftStartOfSegment,
  397. - SCHAR *pRemainingBitsInSegment,
  398. - int *pNumDecodedBits);
  399. -
  400. -static void DecodePCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO pHcr);
  401. -
  402. -static void HcrReorderQuantizedSpectralCoefficients(
  403. - H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  404. - const SamplingRateInfo *pSamplingRateInfo);
  405. -
  406. -static UCHAR errDetectPcwSegmentation(SCHAR remainingBitsInSegment,
  407. - H_HCR_INFO pHcr, PCW_TYPE kind,
  408. - FIXP_DBL *qsc_base_of_cw,
  409. - UCHAR dimension);
  410. -
  411. -static void errDetectWithinSegmentationFinal(H_HCR_INFO pHcr);
  412. -
  413. -/*---------------------------------------------------------------------------------------------
  414. - description: Check if codebook and numSect are within allowed range
  415. -(short only)
  416. ---------------------------------------------------------------------------------------------
  417. -*/
  418. -static void errDetectorInHcrSideinfoShrt(SCHAR cb, SHORT numLine,
  419. - UINT *errorWord) {
  420. - if (cb < ZERO_HCB || cb >= MAX_CB_CHECK || cb == BOOKSCL) {
  421. - *errorWord |= CB_OUT_OF_RANGE_SHORT_BLOCK;
  422. - }
  423. - if (numLine < 0 || numLine > 1024) {
  424. - *errorWord |= LINE_IN_SECT_OUT_OF_RANGE_SHORT_BLOCK;
  425. - }
  426. -}
  427. -
  428. -/*---------------------------------------------------------------------------------------------
  429. - description: Check both HCR lengths
  430. ---------------------------------------------------------------------------------------------
  431. -*/
  432. -static void errDetectorInHcrLengths(SCHAR lengthOfLongestCodeword,
  433. - SHORT lengthOfReorderedSpectralData,
  434. - UINT *errorWord) {
  435. - if (lengthOfReorderedSpectralData < lengthOfLongestCodeword) {
  436. - *errorWord |= HCR_SI_LENGTHS_FAILURE;
  437. - }
  438. -}
  439. -
  440. -/*---------------------------------------------------------------------------------------------
  441. - description: Decode (and adapt if necessary) the two HCR sideinfo
  442. -components: 'reordered_spectral_data_length' and 'longest_codeword_length'
  443. ---------------------------------------------------------------------------------------------
  444. -*/
  445. -
  446. -void CHcr_Read(HANDLE_FDK_BITSTREAM bs,
  447. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  448. - const MP4_ELEMENT_ID globalHcrType) {
  449. - SHORT lengOfReorderedSpectralData;
  450. - SCHAR lengOfLongestCodeword;
  451. -
  452. - pAacDecoderChannelInfo->pDynData->specificTo.aac.lenOfReorderedSpectralData =
  453. - 0;
  454. - pAacDecoderChannelInfo->pDynData->specificTo.aac.lenOfLongestCodeword = 0;
  455. -
  456. - /* ------- SI-Value No 1 ------- */
  457. - lengOfReorderedSpectralData = FDKreadBits(bs, 14) + ERROR_LORSD;
  458. - if (globalHcrType == ID_CPE) {
  459. - if ((lengOfReorderedSpectralData >= 0) &&
  460. - (lengOfReorderedSpectralData <= CPE_TOP_LENGTH)) {
  461. - pAacDecoderChannelInfo->pDynData->specificTo.aac
  462. - .lenOfReorderedSpectralData =
  463. - lengOfReorderedSpectralData; /* the decoded value is within range */
  464. - } else {
  465. - if (lengOfReorderedSpectralData > CPE_TOP_LENGTH) {
  466. - pAacDecoderChannelInfo->pDynData->specificTo.aac
  467. - .lenOfReorderedSpectralData =
  468. - CPE_TOP_LENGTH; /* use valid maximum */
  469. - }
  470. - }
  471. - } else if (globalHcrType == ID_SCE || globalHcrType == ID_LFE ||
  472. - globalHcrType == ID_CCE) {
  473. - if ((lengOfReorderedSpectralData >= 0) &&
  474. - (lengOfReorderedSpectralData <= SCE_TOP_LENGTH)) {
  475. - pAacDecoderChannelInfo->pDynData->specificTo.aac
  476. - .lenOfReorderedSpectralData =
  477. - lengOfReorderedSpectralData; /* the decoded value is within range */
  478. - } else {
  479. - if (lengOfReorderedSpectralData > SCE_TOP_LENGTH) {
  480. - pAacDecoderChannelInfo->pDynData->specificTo.aac
  481. - .lenOfReorderedSpectralData =
  482. - SCE_TOP_LENGTH; /* use valid maximum */
  483. - }
  484. - }
  485. - }
  486. -
  487. - /* ------- SI-Value No 2 ------- */
  488. - lengOfLongestCodeword = FDKreadBits(bs, 6) + ERROR_LOLC;
  489. - if ((lengOfLongestCodeword >= 0) &&
  490. - (lengOfLongestCodeword <= LEN_OF_LONGEST_CW_TOP_LENGTH)) {
  491. - pAacDecoderChannelInfo->pDynData->specificTo.aac.lenOfLongestCodeword =
  492. - lengOfLongestCodeword; /* the decoded value is within range */
  493. - } else {
  494. - if (lengOfLongestCodeword > LEN_OF_LONGEST_CW_TOP_LENGTH) {
  495. - pAacDecoderChannelInfo->pDynData->specificTo.aac.lenOfLongestCodeword =
  496. - LEN_OF_LONGEST_CW_TOP_LENGTH; /* use valid maximum */
  497. - }
  498. - }
  499. -}
  500. -
  501. -/*---------------------------------------------------------------------------------------------
  502. - description: Set up HCR - must be called before every call to
  503. -HcrDecoder(). For short block a sorting algorithm is applied to get the SI in
  504. -the order that HCR could assemble the qsc's as if it is a long block.
  505. ------------------------------------------------------------------------------------------------
  506. - return: error log
  507. ---------------------------------------------------------------------------------------------
  508. -*/
  509. -
  510. -UINT HcrInit(H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  511. - const SamplingRateInfo *pSamplingRateInfo,
  512. - HANDLE_FDK_BITSTREAM bs) {
  513. - CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
  514. - SHORT *pNumLinesInSec;
  515. - UCHAR *pCodeBk;
  516. - SHORT numSection;
  517. - SCHAR cb;
  518. - int numLine;
  519. - int i;
  520. -
  521. - pHcr->decInOut.lengthOfReorderedSpectralData =
  522. - pAacDecoderChannelInfo->pDynData->specificTo.aac
  523. - .lenOfReorderedSpectralData;
  524. - pHcr->decInOut.lengthOfLongestCodeword =
  525. - pAacDecoderChannelInfo->pDynData->specificTo.aac.lenOfLongestCodeword;
  526. - pHcr->decInOut.pQuantizedSpectralCoefficientsBase =
  527. - pAacDecoderChannelInfo->pSpectralCoefficient;
  528. - pHcr->decInOut.quantizedSpectralCoefficientsIdx = 0;
  529. - pHcr->decInOut.pCodebook =
  530. - pAacDecoderChannelInfo->pDynData->specificTo.aac.aCodeBooks4Hcr;
  531. - pHcr->decInOut.pNumLineInSect =
  532. - pAacDecoderChannelInfo->pDynData->specificTo.aac.aNumLineInSec4Hcr;
  533. - pHcr->decInOut.numSection =
  534. - pAacDecoderChannelInfo->pDynData->specificTo.aac.numberSection;
  535. - pHcr->decInOut.errorLog = 0;
  536. - pHcr->nonPcwSideinfo.pResultBase =
  537. - SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
  538. -
  539. - FDKsyncCache(bs);
  540. - pHcr->decInOut.bitstreamAnchor = (INT)FDKgetValidBits(bs);
  541. -
  542. - if (!IsLongBlock(&pAacDecoderChannelInfo->icsInfo)) /* short block */
  543. - {
  544. - SHORT band;
  545. - SHORT maxBand;
  546. - SCHAR group;
  547. - SCHAR winGroupLen;
  548. - SCHAR window;
  549. - SCHAR numUnitInBand;
  550. - SCHAR cntUnitInBand;
  551. - SCHAR groupWin;
  552. - SCHAR cb_prev;
  553. -
  554. - UCHAR *pCodeBook;
  555. - const SHORT *BandOffsets;
  556. - SCHAR numOfGroups;
  557. -
  558. - pCodeBook = pAacDecoderChannelInfo->pDynData->aCodeBook; /* in */
  559. - pNumLinesInSec = pHcr->decInOut.pNumLineInSect; /* out */
  560. - pCodeBk = pHcr->decInOut.pCodebook; /* out */
  561. - BandOffsets =
  562. - GetScaleFactorBandOffsets(pIcsInfo, pSamplingRateInfo); /* aux */
  563. - numOfGroups = GetWindowGroups(pIcsInfo);
  564. -
  565. - numLine = 0;
  566. - numSection = 0;
  567. - cb = pCodeBook[0];
  568. - cb_prev = pCodeBook[0];
  569. -
  570. - /* convert HCR-sideinfo into a unitwise manner: When the cb changes, a new
  571. - * section starts */
  572. -
  573. - *pCodeBk++ = cb_prev;
  574. -
  575. - maxBand = GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->icsInfo);
  576. - for (band = 0; band < maxBand;
  577. - band++) { /* from low to high sfbs i.e. from low to high frequencies */
  578. - numUnitInBand =
  579. - ((BandOffsets[band + 1] - BandOffsets[band]) >>
  580. - FOUR_LOG_DIV_TWO_LOG); /* get the number of units in current sfb */
  581. - for (cntUnitInBand = numUnitInBand; cntUnitInBand != 0;
  582. - cntUnitInBand--) { /* for every unit in the band */
  583. - for (window = 0, group = 0; group < numOfGroups; group++) {
  584. - winGroupLen = (SCHAR)GetWindowGroupLength(
  585. - &pAacDecoderChannelInfo->icsInfo, group);
  586. - for (groupWin = winGroupLen; groupWin != 0; groupWin--, window++) {
  587. - cb = pCodeBook[group * 16 + band];
  588. - if (cb != cb_prev) {
  589. - errDetectorInHcrSideinfoShrt(cb, numLine,
  590. - &pHcr->decInOut.errorLog);
  591. - if (pHcr->decInOut.errorLog != 0) {
  592. - return (pHcr->decInOut.errorLog);
  593. - }
  594. - *pCodeBk++ = cb;
  595. - *pNumLinesInSec++ = numLine;
  596. - numSection++;
  597. -
  598. - cb_prev = cb;
  599. - numLine = LINES_PER_UNIT;
  600. - } else {
  601. - numLine += LINES_PER_UNIT;
  602. - }
  603. - }
  604. - }
  605. - }
  606. - }
  607. -
  608. - numSection++;
  609. -
  610. - errDetectorInHcrSideinfoShrt(cb, numLine, &pHcr->decInOut.errorLog);
  611. - if (numSection <= 0 || numSection > 1024 / 2) {
  612. - pHcr->decInOut.errorLog |= NUM_SECT_OUT_OF_RANGE_SHORT_BLOCK;
  613. - }
  614. - errDetectorInHcrLengths(pHcr->decInOut.lengthOfLongestCodeword,
  615. - pHcr->decInOut.lengthOfReorderedSpectralData,
  616. - &pHcr->decInOut.errorLog);
  617. - if (pHcr->decInOut.errorLog != 0) {
  618. - return (pHcr->decInOut.errorLog);
  619. - }
  620. -
  621. - *pCodeBk = cb;
  622. - *pNumLinesInSec = numLine;
  623. - pHcr->decInOut.numSection = numSection;
  624. -
  625. - } else /* end short block prepare SI */
  626. - { /* long block */
  627. - errDetectorInHcrLengths(pHcr->decInOut.lengthOfLongestCodeword,
  628. - pHcr->decInOut.lengthOfReorderedSpectralData,
  629. - &pHcr->decInOut.errorLog);
  630. - numSection = pHcr->decInOut.numSection;
  631. - pNumLinesInSec = pHcr->decInOut.pNumLineInSect;
  632. - pCodeBk = pHcr->decInOut.pCodebook;
  633. - if (numSection <= 0 || numSection > 64) {
  634. - pHcr->decInOut.errorLog |= NUM_SECT_OUT_OF_RANGE_LONG_BLOCK;
  635. - numSection = 0;
  636. - }
  637. -
  638. - for (i = numSection; i != 0; i--) {
  639. - cb = *pCodeBk++;
  640. -
  641. - if (cb < ZERO_HCB || cb >= MAX_CB_CHECK || cb == BOOKSCL) {
  642. - pHcr->decInOut.errorLog |= CB_OUT_OF_RANGE_LONG_BLOCK;
  643. - }
  644. -
  645. - numLine = *pNumLinesInSec++;
  646. - /* FDK_ASSERT(numLine > 0); */
  647. -
  648. - if ((numLine <= 0) || (numLine > 1024)) {
  649. - pHcr->decInOut.errorLog |= LINE_IN_SECT_OUT_OF_RANGE_LONG_BLOCK;
  650. - }
  651. - }
  652. - if (pHcr->decInOut.errorLog != 0) {
  653. - return (pHcr->decInOut.errorLog);
  654. - }
  655. - }
  656. -
  657. - pCodeBk = pHcr->decInOut.pCodebook;
  658. - for (i = 0; i < numSection; i++) {
  659. - if ((*pCodeBk == NOISE_HCB) || (*pCodeBk == INTENSITY_HCB2) ||
  660. - (*pCodeBk == INTENSITY_HCB)) {
  661. - *pCodeBk = 0;
  662. - }
  663. - pCodeBk++;
  664. - }
  665. -
  666. - /* HCR-sideinfo-input is complete and seems to be valid */
  667. -
  668. - return (pHcr->decInOut.errorLog);
  669. -}
  670. -
  671. -/*---------------------------------------------------------------------------------------------
  672. - description: This function decodes the codewords of the spectral
  673. -coefficients from the bitstream according to the HCR algorithm and stores the
  674. -quantized spectral coefficients in correct order in the output buffer.
  675. ---------------------------------------------------------------------------------------------
  676. -*/
  677. -
  678. -UINT HcrDecoder(H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  679. - const SamplingRateInfo *pSamplingRateInfo,
  680. - HANDLE_FDK_BITSTREAM bs) {
  681. - int pTmp1, pTmp2, pTmp3, pTmp4;
  682. - int pTmp5;
  683. -
  684. - INT bitCntOffst;
  685. - INT saveBitCnt = (INT)FDKgetValidBits(bs); /* save bitstream position */
  686. -
  687. - HcrCalcNumCodeword(pHcr);
  688. -
  689. - HcrSortCodebookAndNumCodewordInSection(pHcr);
  690. -
  691. - HcrPrepareSegmentationGrid(pHcr);
  692. -
  693. - HcrExtendedSectionInfo(pHcr);
  694. -
  695. - if ((pHcr->decInOut.errorLog & HCR_FATAL_PCW_ERROR_MASK) != 0) {
  696. - return (pHcr->decInOut.errorLog); /* sideinfo is massively corrupt, return
  697. - from HCR without having decoded
  698. - anything */
  699. - }
  700. -
  701. - DeriveNumberOfExtendedSortedSectionsInSets(
  702. - pHcr->segmentInfo.numSegment,
  703. - pHcr->sectionInfo.pNumExtendedSortedCodewordInSection,
  704. - pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx,
  705. - pHcr->sectionInfo.pNumExtendedSortedSectionsInSets,
  706. - pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx);
  707. -
  708. - /* store */
  709. - pTmp1 = pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx;
  710. - pTmp2 = pHcr->sectionInfo.extendedSortedCodebookIdx;
  711. - pTmp3 = pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx;
  712. - pTmp4 = pHcr->decInOut.quantizedSpectralCoefficientsIdx;
  713. - pTmp5 = pHcr->sectionInfo.maxLenOfCbInExtSrtSecIdx;
  714. -
  715. - /* ------- decode meaningful PCWs ------ */
  716. - DecodePCWs(bs, pHcr);
  717. -
  718. - if ((pHcr->decInOut.errorLog & HCR_FATAL_PCW_ERROR_MASK) == 0) {
  719. - /* ------ decode the non-PCWs -------- */
  720. - DecodeNonPCWs(bs, pHcr);
  721. - }
  722. -
  723. - errDetectWithinSegmentationFinal(pHcr);
  724. -
  725. - /* restore */
  726. - pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx = pTmp1;
  727. - pHcr->sectionInfo.extendedSortedCodebookIdx = pTmp2;
  728. - pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx = pTmp3;
  729. - pHcr->decInOut.quantizedSpectralCoefficientsIdx = pTmp4;
  730. - pHcr->sectionInfo.maxLenOfCbInExtSrtSecIdx = pTmp5;
  731. -
  732. - HcrReorderQuantizedSpectralCoefficients(pHcr, pAacDecoderChannelInfo,
  733. - pSamplingRateInfo);
  734. -
  735. - /* restore bitstream position */
  736. - bitCntOffst = (INT)FDKgetValidBits(bs) - saveBitCnt;
  737. - if (bitCntOffst) {
  738. - FDKpushBiDirectional(bs, bitCntOffst);
  739. - }
  740. -
  741. - return (pHcr->decInOut.errorLog);
  742. -}
  743. -
  744. -/*---------------------------------------------------------------------------------------------
  745. - description: This function reorders the quantized spectral coefficients
  746. -sectionwise for long- and short-blocks and compares to the LAV (Largest Absolute
  747. -Value of the current codebook) -- a counter is incremented if there is an error
  748. - detected.
  749. - Additional for short-blocks a unit-based-deinterleaving is
  750. -applied. Moreover (for short blocks) the scaling is derived (compare plain
  751. -huffman decoder).
  752. ---------------------------------------------------------------------------------------------
  753. -*/
  754. -
  755. -static void HcrReorderQuantizedSpectralCoefficients(
  756. - H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  757. - const SamplingRateInfo *pSamplingRateInfo) {
  758. - INT qsc;
  759. - UINT abs_qsc;
  760. - UINT i, j;
  761. - USHORT numSpectralValuesInSection;
  762. - FIXP_DBL *pTeVa;
  763. - USHORT lavErrorCnt = 0;
  764. -
  765. - UINT numSection = pHcr->decInOut.numSection;
  766. - SPECTRAL_PTR pQuantizedSpectralCoefficientsBase =
  767. - pHcr->decInOut.pQuantizedSpectralCoefficientsBase;
  768. - FIXP_DBL *pQuantizedSpectralCoefficients =
  769. - SPEC_LONG(pHcr->decInOut.pQuantizedSpectralCoefficientsBase);
  770. - const UCHAR *pCbDimShift = aDimCbShift;
  771. - const USHORT *pLargestAbsVal = aLargestAbsoluteValue;
  772. - UCHAR *pSortedCodebook = pHcr->sectionInfo.pSortedCodebook;
  773. - USHORT *pNumSortedCodewordInSection =
  774. - pHcr->sectionInfo.pNumSortedCodewordInSection;
  775. - USHORT *pReorderOffset = pHcr->sectionInfo.pReorderOffset;
  776. - FIXP_DBL pTempValues[1024];
  777. - FIXP_DBL *pBak = pTempValues;
  778. -
  779. - FDKmemclear(pTempValues, 1024 * sizeof(FIXP_DBL));
  780. -
  781. - /* long and short: check if decoded huffman-values (quantized spectral
  782. - * coefficients) are within range */
  783. - for (i = numSection; i != 0; i--) {
  784. - numSpectralValuesInSection = *pNumSortedCodewordInSection++
  785. - << pCbDimShift[*pSortedCodebook];
  786. - pTeVa = &pTempValues[*pReorderOffset++];
  787. - for (j = numSpectralValuesInSection; j != 0; j--) {
  788. - qsc = *pQuantizedSpectralCoefficients++;
  789. - abs_qsc = fAbs(qsc);
  790. - if (abs_qsc <= pLargestAbsVal[*pSortedCodebook]) {
  791. - *pTeVa++ = (FIXP_DBL)qsc; /* the qsc value is within range */
  792. - } else { /* line is too high .. */
  793. - if (abs_qsc ==
  794. - Q_VALUE_INVALID) { /* .. because of previous marking --> dont set
  795. - LAV flag (would be confusing), just copy out
  796. - the already marked value */
  797. - *pTeVa++ = (FIXP_DBL)qsc;
  798. - } else { /* .. because a too high value was decoded for this cb --> set
  799. - LAV flag */
  800. - *pTeVa++ = (FIXP_DBL)Q_VALUE_INVALID;
  801. - lavErrorCnt += 1;
  802. - }
  803. - }
  804. - }
  805. - pSortedCodebook++;
  806. - }
  807. -
  808. - if (!IsLongBlock(&pAacDecoderChannelInfo->icsInfo)) {
  809. - FIXP_DBL *pOut;
  810. - FIXP_DBL locMax;
  811. - FIXP_DBL tmp;
  812. - SCHAR groupoffset;
  813. - SCHAR group;
  814. - SCHAR band;
  815. - SCHAR groupwin;
  816. - SCHAR window;
  817. - SCHAR numWinGroup;
  818. - SHORT interm;
  819. - SCHAR numSfbTransm;
  820. - SCHAR winGroupLen;
  821. - SHORT index;
  822. - INT msb;
  823. - INT lsb;
  824. -
  825. - SHORT *pScaleFacHcr = pAacDecoderChannelInfo->pDynData->aScaleFactor;
  826. - SHORT *pSfbSclHcr = pAacDecoderChannelInfo->pDynData->aSfbScale;
  827. - const SHORT *BandOffsets = GetScaleFactorBandOffsets(
  828. - &pAacDecoderChannelInfo->icsInfo, pSamplingRateInfo);
  829. -
  830. - pBak = pTempValues;
  831. - /* deinterleave unitwise for short blocks */
  832. - for (window = 0; window < (8); window++) {
  833. - pOut = SPEC(pQuantizedSpectralCoefficientsBase, window,
  834. - pAacDecoderChannelInfo->granuleLength);
  835. - for (i = 0; i < (LINES_PER_UNIT_GROUP); i++) {
  836. - pTeVa = pBak + (window << FOUR_LOG_DIV_TWO_LOG) +
  837. - i * 32; /* distance of lines between unit groups has to be
  838. - constant for every framelength (32)! */
  839. - for (j = (LINES_PER_UNIT); j != 0; j--) {
  840. - *pOut++ = *pTeVa++;
  841. - }
  842. - }
  843. - }
  844. -
  845. - /* short blocks only */
  846. - /* derive global scaling-value for every sfb and every window (as it is done
  847. - * in plain-huffman-decoder at short blocks) */
  848. - groupoffset = 0;
  849. -
  850. - numWinGroup = GetWindowGroups(&pAacDecoderChannelInfo->icsInfo);
  851. - numSfbTransm =
  852. - GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->icsInfo);
  853. -
  854. - for (group = 0; group < numWinGroup; group++) {
  855. - winGroupLen =
  856. - GetWindowGroupLength(&pAacDecoderChannelInfo->icsInfo, group);
  857. - for (band = 0; band < numSfbTransm; band++) {
  858. - interm = group * 16 + band;
  859. - msb = pScaleFacHcr[interm] >> 2;
  860. - lsb = pScaleFacHcr[interm] & 3;
  861. - for (groupwin = 0; groupwin < winGroupLen; groupwin++) {
  862. - window = groupoffset + groupwin;
  863. - pBak = SPEC(pQuantizedSpectralCoefficientsBase, window,
  864. - pAacDecoderChannelInfo->granuleLength);
  865. - locMax = FL2FXCONST_DBL(0.0f);
  866. - for (index = BandOffsets[band]; index < BandOffsets[band + 1];
  867. - index += LINES_PER_UNIT) {
  868. - pTeVa = &pBak[index];
  869. - for (i = LINES_PER_UNIT; i != 0; i--) {
  870. - tmp = (*pTeVa < FL2FXCONST_DBL(0.0f)) ? -*pTeVa++ : *pTeVa++;
  871. - locMax = fixMax(tmp, locMax);
  872. - }
  873. - }
  874. - if (fixp_abs(locMax) > (FIXP_DBL)MAX_QUANTIZED_VALUE) {
  875. - locMax = (FIXP_DBL)MAX_QUANTIZED_VALUE;
  876. - }
  877. - pSfbSclHcr[window * 16 + band] =
  878. - msb - GetScaleFromValue(
  879. - locMax, lsb); /* save global scale maxima in this sfb */
  880. - }
  881. - }
  882. - groupoffset +=
  883. - GetWindowGroupLength(&pAacDecoderChannelInfo->icsInfo, group);
  884. - }
  885. - } else {
  886. - /* copy straight for long-blocks */
  887. - pQuantizedSpectralCoefficients =
  888. - SPEC_LONG(pQuantizedSpectralCoefficientsBase);
  889. - for (i = 1024; i != 0; i--) {
  890. - *pQuantizedSpectralCoefficients++ = *pBak++;
  891. - }
  892. - }
  893. -
  894. - if (lavErrorCnt != 0) {
  895. - pHcr->decInOut.errorLog |= LAV_VIOLATION;
  896. - }
  897. -}
  898. -
  899. -/*---------------------------------------------------------------------------------------------
  900. - description: This function calculates the number of codewords
  901. - for each section (numCodewordInSection) and the number of
  902. -codewords for all sections (numCodeword). For zero and intensity codebooks a
  903. -entry is also done in the variable numCodewordInSection. It is assumed that the
  904. -codebook is a two tuples codebook. This is needed later for the calculation of
  905. -the base addresses for the reordering of the quantize spectral coefficients at
  906. -the end of the hcr tool. The variable numCodeword contain the number of
  907. -codewords which are really in the bitstream. Zero or intensity codebooks does
  908. -not increase the variable numCodewords.
  909. ------------------------------------------------------------------------------------------------
  910. - return: -
  911. ---------------------------------------------------------------------------------------------
  912. -*/
  913. -
  914. -static void HcrCalcNumCodeword(H_HCR_INFO pHcr) {
  915. - int hcrSection;
  916. - UINT numCodeword;
  917. -
  918. - UINT numSection = pHcr->decInOut.numSection;
  919. - UCHAR *pCodebook = pHcr->decInOut.pCodebook;
  920. - SHORT *pNumLineInSection = pHcr->decInOut.pNumLineInSect;
  921. - const UCHAR *pCbDimShift = aDimCbShift;
  922. -
  923. - USHORT *pNumCodewordInSection = pHcr->sectionInfo.pNumCodewordInSection;
  924. -
  925. - numCodeword = 0;
  926. - for (hcrSection = numSection; hcrSection != 0; hcrSection--) {
  927. - *pNumCodewordInSection = *pNumLineInSection++ >> pCbDimShift[*pCodebook];
  928. - if (*pCodebook != 0) {
  929. - numCodeword += *pNumCodewordInSection;
  930. - }
  931. - pNumCodewordInSection++;
  932. - pCodebook++;
  933. - }
  934. - pHcr->sectionInfo.numCodeword = numCodeword;
  935. -}
  936. -
  937. -/*---------------------------------------------------------------------------------------------
  938. - description: This function calculates the number
  939. - of sorted codebooks and sorts the codebooks and the
  940. -numCodewordInSection according to the priority.
  941. ---------------------------------------------------------------------------------------------
  942. -*/
  943. -
  944. -static void HcrSortCodebookAndNumCodewordInSection(H_HCR_INFO pHcr) {
  945. - UINT i, j, k;
  946. - UCHAR temp;
  947. - UINT counter;
  948. - UINT startOffset;
  949. - UINT numZeroSection;
  950. - UCHAR *pDest;
  951. - UINT numSectionDec;
  952. -
  953. - UINT numSection = pHcr->decInOut.numSection;
  954. - UCHAR *pCodebook = pHcr->decInOut.pCodebook;
  955. - UCHAR *pSortedCodebook = pHcr->sectionInfo.pSortedCodebook;
  956. - USHORT *pNumCodewordInSection = pHcr->sectionInfo.pNumCodewordInSection;
  957. - USHORT *pNumSortedCodewordInSection =
  958. - pHcr->sectionInfo.pNumSortedCodewordInSection;
  959. - UCHAR *pCodebookSwitch = pHcr->sectionInfo.pCodebookSwitch;
  960. - USHORT *pReorderOffset = pHcr->sectionInfo.pReorderOffset;
  961. - const UCHAR *pCbPriority = aCbPriority;
  962. - const UCHAR *pMinOfCbPair = aMinOfCbPair;
  963. - const UCHAR *pMaxOfCbPair = aMaxOfCbPair;
  964. - const UCHAR *pCbDimShift = aDimCbShift;
  965. -
  966. - UINT searchStart = 0;
  967. -
  968. - /* calculate *pNumSortedSection and store the priorities in array
  969. - * pSortedCdebook */
  970. - pDest = pSortedCodebook;
  971. - numZeroSection = 0;
  972. - for (i = numSection; i != 0; i--) {
  973. - if (pCbPriority[*pCodebook] == 0) {
  974. - numZeroSection += 1;
  975. - }
  976. - *pDest++ = pCbPriority[*pCodebook++];
  977. - }
  978. - pHcr->sectionInfo.numSortedSection =
  979. - numSection - numZeroSection; /* numSortedSection contains no zero or
  980. - intensity section */
  981. - pCodebook = pHcr->decInOut.pCodebook;
  982. -
  983. - /* sort priorities of the codebooks in array pSortedCdebook[] */
  984. - numSectionDec = numSection - 1;
  985. - if (numSectionDec > 0) {
  986. - counter = numSectionDec;
  987. - for (j = numSectionDec; j != 0; j--) {
  988. - for (i = 0; i < counter; i++) {
  989. - /* swap priorities */
  990. - if (pSortedCodebook[i + 1] > pSortedCodebook[i]) {
  991. - temp = pSortedCodebook[i];
  992. - pSortedCodebook[i] = pSortedCodebook[i + 1];
  993. - pSortedCodebook[i + 1] = temp;
  994. - }
  995. - }
  996. - counter -= 1;
  997. - }
  998. - }
  999. -
  1000. - /* clear codebookSwitch array */
  1001. - for (i = numSection; i != 0; i--) {
  1002. - *pCodebookSwitch++ = 0;
  1003. - }
  1004. - pCodebookSwitch = pHcr->sectionInfo.pCodebookSwitch;
  1005. -
  1006. - /* sort sectionCodebooks and numCodwordsInSection and calculate
  1007. - * pReorderOffst[j] */
  1008. - for (j = 0; j < numSection; j++) {
  1009. - for (i = searchStart; i < numSection; i++) {
  1010. - if (pCodebookSwitch[i] == 0 &&
  1011. - (pMinOfCbPair[pSortedCodebook[j]] == pCodebook[i] ||
  1012. - pMaxOfCbPair[pSortedCodebook[j]] == pCodebook[i])) {
  1013. - pCodebookSwitch[i] = 1;
  1014. - pSortedCodebook[j] = pCodebook[i]; /* sort codebook */
  1015. - pNumSortedCodewordInSection[j] =
  1016. - pNumCodewordInSection[i]; /* sort NumCodewordInSection */
  1017. -
  1018. - startOffset = 0;
  1019. - for (k = 0; k < i; k++) { /* make entry in pReorderOffst */
  1020. - startOffset += pNumCodewordInSection[k] << pCbDimShift[pCodebook[k]];
  1021. - }
  1022. - pReorderOffset[j] =
  1023. - startOffset; /* offset for reordering the codewords */
  1024. -
  1025. - if (i == searchStart) {
  1026. - k = i;
  1027. - while (pCodebookSwitch[k++] == 1) searchStart++;
  1028. - }
  1029. - break;
  1030. - }
  1031. - }
  1032. - }
  1033. -}
  1034. -
  1035. -/*---------------------------------------------------------------------------------------------
  1036. - description: This function calculates the segmentation, which includes
  1037. -numSegment, leftStartOfSegment, rightStartOfSegment and remainingBitsInSegment.
  1038. - The segmentation could be visualized a as kind of
  1039. -'overlay-grid' for the bitstream-block holding the HCR-encoded
  1040. -quantized-spectral-coefficients.
  1041. ---------------------------------------------------------------------------------------------
  1042. -*/
  1043. -
  1044. -static void HcrPrepareSegmentationGrid(H_HCR_INFO pHcr) {
  1045. - USHORT i, j;
  1046. - USHORT numSegment = 0;
  1047. - INT segmentStart = 0;
  1048. - UCHAR segmentWidth;
  1049. - UCHAR lastSegmentWidth;
  1050. - UCHAR sortedCodebook;
  1051. - UCHAR endFlag = 0;
  1052. - INT intermediateResult;
  1053. -
  1054. - SCHAR lengthOfLongestCodeword = pHcr->decInOut.lengthOfLongestCodeword;
  1055. - SHORT lengthOfReorderedSpectralData =
  1056. - pHcr->decInOut.lengthOfReorderedSpectralData;
  1057. - UINT numSortedSection = pHcr->sectionInfo.numSortedSection;
  1058. - UCHAR *pSortedCodebook = pHcr->sectionInfo.pSortedCodebook;
  1059. - USHORT *pNumSortedCodewordInSection =
  1060. - pHcr->sectionInfo.pNumSortedCodewordInSection;
  1061. - INT *pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  1062. - INT *pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  1063. - SCHAR *pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  1064. - const UCHAR *pMaxCwLength = aMaxCwLen;
  1065. -
  1066. - for (i = numSortedSection; i != 0; i--) {
  1067. - sortedCodebook = *pSortedCodebook++;
  1068. - segmentWidth =
  1069. - fMin((INT)pMaxCwLength[sortedCodebook], (INT)lengthOfLongestCodeword);
  1070. -
  1071. - for (j = *pNumSortedCodewordInSection; j != 0; j--) {
  1072. - /* width allows a new segment */
  1073. - intermediateResult = segmentStart;
  1074. - if ((segmentStart + segmentWidth) <= lengthOfReorderedSpectralData) {
  1075. - /* store segment start, segment length and increment the number of
  1076. - * segments */
  1077. - *pLeftStartOfSegment++ = intermediateResult;
  1078. - *pRightStartOfSegment++ = intermediateResult + segmentWidth - 1;
  1079. - *pRemainingBitsInSegment++ = segmentWidth;
  1080. - segmentStart += segmentWidth;
  1081. - numSegment += 1;
  1082. - }
  1083. - /* width does not allow a new segment */
  1084. - else {
  1085. - /* correct the last segment length */
  1086. - pLeftStartOfSegment--;
  1087. - pRightStartOfSegment--;
  1088. - pRemainingBitsInSegment--;
  1089. - segmentStart = *pLeftStartOfSegment;
  1090. -
  1091. - lastSegmentWidth = lengthOfReorderedSpectralData - segmentStart;
  1092. - *pRemainingBitsInSegment = lastSegmentWidth;
  1093. - *pRightStartOfSegment = segmentStart + lastSegmentWidth - 1;
  1094. - endFlag = 1;
  1095. - break;
  1096. - }
  1097. - }
  1098. - pNumSortedCodewordInSection++;
  1099. - if (endFlag != 0) {
  1100. - break;
  1101. - }
  1102. - }
  1103. - pHcr->segmentInfo.numSegment = numSegment;
  1104. -}
  1105. -
  1106. -/*---------------------------------------------------------------------------------------------
  1107. - description: This function adapts the sorted section boundaries to the
  1108. -boundaries of segmentation. If the section lengths does not fit completely into
  1109. -the current segment, the section is spitted into two so called 'extended
  1110. - sections'. The extended-section-info
  1111. -(pNumExtendedSortedCodewordInSectin and pExtendedSortedCodebook) is updated in
  1112. -this case.
  1113. -
  1114. ---------------------------------------------------------------------------------------------
  1115. -*/
  1116. -
  1117. -static void HcrExtendedSectionInfo(H_HCR_INFO pHcr) {
  1118. - UINT srtSecCnt = 0; /* counter for sorted sections */
  1119. - UINT xSrtScCnt = 0; /* counter for extended sorted sections */
  1120. - UINT remainNumCwInSortSec;
  1121. - UINT inSegmentRemainNumCW;
  1122. -
  1123. - UINT numSortedSection = pHcr->sectionInfo.numSortedSection;
  1124. - UCHAR *pSortedCodebook = pHcr->sectionInfo.pSortedCodebook;
  1125. - USHORT *pNumSortedCodewordInSection =
  1126. - pHcr->sectionInfo.pNumSortedCodewordInSection;
  1127. - UCHAR *pExtendedSortedCoBo = pHcr->sectionInfo.pExtendedSortedCodebook;
  1128. - USHORT *pNumExtSortCwInSect =
  1129. - pHcr->sectionInfo.pNumExtendedSortedCodewordInSection;
  1130. - UINT numSegment = pHcr->segmentInfo.numSegment;
  1131. - UCHAR *pMaxLenOfCbInExtSrtSec = pHcr->sectionInfo.pMaxLenOfCbInExtSrtSec;
  1132. - SCHAR lengthOfLongestCodeword = pHcr->decInOut.lengthOfLongestCodeword;
  1133. - const UCHAR *pMaxCwLength = aMaxCwLen;
  1134. -
  1135. - remainNumCwInSortSec = pNumSortedCodewordInSection[srtSecCnt];
  1136. - inSegmentRemainNumCW = numSegment;
  1137. -
  1138. - while (srtSecCnt < numSortedSection) {
  1139. - if (inSegmentRemainNumCW < remainNumCwInSortSec) {
  1140. - pNumExtSortCwInSect[xSrtScCnt] = inSegmentRemainNumCW;
  1141. - pExtendedSortedCoBo[xSrtScCnt] = pSortedCodebook[srtSecCnt];
  1142. -
  1143. - remainNumCwInSortSec -= inSegmentRemainNumCW;
  1144. - inSegmentRemainNumCW = numSegment;
  1145. - /* data of a sorted section was not integrated in extended sorted section
  1146. - */
  1147. - } else if (inSegmentRemainNumCW == remainNumCwInSortSec) {
  1148. - pNumExtSortCwInSect[xSrtScCnt] = inSegmentRemainNumCW;
  1149. - pExtendedSortedCoBo[xSrtScCnt] = pSortedCodebook[srtSecCnt];
  1150. -
  1151. - srtSecCnt++;
  1152. - remainNumCwInSortSec = pNumSortedCodewordInSection[srtSecCnt];
  1153. - inSegmentRemainNumCW = numSegment;
  1154. - /* data of a sorted section was integrated in extended sorted section */
  1155. - } else { /* inSegmentRemainNumCW > remainNumCwInSortSec */
  1156. - pNumExtSortCwInSect[xSrtScCnt] = remainNumCwInSortSec;
  1157. - pExtendedSortedCoBo[xSrtScCnt] = pSortedCodebook[srtSecCnt];
  1158. -
  1159. - inSegmentRemainNumCW -= remainNumCwInSortSec;
  1160. - srtSecCnt++;
  1161. - remainNumCwInSortSec = pNumSortedCodewordInSection[srtSecCnt];
  1162. - /* data of a sorted section was integrated in extended sorted section */
  1163. - }
  1164. - pMaxLenOfCbInExtSrtSec[xSrtScCnt] =
  1165. - fMin((INT)pMaxCwLength[pExtendedSortedCoBo[xSrtScCnt]],
  1166. - (INT)lengthOfLongestCodeword);
  1167. -
  1168. - xSrtScCnt += 1;
  1169. -
  1170. - if (xSrtScCnt >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
  1171. - pHcr->decInOut.errorLog |= EXTENDED_SORTED_COUNTER_OVERFLOW;
  1172. - return;
  1173. - }
  1174. - }
  1175. - pNumExtSortCwInSect[xSrtScCnt] = 0;
  1176. -}
  1177. -
  1178. -/*---------------------------------------------------------------------------------------------
  1179. - description: This function calculates the number of extended sorted
  1180. -sections which belong to the sets. Each set from set 0 (one and only set for the
  1181. -PCWs) till to the last set gets a entry in the array to which
  1182. - 'pNumExtendedSortedSectinsInSets' points to.
  1183. -
  1184. - Calculation: The entrys in
  1185. -pNumExtendedSortedCodewordInSectin are added untill the value numSegment is
  1186. -reached. Then the sum_variable is cleared and the calculation starts from the
  1187. -beginning. As much extended sorted Sections are summed up to reach the value
  1188. -numSegment, as much is the current entry in *pNumExtendedSortedCodewordInSectin.
  1189. ---------------------------------------------------------------------------------------------
  1190. -*/
  1191. -static void DeriveNumberOfExtendedSortedSectionsInSets(
  1192. - UINT numSegment, USHORT *pNumExtendedSortedCodewordInSection,
  1193. - int numExtendedSortedCodewordInSectionIdx,
  1194. - USHORT *pNumExtendedSortedSectionsInSets,
  1195. - int numExtendedSortedSectionsInSetsIdx) {
  1196. - USHORT counter = 0;
  1197. - UINT cwSum = 0;
  1198. - USHORT *pNumExSortCwInSec = pNumExtendedSortedCodewordInSection;
  1199. - USHORT *pNumExSortSecInSets = pNumExtendedSortedSectionsInSets;
  1200. -
  1201. - while (pNumExSortCwInSec[numExtendedSortedCodewordInSectionIdx] != 0) {
  1202. - cwSum += pNumExSortCwInSec[numExtendedSortedCodewordInSectionIdx];
  1203. - numExtendedSortedCodewordInSectionIdx++;
  1204. - if (numExtendedSortedCodewordInSectionIdx >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
  1205. - return;
  1206. - }
  1207. - if (cwSum > numSegment) {
  1208. - return;
  1209. - }
  1210. - counter++;
  1211. - if (counter > 1024 / 4) {
  1212. - return;
  1213. - }
  1214. - if (cwSum == numSegment) {
  1215. - pNumExSortSecInSets[numExtendedSortedSectionsInSetsIdx] = counter;
  1216. - numExtendedSortedSectionsInSetsIdx++;
  1217. - if (numExtendedSortedSectionsInSetsIdx >= MAX_HCR_SETS) {
  1218. - return;
  1219. - }
  1220. - counter = 0;
  1221. - cwSum = 0;
  1222. - }
  1223. - }
  1224. - pNumExSortSecInSets[numExtendedSortedSectionsInSetsIdx] =
  1225. - counter; /* save last entry for the last - probably shorter - set */
  1226. -}
  1227. -
  1228. -/*---------------------------------------------------------------------------------------------
  1229. - description: This function decodes all priority codewords (PCWs) in a
  1230. -spectrum (within set 0). The calculation of the PCWs is managed in two loops.
  1231. -The loopcounter of the outer loop is set to the first value pointer
  1232. - pNumExtendedSortedSectionsInSets points to. This value
  1233. -represents the number of extended sorted sections within set 0. The loopcounter
  1234. -of the inner loop is set to the first value pointer
  1235. - pNumExtendedSortedCodewordInSectin points to. The value
  1236. -represents the number of extended sorted codewords in sections (the original
  1237. -sections have been splitted to go along with the borders of the sets). Each time
  1238. -the number of the extended sorted codewords in sections are de- coded, the
  1239. -pointer 'pNumExtendedSortedCodewordInSectin' is incremented by one.
  1240. ---------------------------------------------------------------------------------------------
  1241. -*/
  1242. -static void DecodePCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO pHcr) {
  1243. - UINT i;
  1244. - USHORT extSortSec;
  1245. - USHORT curExtSortCwInSec;
  1246. - UCHAR codebook;
  1247. - UCHAR dimension;
  1248. - const UINT *pCurrentTree;
  1249. - const SCHAR *pQuantValBase;
  1250. - const SCHAR *pQuantVal;
  1251. -
  1252. - USHORT *pNumExtendedSortedCodewordInSection =
  1253. - pHcr->sectionInfo.pNumExtendedSortedCodewordInSection;
  1254. - int numExtendedSortedCodewordInSectionIdx =
  1255. - pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx;
  1256. - UCHAR *pExtendedSortedCodebook = pHcr->sectionInfo.pExtendedSortedCodebook;
  1257. - int extendedSortedCodebookIdx = pHcr->sectionInfo.extendedSortedCodebookIdx;
  1258. - USHORT *pNumExtendedSortedSectionsInSets =
  1259. - pHcr->sectionInfo.pNumExtendedSortedSectionsInSets;
  1260. - int numExtendedSortedSectionsInSetsIdx =
  1261. - pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx;
  1262. - FIXP_DBL *pQuantizedSpectralCoefficients =
  1263. - SPEC_LONG(pHcr->decInOut.pQuantizedSpectralCoefficientsBase);
  1264. - int quantizedSpectralCoefficientsIdx =
  1265. - pHcr->decInOut.quantizedSpectralCoefficientsIdx;
  1266. - INT *pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  1267. - SCHAR *pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  1268. - UCHAR *pMaxLenOfCbInExtSrtSec = pHcr->sectionInfo.pMaxLenOfCbInExtSrtSec;
  1269. - int maxLenOfCbInExtSrtSecIdx = pHcr->sectionInfo.maxLenOfCbInExtSrtSecIdx;
  1270. - UCHAR maxAllowedCwLen;
  1271. - int numDecodedBits;
  1272. - const UCHAR *pCbDimension = aDimCb;
  1273. - const UCHAR *pCbSign = aSignCb;
  1274. -
  1275. - /* clear result array */
  1276. - FDKmemclear(pQuantizedSpectralCoefficients + quantizedSpectralCoefficientsIdx,
  1277. - 1024 * sizeof(FIXP_DBL));
  1278. -
  1279. - /* decode all PCWs in the extended sorted section(s) belonging to set 0 */
  1280. - for (extSortSec =
  1281. - pNumExtendedSortedSectionsInSets[numExtendedSortedSectionsInSetsIdx];
  1282. - extSortSec != 0; extSortSec--) {
  1283. - codebook =
  1284. - pExtendedSortedCodebook[extendedSortedCodebookIdx]; /* get codebook for
  1285. - this extended
  1286. - sorted section
  1287. - and increment ptr
  1288. - to cb of next
  1289. - ext. sort sec */
  1290. - extendedSortedCodebookIdx++;
  1291. - if (extendedSortedCodebookIdx >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
  1292. - return;
  1293. - }
  1294. - dimension = pCbDimension[codebook]; /* get dimension of codebook of this
  1295. - extended sort. sec. */
  1296. - pCurrentTree =
  1297. - aHuffTable[codebook]; /* convert codebook to pointer to QSCs */
  1298. - pQuantValBase =
  1299. - aQuantTable[codebook]; /* convert codebook to index to table of QSCs */
  1300. - maxAllowedCwLen = pMaxLenOfCbInExtSrtSec[maxLenOfCbInExtSrtSecIdx];
  1301. - maxLenOfCbInExtSrtSecIdx++;
  1302. - if (maxLenOfCbInExtSrtSecIdx >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
  1303. - return;
  1304. - }
  1305. -
  1306. - /* switch for decoding with different codebooks: */
  1307. - if (pCbSign[codebook] ==
  1308. - 0) { /* no sign bits follow after the codeword-body */
  1309. - /* PCW_BodyONLY */
  1310. - /*==============*/
  1311. -
  1312. - for (curExtSortCwInSec = pNumExtendedSortedCodewordInSection
  1313. - [numExtendedSortedCodewordInSectionIdx];
  1314. - curExtSortCwInSec != 0; curExtSortCwInSec--) {
  1315. - numDecodedBits = 0;
  1316. -
  1317. - /* decode PCW_BODY */
  1318. - pQuantVal = DecodePCW_Body(
  1319. - bs, pHcr->decInOut.bitstreamAnchor, pCurrentTree, pQuantValBase,
  1320. - pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits);
  1321. -
  1322. - /* result is written out here because NO sign bits follow the body */
  1323. - for (i = dimension; i != 0; i--) {
  1324. - pQuantizedSpectralCoefficients[quantizedSpectralCoefficientsIdx] =
  1325. - (FIXP_DBL)*pQuantVal++; /* write quant. spec. coef. into
  1326. - spectrum; sign is already valid */
  1327. - quantizedSpectralCoefficientsIdx++;
  1328. - if (quantizedSpectralCoefficientsIdx >= 1024) {
  1329. - return;
  1330. - }
  1331. - }
  1332. -
  1333. - /* one more PCW should be decoded */
  1334. -
  1335. - if (maxAllowedCwLen < (numDecodedBits + ERROR_PCW_BODY_ONLY_TOO_LONG)) {
  1336. - pHcr->decInOut.errorLog |= TOO_MANY_PCW_BODY_BITS_DECODED;
  1337. - }
  1338. -
  1339. - if (1 == errDetectPcwSegmentation(
  1340. - *pRemainingBitsInSegment - ERROR_PCW_BODY, pHcr, PCW_BODY,
  1341. - pQuantizedSpectralCoefficients +
  1342. - quantizedSpectralCoefficientsIdx - dimension,
  1343. - dimension)) {
  1344. - return;
  1345. - }
  1346. - pLeftStartOfSegment++; /* update pointer for decoding the next PCW */
  1347. - pRemainingBitsInSegment++; /* update pointer for decoding the next PCW
  1348. - */
  1349. - }
  1350. - } else if ((codebook < 11) && (pCbSign[codebook] ==
  1351. - 1)) { /* possibly there follow 1,2,3 or 4
  1352. - sign bits after the codeword-body */
  1353. - /* PCW_Body and PCW_Sign */
  1354. - /*=======================*/
  1355. -
  1356. - for (curExtSortCwInSec = pNumExtendedSortedCodewordInSection
  1357. - [numExtendedSortedCodewordInSectionIdx];
  1358. - curExtSortCwInSec != 0; curExtSortCwInSec--) {
  1359. - int err;
  1360. - numDecodedBits = 0;
  1361. -
  1362. - pQuantVal = DecodePCW_Body(
  1363. - bs, pHcr->decInOut.bitstreamAnchor, pCurrentTree, pQuantValBase,
  1364. - pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits);
  1365. -
  1366. - err = DecodePCW_Sign(
  1367. - bs, pHcr->decInOut.bitstreamAnchor, dimension, pQuantVal,
  1368. - pQuantizedSpectralCoefficients, &quantizedSpectralCoefficientsIdx,
  1369. - pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits);
  1370. - if (err != 0) {
  1371. - return;
  1372. - }
  1373. - /* one more PCW should be decoded */
  1374. -
  1375. - if (maxAllowedCwLen < (numDecodedBits + ERROR_PCW_BODY_SIGN_TOO_LONG)) {
  1376. - pHcr->decInOut.errorLog |= TOO_MANY_PCW_BODY_SIGN_BITS_DECODED;
  1377. - }
  1378. -
  1379. - if (1 == errDetectPcwSegmentation(
  1380. - *pRemainingBitsInSegment - ERROR_PCW_BODY_SIGN, pHcr,
  1381. - PCW_BODY_SIGN,
  1382. - pQuantizedSpectralCoefficients +
  1383. - quantizedSpectralCoefficientsIdx - dimension,
  1384. - dimension)) {
  1385. - return;
  1386. - }
  1387. - pLeftStartOfSegment++;
  1388. - pRemainingBitsInSegment++;
  1389. - }
  1390. - } else if ((pCbSign[codebook] == 1) &&
  1391. - (codebook >= 11)) { /* possibly there follow some sign bits and
  1392. - maybe one or two escape sequences after
  1393. - the cw-body */
  1394. - /* PCW_Body, PCW_Sign and maybe PCW_Escape */
  1395. - /*=========================================*/
  1396. -
  1397. - for (curExtSortCwInSec = pNumExtendedSortedCodewordInSection
  1398. - [numExtendedSortedCodewordInSectionIdx];
  1399. - curExtSortCwInSec != 0; curExtSortCwInSec--) {
  1400. - int err;
  1401. - numDecodedBits = 0;
  1402. -
  1403. - /* decode PCW_BODY */
  1404. - pQuantVal = DecodePCW_Body(
  1405. - bs, pHcr->decInOut.bitstreamAnchor, pCurrentTree, pQuantValBase,
  1406. - pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits);
  1407. -
  1408. - err = DecodePCW_Sign(
  1409. - bs, pHcr->decInOut.bitstreamAnchor, dimension, pQuantVal,
  1410. - pQuantizedSpectralCoefficients, &quantizedSpectralCoefficientsIdx,
  1411. - pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits);
  1412. - if (err != 0) {
  1413. - return;
  1414. - }
  1415. -
  1416. - /* decode PCW_ESCAPE if present */
  1417. - quantizedSpectralCoefficientsIdx -= DIMENSION_OF_ESCAPE_CODEBOOK;
  1418. -
  1419. - if (fixp_abs(pQuantizedSpectralCoefficients
  1420. - [quantizedSpectralCoefficientsIdx]) ==
  1421. - (FIXP_DBL)ESCAPE_VALUE) {
  1422. - pQuantizedSpectralCoefficients[quantizedSpectralCoefficientsIdx] =
  1423. - (FIXP_DBL)DecodeEscapeSequence(
  1424. - bs, pHcr->decInOut.bitstreamAnchor,
  1425. - pQuantizedSpectralCoefficients
  1426. - [quantizedSpectralCoefficientsIdx],
  1427. - pLeftStartOfSegment, pRemainingBitsInSegment,
  1428. - &numDecodedBits);
  1429. - }
  1430. - quantizedSpectralCoefficientsIdx++;
  1431. - if (quantizedSpectralCoefficientsIdx >= 1024) {
  1432. - return;
  1433. - }
  1434. -
  1435. - if (fixp_abs(pQuantizedSpectralCoefficients
  1436. - [quantizedSpectralCoefficientsIdx]) ==
  1437. - (FIXP_DBL)ESCAPE_VALUE) {
  1438. - pQuantizedSpectralCoefficients[quantizedSpectralCoefficientsIdx] =
  1439. - (FIXP_DBL)DecodeEscapeSequence(
  1440. - bs, pHcr->decInOut.bitstreamAnchor,
  1441. - pQuantizedSpectralCoefficients
  1442. - [quantizedSpectralCoefficientsIdx],
  1443. - pLeftStartOfSegment, pRemainingBitsInSegment,
  1444. - &numDecodedBits);
  1445. - }
  1446. - quantizedSpectralCoefficientsIdx++;
  1447. - if (quantizedSpectralCoefficientsIdx >= 1024) {
  1448. - return;
  1449. - }
  1450. -
  1451. - /* one more PCW should be decoded */
  1452. -
  1453. - if (maxAllowedCwLen <
  1454. - (numDecodedBits + ERROR_PCW_BODY_SIGN_ESC_TOO_LONG)) {
  1455. - pHcr->decInOut.errorLog |= TOO_MANY_PCW_BODY_SIGN_ESC_BITS_DECODED;
  1456. - }
  1457. -
  1458. - if (1 == errDetectPcwSegmentation(
  1459. - *pRemainingBitsInSegment - ERROR_PCW_BODY_SIGN_ESC, pHcr,
  1460. - PCW_BODY_SIGN_ESC,
  1461. - pQuantizedSpectralCoefficients +
  1462. - quantizedSpectralCoefficientsIdx -
  1463. - DIMENSION_OF_ESCAPE_CODEBOOK,
  1464. - DIMENSION_OF_ESCAPE_CODEBOOK)) {
  1465. - return;
  1466. - }
  1467. - pLeftStartOfSegment++;
  1468. - pRemainingBitsInSegment++;
  1469. - }
  1470. - }
  1471. -
  1472. - /* all PCWs belonging to this extended section should be decoded */
  1473. - numExtendedSortedCodewordInSectionIdx++;
  1474. - if (numExtendedSortedCodewordInSectionIdx >= MAX_SFB_HCR + MAX_HCR_SETS) {
  1475. - return;
  1476. - }
  1477. - }
  1478. - /* all PCWs should be decoded */
  1479. -
  1480. - numExtendedSortedSectionsInSetsIdx++;
  1481. - if (numExtendedSortedSectionsInSetsIdx >= MAX_HCR_SETS) {
  1482. - return;
  1483. - }
  1484. -
  1485. - /* Write back indexes into structure */
  1486. - pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx =
  1487. - numExtendedSortedCodewordInSectionIdx;
  1488. - pHcr->sectionInfo.extendedSortedCodebookIdx = extendedSortedCodebookIdx;
  1489. - pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx =
  1490. - numExtendedSortedSectionsInSetsIdx;
  1491. - pHcr->decInOut.quantizedSpectralCoefficientsIdx =
  1492. - quantizedSpectralCoefficientsIdx;
  1493. - pHcr->sectionInfo.maxLenOfCbInExtSrtSecIdx = maxLenOfCbInExtSrtSecIdx;
  1494. -}
  1495. -
  1496. -/*---------------------------------------------------------------------------------------------
  1497. - description: This function checks immediately after every decoded PCW,
  1498. -whether out of the current segment too many bits have been read or not. If an
  1499. -error occurrs, probably the sideinfo or the HCR-bitstream block holding the
  1500. -huffman encoded quantized spectral coefficients is distorted. In this case the
  1501. -two or four quantized spectral coefficients belonging to the current codeword
  1502. - are marked (for being detected by concealment later).
  1503. ---------------------------------------------------------------------------------------------
  1504. -*/
  1505. -static UCHAR errDetectPcwSegmentation(SCHAR remainingBitsInSegment,
  1506. - H_HCR_INFO pHcr, PCW_TYPE kind,
  1507. - FIXP_DBL *qsc_base_of_cw,
  1508. - UCHAR dimension) {
  1509. - SCHAR i;
  1510. - if (remainingBitsInSegment < 0) {
  1511. - /* log the error */
  1512. - switch (kind) {
  1513. - case PCW_BODY:
  1514. - pHcr->decInOut.errorLog |= SEGMENT_OVERRIDE_ERR_PCW_BODY;
  1515. - break;
  1516. - case PCW_BODY_SIGN:
  1517. - pHcr->decInOut.errorLog |= SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN;
  1518. - break;
  1519. - case PCW_BODY_SIGN_ESC:
  1520. - pHcr->decInOut.errorLog |= SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN_ESC;
  1521. - break;
  1522. - }
  1523. - /* mark the erred lines */
  1524. - for (i = dimension; i != 0; i--) {
  1525. - *qsc_base_of_cw++ = (FIXP_DBL)Q_VALUE_INVALID;
  1526. - }
  1527. - return 1;
  1528. - }
  1529. - return 0;
  1530. -}
  1531. -
  1532. -/*---------------------------------------------------------------------------------------------
  1533. - description: This function checks if all segments are empty after
  1534. -decoding. There are _no lines markded_ as invalid because it could not be traced
  1535. -back where from the remaining bits are.
  1536. ---------------------------------------------------------------------------------------------
  1537. -*/
  1538. -static void errDetectWithinSegmentationFinal(H_HCR_INFO pHcr) {
  1539. - UCHAR segmentationErrorFlag = 0;
  1540. - USHORT i;
  1541. - SCHAR *pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  1542. - UINT numSegment = pHcr->segmentInfo.numSegment;
  1543. -
  1544. - for (i = numSegment; i != 0; i--) {
  1545. - if (*pRemainingBitsInSegment++ != 0) {
  1546. - segmentationErrorFlag = 1;
  1547. - }
  1548. - }
  1549. - if (segmentationErrorFlag == 1) {
  1550. - pHcr->decInOut.errorLog |= BIT_IN_SEGMENTATION_ERROR;
  1551. - }
  1552. -}
  1553. -
  1554. -/*---------------------------------------------------------------------------------------------
  1555. - description: This function walks one step within the decoding tree. Which
  1556. -branch is taken depends on the decoded carryBit input parameter.
  1557. ---------------------------------------------------------------------------------------------
  1558. -*/
  1559. -void CarryBitToBranchValue(UCHAR carryBit, UINT treeNode, UINT *branchValue,
  1560. - UINT *branchNode) {
  1561. - if (carryBit == 0) {
  1562. - *branchNode =
  1563. - (treeNode & MASK_LEFT) >> LEFT_OFFSET; /* MASK_LEFT: 00FFF000 */
  1564. - } else {
  1565. - *branchNode = treeNode & MASK_RIGHT; /* MASK_RIGHT: 00000FFF */
  1566. - }
  1567. -
  1568. - *branchValue = *branchNode & CLR_BIT_10; /* clear bit 10 (if set) */
  1569. -}
  1570. -
  1571. -/*---------------------------------------------------------------------------------------------
  1572. - description: Decodes the body of a priority codeword (PCW)
  1573. ------------------------------------------------------------------------------------------------
  1574. - return: - return value is pointer to first of two or four quantized
  1575. -spectral coefficients
  1576. ---------------------------------------------------------------------------------------------
  1577. -*/
  1578. -static const SCHAR *DecodePCW_Body(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  1579. - const UINT *pCurrentTree,
  1580. - const SCHAR *pQuantValBase,
  1581. - INT *pLeftStartOfSegment,
  1582. - SCHAR *pRemainingBitsInSegment,
  1583. - int *pNumDecodedBits) {
  1584. - UCHAR carryBit;
  1585. - UINT branchNode;
  1586. - UINT treeNode;
  1587. - UINT branchValue;
  1588. - const SCHAR *pQuantVal;
  1589. -
  1590. - /* decode PCW_BODY */
  1591. - treeNode = *pCurrentTree; /* get first node of current tree belonging to
  1592. - current codebook */
  1593. -
  1594. - /* decode whole PCW-codeword-body */
  1595. - while (1) {
  1596. - carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment,
  1597. - pLeftStartOfSegment, /* dummy */
  1598. - FROM_LEFT_TO_RIGHT);
  1599. - *pRemainingBitsInSegment -= 1;
  1600. - *pNumDecodedBits += 1;
  1601. -
  1602. - CarryBitToBranchValue(carryBit, treeNode, &branchValue, &branchNode);
  1603. -
  1604. - if ((branchNode & TEST_BIT_10) ==
  1605. - TEST_BIT_10) { /* test bit 10 ; if set --> codeword-body is complete */
  1606. - break; /* end of branch in tree reached i.e. a whole PCW-Body is decoded
  1607. - */
  1608. - } else {
  1609. - treeNode = *(
  1610. - pCurrentTree +
  1611. - branchValue); /* update treeNode for further step in decoding tree */
  1612. - }
  1613. - }
  1614. -
  1615. - pQuantVal =
  1616. - pQuantValBase + branchValue; /* update pointer to valid first of 2 or 4
  1617. - quantized values */
  1618. -
  1619. - return pQuantVal;
  1620. -}
  1621. -
  1622. -/*---------------------------------------------------------------------------------------------
  1623. - description: This function decodes one escape sequence. In case of a
  1624. -escape codebook and in case of the absolute value of the quantized spectral
  1625. -value == 16, a escapeSequence is decoded in two steps:
  1626. - 1. escape prefix
  1627. - 2. escape word
  1628. ---------------------------------------------------------------------------------------------
  1629. -*/
  1630. -
  1631. -static INT DecodeEscapeSequence(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  1632. - INT quantSpecCoef, INT *pLeftStartOfSegment,
  1633. - SCHAR *pRemainingBitsInSegment,
  1634. - int *pNumDecodedBits) {
  1635. - UINT i;
  1636. - INT sign;
  1637. - UINT escapeOnesCounter = 0;
  1638. - UINT carryBit;
  1639. - INT escape_word = 0;
  1640. -
  1641. - /* decode escape prefix */
  1642. - while (1) {
  1643. - carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment,
  1644. - pLeftStartOfSegment, /* dummy */
  1645. - FROM_LEFT_TO_RIGHT);
  1646. - *pRemainingBitsInSegment -= 1;
  1647. - *pNumDecodedBits += 1;
  1648. -
  1649. - if (carryBit != 0) {
  1650. - escapeOnesCounter += 1;
  1651. - } else {
  1652. - escapeOnesCounter += 4;
  1653. - break;
  1654. - }
  1655. - }
  1656. -
  1657. - /* decode escape word */
  1658. - for (i = escapeOnesCounter; i != 0; i--) {
  1659. - carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment,
  1660. - pLeftStartOfSegment, /* dummy */
  1661. - FROM_LEFT_TO_RIGHT);
  1662. - *pRemainingBitsInSegment -= 1;
  1663. - *pNumDecodedBits += 1;
  1664. -
  1665. - escape_word <<= 1;
  1666. - escape_word = escape_word | carryBit;
  1667. - }
  1668. -
  1669. - sign = (quantSpecCoef >= 0) ? 1 : -1;
  1670. -
  1671. - quantSpecCoef = sign * (((INT)1 << escapeOnesCounter) + escape_word);
  1672. -
  1673. - return quantSpecCoef;
  1674. -}
  1675. -
  1676. -/*---------------------------------------------------------------------------------------------
  1677. - description: Decodes the Signbits of a priority codeword (PCW) and writes
  1678. -out the resulting quantized spectral values into unsorted sections
  1679. ------------------------------------------------------------------------------------------------
  1680. - output: - two or four lines at position in corresponding section
  1681. -(which are not located at the desired position, i.e. they must be reordered in
  1682. -the last of eight function of HCR)
  1683. ------------------------------------------------------------------------------------------------
  1684. - return: - updated pQuantSpecCoef pointer (to next empty storage for a
  1685. -line)
  1686. ---------------------------------------------------------------------------------------------
  1687. -*/
  1688. -static int DecodePCW_Sign(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  1689. - UINT codebookDim, const SCHAR *pQuantVal,
  1690. - FIXP_DBL *pQuantSpecCoef, int *quantSpecCoefIdx,
  1691. - INT *pLeftStartOfSegment,
  1692. - SCHAR *pRemainingBitsInSegment,
  1693. - int *pNumDecodedBits) {
  1694. - UINT i;
  1695. - UINT carryBit;
  1696. - INT quantSpecCoef;
  1697. -
  1698. - for (i = codebookDim; i != 0; i--) {
  1699. - quantSpecCoef = *pQuantVal++;
  1700. - if (quantSpecCoef != 0) {
  1701. - carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment,
  1702. - pLeftStartOfSegment, /* dummy */
  1703. - FROM_LEFT_TO_RIGHT);
  1704. - *pRemainingBitsInSegment -= 1;
  1705. - *pNumDecodedBits += 1;
  1706. - if (*pRemainingBitsInSegment < 0 || *pNumDecodedBits >= (1024 >> 1)) {
  1707. - return -1;
  1708. - }
  1709. -
  1710. - /* adapt sign of values according to the decoded sign bit */
  1711. - if (carryBit != 0) {
  1712. - pQuantSpecCoef[*quantSpecCoefIdx] = -(FIXP_DBL)quantSpecCoef;
  1713. - } else {
  1714. - pQuantSpecCoef[*quantSpecCoefIdx] = (FIXP_DBL)quantSpecCoef;
  1715. - }
  1716. - } else {
  1717. - pQuantSpecCoef[*quantSpecCoefIdx] = FL2FXCONST_DBL(0.0f);
  1718. - }
  1719. - *quantSpecCoefIdx += 1;
  1720. - if (*quantSpecCoefIdx >= 1024) {
  1721. - return -1;
  1722. - }
  1723. - }
  1724. - return 0;
  1725. -}
  1726. -
  1727. -/*---------------------------------------------------------------------------------------------
  1728. - description: Mutes spectral lines which have been marked as erroneous
  1729. -(Q_VALUE_INVALID)
  1730. ---------------------------------------------------------------------------------------------
  1731. -*/
  1732. -void HcrMuteErroneousLines(H_HCR_INFO hHcr) {
  1733. - int c;
  1734. - FIXP_DBL *RESTRICT pLong =
  1735. - SPEC_LONG(hHcr->decInOut.pQuantizedSpectralCoefficientsBase);
  1736. -
  1737. - /* if there is a line with value Q_VALUE_INVALID mute it */
  1738. - for (c = 0; c < 1024; c++) {
  1739. - if (pLong[c] == (FIXP_DBL)Q_VALUE_INVALID) {
  1740. - pLong[c] = FL2FXCONST_DBL(0.0f); /* muting */
  1741. - }
  1742. - }
  1743. -}
  1744. diff --git a/libAACdec/src/aacdec_hcr.h b/libAACdec/src/aacdec_hcr.h
  1745. deleted file mode 100644
  1746. index be21144..0000000
  1747. --- a/libAACdec/src/aacdec_hcr.h
  1748. +++ /dev/null
  1749. @@ -1,128 +0,0 @@
  1750. -/* -----------------------------------------------------------------------------
  1751. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  1752. -
  1753. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  1754. -Forschung e.V. All rights reserved.
  1755. -
  1756. - 1. INTRODUCTION
  1757. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  1758. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  1759. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  1760. -a wide variety of Android devices.
  1761. -
  1762. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  1763. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  1764. -full-bandwidth communications codec by independent studies and is widely
  1765. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  1766. -specifications.
  1767. -
  1768. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  1769. -those of Fraunhofer) may be obtained through Via Licensing
  1770. -(www.vialicensing.com) or through the respective patent owners individually for
  1771. -the purpose of encoding or decoding bit streams in products that are compliant
  1772. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  1773. -Android devices already license these patent claims through Via Licensing or
  1774. -directly from the patent owners, and therefore FDK AAC Codec software may
  1775. -already be covered under those patent licenses when it is used for those
  1776. -licensed purposes only.
  1777. -
  1778. -Commercially-licensed AAC software libraries, including floating-point versions
  1779. -with enhanced sound quality, are also available from Fraunhofer. Users are
  1780. -encouraged to check the Fraunhofer website for additional applications
  1781. -information and documentation.
  1782. -
  1783. -2. COPYRIGHT LICENSE
  1784. -
  1785. -Redistribution and use in source and binary forms, with or without modification,
  1786. -are permitted without payment of copyright license fees provided that you
  1787. -satisfy the following conditions:
  1788. -
  1789. -You must retain the complete text of this software license in redistributions of
  1790. -the FDK AAC Codec or your modifications thereto in source code form.
  1791. -
  1792. -You must retain the complete text of this software license in the documentation
  1793. -and/or other materials provided with redistributions of the FDK AAC Codec or
  1794. -your modifications thereto in binary form. You must make available free of
  1795. -charge copies of the complete source code of the FDK AAC Codec and your
  1796. -modifications thereto to recipients of copies in binary form.
  1797. -
  1798. -The name of Fraunhofer may not be used to endorse or promote products derived
  1799. -from this library without prior written permission.
  1800. -
  1801. -You may not charge copyright license fees for anyone to use, copy or distribute
  1802. -the FDK AAC Codec software or your modifications thereto.
  1803. -
  1804. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  1805. -that you changed the software and the date of any change. For modified versions
  1806. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  1807. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  1808. -AAC Codec Library for Android."
  1809. -
  1810. -3. NO PATENT LICENSE
  1811. -
  1812. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  1813. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  1814. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  1815. -software.
  1816. -
  1817. -You may use this FDK AAC Codec software or modifications thereto only for
  1818. -purposes that are authorized by appropriate patent licenses.
  1819. -
  1820. -4. DISCLAIMER
  1821. -
  1822. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  1823. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  1824. -including but not limited to the implied warranties of merchantability and
  1825. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  1826. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  1827. -or consequential damages, including but not limited to procurement of substitute
  1828. -goods or services; loss of use, data, or profits, or business interruption,
  1829. -however caused and on any theory of liability, whether in contract, strict
  1830. -liability, or tort (including negligence), arising in any way out of the use of
  1831. -this software, even if advised of the possibility of such damage.
  1832. -
  1833. -5. CONTACT INFORMATION
  1834. -
  1835. -Fraunhofer Institute for Integrated Circuits IIS
  1836. -Attention: Audio and Multimedia Departments - FDK AAC LL
  1837. -Am Wolfsmantel 33
  1838. -91058 Erlangen, Germany
  1839. -
  1840. -www.iis.fraunhofer.de/amm
  1841. -amm-info@iis.fraunhofer.de
  1842. ------------------------------------------------------------------------------ */
  1843. -
  1844. -/**************************** AAC decoder library ******************************
  1845. -
  1846. - Author(s): Robert Weidner (DSP Solutions)
  1847. -
  1848. - Description: HCR Decoder: Interface function declaration; common defines
  1849. - and structures; defines for switching error-generator,
  1850. - -detector, and -concealment
  1851. -
  1852. -*******************************************************************************/
  1853. -
  1854. -#ifndef AACDEC_HCR_H
  1855. -#define AACDEC_HCR_H
  1856. -
  1857. -#include "channelinfo.h"
  1858. -#include "FDK_bitstream.h"
  1859. -
  1860. -UINT HcrInit(H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  1861. - const SamplingRateInfo *pSamplingRateInfo,
  1862. - HANDLE_FDK_BITSTREAM bs);
  1863. -UINT HcrDecoder(H_HCR_INFO hHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  1864. - const SamplingRateInfo *pSamplingRateInfo,
  1865. - HANDLE_FDK_BITSTREAM bs);
  1866. -void CarryBitToBranchValue(UCHAR carryBit, UINT treeNode, UINT *branchValue,
  1867. - UINT *branchNode);
  1868. -
  1869. -void CHcr_Read(HANDLE_FDK_BITSTREAM bs,
  1870. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  1871. - const MP4_ELEMENT_ID globalHcrType);
  1872. -void HcrMuteErroneousLines(H_HCR_INFO hHcr);
  1873. -
  1874. -void setHcrType(H_HCR_INFO hHcr, MP4_ELEMENT_ID type);
  1875. -INT getHcrType(H_HCR_INFO hHcr);
  1876. -
  1877. -#endif /* AACDEC_HCR_H */
  1878. diff --git a/libAACdec/src/aacdec_hcr_bit.cpp b/libAACdec/src/aacdec_hcr_bit.cpp
  1879. deleted file mode 100644
  1880. index 0198659..0000000
  1881. --- a/libAACdec/src/aacdec_hcr_bit.cpp
  1882. +++ /dev/null
  1883. @@ -1,164 +0,0 @@
  1884. -/* -----------------------------------------------------------------------------
  1885. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  1886. -
  1887. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  1888. -Forschung e.V. All rights reserved.
  1889. -
  1890. - 1. INTRODUCTION
  1891. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  1892. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  1893. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  1894. -a wide variety of Android devices.
  1895. -
  1896. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  1897. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  1898. -full-bandwidth communications codec by independent studies and is widely
  1899. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  1900. -specifications.
  1901. -
  1902. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  1903. -those of Fraunhofer) may be obtained through Via Licensing
  1904. -(www.vialicensing.com) or through the respective patent owners individually for
  1905. -the purpose of encoding or decoding bit streams in products that are compliant
  1906. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  1907. -Android devices already license these patent claims through Via Licensing or
  1908. -directly from the patent owners, and therefore FDK AAC Codec software may
  1909. -already be covered under those patent licenses when it is used for those
  1910. -licensed purposes only.
  1911. -
  1912. -Commercially-licensed AAC software libraries, including floating-point versions
  1913. -with enhanced sound quality, are also available from Fraunhofer. Users are
  1914. -encouraged to check the Fraunhofer website for additional applications
  1915. -information and documentation.
  1916. -
  1917. -2. COPYRIGHT LICENSE
  1918. -
  1919. -Redistribution and use in source and binary forms, with or without modification,
  1920. -are permitted without payment of copyright license fees provided that you
  1921. -satisfy the following conditions:
  1922. -
  1923. -You must retain the complete text of this software license in redistributions of
  1924. -the FDK AAC Codec or your modifications thereto in source code form.
  1925. -
  1926. -You must retain the complete text of this software license in the documentation
  1927. -and/or other materials provided with redistributions of the FDK AAC Codec or
  1928. -your modifications thereto in binary form. You must make available free of
  1929. -charge copies of the complete source code of the FDK AAC Codec and your
  1930. -modifications thereto to recipients of copies in binary form.
  1931. -
  1932. -The name of Fraunhofer may not be used to endorse or promote products derived
  1933. -from this library without prior written permission.
  1934. -
  1935. -You may not charge copyright license fees for anyone to use, copy or distribute
  1936. -the FDK AAC Codec software or your modifications thereto.
  1937. -
  1938. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  1939. -that you changed the software and the date of any change. For modified versions
  1940. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  1941. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  1942. -AAC Codec Library for Android."
  1943. -
  1944. -3. NO PATENT LICENSE
  1945. -
  1946. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  1947. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  1948. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  1949. -software.
  1950. -
  1951. -You may use this FDK AAC Codec software or modifications thereto only for
  1952. -purposes that are authorized by appropriate patent licenses.
  1953. -
  1954. -4. DISCLAIMER
  1955. -
  1956. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  1957. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  1958. -including but not limited to the implied warranties of merchantability and
  1959. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  1960. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  1961. -or consequential damages, including but not limited to procurement of substitute
  1962. -goods or services; loss of use, data, or profits, or business interruption,
  1963. -however caused and on any theory of liability, whether in contract, strict
  1964. -liability, or tort (including negligence), arising in any way out of the use of
  1965. -this software, even if advised of the possibility of such damage.
  1966. -
  1967. -5. CONTACT INFORMATION
  1968. -
  1969. -Fraunhofer Institute for Integrated Circuits IIS
  1970. -Attention: Audio and Multimedia Departments - FDK AAC LL
  1971. -Am Wolfsmantel 33
  1972. -91058 Erlangen, Germany
  1973. -
  1974. -www.iis.fraunhofer.de/amm
  1975. -amm-info@iis.fraunhofer.de
  1976. ------------------------------------------------------------------------------ */
  1977. -
  1978. -/**************************** AAC decoder library ******************************
  1979. -
  1980. - Author(s): Robert Weidner (DSP Solutions)
  1981. -
  1982. - Description: HCR Decoder: Bitstream reading
  1983. -
  1984. -*******************************************************************************/
  1985. -
  1986. -#include "aacdec_hcr_bit.h"
  1987. -
  1988. -/*---------------------------------------------------------------------------------------------
  1989. - description: This function toggles the read direction.
  1990. ------------------------------------------------------------------------------------------------
  1991. - input: current read direction
  1992. ------------------------------------------------------------------------------------------------
  1993. - return: new read direction
  1994. ---------------------------------------------------------------------------------------------
  1995. -*/
  1996. -UCHAR ToggleReadDirection(UCHAR readDirection) {
  1997. - if (readDirection == FROM_LEFT_TO_RIGHT) {
  1998. - return FROM_RIGHT_TO_LEFT;
  1999. - } else {
  2000. - return FROM_LEFT_TO_RIGHT;
  2001. - }
  2002. -}
  2003. -
  2004. -/*---------------------------------------------------------------------------------------------
  2005. - description: This function returns a bit from the bitstream according to
  2006. -read direction. It is called very often, therefore it makes sense to inline it
  2007. -(runtime).
  2008. ------------------------------------------------------------------------------------------------
  2009. - input: - handle to FDK bitstream
  2010. - - reference value marking start of bitfield
  2011. - - pLeftStartOfSegment
  2012. - - pRightStartOfSegment
  2013. - - readDirection
  2014. ------------------------------------------------------------------------------------------------
  2015. - return: - bit from bitstream
  2016. ---------------------------------------------------------------------------------------------
  2017. -*/
  2018. -UINT HcrGetABitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  2019. - INT *pLeftStartOfSegment,
  2020. - INT *pRightStartOfSegment, UCHAR readDirection) {
  2021. - UINT bit;
  2022. - INT readBitOffset;
  2023. -
  2024. - if (readDirection == FROM_LEFT_TO_RIGHT) {
  2025. - readBitOffset = (INT)FDKgetValidBits(bs) - bsAnchor + *pLeftStartOfSegment;
  2026. - if (readBitOffset) {
  2027. - FDKpushBiDirectional(bs, readBitOffset);
  2028. - }
  2029. -
  2030. - bit = FDKreadBits(bs, 1);
  2031. -
  2032. - *pLeftStartOfSegment += 1;
  2033. - } else {
  2034. - readBitOffset = (INT)FDKgetValidBits(bs) - bsAnchor + *pRightStartOfSegment;
  2035. - if (readBitOffset) {
  2036. - FDKpushBiDirectional(bs, readBitOffset);
  2037. - }
  2038. -
  2039. - /* to be replaced with a brother function of FDKreadBits() */
  2040. - bit = FDKreadBits(bs, 1);
  2041. - FDKpushBack(bs, 2);
  2042. -
  2043. - *pRightStartOfSegment -= 1;
  2044. - }
  2045. -
  2046. - return (bit);
  2047. -}
  2048. diff --git a/libAACdec/src/aacdec_hcr_bit.h b/libAACdec/src/aacdec_hcr_bit.h
  2049. deleted file mode 100644
  2050. index 77242ac..0000000
  2051. --- a/libAACdec/src/aacdec_hcr_bit.h
  2052. +++ /dev/null
  2053. @@ -1,114 +0,0 @@
  2054. -/* -----------------------------------------------------------------------------
  2055. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  2056. -
  2057. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  2058. -Forschung e.V. All rights reserved.
  2059. -
  2060. - 1. INTRODUCTION
  2061. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  2062. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  2063. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  2064. -a wide variety of Android devices.
  2065. -
  2066. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  2067. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  2068. -full-bandwidth communications codec by independent studies and is widely
  2069. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  2070. -specifications.
  2071. -
  2072. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  2073. -those of Fraunhofer) may be obtained through Via Licensing
  2074. -(www.vialicensing.com) or through the respective patent owners individually for
  2075. -the purpose of encoding or decoding bit streams in products that are compliant
  2076. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  2077. -Android devices already license these patent claims through Via Licensing or
  2078. -directly from the patent owners, and therefore FDK AAC Codec software may
  2079. -already be covered under those patent licenses when it is used for those
  2080. -licensed purposes only.
  2081. -
  2082. -Commercially-licensed AAC software libraries, including floating-point versions
  2083. -with enhanced sound quality, are also available from Fraunhofer. Users are
  2084. -encouraged to check the Fraunhofer website for additional applications
  2085. -information and documentation.
  2086. -
  2087. -2. COPYRIGHT LICENSE
  2088. -
  2089. -Redistribution and use in source and binary forms, with or without modification,
  2090. -are permitted without payment of copyright license fees provided that you
  2091. -satisfy the following conditions:
  2092. -
  2093. -You must retain the complete text of this software license in redistributions of
  2094. -the FDK AAC Codec or your modifications thereto in source code form.
  2095. -
  2096. -You must retain the complete text of this software license in the documentation
  2097. -and/or other materials provided with redistributions of the FDK AAC Codec or
  2098. -your modifications thereto in binary form. You must make available free of
  2099. -charge copies of the complete source code of the FDK AAC Codec and your
  2100. -modifications thereto to recipients of copies in binary form.
  2101. -
  2102. -The name of Fraunhofer may not be used to endorse or promote products derived
  2103. -from this library without prior written permission.
  2104. -
  2105. -You may not charge copyright license fees for anyone to use, copy or distribute
  2106. -the FDK AAC Codec software or your modifications thereto.
  2107. -
  2108. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  2109. -that you changed the software and the date of any change. For modified versions
  2110. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  2111. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  2112. -AAC Codec Library for Android."
  2113. -
  2114. -3. NO PATENT LICENSE
  2115. -
  2116. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  2117. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  2118. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  2119. -software.
  2120. -
  2121. -You may use this FDK AAC Codec software or modifications thereto only for
  2122. -purposes that are authorized by appropriate patent licenses.
  2123. -
  2124. -4. DISCLAIMER
  2125. -
  2126. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  2127. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  2128. -including but not limited to the implied warranties of merchantability and
  2129. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  2130. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  2131. -or consequential damages, including but not limited to procurement of substitute
  2132. -goods or services; loss of use, data, or profits, or business interruption,
  2133. -however caused and on any theory of liability, whether in contract, strict
  2134. -liability, or tort (including negligence), arising in any way out of the use of
  2135. -this software, even if advised of the possibility of such damage.
  2136. -
  2137. -5. CONTACT INFORMATION
  2138. -
  2139. -Fraunhofer Institute for Integrated Circuits IIS
  2140. -Attention: Audio and Multimedia Departments - FDK AAC LL
  2141. -Am Wolfsmantel 33
  2142. -91058 Erlangen, Germany
  2143. -
  2144. -www.iis.fraunhofer.de/amm
  2145. -amm-info@iis.fraunhofer.de
  2146. ------------------------------------------------------------------------------ */
  2147. -
  2148. -/**************************** AAC decoder library ******************************
  2149. -
  2150. - Author(s): Robert Weidner (DSP Solutions)
  2151. -
  2152. - Description: HCR Decoder: Bitstream reading prototypes
  2153. -
  2154. -*******************************************************************************/
  2155. -
  2156. -#ifndef AACDEC_HCR_BIT_H
  2157. -#define AACDEC_HCR_BIT_H
  2158. -
  2159. -#include "aacdec_hcr.h"
  2160. -
  2161. -UCHAR ToggleReadDirection(UCHAR readDirection);
  2162. -
  2163. -UINT HcrGetABitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  2164. - INT *pLeftStartOfSegment,
  2165. - INT *pRightStartOfSegment, UCHAR readDirection);
  2166. -
  2167. -#endif /* AACDEC_HCR_BIT_H */
  2168. diff --git a/libAACdec/src/aacdec_hcr_types.h b/libAACdec/src/aacdec_hcr_types.h
  2169. deleted file mode 100644
  2170. index 1cc3cb0..0000000
  2171. --- a/libAACdec/src/aacdec_hcr_types.h
  2172. +++ /dev/null
  2173. @@ -1,432 +0,0 @@
  2174. -/* -----------------------------------------------------------------------------
  2175. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  2176. -
  2177. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  2178. -Forschung e.V. All rights reserved.
  2179. -
  2180. - 1. INTRODUCTION
  2181. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  2182. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  2183. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  2184. -a wide variety of Android devices.
  2185. -
  2186. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  2187. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  2188. -full-bandwidth communications codec by independent studies and is widely
  2189. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  2190. -specifications.
  2191. -
  2192. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  2193. -those of Fraunhofer) may be obtained through Via Licensing
  2194. -(www.vialicensing.com) or through the respective patent owners individually for
  2195. -the purpose of encoding or decoding bit streams in products that are compliant
  2196. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  2197. -Android devices already license these patent claims through Via Licensing or
  2198. -directly from the patent owners, and therefore FDK AAC Codec software may
  2199. -already be covered under those patent licenses when it is used for those
  2200. -licensed purposes only.
  2201. -
  2202. -Commercially-licensed AAC software libraries, including floating-point versions
  2203. -with enhanced sound quality, are also available from Fraunhofer. Users are
  2204. -encouraged to check the Fraunhofer website for additional applications
  2205. -information and documentation.
  2206. -
  2207. -2. COPYRIGHT LICENSE
  2208. -
  2209. -Redistribution and use in source and binary forms, with or without modification,
  2210. -are permitted without payment of copyright license fees provided that you
  2211. -satisfy the following conditions:
  2212. -
  2213. -You must retain the complete text of this software license in redistributions of
  2214. -the FDK AAC Codec or your modifications thereto in source code form.
  2215. -
  2216. -You must retain the complete text of this software license in the documentation
  2217. -and/or other materials provided with redistributions of the FDK AAC Codec or
  2218. -your modifications thereto in binary form. You must make available free of
  2219. -charge copies of the complete source code of the FDK AAC Codec and your
  2220. -modifications thereto to recipients of copies in binary form.
  2221. -
  2222. -The name of Fraunhofer may not be used to endorse or promote products derived
  2223. -from this library without prior written permission.
  2224. -
  2225. -You may not charge copyright license fees for anyone to use, copy or distribute
  2226. -the FDK AAC Codec software or your modifications thereto.
  2227. -
  2228. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  2229. -that you changed the software and the date of any change. For modified versions
  2230. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  2231. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  2232. -AAC Codec Library for Android."
  2233. -
  2234. -3. NO PATENT LICENSE
  2235. -
  2236. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  2237. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  2238. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  2239. -software.
  2240. -
  2241. -You may use this FDK AAC Codec software or modifications thereto only for
  2242. -purposes that are authorized by appropriate patent licenses.
  2243. -
  2244. -4. DISCLAIMER
  2245. -
  2246. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  2247. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  2248. -including but not limited to the implied warranties of merchantability and
  2249. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  2250. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  2251. -or consequential damages, including but not limited to procurement of substitute
  2252. -goods or services; loss of use, data, or profits, or business interruption,
  2253. -however caused and on any theory of liability, whether in contract, strict
  2254. -liability, or tort (including negligence), arising in any way out of the use of
  2255. -this software, even if advised of the possibility of such damage.
  2256. -
  2257. -5. CONTACT INFORMATION
  2258. -
  2259. -Fraunhofer Institute for Integrated Circuits IIS
  2260. -Attention: Audio and Multimedia Departments - FDK AAC LL
  2261. -Am Wolfsmantel 33
  2262. -91058 Erlangen, Germany
  2263. -
  2264. -www.iis.fraunhofer.de/amm
  2265. -amm-info@iis.fraunhofer.de
  2266. ------------------------------------------------------------------------------ */
  2267. -
  2268. -/**************************** AAC decoder library ******************************
  2269. -
  2270. - Author(s): Robert Weidner (DSP Solutions)
  2271. -
  2272. - Description: HCR Decoder: Common defines and structures; defines for
  2273. - switching error-generator, -detector, and -concealment;
  2274. -
  2275. -*******************************************************************************/
  2276. -
  2277. -#ifndef AACDEC_HCR_TYPES_H
  2278. -#define AACDEC_HCR_TYPES_H
  2279. -
  2280. -#include "FDK_bitstream.h"
  2281. -#include "overlapadd.h"
  2282. -
  2283. -/* ------------------------------------------------ */
  2284. -/* ------------------------------------------------ */
  2285. -
  2286. -#define LINES_PER_UNIT 4
  2287. -
  2288. -/* ------------------------------------------------ */
  2289. -/* ------------------------------------------------ */
  2290. -/* ----------- basic HCR configuration ------------ */
  2291. -
  2292. -#define MAX_SFB_HCR \
  2293. - (((1024 / 8) / LINES_PER_UNIT) * 8) /* (8 * 16) is not enough because sfbs \
  2294. - are split in units for blocktype \
  2295. - short */
  2296. -#define NUMBER_OF_UNIT_GROUPS (LINES_PER_UNIT * 8)
  2297. -#define LINES_PER_UNIT_GROUP (1024 / NUMBER_OF_UNIT_GROUPS) /* 15 16 30 32 */
  2298. -
  2299. -/* ------------------------------------------------ */
  2300. -/* ------------------------------------------------ */
  2301. -/* ------------------------------------------------ */
  2302. -
  2303. -#define FROM_LEFT_TO_RIGHT 0
  2304. -#define FROM_RIGHT_TO_LEFT 1
  2305. -
  2306. -#define MAX_CB_PAIRS 23
  2307. -#define MAX_HCR_SETS 14
  2308. -
  2309. -#define ESCAPE_VALUE 16
  2310. -#define POSITION_OF_FLAG_A 21
  2311. -#define POSITION_OF_FLAG_B 20
  2312. -
  2313. -#define MAX_CB 32 /* last used CB is cb #31 when VCB11 is used */
  2314. -
  2315. -#define MAX_CB_CHECK \
  2316. - 32 /* support for VCB11 available -- is more general, could therefore used \
  2317. - in both cases */
  2318. -
  2319. -#define NUMBER_OF_BIT_IN_WORD 32
  2320. -
  2321. -/* log */
  2322. -#define THIRTYTWO_LOG_DIV_TWO_LOG 5
  2323. -#define EIGHT_LOG_DIV_TWO_LOG 3
  2324. -#define FOUR_LOG_DIV_TWO_LOG 2
  2325. -
  2326. -/* borders */
  2327. -#define CPE_TOP_LENGTH 12288
  2328. -#define SCE_TOP_LENGTH 6144
  2329. -#define LEN_OF_LONGEST_CW_TOP_LENGTH 49
  2330. -
  2331. -/* qsc's of high level */
  2332. -#define Q_VALUE_INVALID \
  2333. - 8192 /* mark a invalid line with this value (to be concealed later on) */
  2334. -#define HCR_DIRAC 500 /* a line of high level */
  2335. -
  2336. -/* masks */
  2337. -#define MASK_LEFT 0xFFF000
  2338. -#define MASK_RIGHT 0xFFF
  2339. -#define CLR_BIT_10 0x3FF
  2340. -#define TEST_BIT_10 0x400
  2341. -
  2342. -#define LEFT_OFFSET 12
  2343. -
  2344. -/* when set HCR is replaced by a dummy-module which just fills the outputbuffer
  2345. - * with a dirac sequence */
  2346. -/* use this if HCR is suspected to write in other modules -- if error is stell
  2347. - * there, HCR is innocent */
  2348. -
  2349. -/* ------------------------------ */
  2350. -/* - insert HCR errors - */
  2351. -/* ------------------------------ */
  2352. -
  2353. -/* modify input lengths -- high protected */
  2354. -#define ERROR_LORSD 0 /* offset: error if different from zero */
  2355. -#define ERROR_LOLC 0 /* offset: error if different from zero */
  2356. -
  2357. -/* segments are earlier empty as expected when decoding PCWs */
  2358. -#define ERROR_PCW_BODY \
  2359. - 0 /* set a positive values to trigger the error (make segments earlyer \
  2360. - appear to be empty) */
  2361. -#define ERROR_PCW_BODY_SIGN \
  2362. - 0 /* set a positive values to trigger the error (make segments earlyer \
  2363. - appear to be empty) */
  2364. -#define ERROR_PCW_BODY_SIGN_ESC \
  2365. - 0 /* set a positive values to trigger the error (make segments earlyer \
  2366. - appear to be empty) */
  2367. -
  2368. -/* pretend there are too many bits decoded (enlarge length of codeword) at PCWs
  2369. - * -- use a positive value */
  2370. -#define ERROR_PCW_BODY_ONLY_TOO_LONG \
  2371. - 0 /* set a positive values to trigger the error */
  2372. -#define ERROR_PCW_BODY_SIGN_TOO_LONG \
  2373. - 0 /* set a positive values to trigger the error */
  2374. -#define ERROR_PCW_BODY_SIGN_ESC_TOO_LONG \
  2375. - 0 /* set a positive values to trigger the error */
  2376. -
  2377. -/* modify HCR bitstream block */
  2378. -
  2379. -#define MODULO_DIVISOR_HCR 30
  2380. -
  2381. -/* ------------------------------ */
  2382. -/* - detect HCR errors - */
  2383. -/* ------------------------------ */
  2384. -/* check input data */
  2385. -
  2386. -/* during decoding */
  2387. -
  2388. -/* all the segments are checked -- therefore -- if this check passes, its a kind
  2389. - of evidence that the decoded PCWs and non-PCWs are fine */
  2390. -
  2391. -/* if a codeword is decoded there exists a border for the number of bits, which
  2392. - are allowed to read for this codeword. This border is the minimum of the
  2393. - length of the longest codeword (for the currently used codebook) and the
  2394. - separately transmitted 'lengthOfLongestCodeword' in this frame and channel.
  2395. - The number of decoded bits is counted (for PCWs only -- there it makes really
  2396. - sense in my opinion). If this number exceeds the border (derived as minimum
  2397. - -- see above), a error is detected. */
  2398. -
  2399. -/* -----------------------------------------------------------------------------------------------------
  2400. - This error check could be set to zero because due to a test within
  2401. - RVLC-Escape-huffman-Decoder a too long codeword could not be detected -- it
  2402. - seems that for RVLC-Escape-Codeword the coderoom is used to 100%. Therefore I
  2403. - assume that the coderoom is used to 100% also for the codebooks 1..11 used at
  2404. - HCR Therefore this test is deactivated pending further notice
  2405. - -----------------------------------------------------------------------------------------------------
  2406. - */
  2407. -
  2408. -/* test if the number of remaining bits in a segment is _below_ zero. If there
  2409. - are no errors the lowest allowed value for remainingBitsInSegment is zero.
  2410. - This check also could be set to zero (save runtime) */
  2411. -
  2412. -/* other */
  2413. -/* when set to '1', avoid setting the LAV-Flag in errorLog due to a
  2414. - previous-line-marking (at PCW decoder). A little more runtime is needed then
  2415. - when writing values out into output-buffer. */
  2416. -
  2417. -/* ------------------------------ */
  2418. -/* - conceal HCR errors - */
  2419. -/* ------------------------------ */
  2420. -
  2421. -#define HCR_ERROR_CONCEALMENT \
  2422. - 1 /* if set to '1', HCR _mutes_ the erred quantized spectral coefficients */
  2423. -
  2424. -// ------------------------------------------------------------------------------------------------------------------
  2425. -// errorLog: A word of 32 bits used for
  2426. -// logging possible errors within HCR
  2427. -// in case of distorted
  2428. -// bitstreams. Table of all
  2429. -// known errors:
  2430. -// ------------------------------------------------------------------------------------------------------------------------
  2431. -// bit fatal location meaning
  2432. -// ----+-----+-----------+--------------------------------------
  2433. -#define SEGMENT_OVERRIDE_ERR_PCW_BODY \
  2434. - 0x80000000 // 31 no PCW-Dec During PCW decoding it is checked after
  2435. - // every PCW if there are too many bits decoded (immediate
  2436. - // check).
  2437. -#define SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN \
  2438. - 0x40000000 // 30 no PCW-Dec During PCW decoding it is checked after
  2439. - // every PCW if there are too many bits decoded (immediate
  2440. - // check).
  2441. -#define SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN_ESC \
  2442. - 0x20000000 // 29 no PCW-Dec During PCW decoding it is checked after
  2443. - // every PCW if there are too many bits decoded (immediate
  2444. - // check).
  2445. -#define EXTENDED_SORTED_COUNTER_OVERFLOW \
  2446. - 0x10000000 // 28 yes Init-Dec Error during extending sideinfo
  2447. - // (neither a PCW nor a nonPCW was decoded so far)
  2448. - // 0x08000000 // 27 reserved
  2449. - // 0x04000000 // 26 reserved
  2450. - // 0x02000000 // 25 reserved
  2451. - // 0x01000000 // 24 reserved
  2452. - // 0x00800000 // 23 reserved
  2453. - // 0x00400000 // 22 reserved
  2454. - // 0x00200000 // 21 reserved
  2455. - // 0x00100000 // 20 reserved
  2456. -
  2457. -/* special errors */
  2458. -#define TOO_MANY_PCW_BODY_BITS_DECODED \
  2459. - 0x00080000 // 19 yes PCW-Dec During PCW-body-decoding too many bits
  2460. - // have been read from bitstream -- advice: skip non-PCW decoding
  2461. -#define TOO_MANY_PCW_BODY_SIGN_BITS_DECODED \
  2462. - 0x00040000 // 18 yes PCW-Dec During PCW-body-sign-decoding too many
  2463. - // bits have been read from bitstream -- advice: skip non-PCW
  2464. - // decoding
  2465. -#define TOO_MANY_PCW_BODY_SIGN_ESC_BITS_DECODED \
  2466. - 0x00020000 // 17 yes PCW-Dec During PCW-body-sign-esc-decoding too
  2467. - // many bits have been read from bitstream -- advice: skip
  2468. - // non-PCW decoding
  2469. -
  2470. -// 0x00010000 // 16 reserved
  2471. -#define STATE_ERROR_BODY_ONLY \
  2472. - 0x00008000 // 15 no NonPCW-Dec State machine returned with error
  2473. -#define STATE_ERROR_BODY_SIGN__BODY \
  2474. - 0x00004000 // 14 no NonPCW-Dec State machine returned with error
  2475. -#define STATE_ERROR_BODY_SIGN__SIGN \
  2476. - 0x00002000 // 13 no NonPCW-Dec State machine returned with error
  2477. -#define STATE_ERROR_BODY_SIGN_ESC__BODY \
  2478. - 0x00001000 // 12 no NonPCW-Dec State machine returned with error
  2479. -#define STATE_ERROR_BODY_SIGN_ESC__SIGN \
  2480. - 0x00000800 // 11 no NonPCW-Dec State machine returned with error
  2481. -#define STATE_ERROR_BODY_SIGN_ESC__ESC_PREFIX \
  2482. - 0x00000400 // 10 no NonPCW-Dec State machine returned with error
  2483. -#define STATE_ERROR_BODY_SIGN_ESC__ESC_WORD \
  2484. - 0x00000200 // 9 no NonPCW-Dec State machine returned with error
  2485. -#define HCR_SI_LENGTHS_FAILURE \
  2486. - 0x00000100 // 8 yes Init-Dec LengthOfLongestCodeword must not be
  2487. - // less than lenghtOfReorderedSpectralData
  2488. -#define NUM_SECT_OUT_OF_RANGE_SHORT_BLOCK \
  2489. - 0x00000080 // 7 yes Init-Dec The number of sections is not within
  2490. - // the allowed range (short block)
  2491. -#define NUM_SECT_OUT_OF_RANGE_LONG_BLOCK \
  2492. - 0x00000040 // 6 yes Init-Dec The number of sections is not within
  2493. - // the allowed range (long block)
  2494. -#define LINE_IN_SECT_OUT_OF_RANGE_SHORT_BLOCK \
  2495. - 0x00000020 // 5 yes Init-Dec The number of lines per section is not
  2496. - // within the allowed range (short block)
  2497. -#define CB_OUT_OF_RANGE_SHORT_BLOCK \
  2498. - 0x00000010 // 4 yes Init-Dec The codebook is not within the allowed
  2499. - // range (short block)
  2500. -#define LINE_IN_SECT_OUT_OF_RANGE_LONG_BLOCK \
  2501. - 0x00000008 // 3 yes Init-Dec The number of lines per section is not
  2502. - // within the allowed range (long block)
  2503. -#define CB_OUT_OF_RANGE_LONG_BLOCK \
  2504. - 0x00000004 // 2 yes Init-Dec The codebook is not within the allowed
  2505. - // range (long block)
  2506. -#define LAV_VIOLATION \
  2507. - 0x00000002 // 1 no Final The absolute value of at least one
  2508. - // decoded line was too high for the according codebook.
  2509. -#define BIT_IN_SEGMENTATION_ERROR \
  2510. - 0x00000001 // 0 no Final After PCW and non-PWC-decoding at least
  2511. - // one segment is not zero (global check).
  2512. -
  2513. -/*----------*/
  2514. -#define HCR_FATAL_PCW_ERROR_MASK 0x100E01FC
  2515. -
  2516. -typedef enum { PCW_BODY, PCW_BODY_SIGN, PCW_BODY_SIGN_ESC } PCW_TYPE;
  2517. -
  2518. -/* interface Decoder <---> HCR */
  2519. -typedef struct {
  2520. - UINT errorLog;
  2521. - SPECTRAL_PTR pQuantizedSpectralCoefficientsBase;
  2522. - int quantizedSpectralCoefficientsIdx;
  2523. - SHORT lengthOfReorderedSpectralData;
  2524. - SHORT numSection;
  2525. - SHORT *pNumLineInSect;
  2526. - INT bitstreamAnchor;
  2527. - SCHAR lengthOfLongestCodeword;
  2528. - UCHAR *pCodebook;
  2529. -} HCR_INPUT_OUTPUT;
  2530. -
  2531. -typedef struct {
  2532. - const UCHAR *pMinOfCbPair;
  2533. - const UCHAR *pMaxOfCbPair;
  2534. -} HCR_CB_PAIRS;
  2535. -
  2536. -typedef struct {
  2537. - const USHORT *pLargestAbsVal;
  2538. - const UCHAR *pMaxCwLength;
  2539. - const UCHAR *pCbDimension;
  2540. - const UCHAR *pCbDimShift;
  2541. - const UCHAR *pCbSign;
  2542. - const UCHAR *pCbPriority;
  2543. -} HCR_TABLE_INFO;
  2544. -
  2545. -typedef struct {
  2546. - UINT numSegment;
  2547. - UINT pSegmentBitfield[((1024 >> 1) / NUMBER_OF_BIT_IN_WORD + 1)];
  2548. - UINT pCodewordBitfield[((1024 >> 1) / NUMBER_OF_BIT_IN_WORD + 1)];
  2549. - UINT segmentOffset;
  2550. - INT pLeftStartOfSegment[1024 >> 1];
  2551. - INT pRightStartOfSegment[1024 >> 1];
  2552. - SCHAR pRemainingBitsInSegment[1024 >> 1];
  2553. - UCHAR readDirection;
  2554. - UCHAR numWordForBitfield;
  2555. - USHORT pNumBitValidInLastWord;
  2556. -} HCR_SEGMENT_INFO;
  2557. -
  2558. -typedef struct {
  2559. - UINT numCodeword;
  2560. - UINT numSortedSection;
  2561. - USHORT pNumCodewordInSection[MAX_SFB_HCR];
  2562. - USHORT pNumSortedCodewordInSection[MAX_SFB_HCR];
  2563. - USHORT pNumExtendedSortedCodewordInSection[MAX_SFB_HCR + MAX_HCR_SETS];
  2564. - int numExtendedSortedCodewordInSectionIdx;
  2565. - USHORT pNumExtendedSortedSectionsInSets[MAX_HCR_SETS];
  2566. - int numExtendedSortedSectionsInSetsIdx;
  2567. - USHORT pReorderOffset[MAX_SFB_HCR];
  2568. - UCHAR pSortedCodebook[MAX_SFB_HCR];
  2569. -
  2570. - UCHAR pExtendedSortedCodebook[MAX_SFB_HCR + MAX_HCR_SETS];
  2571. - int extendedSortedCodebookIdx;
  2572. - UCHAR pMaxLenOfCbInExtSrtSec[MAX_SFB_HCR + MAX_HCR_SETS];
  2573. - int maxLenOfCbInExtSrtSecIdx;
  2574. - UCHAR pCodebookSwitch[MAX_SFB_HCR];
  2575. -} HCR_SECTION_INFO;
  2576. -
  2577. -typedef UINT (*STATEFUNC)(HANDLE_FDK_BITSTREAM, void *);
  2578. -
  2579. -typedef struct {
  2580. - /* worst-case and 1024/4 non-PCWs exist in worst-case */
  2581. - FIXP_DBL
  2582. - *pResultBase; /* Base address for spectral data output target buffer */
  2583. - UINT iNode[1024 >> 2]; /* Helper indices for code books */
  2584. - USHORT
  2585. - iResultPointer[1024 >> 2]; /* Helper indices for accessing pResultBase */
  2586. - UINT pEscapeSequenceInfo[1024 >> 2];
  2587. - UINT codewordOffset;
  2588. - STATEFUNC pState;
  2589. - UCHAR pCodebook[1024 >> 2];
  2590. - UCHAR pCntSign[1024 >> 2];
  2591. - /* this array holds the states coded as integer values within the range
  2592. - * [0,1,..,7] */
  2593. - SCHAR pSta[1024 >> 2];
  2594. -} HCR_NON_PCW_SIDEINFO;
  2595. -
  2596. -typedef struct {
  2597. - HCR_INPUT_OUTPUT decInOut;
  2598. - HCR_SEGMENT_INFO segmentInfo;
  2599. - HCR_SECTION_INFO sectionInfo;
  2600. - HCR_NON_PCW_SIDEINFO nonPcwSideinfo;
  2601. -} CErHcrInfo;
  2602. -
  2603. -typedef CErHcrInfo *H_HCR_INFO;
  2604. -
  2605. -#endif /* AACDEC_HCR_TYPES_H */
  2606. diff --git a/libAACdec/src/aacdec_hcrs.cpp b/libAACdec/src/aacdec_hcrs.cpp
  2607. deleted file mode 100644
  2608. index d2bc867..0000000
  2609. --- a/libAACdec/src/aacdec_hcrs.cpp
  2610. +++ /dev/null
  2611. @@ -1,1551 +0,0 @@
  2612. -/* -----------------------------------------------------------------------------
  2613. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  2614. -
  2615. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  2616. -Forschung e.V. All rights reserved.
  2617. -
  2618. - 1. INTRODUCTION
  2619. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  2620. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  2621. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  2622. -a wide variety of Android devices.
  2623. -
  2624. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  2625. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  2626. -full-bandwidth communications codec by independent studies and is widely
  2627. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  2628. -specifications.
  2629. -
  2630. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  2631. -those of Fraunhofer) may be obtained through Via Licensing
  2632. -(www.vialicensing.com) or through the respective patent owners individually for
  2633. -the purpose of encoding or decoding bit streams in products that are compliant
  2634. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  2635. -Android devices already license these patent claims through Via Licensing or
  2636. -directly from the patent owners, and therefore FDK AAC Codec software may
  2637. -already be covered under those patent licenses when it is used for those
  2638. -licensed purposes only.
  2639. -
  2640. -Commercially-licensed AAC software libraries, including floating-point versions
  2641. -with enhanced sound quality, are also available from Fraunhofer. Users are
  2642. -encouraged to check the Fraunhofer website for additional applications
  2643. -information and documentation.
  2644. -
  2645. -2. COPYRIGHT LICENSE
  2646. -
  2647. -Redistribution and use in source and binary forms, with or without modification,
  2648. -are permitted without payment of copyright license fees provided that you
  2649. -satisfy the following conditions:
  2650. -
  2651. -You must retain the complete text of this software license in redistributions of
  2652. -the FDK AAC Codec or your modifications thereto in source code form.
  2653. -
  2654. -You must retain the complete text of this software license in the documentation
  2655. -and/or other materials provided with redistributions of the FDK AAC Codec or
  2656. -your modifications thereto in binary form. You must make available free of
  2657. -charge copies of the complete source code of the FDK AAC Codec and your
  2658. -modifications thereto to recipients of copies in binary form.
  2659. -
  2660. -The name of Fraunhofer may not be used to endorse or promote products derived
  2661. -from this library without prior written permission.
  2662. -
  2663. -You may not charge copyright license fees for anyone to use, copy or distribute
  2664. -the FDK AAC Codec software or your modifications thereto.
  2665. -
  2666. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  2667. -that you changed the software and the date of any change. For modified versions
  2668. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  2669. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  2670. -AAC Codec Library for Android."
  2671. -
  2672. -3. NO PATENT LICENSE
  2673. -
  2674. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  2675. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  2676. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  2677. -software.
  2678. -
  2679. -You may use this FDK AAC Codec software or modifications thereto only for
  2680. -purposes that are authorized by appropriate patent licenses.
  2681. -
  2682. -4. DISCLAIMER
  2683. -
  2684. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  2685. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  2686. -including but not limited to the implied warranties of merchantability and
  2687. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  2688. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  2689. -or consequential damages, including but not limited to procurement of substitute
  2690. -goods or services; loss of use, data, or profits, or business interruption,
  2691. -however caused and on any theory of liability, whether in contract, strict
  2692. -liability, or tort (including negligence), arising in any way out of the use of
  2693. -this software, even if advised of the possibility of such damage.
  2694. -
  2695. -5. CONTACT INFORMATION
  2696. -
  2697. -Fraunhofer Institute for Integrated Circuits IIS
  2698. -Attention: Audio and Multimedia Departments - FDK AAC LL
  2699. -Am Wolfsmantel 33
  2700. -91058 Erlangen, Germany
  2701. -
  2702. -www.iis.fraunhofer.de/amm
  2703. -amm-info@iis.fraunhofer.de
  2704. ------------------------------------------------------------------------------ */
  2705. -
  2706. -/**************************** AAC decoder library ******************************
  2707. -
  2708. - Author(s): Robert Weidner (DSP Solutions)
  2709. -
  2710. - Description: HCR Decoder: Prepare decoding of non-PCWs, segmentation- and
  2711. - bitfield-handling, HCR-Statemachine
  2712. -
  2713. -*******************************************************************************/
  2714. -
  2715. -#include "aacdec_hcrs.h"
  2716. -
  2717. -#include "aacdec_hcr.h"
  2718. -
  2719. -#include "aacdec_hcr_bit.h"
  2720. -#include "aac_rom.h"
  2721. -#include "aac_ram.h"
  2722. -
  2723. -static UINT InitSegmentBitfield(UINT *pNumSegment,
  2724. - SCHAR *pRemainingBitsInSegment,
  2725. - UINT *pSegmentBitfield,
  2726. - UCHAR *pNumWordForBitfield,
  2727. - USHORT *pNumBitValidInLastWord);
  2728. -
  2729. -static void InitNonPCWSideInformationForCurrentSet(H_HCR_INFO pHcr);
  2730. -
  2731. -static INT ModuloValue(INT input, INT bufferlength);
  2732. -
  2733. -static void ClearBitFromBitfield(STATEFUNC *ptrState, UINT offset,
  2734. - UINT *pBitfield);
  2735. -
  2736. -/*---------------------------------------------------------------------------------------------
  2737. - description: This function decodes all non-priority codewords (non-PCWs) by
  2738. -using a state-machine.
  2739. ---------------------------------------------------------------------------------------------
  2740. -*/
  2741. -void DecodeNonPCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO pHcr) {
  2742. - UINT numValidSegment;
  2743. - INT segmentOffset;
  2744. - INT codewordOffsetBase;
  2745. - INT codewordOffset;
  2746. - UINT trial;
  2747. -
  2748. - UINT *pNumSegment;
  2749. - SCHAR *pRemainingBitsInSegment;
  2750. - UINT *pSegmentBitfield;
  2751. - UCHAR *pNumWordForBitfield;
  2752. - USHORT *pNumBitValidInLastWord;
  2753. - UINT *pCodewordBitfield;
  2754. - INT bitfieldWord;
  2755. - INT bitInWord;
  2756. - UINT tempWord;
  2757. - UINT interMediateWord;
  2758. - INT tempBit;
  2759. - INT carry;
  2760. -
  2761. - UINT numCodeword;
  2762. - UCHAR numSet;
  2763. - UCHAR currentSet;
  2764. - UINT codewordInSet;
  2765. - UINT remainingCodewordsInSet;
  2766. - SCHAR *pSta;
  2767. - UINT ret;
  2768. -
  2769. - pNumSegment = &(pHcr->segmentInfo.numSegment);
  2770. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  2771. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  2772. - pNumWordForBitfield = &(pHcr->segmentInfo.numWordForBitfield);
  2773. - pNumBitValidInLastWord = &(pHcr->segmentInfo.pNumBitValidInLastWord);
  2774. - pSta = pHcr->nonPcwSideinfo.pSta;
  2775. -
  2776. - numValidSegment = InitSegmentBitfield(pNumSegment, pRemainingBitsInSegment,
  2777. - pSegmentBitfield, pNumWordForBitfield,
  2778. - pNumBitValidInLastWord);
  2779. -
  2780. - if (numValidSegment != 0) {
  2781. - numCodeword = pHcr->sectionInfo.numCodeword;
  2782. - numSet = ((numCodeword - 1) / *pNumSegment) + 1;
  2783. -
  2784. - pHcr->segmentInfo.readDirection = FROM_RIGHT_TO_LEFT;
  2785. -
  2786. - /* Process sets subsequently */
  2787. - for (currentSet = 1; currentSet < numSet; currentSet++) {
  2788. - /* step 1 */
  2789. - numCodeword -=
  2790. - *pNumSegment; /* number of remaining non PCWs [for all sets] */
  2791. - if (numCodeword < *pNumSegment) {
  2792. - codewordInSet = numCodeword; /* for last set */
  2793. - } else {
  2794. - codewordInSet = *pNumSegment; /* for all sets except last set */
  2795. - }
  2796. -
  2797. - /* step 2 */
  2798. - /* prepare array 'CodewordBitfield'; as much ones are written from left in
  2799. - * all words, as much decodedCodewordInSetCounter nonPCWs exist in this
  2800. - * set */
  2801. - tempWord = 0xFFFFFFFF;
  2802. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  2803. -
  2804. - for (bitfieldWord = *pNumWordForBitfield; bitfieldWord != 0;
  2805. - bitfieldWord--) { /* loop over all used words */
  2806. - if (codewordInSet > NUMBER_OF_BIT_IN_WORD) { /* more codewords than
  2807. - number of bits => fill
  2808. - ones */
  2809. - /* fill a whole word with ones */
  2810. - *pCodewordBitfield++ = tempWord;
  2811. - codewordInSet -= NUMBER_OF_BIT_IN_WORD; /* subtract number of bits */
  2812. - } else {
  2813. - /* prepare last tempWord */
  2814. - for (remainingCodewordsInSet = codewordInSet;
  2815. - remainingCodewordsInSet < NUMBER_OF_BIT_IN_WORD;
  2816. - remainingCodewordsInSet++) {
  2817. - tempWord =
  2818. - tempWord &
  2819. - ~(1
  2820. - << (NUMBER_OF_BIT_IN_WORD - 1 -
  2821. - remainingCodewordsInSet)); /* set a zero at bit number
  2822. - (NUMBER_OF_BIT_IN_WORD-1-i)
  2823. - in tempWord */
  2824. - }
  2825. - *pCodewordBitfield++ = tempWord;
  2826. - tempWord = 0x00000000;
  2827. - }
  2828. - }
  2829. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  2830. -
  2831. - /* step 3 */
  2832. - /* build non-PCW sideinfo for each non-PCW of the current set */
  2833. - InitNonPCWSideInformationForCurrentSet(pHcr);
  2834. -
  2835. - /* step 4 */
  2836. - /* decode all non-PCWs belonging to this set */
  2837. -
  2838. - /* loop over trials */
  2839. - codewordOffsetBase = 0;
  2840. - for (trial = *pNumSegment; trial > 0; trial--) {
  2841. - /* loop over number of words in bitfields */
  2842. - segmentOffset = 0; /* start at zero in every segment */
  2843. - pHcr->segmentInfo.segmentOffset =
  2844. - segmentOffset; /* store in structure for states */
  2845. - codewordOffset = codewordOffsetBase;
  2846. - pHcr->nonPcwSideinfo.codewordOffset =
  2847. - codewordOffset; /* store in structure for states */
  2848. -
  2849. - for (bitfieldWord = 0; bitfieldWord < *pNumWordForBitfield;
  2850. - bitfieldWord++) {
  2851. - /* derive tempWord with bitwise and */
  2852. - tempWord =
  2853. - pSegmentBitfield[bitfieldWord] & pCodewordBitfield[bitfieldWord];
  2854. -
  2855. - /* if tempWord is not zero, decode something */
  2856. - if (tempWord != 0) {
  2857. - /* loop over all bits in tempWord; start state machine if & is true
  2858. - */
  2859. - for (bitInWord = NUMBER_OF_BIT_IN_WORD; bitInWord > 0;
  2860. - bitInWord--) {
  2861. - interMediateWord = ((UINT)1 << (bitInWord - 1));
  2862. - if ((tempWord & interMediateWord) == interMediateWord) {
  2863. - /* get state and start state machine */
  2864. - pHcr->nonPcwSideinfo.pState =
  2865. - aStateConstant2State[pSta[codewordOffset]];
  2866. -
  2867. - while (pHcr->nonPcwSideinfo.pState) {
  2868. - ret = ((STATEFUNC)pHcr->nonPcwSideinfo.pState)(bs, pHcr);
  2869. - if (ret != 0) {
  2870. - return;
  2871. - }
  2872. - }
  2873. - }
  2874. -
  2875. - /* update both offsets */
  2876. - segmentOffset += 1; /* add NUMBER_OF_BIT_IN_WORD times one */
  2877. - pHcr->segmentInfo.segmentOffset = segmentOffset;
  2878. - codewordOffset += 1; /* add NUMBER_OF_BIT_IN_WORD times one */
  2879. - codewordOffset =
  2880. - ModuloValue(codewordOffset,
  2881. - *pNumSegment); /* index of the current codeword
  2882. - lies within modulo range */
  2883. - pHcr->nonPcwSideinfo.codewordOffset = codewordOffset;
  2884. - }
  2885. - } else {
  2886. - segmentOffset +=
  2887. - NUMBER_OF_BIT_IN_WORD; /* add NUMBER_OF_BIT_IN_WORD at once */
  2888. - pHcr->segmentInfo.segmentOffset = segmentOffset;
  2889. - codewordOffset +=
  2890. - NUMBER_OF_BIT_IN_WORD; /* add NUMBER_OF_BIT_IN_WORD at once */
  2891. - codewordOffset = ModuloValue(
  2892. - codewordOffset,
  2893. - *pNumSegment); /* index of the current codeword lies within
  2894. - modulo range */
  2895. - pHcr->nonPcwSideinfo.codewordOffset = codewordOffset;
  2896. - }
  2897. - } /* end of bitfield word loop */
  2898. -
  2899. - /* decrement codeword - pointer */
  2900. - codewordOffsetBase -= 1;
  2901. - codewordOffsetBase =
  2902. - ModuloValue(codewordOffsetBase, *pNumSegment); /* index of the
  2903. - current codeword
  2904. - base lies within
  2905. - modulo range */
  2906. -
  2907. - /* rotate numSegment bits in codewordBitfield */
  2908. - /* rotation of *numSegment bits in bitfield of codewords
  2909. - * (circle-rotation) */
  2910. - /* get last valid bit */
  2911. - tempBit = pCodewordBitfield[*pNumWordForBitfield - 1] &
  2912. - (1 << (NUMBER_OF_BIT_IN_WORD - *pNumBitValidInLastWord));
  2913. - tempBit = tempBit >> (NUMBER_OF_BIT_IN_WORD - *pNumBitValidInLastWord);
  2914. -
  2915. - /* write zero into place where tempBit was fetched from */
  2916. - pCodewordBitfield[*pNumWordForBitfield - 1] =
  2917. - pCodewordBitfield[*pNumWordForBitfield - 1] &
  2918. - ~(1 << (NUMBER_OF_BIT_IN_WORD - *pNumBitValidInLastWord));
  2919. -
  2920. - /* rotate last valid word */
  2921. - pCodewordBitfield[*pNumWordForBitfield - 1] =
  2922. - pCodewordBitfield[*pNumWordForBitfield - 1] >> 1;
  2923. -
  2924. - /* transfare carry bit 0 from current word into bitposition 31 from next
  2925. - * word and rotate current word */
  2926. - for (bitfieldWord = *pNumWordForBitfield - 2; bitfieldWord > -1;
  2927. - bitfieldWord--) {
  2928. - /* get carry (=bit at position 0) from current word */
  2929. - carry = pCodewordBitfield[bitfieldWord] & 1;
  2930. -
  2931. - /* put the carry bit at position 31 into word right from current word
  2932. - */
  2933. - pCodewordBitfield[bitfieldWord + 1] =
  2934. - pCodewordBitfield[bitfieldWord + 1] |
  2935. - (carry << (NUMBER_OF_BIT_IN_WORD - 1));
  2936. -
  2937. - /* shift current word */
  2938. - pCodewordBitfield[bitfieldWord] =
  2939. - pCodewordBitfield[bitfieldWord] >> 1;
  2940. - }
  2941. -
  2942. - /* put tempBit into free bit-position 31 from first word */
  2943. - pCodewordBitfield[0] =
  2944. - pCodewordBitfield[0] | (tempBit << (NUMBER_OF_BIT_IN_WORD - 1));
  2945. -
  2946. - } /* end of trial loop */
  2947. -
  2948. - /* toggle read direction */
  2949. - pHcr->segmentInfo.readDirection =
  2950. - ToggleReadDirection(pHcr->segmentInfo.readDirection);
  2951. - }
  2952. - /* end of set loop */
  2953. -
  2954. - /* all non-PCWs of this spectrum are decoded */
  2955. - }
  2956. -
  2957. - /* all PCWs and all non PCWs are decoded. They are unbacksorted in output
  2958. - * buffer. Here is the Interface with comparing QSCs to asm decoding */
  2959. -}
  2960. -
  2961. -/*---------------------------------------------------------------------------------------------
  2962. - description: This function prepares the bitfield used for the
  2963. - segments. The list is set up once to be used in all
  2964. -following sets. If a segment is decoded empty, the according bit from the
  2965. -Bitfield is removed.
  2966. ------------------------------------------------------------------------------------------------
  2967. - return: numValidSegment = the number of valid segments
  2968. ---------------------------------------------------------------------------------------------
  2969. -*/
  2970. -static UINT InitSegmentBitfield(UINT *pNumSegment,
  2971. - SCHAR *pRemainingBitsInSegment,
  2972. - UINT *pSegmentBitfield,
  2973. - UCHAR *pNumWordForBitfield,
  2974. - USHORT *pNumBitValidInLastWord) {
  2975. - SHORT i;
  2976. - USHORT r;
  2977. - UCHAR bitfieldWord;
  2978. - UINT tempWord;
  2979. - USHORT numValidSegment;
  2980. -
  2981. - *pNumWordForBitfield =
  2982. - (*pNumSegment == 0)
  2983. - ? 0
  2984. - : ((*pNumSegment - 1) >> THIRTYTWO_LOG_DIV_TWO_LOG) + 1;
  2985. -
  2986. - /* loop over all words, which are completely used or only partial */
  2987. - /* bit in pSegmentBitfield is zero if segment is empty; bit in
  2988. - * pSegmentBitfield is one if segment is not empty */
  2989. - numValidSegment = 0;
  2990. - *pNumBitValidInLastWord = *pNumSegment;
  2991. -
  2992. - /* loop over words */
  2993. - for (bitfieldWord = 0; bitfieldWord < *pNumWordForBitfield - 1;
  2994. - bitfieldWord++) {
  2995. - tempWord = 0xFFFFFFFF; /* set ones */
  2996. - r = bitfieldWord << THIRTYTWO_LOG_DIV_TWO_LOG;
  2997. - for (i = 0; i < NUMBER_OF_BIT_IN_WORD; i++) {
  2998. - if (pRemainingBitsInSegment[r + i] == 0) {
  2999. - tempWord = tempWord & ~(1 << (NUMBER_OF_BIT_IN_WORD - 1 -
  3000. - i)); /* set a zero at bit number
  3001. - (NUMBER_OF_BIT_IN_WORD-1-i) in
  3002. - tempWord */
  3003. - } else {
  3004. - numValidSegment += 1; /* count segments which are not empty */
  3005. - }
  3006. - }
  3007. - pSegmentBitfield[bitfieldWord] = tempWord; /* store result */
  3008. - *pNumBitValidInLastWord -= NUMBER_OF_BIT_IN_WORD; /* calculate number of
  3009. - zeros on LSB side in
  3010. - the last word */
  3011. - }
  3012. -
  3013. - /* calculate last word: prepare special tempWord */
  3014. - tempWord = 0xFFFFFFFF;
  3015. - for (i = 0; i < (NUMBER_OF_BIT_IN_WORD - *pNumBitValidInLastWord); i++) {
  3016. - tempWord = tempWord & ~(1 << i); /* clear bit i in tempWord */
  3017. - }
  3018. -
  3019. - /* calculate last word */
  3020. - r = bitfieldWord << THIRTYTWO_LOG_DIV_TWO_LOG;
  3021. - for (i = 0; i < *pNumBitValidInLastWord; i++) {
  3022. - if (pRemainingBitsInSegment[r + i] == 0) {
  3023. - tempWord = tempWord & ~(1 << (NUMBER_OF_BIT_IN_WORD - 1 -
  3024. - i)); /* set a zero at bit number
  3025. - (NUMBER_OF_BIT_IN_WORD-1-i) in
  3026. - tempWord */
  3027. - } else {
  3028. - numValidSegment += 1; /* count segments which are not empty */
  3029. - }
  3030. - }
  3031. - pSegmentBitfield[bitfieldWord] = tempWord; /* store result */
  3032. -
  3033. - return numValidSegment;
  3034. -}
  3035. -
  3036. -/*---------------------------------------------------------------------------------------------
  3037. - description: This function sets up sideinfo for the non-PCW decoder (for the
  3038. -current set).
  3039. ----------------------------------------------------------------------------------------------*/
  3040. -static void InitNonPCWSideInformationForCurrentSet(H_HCR_INFO pHcr) {
  3041. - USHORT i, k;
  3042. - UCHAR codebookDim;
  3043. - UINT startNode;
  3044. -
  3045. - UCHAR *pCodebook = pHcr->nonPcwSideinfo.pCodebook;
  3046. - UINT *iNode = pHcr->nonPcwSideinfo.iNode;
  3047. - UCHAR *pCntSign = pHcr->nonPcwSideinfo.pCntSign;
  3048. - USHORT *iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
  3049. - UINT *pEscapeSequenceInfo = pHcr->nonPcwSideinfo.pEscapeSequenceInfo;
  3050. - SCHAR *pSta = pHcr->nonPcwSideinfo.pSta;
  3051. - USHORT *pNumExtendedSortedCodewordInSection =
  3052. - pHcr->sectionInfo.pNumExtendedSortedCodewordInSection;
  3053. - int numExtendedSortedCodewordInSectionIdx =
  3054. - pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx;
  3055. - UCHAR *pExtendedSortedCodebook = pHcr->sectionInfo.pExtendedSortedCodebook;
  3056. - int extendedSortedCodebookIdx = pHcr->sectionInfo.extendedSortedCodebookIdx;
  3057. - USHORT *pNumExtendedSortedSectionsInSets =
  3058. - pHcr->sectionInfo.pNumExtendedSortedSectionsInSets;
  3059. - int numExtendedSortedSectionsInSetsIdx =
  3060. - pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx;
  3061. - int quantizedSpectralCoefficientsIdx =
  3062. - pHcr->decInOut.quantizedSpectralCoefficientsIdx;
  3063. - const UCHAR *pCbDimension = aDimCb;
  3064. - int iterationCounter = 0;
  3065. -
  3066. - /* loop over number of extended sorted sections in the current set so all
  3067. - * codewords sideinfo variables within this set can be prepared for decoding
  3068. - */
  3069. - for (i = pNumExtendedSortedSectionsInSets[numExtendedSortedSectionsInSetsIdx];
  3070. - i != 0; i--) {
  3071. - codebookDim =
  3072. - pCbDimension[pExtendedSortedCodebook[extendedSortedCodebookIdx]];
  3073. - startNode = *aHuffTable[pExtendedSortedCodebook[extendedSortedCodebookIdx]];
  3074. -
  3075. - for (k = pNumExtendedSortedCodewordInSection
  3076. - [numExtendedSortedCodewordInSectionIdx];
  3077. - k != 0; k--) {
  3078. - iterationCounter++;
  3079. - if (iterationCounter > (1024 >> 2)) {
  3080. - return;
  3081. - }
  3082. - *pSta++ = aCodebook2StartInt
  3083. - [pExtendedSortedCodebook[extendedSortedCodebookIdx]];
  3084. - *pCodebook++ = pExtendedSortedCodebook[extendedSortedCodebookIdx];
  3085. - *iNode++ = startNode;
  3086. - *pCntSign++ = 0;
  3087. - *iResultPointer++ = quantizedSpectralCoefficientsIdx;
  3088. - *pEscapeSequenceInfo++ = 0;
  3089. - quantizedSpectralCoefficientsIdx +=
  3090. - codebookDim; /* update pointer by codebookDim --> point to next
  3091. - starting value for writing out */
  3092. - if (quantizedSpectralCoefficientsIdx >= 1024) {
  3093. - return;
  3094. - }
  3095. - }
  3096. - numExtendedSortedCodewordInSectionIdx++; /* inc ptr for next ext sort sec in
  3097. - current set */
  3098. - extendedSortedCodebookIdx++; /* inc ptr for next ext sort sec in current set
  3099. - */
  3100. - if (numExtendedSortedCodewordInSectionIdx >= (MAX_SFB_HCR + MAX_HCR_SETS) ||
  3101. - extendedSortedCodebookIdx >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
  3102. - return;
  3103. - }
  3104. - }
  3105. - numExtendedSortedSectionsInSetsIdx++; /* inc ptr for next set of non-PCWs */
  3106. - if (numExtendedSortedCodewordInSectionIdx >= (MAX_SFB_HCR + MAX_HCR_SETS)) {
  3107. - return;
  3108. - }
  3109. -
  3110. - /* Write back indexes */
  3111. - pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx =
  3112. - numExtendedSortedCodewordInSectionIdx;
  3113. - pHcr->sectionInfo.extendedSortedCodebookIdx = extendedSortedCodebookIdx;
  3114. - pHcr->sectionInfo.numExtendedSortedSectionsInSetsIdx =
  3115. - numExtendedSortedSectionsInSetsIdx;
  3116. - pHcr->sectionInfo.numExtendedSortedCodewordInSectionIdx =
  3117. - numExtendedSortedCodewordInSectionIdx;
  3118. - pHcr->decInOut.quantizedSpectralCoefficientsIdx =
  3119. - quantizedSpectralCoefficientsIdx;
  3120. -}
  3121. -
  3122. -/*---------------------------------------------------------------------------------------------
  3123. - description: This function returns the input value if the value is in the
  3124. - range of bufferlength. If <input> is smaller, one bufferlength
  3125. -is added, if <input> is bigger one bufferlength is subtracted.
  3126. ------------------------------------------------------------------------------------------------
  3127. - return: modulo result
  3128. ---------------------------------------------------------------------------------------------
  3129. -*/
  3130. -static INT ModuloValue(INT input, INT bufferlength) {
  3131. - if (input > (bufferlength - 1)) {
  3132. - return (input - bufferlength);
  3133. - }
  3134. - if (input < 0) {
  3135. - return (input + bufferlength);
  3136. - }
  3137. - return input;
  3138. -}
  3139. -
  3140. -/*---------------------------------------------------------------------------------------------
  3141. - description: This function clears a bit from current bitfield and
  3142. - switches off the statemachine.
  3143. -
  3144. - A bit is cleared in two cases:
  3145. - a) a codeword is decoded, then a bit is cleared in codeword
  3146. -bitfield b) a segment is decoded empty, then a bit is cleared in segment
  3147. -bitfield
  3148. ---------------------------------------------------------------------------------------------
  3149. -*/
  3150. -static void ClearBitFromBitfield(STATEFUNC *ptrState, UINT offset,
  3151. - UINT *pBitfield) {
  3152. - UINT numBitfieldWord;
  3153. - UINT numBitfieldBit;
  3154. -
  3155. - /* get both values needed for clearing the bit */
  3156. - numBitfieldWord = offset >> THIRTYTWO_LOG_DIV_TWO_LOG; /* int = wordNr */
  3157. - numBitfieldBit = offset - (numBitfieldWord
  3158. - << THIRTYTWO_LOG_DIV_TWO_LOG); /* fract = bitNr */
  3159. -
  3160. - /* clear a bit in bitfield */
  3161. - pBitfield[numBitfieldWord] =
  3162. - pBitfield[numBitfieldWord] &
  3163. - ~(1 << (NUMBER_OF_BIT_IN_WORD - 1 - numBitfieldBit));
  3164. -
  3165. - /* switch off state machine because codeword is decoded and/or because segment
  3166. - * is empty */
  3167. - *ptrState = NULL;
  3168. -}
  3169. -
  3170. -/* =========================================================================================
  3171. - the states of the statemachine
  3172. - =========================================================================================
  3173. - */
  3174. -
  3175. -/*---------------------------------------------------------------------------------------------
  3176. - description: Decodes the body of a codeword. This State is used for
  3177. -codebooks 1,2,5 and 6. No sign bits are decoded, because the table of the
  3178. -quantized spectral values has got a valid sign at the quantized spectral lines.
  3179. ------------------------------------------------------------------------------------------------
  3180. - output: Two or four quantizes spectral values written at position
  3181. -where pResultPointr points to
  3182. ------------------------------------------------------------------------------------------------
  3183. - return: 0
  3184. ---------------------------------------------------------------------------------------------
  3185. -*/
  3186. -UINT Hcr_State_BODY_ONLY(HANDLE_FDK_BITSTREAM bs, void *ptr) {
  3187. - H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
  3188. - UINT *pSegmentBitfield;
  3189. - UINT *pCodewordBitfield;
  3190. - UINT segmentOffset;
  3191. - FIXP_DBL *pResultBase;
  3192. - UINT *iNode;
  3193. - USHORT *iResultPointer;
  3194. - UINT codewordOffset;
  3195. - UINT branchNode;
  3196. - UINT branchValue;
  3197. - UINT iQSC;
  3198. - UINT treeNode;
  3199. - UCHAR carryBit;
  3200. - INT *pLeftStartOfSegment;
  3201. - INT *pRightStartOfSegment;
  3202. - SCHAR *pRemainingBitsInSegment;
  3203. - UCHAR readDirection;
  3204. - UCHAR *pCodebook;
  3205. - UCHAR dimCntr;
  3206. - const UINT *pCurrentTree;
  3207. - const UCHAR *pCbDimension;
  3208. - const SCHAR *pQuantVal;
  3209. - const SCHAR *pQuantValBase;
  3210. -
  3211. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  3212. - pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  3213. - pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  3214. - readDirection = pHcr->segmentInfo.readDirection;
  3215. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  3216. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  3217. - segmentOffset = pHcr->segmentInfo.segmentOffset;
  3218. -
  3219. - pCodebook = pHcr->nonPcwSideinfo.pCodebook;
  3220. - iNode = pHcr->nonPcwSideinfo.iNode;
  3221. - pResultBase = pHcr->nonPcwSideinfo.pResultBase;
  3222. - iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
  3223. - codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
  3224. -
  3225. - pCbDimension = aDimCb;
  3226. -
  3227. - treeNode = iNode[codewordOffset];
  3228. - pCurrentTree = aHuffTable[pCodebook[codewordOffset]];
  3229. -
  3230. - for (; pRemainingBitsInSegment[segmentOffset] > 0;
  3231. - pRemainingBitsInSegment[segmentOffset] -= 1) {
  3232. - carryBit = HcrGetABitFromBitstream(
  3233. - bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
  3234. - &pRightStartOfSegment[segmentOffset], readDirection);
  3235. -
  3236. - CarryBitToBranchValue(carryBit, /* make a step in decoding tree */
  3237. - treeNode, &branchValue, &branchNode);
  3238. -
  3239. - /* if end of branch reached write out lines and count bits needed for sign,
  3240. - * otherwise store node in codeword sideinfo */
  3241. - if ((branchNode & TEST_BIT_10) ==
  3242. - TEST_BIT_10) { /* test bit 10 ; ==> body is complete */
  3243. - pQuantValBase = aQuantTable[pCodebook[codewordOffset]]; /* get base
  3244. - address of
  3245. - quantized
  3246. - values
  3247. - belonging to
  3248. - current
  3249. - codebook */
  3250. - pQuantVal = pQuantValBase + branchValue; /* set pointer to first valid
  3251. - line [of 2 or 4 quantized
  3252. - values] */
  3253. -
  3254. - iQSC = iResultPointer[codewordOffset]; /* get position of first line for
  3255. - writing out result */
  3256. -
  3257. - for (dimCntr = pCbDimension[pCodebook[codewordOffset]]; dimCntr != 0;
  3258. - dimCntr--) {
  3259. - pResultBase[iQSC++] =
  3260. - (FIXP_DBL)*pQuantVal++; /* write out 2 or 4 lines into
  3261. - spectrum; no Sign bits
  3262. - available in this state */
  3263. - }
  3264. -
  3265. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3266. - pCodewordBitfield); /* clear a bit in bitfield and
  3267. - switch off statemachine */
  3268. - pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
  3269. - for loop counter (see
  3270. - above) is done here */
  3271. - break; /* end of branch in tree reached i.e. a whole nonPCW-Body is
  3272. - decoded */
  3273. - } else { /* body is not decoded completely: */
  3274. - treeNode = *(
  3275. - pCurrentTree +
  3276. - branchValue); /* update treeNode for further step in decoding tree */
  3277. - }
  3278. - }
  3279. - iNode[codewordOffset] = treeNode; /* store updated treeNode because maybe
  3280. - decoding of codeword body not finished
  3281. - yet */
  3282. -
  3283. - if (pRemainingBitsInSegment[segmentOffset] <= 0) {
  3284. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3285. - pSegmentBitfield); /* clear a bit in bitfield and
  3286. - switch off statemachine */
  3287. -
  3288. - if (pRemainingBitsInSegment[segmentOffset] < 0) {
  3289. - pHcr->decInOut.errorLog |= STATE_ERROR_BODY_ONLY;
  3290. - return BODY_ONLY;
  3291. - }
  3292. - }
  3293. -
  3294. - return STOP_THIS_STATE;
  3295. -}
  3296. -
  3297. -/*---------------------------------------------------------------------------------------------
  3298. - description: Decodes the codeword body, writes out result and counts the
  3299. -number of quantized spectral values, which are different form zero. For those
  3300. -values sign bits are needed.
  3301. -
  3302. - If sign bit counter cntSign is different from zero, switch to
  3303. -next state to decode sign Bits there. If sign bit counter cntSign is zero, no
  3304. -sign bits are needed and codeword is decoded.
  3305. ------------------------------------------------------------------------------------------------
  3306. - output: Two or four written quantizes spectral values written at
  3307. -position where pResultPointr points to. The signs of those lines may be wrong.
  3308. -If the signs [on just one signle sign] is wrong, the next state will correct it.
  3309. ------------------------------------------------------------------------------------------------
  3310. - return: 0
  3311. ---------------------------------------------------------------------------------------------
  3312. -*/
  3313. -UINT Hcr_State_BODY_SIGN__BODY(HANDLE_FDK_BITSTREAM bs, void *ptr) {
  3314. - H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
  3315. - SCHAR *pRemainingBitsInSegment;
  3316. - INT *pLeftStartOfSegment;
  3317. - INT *pRightStartOfSegment;
  3318. - UCHAR readDirection;
  3319. - UINT *pSegmentBitfield;
  3320. - UINT *pCodewordBitfield;
  3321. - UINT segmentOffset;
  3322. -
  3323. - UCHAR *pCodebook;
  3324. - UINT *iNode;
  3325. - UCHAR *pCntSign;
  3326. - FIXP_DBL *pResultBase;
  3327. - USHORT *iResultPointer;
  3328. - UINT codewordOffset;
  3329. -
  3330. - UINT iQSC;
  3331. - UINT cntSign;
  3332. - UCHAR dimCntr;
  3333. - UCHAR carryBit;
  3334. - SCHAR *pSta;
  3335. - UINT treeNode;
  3336. - UINT branchValue;
  3337. - UINT branchNode;
  3338. - const UCHAR *pCbDimension;
  3339. - const UINT *pCurrentTree;
  3340. - const SCHAR *pQuantValBase;
  3341. - const SCHAR *pQuantVal;
  3342. -
  3343. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  3344. - pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  3345. - pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  3346. - readDirection = pHcr->segmentInfo.readDirection;
  3347. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  3348. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  3349. - segmentOffset = pHcr->segmentInfo.segmentOffset;
  3350. -
  3351. - pCodebook = pHcr->nonPcwSideinfo.pCodebook;
  3352. - iNode = pHcr->nonPcwSideinfo.iNode;
  3353. - pCntSign = pHcr->nonPcwSideinfo.pCntSign;
  3354. - pResultBase = pHcr->nonPcwSideinfo.pResultBase;
  3355. - iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
  3356. - codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
  3357. - pSta = pHcr->nonPcwSideinfo.pSta;
  3358. -
  3359. - pCbDimension = aDimCb;
  3360. -
  3361. - treeNode = iNode[codewordOffset];
  3362. - pCurrentTree = aHuffTable[pCodebook[codewordOffset]];
  3363. -
  3364. - for (; pRemainingBitsInSegment[segmentOffset] > 0;
  3365. - pRemainingBitsInSegment[segmentOffset] -= 1) {
  3366. - carryBit = HcrGetABitFromBitstream(
  3367. - bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
  3368. - &pRightStartOfSegment[segmentOffset], readDirection);
  3369. -
  3370. - CarryBitToBranchValue(carryBit, /* make a step in decoding tree */
  3371. - treeNode, &branchValue, &branchNode);
  3372. -
  3373. - /* if end of branch reached write out lines and count bits needed for sign,
  3374. - * otherwise store node in codeword sideinfo */
  3375. - if ((branchNode & TEST_BIT_10) ==
  3376. - TEST_BIT_10) { /* test bit 10 ; if set body complete */
  3377. - /* body completely decoded; branchValue is valid, set pQuantVal to first
  3378. - * (of two or four) quantized spectral coefficients */
  3379. - pQuantValBase = aQuantTable[pCodebook[codewordOffset]]; /* get base
  3380. - address of
  3381. - quantized
  3382. - values
  3383. - belonging to
  3384. - current
  3385. - codebook */
  3386. - pQuantVal = pQuantValBase + branchValue; /* set pointer to first valid
  3387. - line [of 2 or 4 quantized
  3388. - values] */
  3389. -
  3390. - iQSC = iResultPointer[codewordOffset]; /* get position of first line for
  3391. - writing result */
  3392. -
  3393. - /* codeword decoding result is written out here: Write out 2 or 4
  3394. - * quantized spectral values with probably */
  3395. - /* wrong sign and count number of values which are different from zero for
  3396. - * sign bit decoding [which happens in next state] */
  3397. - cntSign = 0;
  3398. - for (dimCntr = pCbDimension[pCodebook[codewordOffset]]; dimCntr != 0;
  3399. - dimCntr--) {
  3400. - pResultBase[iQSC++] =
  3401. - (FIXP_DBL)*pQuantVal; /* write quant. spec. coef. into spectrum */
  3402. - if (*pQuantVal++ != 0) {
  3403. - cntSign += 1;
  3404. - }
  3405. - }
  3406. -
  3407. - if (cntSign == 0) {
  3408. - ClearBitFromBitfield(
  3409. - &(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3410. - pCodewordBitfield); /* clear a bit in bitfield and switch off
  3411. - statemachine */
  3412. - } else {
  3413. - pCntSign[codewordOffset] = cntSign; /* write sign count result into
  3414. - codewordsideinfo of current
  3415. - codeword */
  3416. - pSta[codewordOffset] = BODY_SIGN__SIGN; /* change state */
  3417. - pHcr->nonPcwSideinfo.pState =
  3418. - aStateConstant2State[pSta[codewordOffset]]; /* get state from
  3419. - separate array of
  3420. - cw-sideinfo */
  3421. - }
  3422. - pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
  3423. - for loop counter (see
  3424. - above) is done here */
  3425. - break; /* end of branch in tree reached i.e. a whole nonPCW-Body is
  3426. - decoded */
  3427. - } else { /* body is not decoded completely: */
  3428. - treeNode = *(
  3429. - pCurrentTree +
  3430. - branchValue); /* update treeNode for further step in decoding tree */
  3431. - }
  3432. - }
  3433. - iNode[codewordOffset] = treeNode; /* store updated treeNode because maybe
  3434. - decoding of codeword body not finished
  3435. - yet */
  3436. -
  3437. - if (pRemainingBitsInSegment[segmentOffset] <= 0) {
  3438. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3439. - pSegmentBitfield); /* clear a bit in bitfield and
  3440. - switch off statemachine */
  3441. -
  3442. - if (pRemainingBitsInSegment[segmentOffset] < 0) {
  3443. - pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN__BODY;
  3444. - return BODY_SIGN__BODY;
  3445. - }
  3446. - }
  3447. -
  3448. - return STOP_THIS_STATE;
  3449. -}
  3450. -
  3451. -/*---------------------------------------------------------------------------------------------
  3452. - description: This state decodes the sign bits belonging to a codeword. The
  3453. -state is called as often in different "trials" until pCntSgn[codewordOffset] is
  3454. -zero.
  3455. ------------------------------------------------------------------------------------------------
  3456. - output: The two or four quantizes spectral values (written in previous
  3457. -state) have now the correct sign.
  3458. ------------------------------------------------------------------------------------------------
  3459. - return: 0
  3460. ---------------------------------------------------------------------------------------------
  3461. -*/
  3462. -UINT Hcr_State_BODY_SIGN__SIGN(HANDLE_FDK_BITSTREAM bs, void *ptr) {
  3463. - H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
  3464. - SCHAR *pRemainingBitsInSegment;
  3465. - INT *pLeftStartOfSegment;
  3466. - INT *pRightStartOfSegment;
  3467. - UCHAR readDirection;
  3468. - UINT *pSegmentBitfield;
  3469. - UINT *pCodewordBitfield;
  3470. - UINT segmentOffset;
  3471. -
  3472. - UCHAR *pCntSign;
  3473. - FIXP_DBL *pResultBase;
  3474. - USHORT *iResultPointer;
  3475. - UINT codewordOffset;
  3476. -
  3477. - UCHAR carryBit;
  3478. - UINT iQSC;
  3479. - UCHAR cntSign;
  3480. -
  3481. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  3482. - pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  3483. - pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  3484. - readDirection = pHcr->segmentInfo.readDirection;
  3485. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  3486. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  3487. - segmentOffset = pHcr->segmentInfo.segmentOffset;
  3488. -
  3489. - /*pCodebook = */
  3490. - pCntSign = pHcr->nonPcwSideinfo.pCntSign;
  3491. - pResultBase = pHcr->nonPcwSideinfo.pResultBase;
  3492. - iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
  3493. - codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
  3494. -
  3495. - iQSC = iResultPointer[codewordOffset];
  3496. - cntSign = pCntSign[codewordOffset];
  3497. -
  3498. - /* loop for sign bit decoding */
  3499. - for (; pRemainingBitsInSegment[segmentOffset] > 0;
  3500. - pRemainingBitsInSegment[segmentOffset] -= 1) {
  3501. - carryBit = HcrGetABitFromBitstream(
  3502. - bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
  3503. - &pRightStartOfSegment[segmentOffset], readDirection);
  3504. - cntSign -=
  3505. - 1; /* decrement sign counter because one sign bit has been read */
  3506. -
  3507. - /* search for a line (which was decoded in previous state) which is not
  3508. - * zero. [This value will get a sign] */
  3509. - while (pResultBase[iQSC] == (FIXP_DBL)0) {
  3510. - if (++iQSC >= 1024) { /* points to current value different from zero */
  3511. - return BODY_SIGN__SIGN;
  3512. - }
  3513. - }
  3514. -
  3515. - /* put sign together with line; if carryBit is zero, the sign is ok already;
  3516. - * no write operation necessary in this case */
  3517. - if (carryBit != 0) {
  3518. - pResultBase[iQSC] = -pResultBase[iQSC]; /* carryBit = 1 --> minus */
  3519. - }
  3520. -
  3521. - iQSC++; /* update pointer to next (maybe valid) value */
  3522. -
  3523. - if (cntSign == 0) { /* if (cntSign==0) ==> set state CODEWORD_DECODED */
  3524. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3525. - pCodewordBitfield); /* clear a bit in bitfield and
  3526. - switch off statemachine */
  3527. - pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
  3528. - for loop counter (see
  3529. - above) is done here */
  3530. - break; /* whole nonPCW-Body and according sign bits are decoded */
  3531. - }
  3532. - }
  3533. - pCntSign[codewordOffset] = cntSign;
  3534. - iResultPointer[codewordOffset] = iQSC; /* store updated pResultPointer */
  3535. -
  3536. - if (pRemainingBitsInSegment[segmentOffset] <= 0) {
  3537. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3538. - pSegmentBitfield); /* clear a bit in bitfield and
  3539. - switch off statemachine */
  3540. -
  3541. - if (pRemainingBitsInSegment[segmentOffset] < 0) {
  3542. - pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN__SIGN;
  3543. - return BODY_SIGN__SIGN;
  3544. - }
  3545. - }
  3546. -
  3547. - return STOP_THIS_STATE;
  3548. -}
  3549. -
  3550. -/*---------------------------------------------------------------------------------------------
  3551. - description: Decodes the codeword body in case of codebook is 11. Writes
  3552. -out resulting two or four lines [with probably wrong sign] and counts the number
  3553. -of lines, which are different form zero. This information is needed in next
  3554. - state where sign bits will be decoded, if necessary.
  3555. - If sign bit counter cntSign is zero, no sign bits are needed
  3556. -and codeword is decoded completely.
  3557. ------------------------------------------------------------------------------------------------
  3558. - output: Two lines (quantizes spectral coefficients) which are probably
  3559. -wrong. The sign may be wrong and if one or two values is/are 16, the following
  3560. -states will decode the escape sequence to correct the values which are wirtten
  3561. -here.
  3562. ------------------------------------------------------------------------------------------------
  3563. - return: 0
  3564. ---------------------------------------------------------------------------------------------
  3565. -*/
  3566. -UINT Hcr_State_BODY_SIGN_ESC__BODY(HANDLE_FDK_BITSTREAM bs, void *ptr) {
  3567. - H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
  3568. - SCHAR *pRemainingBitsInSegment;
  3569. - INT *pLeftStartOfSegment;
  3570. - INT *pRightStartOfSegment;
  3571. - UCHAR readDirection;
  3572. - UINT *pSegmentBitfield;
  3573. - UINT *pCodewordBitfield;
  3574. - UINT segmentOffset;
  3575. -
  3576. - UINT *iNode;
  3577. - UCHAR *pCntSign;
  3578. - FIXP_DBL *pResultBase;
  3579. - USHORT *iResultPointer;
  3580. - UINT codewordOffset;
  3581. -
  3582. - UCHAR carryBit;
  3583. - UINT iQSC;
  3584. - UINT cntSign;
  3585. - UINT dimCntr;
  3586. - UINT treeNode;
  3587. - SCHAR *pSta;
  3588. - UINT branchNode;
  3589. - UINT branchValue;
  3590. - const UINT *pCurrentTree;
  3591. - const SCHAR *pQuantValBase;
  3592. - const SCHAR *pQuantVal;
  3593. -
  3594. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  3595. - pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  3596. - pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  3597. - readDirection = pHcr->segmentInfo.readDirection;
  3598. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  3599. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  3600. - segmentOffset = pHcr->segmentInfo.segmentOffset;
  3601. -
  3602. - iNode = pHcr->nonPcwSideinfo.iNode;
  3603. - pCntSign = pHcr->nonPcwSideinfo.pCntSign;
  3604. - pResultBase = pHcr->nonPcwSideinfo.pResultBase;
  3605. - iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
  3606. - codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
  3607. - pSta = pHcr->nonPcwSideinfo.pSta;
  3608. -
  3609. - treeNode = iNode[codewordOffset];
  3610. - pCurrentTree = aHuffTable[ESCAPE_CODEBOOK];
  3611. -
  3612. - for (; pRemainingBitsInSegment[segmentOffset] > 0;
  3613. - pRemainingBitsInSegment[segmentOffset] -= 1) {
  3614. - carryBit = HcrGetABitFromBitstream(
  3615. - bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
  3616. - &pRightStartOfSegment[segmentOffset], readDirection);
  3617. -
  3618. - /* make a step in tree */
  3619. - CarryBitToBranchValue(carryBit, treeNode, &branchValue, &branchNode);
  3620. -
  3621. - /* if end of branch reached write out lines and count bits needed for sign,
  3622. - * otherwise store node in codeword sideinfo */
  3623. - if ((branchNode & TEST_BIT_10) ==
  3624. - TEST_BIT_10) { /* test bit 10 ; if set body complete */
  3625. -
  3626. - /* body completely decoded; branchValue is valid */
  3627. - /* set pQuantVol to first (of two or four) quantized spectral coefficients
  3628. - */
  3629. - pQuantValBase = aQuantTable[ESCAPE_CODEBOOK]; /* get base address of
  3630. - quantized values
  3631. - belonging to current
  3632. - codebook */
  3633. - pQuantVal = pQuantValBase + branchValue; /* set pointer to first valid
  3634. - line [of 2 or 4 quantized
  3635. - values] */
  3636. -
  3637. - /* make backup from original resultPointer in node storage for state
  3638. - * BODY_SIGN_ESC__SIGN */
  3639. - iNode[codewordOffset] = iResultPointer[codewordOffset];
  3640. -
  3641. - /* get position of first line for writing result */
  3642. - iQSC = iResultPointer[codewordOffset];
  3643. -
  3644. - /* codeword decoding result is written out here: Write out 2 or 4
  3645. - * quantized spectral values with probably */
  3646. - /* wrong sign and count number of values which are different from zero for
  3647. - * sign bit decoding [which happens in next state] */
  3648. - cntSign = 0;
  3649. -
  3650. - for (dimCntr = DIMENSION_OF_ESCAPE_CODEBOOK; dimCntr != 0; dimCntr--) {
  3651. - pResultBase[iQSC++] =
  3652. - (FIXP_DBL)*pQuantVal; /* write quant. spec. coef. into spectrum */
  3653. - if (*pQuantVal++ != 0) {
  3654. - cntSign += 1;
  3655. - }
  3656. - }
  3657. -
  3658. - if (cntSign == 0) {
  3659. - ClearBitFromBitfield(
  3660. - &(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3661. - pCodewordBitfield); /* clear a bit in bitfield and switch off
  3662. - statemachine */
  3663. - /* codeword decoded */
  3664. - } else {
  3665. - /* write sign count result into codewordsideinfo of current codeword */
  3666. - pCntSign[codewordOffset] = cntSign;
  3667. - pSta[codewordOffset] = BODY_SIGN_ESC__SIGN; /* change state */
  3668. - pHcr->nonPcwSideinfo.pState =
  3669. - aStateConstant2State[pSta[codewordOffset]]; /* get state from
  3670. - separate array of
  3671. - cw-sideinfo */
  3672. - }
  3673. - pRemainingBitsInSegment[segmentOffset] -= 1; /* the last reinitialzation
  3674. - of for loop counter (see
  3675. - above) is done here */
  3676. - break; /* end of branch in tree reached i.e. a whole nonPCW-Body is
  3677. - decoded */
  3678. - } else { /* body is not decoded completely: */
  3679. - /* update treeNode for further step in decoding tree and store updated
  3680. - * treeNode because maybe no more bits left in segment */
  3681. - treeNode = *(pCurrentTree + branchValue);
  3682. - iNode[codewordOffset] = treeNode;
  3683. - }
  3684. - }
  3685. -
  3686. - if (pRemainingBitsInSegment[segmentOffset] <= 0) {
  3687. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3688. - pSegmentBitfield); /* clear a bit in bitfield and
  3689. - switch off statemachine */
  3690. -
  3691. - if (pRemainingBitsInSegment[segmentOffset] < 0) {
  3692. - pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN_ESC__BODY;
  3693. - return BODY_SIGN_ESC__BODY;
  3694. - }
  3695. - }
  3696. -
  3697. - return STOP_THIS_STATE;
  3698. -}
  3699. -
  3700. -/*---------------------------------------------------------------------------------------------
  3701. - description: This state decodes the sign bits, if a codeword of codebook 11
  3702. -needs some. A flag named 'flagB' in codeword sideinfo is set, if the second line
  3703. -of quantized spectral values is 16. The 'flagB' is used in case of decoding of a
  3704. -escape sequence is necessary as far as the second line is concerned.
  3705. -
  3706. - If only the first line needs an escape sequence, the flagB is
  3707. -cleared. If only the second line needs an escape sequence, the flagB is not
  3708. -used.
  3709. -
  3710. - For storing sideinfo in case of escape sequence decoding one
  3711. -single word can be used for both escape sequences because they are decoded not
  3712. -at the same time:
  3713. -
  3714. -
  3715. - bit 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5
  3716. -4 3 2 1 0
  3717. - ===== == == =========== ===========
  3718. -=================================== ^ ^ ^ ^ ^
  3719. -^ | | | | | | res. flagA flagB
  3720. -escapePrefixUp escapePrefixDown escapeWord
  3721. -
  3722. ------------------------------------------------------------------------------------------------
  3723. - output: Two lines with correct sign. If one or two values is/are 16,
  3724. -the lines are not valid, otherwise they are.
  3725. ------------------------------------------------------------------------------------------------
  3726. - return: 0
  3727. ---------------------------------------------------------------------------------------------
  3728. -*/
  3729. -UINT Hcr_State_BODY_SIGN_ESC__SIGN(HANDLE_FDK_BITSTREAM bs, void *ptr) {
  3730. - H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
  3731. - SCHAR *pRemainingBitsInSegment;
  3732. - INT *pLeftStartOfSegment;
  3733. - INT *pRightStartOfSegment;
  3734. - UCHAR readDirection;
  3735. - UINT *pSegmentBitfield;
  3736. - UINT *pCodewordBitfield;
  3737. - UINT segmentOffset;
  3738. -
  3739. - UINT *iNode;
  3740. - UCHAR *pCntSign;
  3741. - FIXP_DBL *pResultBase;
  3742. - USHORT *iResultPointer;
  3743. - UINT *pEscapeSequenceInfo;
  3744. - UINT codewordOffset;
  3745. -
  3746. - UINT iQSC;
  3747. - UCHAR cntSign;
  3748. - UINT flagA;
  3749. - UINT flagB;
  3750. - UINT flags;
  3751. - UCHAR carryBit;
  3752. - SCHAR *pSta;
  3753. -
  3754. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  3755. - pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  3756. - pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  3757. - readDirection = pHcr->segmentInfo.readDirection;
  3758. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  3759. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  3760. - segmentOffset = pHcr->segmentInfo.segmentOffset;
  3761. -
  3762. - iNode = pHcr->nonPcwSideinfo.iNode;
  3763. - pCntSign = pHcr->nonPcwSideinfo.pCntSign;
  3764. - pResultBase = pHcr->nonPcwSideinfo.pResultBase;
  3765. - iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
  3766. - pEscapeSequenceInfo = pHcr->nonPcwSideinfo.pEscapeSequenceInfo;
  3767. - codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
  3768. - pSta = pHcr->nonPcwSideinfo.pSta;
  3769. -
  3770. - iQSC = iResultPointer[codewordOffset];
  3771. - cntSign = pCntSign[codewordOffset];
  3772. -
  3773. - /* loop for sign bit decoding */
  3774. - for (; pRemainingBitsInSegment[segmentOffset] > 0;
  3775. - pRemainingBitsInSegment[segmentOffset] -= 1) {
  3776. - carryBit = HcrGetABitFromBitstream(
  3777. - bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
  3778. - &pRightStartOfSegment[segmentOffset], readDirection);
  3779. -
  3780. - /* decrement sign counter because one sign bit has been read */
  3781. - cntSign -= 1;
  3782. - pCntSign[codewordOffset] = cntSign;
  3783. -
  3784. - /* get a quantized spectral value (which was decoded in previous state)
  3785. - * which is not zero. [This value will get a sign] */
  3786. - while (pResultBase[iQSC] == (FIXP_DBL)0) {
  3787. - if (++iQSC >= 1024) {
  3788. - return BODY_SIGN_ESC__SIGN;
  3789. - }
  3790. - }
  3791. - iResultPointer[codewordOffset] = iQSC;
  3792. -
  3793. - /* put negative sign together with quantized spectral value; if carryBit is
  3794. - * zero, the sign is ok already; no write operation necessary in this case
  3795. - */
  3796. - if (carryBit != 0) {
  3797. - pResultBase[iQSC] = -pResultBase[iQSC]; /* carryBit = 1 --> minus */
  3798. - }
  3799. - iQSC++; /* update index to next (maybe valid) value */
  3800. - iResultPointer[codewordOffset] = iQSC;
  3801. -
  3802. - if (cntSign == 0) {
  3803. - /* all sign bits are decoded now */
  3804. - pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
  3805. - for loop counter (see
  3806. - above) is done here */
  3807. -
  3808. - /* check decoded values if codeword is decoded: Check if one or two escape
  3809. - * sequences 16 follow */
  3810. -
  3811. - /* step 0 */
  3812. - /* restore pointer to first decoded quantized value [ = original
  3813. - * pResultPointr] from index iNode prepared in State_BODY_SIGN_ESC__BODY
  3814. - */
  3815. - iQSC = iNode[codewordOffset];
  3816. -
  3817. - /* step 1 */
  3818. - /* test first value if escape sequence follows */
  3819. - flagA = 0; /* for first possible escape sequence */
  3820. - if (fixp_abs(pResultBase[iQSC++]) == (FIXP_DBL)ESCAPE_VALUE) {
  3821. - flagA = 1;
  3822. - }
  3823. -
  3824. - /* step 2 */
  3825. - /* test second value if escape sequence follows */
  3826. - flagB = 0; /* for second possible escape sequence */
  3827. - if (fixp_abs(pResultBase[iQSC]) == (FIXP_DBL)ESCAPE_VALUE) {
  3828. - flagB = 1;
  3829. - }
  3830. -
  3831. - /* step 3 */
  3832. - /* evaluate flag result and go on if necessary */
  3833. - if (!flagA && !flagB) {
  3834. - ClearBitFromBitfield(
  3835. - &(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3836. - pCodewordBitfield); /* clear a bit in bitfield and switch off
  3837. - statemachine */
  3838. - } else {
  3839. - /* at least one of two lines is 16 */
  3840. - /* store both flags at correct positions in non PCW codeword sideinfo
  3841. - * pEscapeSequenceInfo[codewordOffset] */
  3842. - flags = flagA << POSITION_OF_FLAG_A;
  3843. - flags |= (flagB << POSITION_OF_FLAG_B);
  3844. - pEscapeSequenceInfo[codewordOffset] = flags;
  3845. -
  3846. - /* set next state */
  3847. - pSta[codewordOffset] = BODY_SIGN_ESC__ESC_PREFIX;
  3848. - pHcr->nonPcwSideinfo.pState =
  3849. - aStateConstant2State[pSta[codewordOffset]]; /* get state from
  3850. - separate array of
  3851. - cw-sideinfo */
  3852. -
  3853. - /* set result pointer to the first line of the two decoded lines */
  3854. - iResultPointer[codewordOffset] = iNode[codewordOffset];
  3855. -
  3856. - if (!flagA && flagB) {
  3857. - /* update pResultPointr ==> state Stat_BODY_SIGN_ESC__ESC_WORD writes
  3858. - * to correct position. Second value is the one and only escape value
  3859. - */
  3860. - iQSC = iResultPointer[codewordOffset];
  3861. - iQSC++;
  3862. - iResultPointer[codewordOffset] = iQSC;
  3863. - }
  3864. -
  3865. - } /* at least one of two lines is 16 */
  3866. - break; /* nonPCW-Body at cb 11 and according sign bits are decoded */
  3867. -
  3868. - } /* if ( cntSign == 0 ) */
  3869. - } /* loop over remaining Bits in segment */
  3870. -
  3871. - if (pRemainingBitsInSegment[segmentOffset] <= 0) {
  3872. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3873. - pSegmentBitfield); /* clear a bit in bitfield and
  3874. - switch off statemachine */
  3875. -
  3876. - if (pRemainingBitsInSegment[segmentOffset] < 0) {
  3877. - pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN_ESC__SIGN;
  3878. - return BODY_SIGN_ESC__SIGN;
  3879. - }
  3880. - }
  3881. - return STOP_THIS_STATE;
  3882. -}
  3883. -
  3884. -/*---------------------------------------------------------------------------------------------
  3885. - description: Decode escape prefix of first or second escape sequence. The
  3886. -escape prefix consists of ones. The following zero is also decoded here.
  3887. ------------------------------------------------------------------------------------------------
  3888. - output: If the single separator-zero which follows the
  3889. -escape-prefix-ones is not yet decoded: The value 'escapePrefixUp' in word
  3890. -pEscapeSequenceInfo[codewordOffset] is updated.
  3891. -
  3892. - If the single separator-zero which follows the
  3893. -escape-prefix-ones is decoded: Two updated values 'escapePrefixUp' and
  3894. -'escapePrefixDown' in word pEscapeSequenceInfo[codewordOffset]. This State is
  3895. -finished. Switch to next state.
  3896. ------------------------------------------------------------------------------------------------
  3897. - return: 0
  3898. ---------------------------------------------------------------------------------------------
  3899. -*/
  3900. -UINT Hcr_State_BODY_SIGN_ESC__ESC_PREFIX(HANDLE_FDK_BITSTREAM bs, void *ptr) {
  3901. - H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
  3902. - SCHAR *pRemainingBitsInSegment;
  3903. - INT *pLeftStartOfSegment;
  3904. - INT *pRightStartOfSegment;
  3905. - UCHAR readDirection;
  3906. - UINT *pSegmentBitfield;
  3907. - UINT segmentOffset;
  3908. - UINT *pEscapeSequenceInfo;
  3909. - UINT codewordOffset;
  3910. - UCHAR carryBit;
  3911. - UINT escapePrefixUp;
  3912. - SCHAR *pSta;
  3913. -
  3914. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  3915. - pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  3916. - pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  3917. - readDirection = pHcr->segmentInfo.readDirection;
  3918. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  3919. - segmentOffset = pHcr->segmentInfo.segmentOffset;
  3920. - pEscapeSequenceInfo = pHcr->nonPcwSideinfo.pEscapeSequenceInfo;
  3921. - codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
  3922. - pSta = pHcr->nonPcwSideinfo.pSta;
  3923. -
  3924. - escapePrefixUp =
  3925. - (pEscapeSequenceInfo[codewordOffset] & MASK_ESCAPE_PREFIX_UP) >>
  3926. - LSB_ESCAPE_PREFIX_UP;
  3927. -
  3928. - /* decode escape prefix */
  3929. - for (; pRemainingBitsInSegment[segmentOffset] > 0;
  3930. - pRemainingBitsInSegment[segmentOffset] -= 1) {
  3931. - carryBit = HcrGetABitFromBitstream(
  3932. - bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
  3933. - &pRightStartOfSegment[segmentOffset], readDirection);
  3934. -
  3935. - /* count ones and store sum in escapePrefixUp */
  3936. - if (carryBit == 1) {
  3937. - escapePrefixUp += 1; /* update conter for ones */
  3938. -
  3939. - /* store updated counter in sideinfo of current codeword */
  3940. - pEscapeSequenceInfo[codewordOffset] &=
  3941. - ~MASK_ESCAPE_PREFIX_UP; /* delete old escapePrefixUp */
  3942. - escapePrefixUp <<= LSB_ESCAPE_PREFIX_UP; /* shift to correct position */
  3943. - pEscapeSequenceInfo[codewordOffset] |=
  3944. - escapePrefixUp; /* insert new escapePrefixUp */
  3945. - escapePrefixUp >>= LSB_ESCAPE_PREFIX_UP; /* shift back down */
  3946. - } else { /* separator [zero] reached */
  3947. - pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
  3948. - for loop counter (see
  3949. - above) is done here */
  3950. - escapePrefixUp +=
  3951. - 4; /* if escape_separator '0' appears, add 4 and ==> break */
  3952. -
  3953. - /* store escapePrefixUp in pEscapeSequenceInfo[codewordOffset] at bit
  3954. - * position escapePrefixUp */
  3955. - pEscapeSequenceInfo[codewordOffset] &=
  3956. - ~MASK_ESCAPE_PREFIX_UP; /* delete old escapePrefixUp */
  3957. - escapePrefixUp <<= LSB_ESCAPE_PREFIX_UP; /* shift to correct position */
  3958. - pEscapeSequenceInfo[codewordOffset] |=
  3959. - escapePrefixUp; /* insert new escapePrefixUp */
  3960. - escapePrefixUp >>= LSB_ESCAPE_PREFIX_UP; /* shift back down */
  3961. -
  3962. - /* store escapePrefixUp in pEscapeSequenceInfo[codewordOffset] at bit
  3963. - * position escapePrefixDown */
  3964. - pEscapeSequenceInfo[codewordOffset] &=
  3965. - ~MASK_ESCAPE_PREFIX_DOWN; /* delete old escapePrefixDown */
  3966. - escapePrefixUp <<= LSB_ESCAPE_PREFIX_DOWN; /* shift to correct position */
  3967. - pEscapeSequenceInfo[codewordOffset] |=
  3968. - escapePrefixUp; /* insert new escapePrefixDown */
  3969. -
  3970. - pSta[codewordOffset] = BODY_SIGN_ESC__ESC_WORD; /* set next state */
  3971. - pHcr->nonPcwSideinfo.pState =
  3972. - aStateConstant2State[pSta[codewordOffset]]; /* get state from separate
  3973. - array of cw-sideinfo */
  3974. - break;
  3975. - }
  3976. - }
  3977. -
  3978. - if (pRemainingBitsInSegment[segmentOffset] <= 0) {
  3979. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  3980. - pSegmentBitfield); /* clear a bit in bitfield and
  3981. - switch off statemachine */
  3982. -
  3983. - if (pRemainingBitsInSegment[segmentOffset] < 0) {
  3984. - pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN_ESC__ESC_PREFIX;
  3985. - return BODY_SIGN_ESC__ESC_PREFIX;
  3986. - }
  3987. - }
  3988. -
  3989. - return STOP_THIS_STATE;
  3990. -}
  3991. -
  3992. -/*---------------------------------------------------------------------------------------------
  3993. - description: Decode escapeWord of escape sequence. If the escape sequence
  3994. -is decoded completely, assemble quantized-spectral-escape-coefficient and
  3995. -replace the previous decoded 16 by the new value. Test flagB. If flagB is set,
  3996. -the second escape sequence must be decoded. If flagB is not set, the codeword is
  3997. -decoded and the state machine is switched off.
  3998. ------------------------------------------------------------------------------------------------
  3999. - output: Two lines with valid sign. At least one of both lines has got
  4000. -the correct value.
  4001. ------------------------------------------------------------------------------------------------
  4002. - return: 0
  4003. ---------------------------------------------------------------------------------------------
  4004. -*/
  4005. -UINT Hcr_State_BODY_SIGN_ESC__ESC_WORD(HANDLE_FDK_BITSTREAM bs, void *ptr) {
  4006. - H_HCR_INFO pHcr = (H_HCR_INFO)ptr;
  4007. - SCHAR *pRemainingBitsInSegment;
  4008. - INT *pLeftStartOfSegment;
  4009. - INT *pRightStartOfSegment;
  4010. - UCHAR readDirection;
  4011. - UINT *pSegmentBitfield;
  4012. - UINT *pCodewordBitfield;
  4013. - UINT segmentOffset;
  4014. -
  4015. - FIXP_DBL *pResultBase;
  4016. - USHORT *iResultPointer;
  4017. - UINT *pEscapeSequenceInfo;
  4018. - UINT codewordOffset;
  4019. -
  4020. - UINT escapeWord;
  4021. - UINT escapePrefixDown;
  4022. - UINT escapePrefixUp;
  4023. - UCHAR carryBit;
  4024. - UINT iQSC;
  4025. - INT sign;
  4026. - UINT flagA;
  4027. - UINT flagB;
  4028. - SCHAR *pSta;
  4029. -
  4030. - pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment;
  4031. - pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment;
  4032. - pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment;
  4033. - readDirection = pHcr->segmentInfo.readDirection;
  4034. - pSegmentBitfield = pHcr->segmentInfo.pSegmentBitfield;
  4035. - pCodewordBitfield = pHcr->segmentInfo.pCodewordBitfield;
  4036. - segmentOffset = pHcr->segmentInfo.segmentOffset;
  4037. -
  4038. - pResultBase = pHcr->nonPcwSideinfo.pResultBase;
  4039. - iResultPointer = pHcr->nonPcwSideinfo.iResultPointer;
  4040. - pEscapeSequenceInfo = pHcr->nonPcwSideinfo.pEscapeSequenceInfo;
  4041. - codewordOffset = pHcr->nonPcwSideinfo.codewordOffset;
  4042. - pSta = pHcr->nonPcwSideinfo.pSta;
  4043. -
  4044. - escapeWord = pEscapeSequenceInfo[codewordOffset] & MASK_ESCAPE_WORD;
  4045. - escapePrefixDown =
  4046. - (pEscapeSequenceInfo[codewordOffset] & MASK_ESCAPE_PREFIX_DOWN) >>
  4047. - LSB_ESCAPE_PREFIX_DOWN;
  4048. -
  4049. - /* decode escape word */
  4050. - for (; pRemainingBitsInSegment[segmentOffset] > 0;
  4051. - pRemainingBitsInSegment[segmentOffset] -= 1) {
  4052. - carryBit = HcrGetABitFromBitstream(
  4053. - bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset],
  4054. - &pRightStartOfSegment[segmentOffset], readDirection);
  4055. -
  4056. - /* build escape word */
  4057. - escapeWord <<=
  4058. - 1; /* left shift previous decoded part of escapeWord by on bit */
  4059. - escapeWord = escapeWord | carryBit; /* assemble escape word by bitwise or */
  4060. -
  4061. - /* decrement counter for length of escape word because one more bit was
  4062. - * decoded */
  4063. - escapePrefixDown -= 1;
  4064. -
  4065. - /* store updated escapePrefixDown */
  4066. - pEscapeSequenceInfo[codewordOffset] &=
  4067. - ~MASK_ESCAPE_PREFIX_DOWN; /* delete old escapePrefixDown */
  4068. - escapePrefixDown <<= LSB_ESCAPE_PREFIX_DOWN; /* shift to correct position */
  4069. - pEscapeSequenceInfo[codewordOffset] |=
  4070. - escapePrefixDown; /* insert new escapePrefixDown */
  4071. - escapePrefixDown >>= LSB_ESCAPE_PREFIX_DOWN; /* shift back */
  4072. -
  4073. - /* store updated escapeWord */
  4074. - pEscapeSequenceInfo[codewordOffset] &=
  4075. - ~MASK_ESCAPE_WORD; /* delete old escapeWord */
  4076. - pEscapeSequenceInfo[codewordOffset] |=
  4077. - escapeWord; /* insert new escapeWord */
  4078. -
  4079. - if (escapePrefixDown == 0) {
  4080. - pRemainingBitsInSegment[segmentOffset] -= 1; /* last reinitialzation of
  4081. - for loop counter (see
  4082. - above) is done here */
  4083. -
  4084. - /* escape sequence decoded. Assemble escape-line and replace original line
  4085. - */
  4086. -
  4087. - /* step 0 */
  4088. - /* derive sign */
  4089. - iQSC = iResultPointer[codewordOffset];
  4090. - sign = (pResultBase[iQSC] >= (FIXP_DBL)0)
  4091. - ? 1
  4092. - : -1; /* get sign of escape value 16 */
  4093. -
  4094. - /* step 1 */
  4095. - /* get escapePrefixUp */
  4096. - escapePrefixUp =
  4097. - (pEscapeSequenceInfo[codewordOffset] & MASK_ESCAPE_PREFIX_UP) >>
  4098. - LSB_ESCAPE_PREFIX_UP;
  4099. -
  4100. - /* step 2 */
  4101. - /* calculate escape value */
  4102. - pResultBase[iQSC] =
  4103. - (FIXP_DBL)(sign * (((INT)1 << escapePrefixUp) + (INT)escapeWord));
  4104. -
  4105. - /* get both flags from sideinfo (flags are not shifted to the
  4106. - * lsb-position) */
  4107. - flagA = pEscapeSequenceInfo[codewordOffset] & MASK_FLAG_A;
  4108. - flagB = pEscapeSequenceInfo[codewordOffset] & MASK_FLAG_B;
  4109. -
  4110. - /* step 3 */
  4111. - /* clear the whole escape sideinfo word */
  4112. - pEscapeSequenceInfo[codewordOffset] = 0;
  4113. -
  4114. - /* change state in dependence of flag flagB */
  4115. - if (flagA != 0) {
  4116. - /* first escape sequence decoded; previous decoded 16 has been replaced
  4117. - * by valid line */
  4118. -
  4119. - /* clear flagA in sideinfo word because this escape sequence has already
  4120. - * beed decoded */
  4121. - pEscapeSequenceInfo[codewordOffset] &= ~MASK_FLAG_A;
  4122. -
  4123. - if (flagB == 0) {
  4124. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  4125. - pCodewordBitfield); /* clear a bit in bitfield
  4126. - and switch off
  4127. - statemachine */
  4128. - } else {
  4129. - /* updated pointer to next and last 16 */
  4130. - iQSC++;
  4131. - iResultPointer[codewordOffset] = iQSC;
  4132. -
  4133. - /* change state */
  4134. - pSta[codewordOffset] = BODY_SIGN_ESC__ESC_PREFIX;
  4135. - pHcr->nonPcwSideinfo.pState =
  4136. - aStateConstant2State[pSta[codewordOffset]]; /* get state from
  4137. - separate array of
  4138. - cw-sideinfo */
  4139. - }
  4140. - } else {
  4141. - ClearBitFromBitfield(
  4142. - &(pHcr->nonPcwSideinfo.pState), segmentOffset,
  4143. - pCodewordBitfield); /* clear a bit in bitfield and switch off
  4144. - statemachine */
  4145. - }
  4146. - break;
  4147. - }
  4148. - }
  4149. -
  4150. - if (pRemainingBitsInSegment[segmentOffset] <= 0) {
  4151. - ClearBitFromBitfield(&(pHcr->nonPcwSideinfo.pState), segmentOffset,
  4152. - pSegmentBitfield); /* clear a bit in bitfield and
  4153. - switch off statemachine */
  4154. -
  4155. - if (pRemainingBitsInSegment[segmentOffset] < 0) {
  4156. - pHcr->decInOut.errorLog |= STATE_ERROR_BODY_SIGN_ESC__ESC_WORD;
  4157. - return BODY_SIGN_ESC__ESC_WORD;
  4158. - }
  4159. - }
  4160. -
  4161. - return STOP_THIS_STATE;
  4162. -}
  4163. diff --git a/libAACdec/src/aacdec_hcrs.h b/libAACdec/src/aacdec_hcrs.h
  4164. deleted file mode 100644
  4165. index acb2f40..0000000
  4166. --- a/libAACdec/src/aacdec_hcrs.h
  4167. +++ /dev/null
  4168. @@ -1,176 +0,0 @@
  4169. -/* -----------------------------------------------------------------------------
  4170. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  4171. -
  4172. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  4173. -Forschung e.V. All rights reserved.
  4174. -
  4175. - 1. INTRODUCTION
  4176. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  4177. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  4178. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  4179. -a wide variety of Android devices.
  4180. -
  4181. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  4182. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  4183. -full-bandwidth communications codec by independent studies and is widely
  4184. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  4185. -specifications.
  4186. -
  4187. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  4188. -those of Fraunhofer) may be obtained through Via Licensing
  4189. -(www.vialicensing.com) or through the respective patent owners individually for
  4190. -the purpose of encoding or decoding bit streams in products that are compliant
  4191. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  4192. -Android devices already license these patent claims through Via Licensing or
  4193. -directly from the patent owners, and therefore FDK AAC Codec software may
  4194. -already be covered under those patent licenses when it is used for those
  4195. -licensed purposes only.
  4196. -
  4197. -Commercially-licensed AAC software libraries, including floating-point versions
  4198. -with enhanced sound quality, are also available from Fraunhofer. Users are
  4199. -encouraged to check the Fraunhofer website for additional applications
  4200. -information and documentation.
  4201. -
  4202. -2. COPYRIGHT LICENSE
  4203. -
  4204. -Redistribution and use in source and binary forms, with or without modification,
  4205. -are permitted without payment of copyright license fees provided that you
  4206. -satisfy the following conditions:
  4207. -
  4208. -You must retain the complete text of this software license in redistributions of
  4209. -the FDK AAC Codec or your modifications thereto in source code form.
  4210. -
  4211. -You must retain the complete text of this software license in the documentation
  4212. -and/or other materials provided with redistributions of the FDK AAC Codec or
  4213. -your modifications thereto in binary form. You must make available free of
  4214. -charge copies of the complete source code of the FDK AAC Codec and your
  4215. -modifications thereto to recipients of copies in binary form.
  4216. -
  4217. -The name of Fraunhofer may not be used to endorse or promote products derived
  4218. -from this library without prior written permission.
  4219. -
  4220. -You may not charge copyright license fees for anyone to use, copy or distribute
  4221. -the FDK AAC Codec software or your modifications thereto.
  4222. -
  4223. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  4224. -that you changed the software and the date of any change. For modified versions
  4225. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  4226. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  4227. -AAC Codec Library for Android."
  4228. -
  4229. -3. NO PATENT LICENSE
  4230. -
  4231. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  4232. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  4233. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  4234. -software.
  4235. -
  4236. -You may use this FDK AAC Codec software or modifications thereto only for
  4237. -purposes that are authorized by appropriate patent licenses.
  4238. -
  4239. -4. DISCLAIMER
  4240. -
  4241. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  4242. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  4243. -including but not limited to the implied warranties of merchantability and
  4244. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  4245. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  4246. -or consequential damages, including but not limited to procurement of substitute
  4247. -goods or services; loss of use, data, or profits, or business interruption,
  4248. -however caused and on any theory of liability, whether in contract, strict
  4249. -liability, or tort (including negligence), arising in any way out of the use of
  4250. -this software, even if advised of the possibility of such damage.
  4251. -
  4252. -5. CONTACT INFORMATION
  4253. -
  4254. -Fraunhofer Institute for Integrated Circuits IIS
  4255. -Attention: Audio and Multimedia Departments - FDK AAC LL
  4256. -Am Wolfsmantel 33
  4257. -91058 Erlangen, Germany
  4258. -
  4259. -www.iis.fraunhofer.de/amm
  4260. -amm-info@iis.fraunhofer.de
  4261. ------------------------------------------------------------------------------ */
  4262. -
  4263. -/**************************** AAC decoder library ******************************
  4264. -
  4265. - Author(s): Robert Weidner (DSP Solutions)
  4266. -
  4267. - Description: HCR Decoder: Defines of state-constants, masks and
  4268. - state-prototypes
  4269. -
  4270. -*******************************************************************************/
  4271. -
  4272. -#ifndef AACDEC_HCRS_H
  4273. -#define AACDEC_HCRS_H
  4274. -
  4275. -#include "FDK_bitstream.h"
  4276. -#include "aacdec_hcr_types.h"
  4277. -/* The four different kinds of types of states are: */
  4278. -/* different states are defined as constants */ /* start middle=self next
  4279. - stop */
  4280. -#define STOP_THIS_STATE \
  4281. - 0 /* */
  4282. -#define BODY_ONLY \
  4283. - 1 /* X X X */
  4284. -#define BODY_SIGN__BODY \
  4285. - 2 /* X X X X [stop if no sign] */
  4286. -#define BODY_SIGN__SIGN \
  4287. - 3 /* X X [stop if sign bits decoded] */
  4288. -#define BODY_SIGN_ESC__BODY \
  4289. - 4 /* X X X X [stop if no sign] */
  4290. -#define BODY_SIGN_ESC__SIGN \
  4291. - 5 /* X X X [stop if no escape sequence] */
  4292. -#define BODY_SIGN_ESC__ESC_PREFIX \
  4293. - 6 /* X X */
  4294. -#define BODY_SIGN_ESC__ESC_WORD \
  4295. - 7 /* X X X [stop if abs(second qsc) != 16] */
  4296. -
  4297. -/* examples: */
  4298. -
  4299. -/* BODY_ONLY means only the codeword body will be decoded; no
  4300. - * sign bits will follow and no escapesequence will follow */
  4301. -
  4302. -/* BODY_SIGN__BODY means that the codeword consists of two parts;
  4303. - * body and sign part. The part '__BODY' after the two underscores shows */
  4304. -/* that the bits which are currently decoded belong
  4305. - * to the '__BODY' of the codeword and not to the sign part. */
  4306. -
  4307. -/* BODY_SIGN_ESC__ESC_PB means that the codeword consists of three parts;
  4308. - * body, sign and (here: two) escape sequences; */
  4309. -/* P = Prefix = ones */
  4310. -/* W = Escape Word */
  4311. -/* A = first possible (of two) Escape sequeces */
  4312. -/* B = second possible (of two) Escape sequeces */
  4313. -/* The part after the two underscores shows that
  4314. - * the current bits which are decoded belong to the '__ESC_PB' - part of the */
  4315. -/* codeword. That means the body and the sign bits
  4316. - * are decoded completely and the bits which are decoded now belong to */
  4317. -/* the escape sequence [P = prefix; B=second
  4318. - * possible escape sequence] */
  4319. -
  4320. -#define MSB_31_MASK 0x80000000 /* masks MSB (= Bit 31) in a 32 bit word */
  4321. -#define DIMENSION_OF_ESCAPE_CODEBOOK 2 /* for cb >= 11 is dimension 2 */
  4322. -#define ESCAPE_CODEBOOK 11
  4323. -
  4324. -#define MASK_ESCAPE_PREFIX_UP 0x000F0000
  4325. -#define LSB_ESCAPE_PREFIX_UP 16
  4326. -
  4327. -#define MASK_ESCAPE_PREFIX_DOWN 0x0000F000
  4328. -#define LSB_ESCAPE_PREFIX_DOWN 12
  4329. -
  4330. -#define MASK_ESCAPE_WORD 0x00000FFF
  4331. -#define MASK_FLAG_A 0x00200000
  4332. -#define MASK_FLAG_B 0x00100000
  4333. -
  4334. -extern void DecodeNonPCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO hHcr);
  4335. -
  4336. -UINT Hcr_State_BODY_ONLY(HANDLE_FDK_BITSTREAM, void*);
  4337. -UINT Hcr_State_BODY_SIGN__BODY(HANDLE_FDK_BITSTREAM, void*);
  4338. -UINT Hcr_State_BODY_SIGN__SIGN(HANDLE_FDK_BITSTREAM, void*);
  4339. -UINT Hcr_State_BODY_SIGN_ESC__BODY(HANDLE_FDK_BITSTREAM, void*);
  4340. -UINT Hcr_State_BODY_SIGN_ESC__SIGN(HANDLE_FDK_BITSTREAM, void*);
  4341. -UINT Hcr_State_BODY_SIGN_ESC__ESC_PREFIX(HANDLE_FDK_BITSTREAM, void*);
  4342. -UINT Hcr_State_BODY_SIGN_ESC__ESC_WORD(HANDLE_FDK_BITSTREAM, void*);
  4343. -
  4344. -#endif /* AACDEC_HCRS_H */
  4345. diff --git a/libAACdec/src/aacdecoder.cpp b/libAACdec/src/aacdecoder.cpp
  4346. index 2419ecc..6c03567 100644
  4347. --- a/libAACdec/src/aacdecoder.cpp
  4348. +++ b/libAACdec/src/aacdecoder.cpp
  4349. @@ -163,17 +163,12 @@ amm-info@iis.fraunhofer.de
  4350. #include "sac_dec_lib.h"
  4351. -#include "aacdec_hcr.h"
  4352. -#include "rvlc.h"
  4353. -
  4354. #include "usacdec_lpd.h"
  4355. #include "ac_arith_coder.h"
  4356. #include "tpdec_lib.h"
  4357. -#include "conceal.h"
  4358. -
  4359. #include "FDK_crc.h"
  4360. #define PS_IS_EXPLICITLY_DISABLED(aot, flags) \
  4361. (((aot) == AOT_DRM_AAC) && !(flags & AC_PS_PRESENT))
  4362. @@ -1191,10 +1186,6 @@ LINKSPEC_CPP HANDLE_AACDECODER CAacDecoder_Open(
  4363. /* initialize progam config */
  4364. CProgramConfig_Init(&self->pce);
  4365. - /* initialize error concealment common data */
  4366. - CConcealment_InitCommonData(&self->concealCommonData);
  4367. - self->concealMethodUser = ConcealMethodNone; /* undefined -> auto mode */
  4368. -
  4369. self->hDrcInfo = GetDrcInfo();
  4370. if (self->hDrcInfo == NULL) {
  4371. goto bail;
  4372. @@ -1202,8 +1193,7 @@ LINKSPEC_CPP HANDLE_AACDECODER CAacDecoder_Open(
  4373. /* Init common DRC structure */
  4374. aacDecoder_drcInit(self->hDrcInfo);
  4375. /* Set default frame delay */
  4376. - aacDecoder_drcSetParam(self->hDrcInfo, DRC_BS_DELAY,
  4377. - CConcealment_GetDelay(&self->concealCommonData));
  4378. + aacDecoder_drcSetParam(self->hDrcInfo, DRC_BS_DELAY, 0);
  4379. self->workBufferCore2 = GetWorkBufferCore2();
  4380. if (self->workBufferCore2 == NULL) goto bail;
  4381. @@ -2085,15 +2075,6 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
  4382. if (self->pAacDecoderStaticChannelInfo[ch]->pCpeStaticData !=
  4383. NULL) {
  4384. self->pAacDecoderStaticChannelInfo[ch]
  4385. - ->pCpeStaticData->jointStereoPersistentData
  4386. - .spectralCoeffs[ch2] =
  4387. - self->pAacDecoderStaticChannelInfo[ch]
  4388. - ->concealmentInfo.spectralCoefficient;
  4389. - self->pAacDecoderStaticChannelInfo[ch]
  4390. - ->pCpeStaticData->jointStereoPersistentData.specScale[ch2] =
  4391. - self->pAacDecoderStaticChannelInfo[ch]
  4392. - ->concealmentInfo.specScale;
  4393. - self->pAacDecoderStaticChannelInfo[ch]
  4394. ->pCpeStaticData->jointStereoPersistentData.scratchBuffer =
  4395. (FIXP_DBL *)self->pTimeData2;
  4396. }
  4397. @@ -2193,12 +2174,6 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
  4398. /* Delete mixdown metadata from the past */
  4399. pcmDmx_Reset(self->hPcmUtils, PCMDMX_RESET_BS_DATA);
  4400. - /* Reset concealment only if ASC changed. Otherwise it will be done with
  4401. - any config callback. E.g. every time the LATM SMC is present. */
  4402. - CConcealment_InitChannelData(
  4403. - &self->pAacDecoderStaticChannelInfo[ch]->concealmentInfo,
  4404. - &self->concealCommonData, initRenderMode,
  4405. - self->streamInfo.aacSamplesPerFrame);
  4406. ch++;
  4407. chIdx++;
  4408. }
  4409. @@ -2336,12 +2311,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
  4410. int ch;
  4411. /* Clear history */
  4412. for (ch = 0; ch < self->aacChannels; ch++) {
  4413. - /* Reset concealment */
  4414. - CConcealment_InitChannelData(
  4415. - &self->pAacDecoderStaticChannelInfo[ch]->concealmentInfo,
  4416. - &self->concealCommonData,
  4417. - self->pAacDecoderChannelInfo[0]->renderMode,
  4418. - self->streamInfo.aacSamplesPerFrame);
  4419. /* Clear overlap-add buffers to avoid clicks. */
  4420. FDKmemclear(self->pAacDecoderStaticChannelInfo[ch]->pOverlapBuffer,
  4421. OverlapBufferSize * sizeof(FIXP_DBL));
  4422. @@ -2403,15 +2372,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
  4423. if (ch >= self->aacChannels) {
  4424. return AAC_DEC_UNKNOWN;
  4425. }
  4426. -
  4427. - /* if last frame was broken and this frame is no independent frame,
  4428. - * correct decoding is impossible we need to trigger concealment */
  4429. - if ((CConcealment_GetLastFrameOk(
  4430. - &self->pAacDecoderStaticChannelInfo[ch]->concealmentInfo,
  4431. - 1) == 0) &&
  4432. - !(self->flags[streamIndex] & AC_INDEP)) {
  4433. - self->frameOK = 0;
  4434. - }
  4435. ch++;
  4436. }
  4437. }
  4438. @@ -3081,13 +3041,8 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
  4439. * following concealment method, mark the frame as erroneous */
  4440. {
  4441. CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
  4442. - CConcealmentInfo *hConcealmentInfo =
  4443. - &pAacDecoderStaticChannelInfo->concealmentInfo;
  4444. const int mute_release_active =
  4445. - (self->frameOK && !(flags & AACDEC_CONCEAL)) &&
  4446. - ((hConcealmentInfo->concealState >= ConcealState_Mute) &&
  4447. - (hConcealmentInfo->cntValidFrames + 1 <=
  4448. - hConcealmentInfo->pConcealParams->numMuteReleaseFrames));
  4449. + (self->frameOK && !(flags & AACDEC_CONCEAL));
  4450. const int icsIsInvalid = (GetScaleFactorBandsTransmitted(pIcsInfo) >
  4451. GetScaleFactorBandsTotal(pIcsInfo));
  4452. const int icsInfoUsedinFadeOut =
  4453. @@ -3098,29 +3053,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
  4454. }
  4455. }
  4456. - /*
  4457. - Conceal defective spectral data
  4458. - */
  4459. - {
  4460. - CAacDecoderChannelInfo **ppAacDecoderChannelInfo =
  4461. - &pAacDecoderChannelInfo;
  4462. - CAacDecoderStaticChannelInfo **ppAacDecoderStaticChannelInfo =
  4463. - &pAacDecoderStaticChannelInfo;
  4464. - {
  4465. - concealApplyReturnCode = CConcealment_Apply(
  4466. - &(*ppAacDecoderStaticChannelInfo)->concealmentInfo,
  4467. - *ppAacDecoderChannelInfo, *ppAacDecoderStaticChannelInfo,
  4468. - &self->samplingRateInfo[streamIndex],
  4469. - self->streamInfo.aacSamplesPerFrame,
  4470. - pAacDecoderStaticChannelInfo->last_lpd_mode,
  4471. - (self->frameOK && !(flags & AACDEC_CONCEAL)),
  4472. - self->flags[streamIndex]);
  4473. - }
  4474. - }
  4475. - if (concealApplyReturnCode == -1) {
  4476. - frameOk_butConceal = 1;
  4477. - }
  4478. -
  4479. if (flags & (AACDEC_INTR)) {
  4480. /* Reset DRC control data for this channel */
  4481. aacDecoder_drcInitChannelData(&pAacDecoderStaticChannelInfo->drcData);
  4482. @@ -3191,20 +3123,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
  4483. ErrorStatus = AAC_DEC_UNKNOWN;
  4484. break;
  4485. }
  4486. - /* TimeDomainFading */
  4487. - if (!CConceal_TDFading_Applied[c]) {
  4488. - CConceal_TDFading_Applied[c] = CConcealment_TDFading(
  4489. - self->streamInfo.aacSamplesPerFrame,
  4490. - &self->pAacDecoderStaticChannelInfo[c], pTimeData + offset, 0);
  4491. - if (c + 1 < (8) && c < aacChannels - 1) {
  4492. - /* update next TDNoise Seed to avoid muting in case of Parametric
  4493. - * Stereo */
  4494. - self->pAacDecoderStaticChannelInfo[c + 1]
  4495. - ->concealmentInfo.TDNoiseSeed =
  4496. - self->pAacDecoderStaticChannelInfo[c]
  4497. - ->concealmentInfo.TDNoiseSeed;
  4498. - }
  4499. - }
  4500. }
  4501. }
  4502. @@ -3249,11 +3167,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
  4503. }
  4504. }
  4505. - /* Add additional concealment delay */
  4506. - self->streamInfo.outputDelay +=
  4507. - CConcealment_GetDelay(&self->concealCommonData) *
  4508. - self->streamInfo.aacSamplesPerFrame;
  4509. -
  4510. /* Map DRC data to StreamInfo structure */
  4511. aacDecoder_drcGetInfo(self->hDrcInfo, &self->streamInfo.drcPresMode,
  4512. &self->streamInfo.drcProgRefLev);
  4513. diff --git a/libAACdec/src/aacdecoder.h b/libAACdec/src/aacdecoder.h
  4514. index 0711160..3750389 100644
  4515. --- a/libAACdec/src/aacdecoder.h
  4516. +++ b/libAACdec/src/aacdecoder.h
  4517. @@ -236,9 +236,6 @@ struct AAC_DECODER_INSTANCE {
  4518. 1)]; /*!< Pointer to persistent data shared by both channels of a CPE.
  4519. This structure is allocated once for each CPE. */
  4520. - CConcealParams concealCommonData;
  4521. - CConcealmentMethod concealMethodUser;
  4522. -
  4523. CUsacCoreExtensions usacCoreExt; /*!< Data and handles to extend USAC FD/LPD
  4524. core decoder (SBR, MPS, ...) */
  4525. UINT numUsacElements[(1 * 1)];
  4526. diff --git a/libAACdec/src/aacdecoder_lib.cpp b/libAACdec/src/aacdecoder_lib.cpp
  4527. index bde978e..1fc6ea0 100644
  4528. --- a/libAACdec/src/aacdecoder_lib.cpp
  4529. +++ b/libAACdec/src/aacdecoder_lib.cpp
  4530. @@ -107,8 +107,6 @@ amm-info@iis.fraunhofer.de
  4531. #include "tpdec_lib.h"
  4532. #include "FDK_core.h" /* FDK_tools version info */
  4533. -#include "conceal.h"
  4534. -
  4535. #include "aacdec_drc.h"
  4536. #include "sac_dec_lib.h"
  4537. @@ -280,26 +278,6 @@ static INT aacDecoder_ConfigCallback(void *handle,
  4538. { err = aacDecoder_Config(self, pAscStruct, configMode, configChanged); }
  4539. }
  4540. if (err == AAC_DEC_OK) {
  4541. - /*
  4542. - revert concealment method if either
  4543. - - Interpolation concealment might not be meaningful
  4544. - - Interpolation concealment is not implemented
  4545. - */
  4546. - if ((self->flags[0] & (AC_LD | AC_ELD) &&
  4547. - (self->concealMethodUser == ConcealMethodNone) &&
  4548. - CConcealment_GetDelay(&self->concealCommonData) >
  4549. - 0) /* might not be meaningful but allow if user has set it
  4550. - expicitly */
  4551. - || (self->flags[0] & (AC_USAC | AC_RSVD50 | AC_RSV603DA) &&
  4552. - CConcealment_GetDelay(&self->concealCommonData) >
  4553. - 0) /* not implemented */
  4554. - ) {
  4555. - /* Revert to error concealment method Noise Substitution.
  4556. - Because interpolation is not implemented for USAC or
  4557. - the additional delay is unwanted for low delay codecs. */
  4558. - setConcealMethod(self, 1);
  4559. - }
  4560. - aacDecoder_setMetadataExpiry(self, self->metadataExpiry);
  4561. errTp = TRANSPORTDEC_OK;
  4562. } else {
  4563. if (err == AAC_DEC_NEED_TO_RESTART) {
  4564. @@ -529,17 +507,12 @@ static AAC_DECODER_ERROR setConcealMethod(
  4565. const HANDLE_AACDECODER self, /*!< Handle of the decoder instance */
  4566. const INT method) {
  4567. AAC_DECODER_ERROR errorStatus = AAC_DEC_OK;
  4568. - CConcealParams *pConcealData = NULL;
  4569. int method_revert = 0;
  4570. HANDLE_AAC_DRC hDrcInfo = NULL;
  4571. HANDLE_PCM_DOWNMIX hPcmDmx = NULL;
  4572. - CConcealmentMethod backupMethod = ConcealMethodNone;
  4573. - int backupDelay = 0;
  4574. - int bsDelay = 0;
  4575. /* check decoder handle */
  4576. if (self != NULL) {
  4577. - pConcealData = &self->concealCommonData;
  4578. hDrcInfo = self->hDrcInfo;
  4579. hPcmDmx = self->hPcmUtils;
  4580. if (self->flags[0] & (AC_USAC | AC_RSVD50 | AC_RSV603DA) && method >= 2) {
  4581. @@ -555,33 +528,13 @@ static AAC_DECODER_ERROR setConcealMethod(
  4582. }
  4583. }
  4584. - /* Get current method/delay */
  4585. - backupMethod = CConcealment_GetMethod(pConcealData);
  4586. - backupDelay = CConcealment_GetDelay(pConcealData);
  4587. -
  4588. - /* Be sure to set AAC and SBR concealment method simultaneously! */
  4589. - errorStatus = CConcealment_SetParams(
  4590. - pConcealData,
  4591. - (method_revert == 0) ? (int)method : (int)1, // concealMethod
  4592. - AACDEC_CONCEAL_PARAM_NOT_SPECIFIED, // concealFadeOutSlope
  4593. - AACDEC_CONCEAL_PARAM_NOT_SPECIFIED, // concealFadeInSlope
  4594. - AACDEC_CONCEAL_PARAM_NOT_SPECIFIED, // concealMuteRelease
  4595. - AACDEC_CONCEAL_PARAM_NOT_SPECIFIED // concealComfNoiseLevel
  4596. - );
  4597. - if ((errorStatus != AAC_DEC_OK) && (errorStatus != AAC_DEC_INVALID_HANDLE)) {
  4598. - goto bail;
  4599. - }
  4600. -
  4601. - /* Get new delay */
  4602. - bsDelay = CConcealment_GetDelay(pConcealData);
  4603. -
  4604. - errorStatus = aacDecoder_drcSetParam(hDrcInfo, DRC_BS_DELAY, bsDelay);
  4605. + errorStatus = aacDecoder_drcSetParam(hDrcInfo, DRC_BS_DELAY, 0);
  4606. if ((errorStatus != AAC_DEC_OK) && (errorStatus != AAC_DEC_INVALID_HANDLE)) {
  4607. goto bail;
  4608. }
  4609. if (errorStatus == AAC_DEC_OK) {
  4610. - PCMDMX_ERROR err = pcmDmx_SetParam(hPcmDmx, DMX_BS_DATA_DELAY, bsDelay);
  4611. + PCMDMX_ERROR err = pcmDmx_SetParam(hPcmDmx, DMX_BS_DATA_DELAY, 0);
  4612. switch (err) {
  4613. case PCMDMX_INVALID_HANDLE:
  4614. errorStatus = AAC_DEC_INVALID_HANDLE;
  4615. @@ -596,15 +549,10 @@ static AAC_DECODER_ERROR setConcealMethod(
  4616. bail:
  4617. if ((errorStatus != AAC_DEC_OK) && (errorStatus != AAC_DEC_INVALID_HANDLE)) {
  4618. - /* Revert to the initial state */
  4619. - CConcealment_SetParams(
  4620. - pConcealData, (int)backupMethod, AACDEC_CONCEAL_PARAM_NOT_SPECIFIED,
  4621. - AACDEC_CONCEAL_PARAM_NOT_SPECIFIED, AACDEC_CONCEAL_PARAM_NOT_SPECIFIED,
  4622. - AACDEC_CONCEAL_PARAM_NOT_SPECIFIED);
  4623. /* Revert DRC bitstream delay */
  4624. - aacDecoder_drcSetParam(hDrcInfo, DRC_BS_DELAY, backupDelay);
  4625. + aacDecoder_drcSetParam(hDrcInfo, DRC_BS_DELAY, 0);
  4626. /* Revert PCM mixdown bitstream delay */
  4627. - pcmDmx_SetParam(hPcmDmx, DMX_BS_DATA_DELAY, backupDelay);
  4628. + pcmDmx_SetParam(hPcmDmx, DMX_BS_DATA_DELAY, 0);
  4629. }
  4630. return errorStatus;
  4631. @@ -834,9 +782,6 @@ LINKSPEC_CPP AAC_DECODER_ERROR aacDecoder_SetParam(
  4632. packed into a helper function which keeps all modules and libs in a
  4633. consistent state even in the case an error occures. */
  4634. errorStatus = setConcealMethod(self, value);
  4635. - if (errorStatus == AAC_DEC_OK) {
  4636. - self->concealMethodUser = (CConcealmentMethod)value;
  4637. - }
  4638. break;
  4639. default:
  4640. @@ -966,8 +911,7 @@ LINKSPEC_CPP HANDLE_AACDECODER aacDecoder_Open(TRANSPORT_TYPE transportFmt,
  4641. aacDec->limiterEnableCurr = 0;
  4642. /* Assure that all modules have same delay */
  4643. - if (setConcealMethod(aacDec,
  4644. - CConcealment_GetMethod(&aacDec->concealCommonData))) {
  4645. + if (setConcealMethod(aacDec, 0)) {
  4646. err = -1;
  4647. goto bail;
  4648. }
  4649. @@ -1359,9 +1303,7 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
  4650. break;
  4651. }
  4652. - if ((ErrorStatus != AAC_DEC_OK) || (flags & AACDEC_CONCEAL) ||
  4653. - self->pAacDecoderStaticChannelInfo[0]->concealmentInfo.concealState >
  4654. - ConcealState_FadeIn) {
  4655. + if ((ErrorStatus != AAC_DEC_OK) || (flags & AACDEC_CONCEAL)) {
  4656. self->frameOK = 0; /* if an error has occured do concealment in the SBR
  4657. decoder too */
  4658. }
  4659. @@ -1457,9 +1399,6 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
  4660. domain signal before the QMF synthesis. Therefore the DRC gains
  4661. need to be delayed by the QMF synthesis delay. */
  4662. if (self->mpsEnableCurr) drcDelay = 257;
  4663. - /* Take into account concealment delay */
  4664. - drcDelay += CConcealment_GetDelay(&self->concealCommonData) *
  4665. - self->streamInfo.frameSize;
  4666. for (ch = 0; ch < self->streamInfo.numChannels; ch++) {
  4667. UCHAR mapValue = FDK_chMapDescr_getMapValue(
  4668. diff --git a/libAACdec/src/block.cpp b/libAACdec/src/block.cpp
  4669. index b3d09a6..a394cd7 100644
  4670. --- a/libAACdec/src/block.cpp
  4671. +++ b/libAACdec/src/block.cpp
  4672. @@ -114,9 +114,6 @@ amm-info@iis.fraunhofer.de
  4673. #include "ac_arith_coder.h"
  4674. -#include "aacdec_hcr.h"
  4675. -#include "rvlc.h"
  4676. -
  4677. #if defined(__arm__)
  4678. #include "arm/block_arm.cpp"
  4679. #endif
  4680. @@ -331,12 +328,7 @@ AAC_DECODER_ERROR CBlock_ReadSectionData(
  4681. int group;
  4682. UCHAR sect_cb;
  4683. UCHAR *pCodeBook = pAacDecoderChannelInfo->pDynData->aCodeBook;
  4684. - /* HCR input (long) */
  4685. - SHORT *pNumLinesInSec =
  4686. - pAacDecoderChannelInfo->pDynData->specificTo.aac.aNumLineInSec4Hcr;
  4687. int numLinesInSecIdx = 0;
  4688. - UCHAR *pHcrCodeBook =
  4689. - pAacDecoderChannelInfo->pDynData->specificTo.aac.aCodeBooks4Hcr;
  4690. const SHORT *BandOffsets = GetScaleFactorBandOffsets(
  4691. &pAacDecoderChannelInfo->icsInfo, pSamplingRateInfo);
  4692. pAacDecoderChannelInfo->pDynData->specificTo.aac.numberSection = 0;
  4693. @@ -376,22 +368,8 @@ AAC_DECODER_ERROR CBlock_ReadSectionData(
  4694. top = band + sect_len;
  4695. if (flags & AC_ER_HCR) {
  4696. - /* HCR input (long) -- collecting sideinfo (for HCR-_long_ only) */
  4697. - if (numLinesInSecIdx >= MAX_SFB_HCR) {
  4698. - return AAC_DEC_PARSE_ERROR;
  4699. - }
  4700. - if (top > (int)GetNumberOfScaleFactorBands(
  4701. - &pAacDecoderChannelInfo->icsInfo, pSamplingRateInfo)) {
  4702. - return AAC_DEC_PARSE_ERROR;
  4703. - }
  4704. - pNumLinesInSec[numLinesInSecIdx] = BandOffsets[top] - BandOffsets[band];
  4705. - numLinesInSecIdx++;
  4706. - if (sect_cb == BOOKSCL) {
  4707. - return AAC_DEC_INVALID_CODE_BOOK;
  4708. - } else {
  4709. - *pHcrCodeBook++ = sect_cb;
  4710. - }
  4711. - pAacDecoderChannelInfo->pDynData->specificTo.aac.numberSection++;
  4712. + /* HCR disabled */
  4713. + return AAC_DEC_PARSE_ERROR;
  4714. }
  4715. /* Check spectral line limits */
  4716. @@ -718,41 +696,12 @@ AAC_DECODER_ERROR CBlock_ReadSpectralData(
  4717. /* plain huffman decoding (short) finished */
  4718. }
  4719. - /* HCR - Huffman Codeword Reordering short */
  4720. else /* if ( flags & AC_ER_HCR ) */
  4721. {
  4722. - H_HCR_INFO hHcr = &pAacDecoderChannelInfo->pComData->overlay.aac.erHcrInfo;
  4723. -
  4724. - int hcrStatus = 0;
  4725. -
  4726. - /* advanced Huffman decoding starts here (HCR decoding :) */
  4727. - if (pAacDecoderChannelInfo->pDynData->specificTo.aac
  4728. - .lenOfReorderedSpectralData != 0) {
  4729. - /* HCR initialization short */
  4730. - hcrStatus = HcrInit(hHcr, pAacDecoderChannelInfo, pSamplingRateInfo, bs);
  4731. -
  4732. - if (hcrStatus != 0) {
  4733. - return AAC_DEC_DECODE_FRAME_ERROR;
  4734. - }
  4735. -
  4736. - /* HCR decoding short */
  4737. - hcrStatus =
  4738. - HcrDecoder(hHcr, pAacDecoderChannelInfo, pSamplingRateInfo, bs);
  4739. -
  4740. - if (hcrStatus != 0) {
  4741. -#if HCR_ERROR_CONCEALMENT
  4742. - HcrMuteErroneousLines(hHcr);
  4743. -#else
  4744. - return AAC_DEC_DECODE_FRAME_ERROR;
  4745. -#endif /* HCR_ERROR_CONCEALMENT */
  4746. - }
  4747. -
  4748. - FDKpushFor(bs, pAacDecoderChannelInfo->pDynData->specificTo.aac
  4749. - .lenOfReorderedSpectralData);
  4750. - }
  4751. + /* HCR - Huffman Codeword Reordering disabled */
  4752. + return AAC_DEC_DECODE_FRAME_ERROR;
  4753. }
  4754. - /* HCR - Huffman Codeword Reordering short finished */
  4755. if (IsLongBlock(&pAacDecoderChannelInfo->icsInfo) &&
  4756. !(flags & (AC_ELD | AC_SCALABLE))) {
  4757. diff --git a/libAACdec/src/channel.cpp b/libAACdec/src/channel.cpp
  4758. index a020034..e17ccf4 100644
  4759. --- a/libAACdec/src/channel.cpp
  4760. +++ b/libAACdec/src/channel.cpp
  4761. @@ -106,12 +106,6 @@ amm-info@iis.fraunhofer.de
  4762. #include "aacdec_tns.h"
  4763. #include "FDK_bitstream.h"
  4764. -#include "conceal.h"
  4765. -
  4766. -#include "rvlc.h"
  4767. -
  4768. -#include "aacdec_hcr.h"
  4769. -
  4770. #include "usacdec_lpd.h"
  4771. #include "usacdec_fac.h"
  4772. @@ -376,9 +370,6 @@ void CChannelElement_Decode(
  4773. ->pCpeStaticData->jointStereoPersistentData.clearSpectralCoeffs = 0;
  4774. }
  4775. }
  4776. -
  4777. - CRvlc_ElementCheck(pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo,
  4778. - flags, el_channels);
  4779. }
  4780. void CChannel_CodebookTableInit(
  4781. @@ -596,8 +587,8 @@ AAC_DECODER_ERROR CChannelElement_Read(
  4782. case scale_factor_data:
  4783. if (flags & AC_ER_RVLC) {
  4784. - /* read RVLC data from bitstream (error sens. cat. 1) */
  4785. - CRvlc_Read(pAacDecoderChannelInfo[ch], hBs);
  4786. + /* RVLC not supported */
  4787. + error = AAC_DEC_DECODE_FRAME_ERROR;
  4788. } else {
  4789. error = CBlock_ReadScaleFactorData(pAacDecoderChannelInfo[ch], hBs,
  4790. flags);
  4791. @@ -730,15 +721,13 @@ AAC_DECODER_ERROR CChannelElement_Read(
  4792. } break;
  4793. case esc2_rvlc:
  4794. if (flags & AC_ER_RVLC) {
  4795. - CRvlc_Decode(pAacDecoderChannelInfo[ch],
  4796. - pAacDecoderStaticChannelInfo[ch], hBs);
  4797. + error = AAC_DEC_UNSUPPORTED_FORMAT;
  4798. }
  4799. break;
  4800. case esc1_hcr:
  4801. if (flags & AC_ER_HCR) {
  4802. - CHcr_Read(hBs, pAacDecoderChannelInfo[ch],
  4803. - numberOfChannels == 2 ? ID_CPE : ID_SCE);
  4804. + error = AAC_DEC_UNSUPPORTED_FORMAT;
  4805. }
  4806. break;
  4807. diff --git a/libAACdec/src/channelinfo.h b/libAACdec/src/channelinfo.h
  4808. index 4523400..04f0012 100644
  4809. --- a/libAACdec/src/channelinfo.h
  4810. +++ b/libAACdec/src/channelinfo.h
  4811. @@ -117,17 +117,12 @@ amm-info@iis.fraunhofer.de
  4812. #include "aacdec_pns.h"
  4813. -#include "aacdec_hcr_types.h"
  4814. -#include "rvlc_info.h"
  4815. -
  4816. #include "usacdec_acelp.h"
  4817. #include "usacdec_const.h"
  4818. #include "usacdec_rom.h"
  4819. #include "ac_arith_coder.h"
  4820. -#include "conceal_types.h"
  4821. -
  4822. #include "aacdec_drc_types.h"
  4823. #define WB_SECTION_SIZE (1024 * 2)
  4824. @@ -257,7 +252,6 @@ typedef struct {
  4825. ULONG nfRandomSeed; /* seed value for USAC noise filling random generator */
  4826. CDrcChannelData drcData;
  4827. - CConcealmentInfo concealmentInfo;
  4828. CpePersistentData *pCpeStaticData;
  4829. @@ -280,11 +274,6 @@ typedef struct {
  4830. shouldBeUnion {
  4831. struct {
  4832. CPulseData PulseData;
  4833. - SHORT aNumLineInSec4Hcr[MAX_SFB_HCR]; /* needed once for all channels
  4834. - except for Drm syntax */
  4835. - UCHAR
  4836. - aCodeBooks4Hcr[MAX_SFB_HCR]; /* needed once for all channels except for
  4837. - Drm syntax. Same as "aCodeBook" ? */
  4838. SHORT lenOfReorderedSpectralData;
  4839. SCHAR lenOfLongestCodeword;
  4840. SCHAR numberSection;
  4841. @@ -325,17 +314,6 @@ typedef struct {
  4842. CJointStereoData jointStereoData; /* One for one element */
  4843. - shouldBeUnion {
  4844. - struct {
  4845. - CErHcrInfo erHcrInfo;
  4846. - CErRvlcInfo erRvlcInfo;
  4847. - SHORT aRvlcScfEsc[RVLC_MAX_SFB]; /* needed once for all channels */
  4848. - SHORT aRvlcScfFwd[RVLC_MAX_SFB]; /* needed once for all channels */
  4849. - SHORT aRvlcScfBwd[RVLC_MAX_SFB]; /* needed once for all channels */
  4850. - } aac;
  4851. - }
  4852. - overlay;
  4853. -
  4854. } CAacDecoderCommonData;
  4855. typedef struct {
  4856. diff --git a/libAACdec/src/conceal.cpp b/libAACdec/src/conceal.cpp
  4857. deleted file mode 100644
  4858. index 5895cb8..0000000
  4859. --- a/libAACdec/src/conceal.cpp
  4860. +++ /dev/null
  4861. @@ -1,2095 +0,0 @@
  4862. -/* -----------------------------------------------------------------------------
  4863. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  4864. -
  4865. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  4866. -Forschung e.V. All rights reserved.
  4867. -
  4868. - 1. INTRODUCTION
  4869. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  4870. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  4871. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  4872. -a wide variety of Android devices.
  4873. -
  4874. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  4875. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  4876. -full-bandwidth communications codec by independent studies and is widely
  4877. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  4878. -specifications.
  4879. -
  4880. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  4881. -those of Fraunhofer) may be obtained through Via Licensing
  4882. -(www.vialicensing.com) or through the respective patent owners individually for
  4883. -the purpose of encoding or decoding bit streams in products that are compliant
  4884. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  4885. -Android devices already license these patent claims through Via Licensing or
  4886. -directly from the patent owners, and therefore FDK AAC Codec software may
  4887. -already be covered under those patent licenses when it is used for those
  4888. -licensed purposes only.
  4889. -
  4890. -Commercially-licensed AAC software libraries, including floating-point versions
  4891. -with enhanced sound quality, are also available from Fraunhofer. Users are
  4892. -encouraged to check the Fraunhofer website for additional applications
  4893. -information and documentation.
  4894. -
  4895. -2. COPYRIGHT LICENSE
  4896. -
  4897. -Redistribution and use in source and binary forms, with or without modification,
  4898. -are permitted without payment of copyright license fees provided that you
  4899. -satisfy the following conditions:
  4900. -
  4901. -You must retain the complete text of this software license in redistributions of
  4902. -the FDK AAC Codec or your modifications thereto in source code form.
  4903. -
  4904. -You must retain the complete text of this software license in the documentation
  4905. -and/or other materials provided with redistributions of the FDK AAC Codec or
  4906. -your modifications thereto in binary form. You must make available free of
  4907. -charge copies of the complete source code of the FDK AAC Codec and your
  4908. -modifications thereto to recipients of copies in binary form.
  4909. -
  4910. -The name of Fraunhofer may not be used to endorse or promote products derived
  4911. -from this library without prior written permission.
  4912. -
  4913. -You may not charge copyright license fees for anyone to use, copy or distribute
  4914. -the FDK AAC Codec software or your modifications thereto.
  4915. -
  4916. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  4917. -that you changed the software and the date of any change. For modified versions
  4918. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  4919. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  4920. -AAC Codec Library for Android."
  4921. -
  4922. -3. NO PATENT LICENSE
  4923. -
  4924. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  4925. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  4926. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  4927. -software.
  4928. -
  4929. -You may use this FDK AAC Codec software or modifications thereto only for
  4930. -purposes that are authorized by appropriate patent licenses.
  4931. -
  4932. -4. DISCLAIMER
  4933. -
  4934. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  4935. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  4936. -including but not limited to the implied warranties of merchantability and
  4937. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  4938. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  4939. -or consequential damages, including but not limited to procurement of substitute
  4940. -goods or services; loss of use, data, or profits, or business interruption,
  4941. -however caused and on any theory of liability, whether in contract, strict
  4942. -liability, or tort (including negligence), arising in any way out of the use of
  4943. -this software, even if advised of the possibility of such damage.
  4944. -
  4945. -5. CONTACT INFORMATION
  4946. -
  4947. -Fraunhofer Institute for Integrated Circuits IIS
  4948. -Attention: Audio and Multimedia Departments - FDK AAC LL
  4949. -Am Wolfsmantel 33
  4950. -91058 Erlangen, Germany
  4951. -
  4952. -www.iis.fraunhofer.de/amm
  4953. -amm-info@iis.fraunhofer.de
  4954. ------------------------------------------------------------------------------ */
  4955. -
  4956. -/**************************** AAC decoder library ******************************
  4957. -
  4958. - Author(s): Josef Hoepfl
  4959. -
  4960. - Description: independent channel concealment
  4961. -
  4962. -*******************************************************************************/
  4963. -
  4964. -/*!
  4965. - \page concealment AAC core concealment
  4966. -
  4967. - This AAC core implementation includes a concealment function, which can be
  4968. - enabled using the several defines during compilation.
  4969. -
  4970. - There are various tests inside the core, starting with simple CRC tests and
  4971. - ending in a variety of plausibility checks. If such a check indicates an
  4972. - invalid bitstream, then concealment is applied.
  4973. -
  4974. - Concealment is also applied when the calling main program indicates a
  4975. - distorted or missing data frame using the frameOK flag. This is used for error
  4976. - detection on the transport layer. (See below)
  4977. -
  4978. - There are three concealment-modes:
  4979. -
  4980. - 1) Muting: The spectral data is simply set to zero in case of an detected
  4981. - error.
  4982. -
  4983. - 2) Noise substitution: In case of an detected error, concealment copies the
  4984. - last frame and adds attenuates the spectral data. For this mode you have to
  4985. - set the #CONCEAL_NOISE define. Noise substitution adds no additional delay.
  4986. -
  4987. - 3) Interpolation: The interpolation routine swaps the spectral data from the
  4988. - previous and the current frame just before the final frequency to time
  4989. - conversion. In case a single frame is corrupted, concealmant interpolates
  4990. - between the last good and the first good frame to create the spectral data for
  4991. - the missing frame. If multiple frames are corrupted, concealment implements
  4992. - first a fade out based on slightly modified spectral values from the last good
  4993. - frame. As soon as good frames are available, concealmant fades in the new
  4994. - spectral data. For this mode you have to set the #CONCEAL_INTER define. Note
  4995. - that in this case, you also need to set #SBR_BS_DELAY_ENABLE, which basically
  4996. - adds approriate delay in the SBR decoder. Note that the
  4997. - Interpolating-Concealment increases the delay of your decoder by one frame and
  4998. - that it does require additional resources such as memory and computational
  4999. - complexity.
  5000. -
  5001. - <h2>How concealment can be used with errors on the transport layer</h2>
  5002. -
  5003. - Many errors can or have to be detected on the transport layer. For example in
  5004. - IP based systems packet loss can occur. The transport protocol used should
  5005. - indicate such packet loss by inserting an empty frame with frameOK=0.
  5006. -*/
  5007. -
  5008. -#include "conceal.h"
  5009. -
  5010. -#include "aac_rom.h"
  5011. -#include "genericStds.h"
  5012. -
  5013. -/* PNS (of block) */
  5014. -#include "aacdec_pns.h"
  5015. -#include "block.h"
  5016. -
  5017. -#define CONCEAL_DFLT_COMF_NOISE_LEVEL (0x100000)
  5018. -
  5019. -#define CONCEAL_NOT_DEFINED ((UCHAR)-1)
  5020. -
  5021. -/* default settings */
  5022. -#define CONCEAL_DFLT_FADEOUT_FRAMES (6)
  5023. -#define CONCEAL_DFLT_FADEIN_FRAMES (5)
  5024. -#define CONCEAL_DFLT_MUTE_RELEASE_FRAMES (0)
  5025. -
  5026. -#define CONCEAL_DFLT_FADE_FACTOR (0.707106781186548f) /* 1/sqrt(2) */
  5027. -
  5028. -/* some often used constants: */
  5029. -#define FIXP_ZERO FL2FXCONST_DBL(0.0f)
  5030. -#define FIXP_ONE FL2FXCONST_DBL(1.0f)
  5031. -#define FIXP_FL_CORRECTION FL2FXCONST_DBL(0.53333333333333333f)
  5032. -
  5033. -/* For parameter conversion */
  5034. -#define CONCEAL_PARAMETER_BITS (8)
  5035. -#define CONCEAL_MAX_QUANT_FACTOR ((1 << CONCEAL_PARAMETER_BITS) - 1)
  5036. -/*#define CONCEAL_MIN_ATTENUATION_FACTOR_025 ( FL2FXCONST_DBL(0.971627951577106174) )*/ /* -0.25 dB */
  5037. -#define CONCEAL_MIN_ATTENUATION_FACTOR_025_LD \
  5038. - FL2FXCONST_DBL(-0.041524101186092029596853445212299)
  5039. -/*#define CONCEAL_MIN_ATTENUATION_FACTOR_050 ( FL2FXCONST_DBL(0.944060876285923380) )*/ /* -0.50 dB */
  5040. -#define CONCEAL_MIN_ATTENUATION_FACTOR_050_LD \
  5041. - FL2FXCONST_DBL(-0.083048202372184059253597008145293)
  5042. -
  5043. -typedef enum {
  5044. - CConcealment_NoExpand,
  5045. - CConcealment_Expand,
  5046. - CConcealment_Compress
  5047. -} CConcealmentExpandType;
  5048. -
  5049. -static const FIXP_SGL facMod4Table[4] = {
  5050. - FL2FXCONST_SGL(0.500000000f), /* FIXP_SGL(0x4000), 2^-(1-0,00) */
  5051. - FL2FXCONST_SGL(0.594603558f), /* FIXP_SGL(0x4c1b), 2^-(1-0,25) */
  5052. - FL2FXCONST_SGL(0.707106781f), /* FIXP_SGL(0x5a82), 2^-(1-0,50) */
  5053. - FL2FXCONST_SGL(0.840896415f) /* FIXP_SGL(0x6ba2) 2^-(1-0,75) */
  5054. -};
  5055. -
  5056. -static void CConcealment_CalcBandEnergy(
  5057. - FIXP_DBL *spectrum, const SamplingRateInfo *pSamplingRateInfo,
  5058. - const int blockType, CConcealmentExpandType ex, int *sfbEnergy);
  5059. -
  5060. -static void CConcealment_InterpolateBuffer(FIXP_DBL *spectrum,
  5061. - SHORT *pSpecScalePrev,
  5062. - SHORT *pSpecScaleAct,
  5063. - SHORT *pSpecScaleOut, int *enPrv,
  5064. - int *enAct, int sfbCnt,
  5065. - const SHORT *pSfbOffset);
  5066. -
  5067. -static int CConcealment_ApplyInter(
  5068. - CConcealmentInfo *pConcealmentInfo,
  5069. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  5070. - const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
  5071. - const int improveTonal, const int frameOk, const int mute_release_active);
  5072. -
  5073. -static int CConcealment_ApplyNoise(
  5074. - CConcealmentInfo *pConcealmentInfo,
  5075. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  5076. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  5077. - const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
  5078. - const UINT flags);
  5079. -
  5080. -static void CConcealment_UpdateState(
  5081. - CConcealmentInfo *pConcealmentInfo, int frameOk,
  5082. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  5083. - const int samplesPerFrame, CAacDecoderChannelInfo *pAacDecoderChannelInfo);
  5084. -
  5085. -static void CConcealment_ApplyRandomSign(int iRandomPhase, FIXP_DBL *spec,
  5086. - int samplesPerFrame);
  5087. -
  5088. -/* TimeDomainFading */
  5089. -static void CConcealment_TDFadePcmAtt(int start, int len, FIXP_DBL fadeStart,
  5090. - FIXP_DBL fadeStop, FIXP_PCM *pcmdata);
  5091. -static void CConcealment_TDFadeFillFadingStations(FIXP_DBL *fadingStations,
  5092. - int *fadingSteps,
  5093. - FIXP_DBL fadeStop,
  5094. - FIXP_DBL fadeStart,
  5095. - TDfadingType fadingType);
  5096. -static void CConcealment_TDFading_doLinearFadingSteps(int *fadingSteps);
  5097. -
  5098. -/* Streamline the state machine */
  5099. -static int CConcealment_ApplyFadeOut(
  5100. - int mode, CConcealmentInfo *pConcealmentInfo,
  5101. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  5102. - const int samplesPerFrame, CAacDecoderChannelInfo *pAacDecoderChannelInfo);
  5103. -
  5104. -static int CConcealment_TDNoise_Random(ULONG *seed);
  5105. -static void CConcealment_TDNoise_Apply(CConcealmentInfo *const pConcealmentInfo,
  5106. - const int len, FIXP_PCM *const pcmdata);
  5107. -
  5108. -static BLOCK_TYPE CConcealment_GetWinSeq(int prevWinSeq) {
  5109. - BLOCK_TYPE newWinSeq = BLOCK_LONG;
  5110. -
  5111. - /* Try to have only long blocks */
  5112. - if (prevWinSeq == BLOCK_START || prevWinSeq == BLOCK_SHORT) {
  5113. - newWinSeq = BLOCK_STOP;
  5114. - }
  5115. -
  5116. - return (newWinSeq);
  5117. -}
  5118. -
  5119. -/*!
  5120. - \brief Init common concealment information data
  5121. -
  5122. - \param pConcealCommonData Pointer to the concealment common data structure.
  5123. -*/
  5124. -void CConcealment_InitCommonData(CConcealParams *pConcealCommonData) {
  5125. - if (pConcealCommonData != NULL) {
  5126. - int i;
  5127. -
  5128. - /* Set default error concealment technique */
  5129. - pConcealCommonData->method = ConcealMethodInter;
  5130. -
  5131. - pConcealCommonData->numFadeOutFrames = CONCEAL_DFLT_FADEOUT_FRAMES;
  5132. - pConcealCommonData->numFadeInFrames = CONCEAL_DFLT_FADEIN_FRAMES;
  5133. - pConcealCommonData->numMuteReleaseFrames = CONCEAL_DFLT_MUTE_RELEASE_FRAMES;
  5134. -
  5135. - pConcealCommonData->comfortNoiseLevel =
  5136. - (FIXP_DBL)CONCEAL_DFLT_COMF_NOISE_LEVEL;
  5137. -
  5138. - /* Init fade factors (symetric) */
  5139. - pConcealCommonData->fadeOutFactor[0] =
  5140. - FL2FXCONST_SGL(CONCEAL_DFLT_FADE_FACTOR);
  5141. - pConcealCommonData->fadeInFactor[0] = pConcealCommonData->fadeOutFactor[0];
  5142. -
  5143. - for (i = 1; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
  5144. - pConcealCommonData->fadeOutFactor[i] =
  5145. - FX_DBL2FX_SGL(fMult(pConcealCommonData->fadeOutFactor[i - 1],
  5146. - FL2FXCONST_SGL(CONCEAL_DFLT_FADE_FACTOR)));
  5147. - pConcealCommonData->fadeInFactor[i] =
  5148. - pConcealCommonData->fadeOutFactor[i];
  5149. - }
  5150. - }
  5151. -}
  5152. -
  5153. -/*!
  5154. - \brief Get current concealment method.
  5155. -
  5156. - \param pConcealCommonData Pointer to common concealment data (for all
  5157. - channels)
  5158. -*/
  5159. -CConcealmentMethod CConcealment_GetMethod(CConcealParams *pConcealCommonData) {
  5160. - CConcealmentMethod method = ConcealMethodNone;
  5161. -
  5162. - if (pConcealCommonData != NULL) {
  5163. - method = pConcealCommonData->method;
  5164. - }
  5165. -
  5166. - return (method);
  5167. -}
  5168. -
  5169. -/*!
  5170. - \brief Init concealment information for each channel
  5171. -
  5172. - \param pConcealChannelInfo Pointer to the channel related concealment info
  5173. - structure to be initialized. \param pConcealCommonData Pointer to common
  5174. - concealment data (for all channels) \param initRenderMode Initial render
  5175. - mode to be set for the current channel. \param samplesPerFrame The number
  5176. - of samples per frame.
  5177. -*/
  5178. -void CConcealment_InitChannelData(CConcealmentInfo *pConcealChannelInfo,
  5179. - CConcealParams *pConcealCommonData,
  5180. - AACDEC_RENDER_MODE initRenderMode,
  5181. - int samplesPerFrame) {
  5182. - int i;
  5183. - pConcealChannelInfo->TDNoiseSeed = 0;
  5184. - FDKmemclear(pConcealChannelInfo->TDNoiseStates,
  5185. - sizeof(pConcealChannelInfo->TDNoiseStates));
  5186. - pConcealChannelInfo->TDNoiseCoef[0] = FL2FXCONST_SGL(0.05f);
  5187. - pConcealChannelInfo->TDNoiseCoef[1] = FL2FXCONST_SGL(0.5f);
  5188. - pConcealChannelInfo->TDNoiseCoef[2] = FL2FXCONST_SGL(0.45f);
  5189. -
  5190. - pConcealChannelInfo->pConcealParams = pConcealCommonData;
  5191. -
  5192. - pConcealChannelInfo->lastRenderMode = initRenderMode;
  5193. -
  5194. - pConcealChannelInfo->windowShape = CONCEAL_NOT_DEFINED;
  5195. - pConcealChannelInfo->windowSequence = BLOCK_LONG; /* default type */
  5196. - pConcealChannelInfo->lastWinGrpLen = 1;
  5197. -
  5198. - pConcealChannelInfo->concealState = ConcealState_Ok;
  5199. -
  5200. - FDKmemclear(pConcealChannelInfo->spectralCoefficient,
  5201. - 1024 * sizeof(FIXP_CNCL));
  5202. -
  5203. - for (i = 0; i < 8; i++) {
  5204. - pConcealChannelInfo->specScale[i] = 0;
  5205. - }
  5206. -
  5207. - pConcealChannelInfo->iRandomPhase = 0;
  5208. -
  5209. - pConcealChannelInfo->prevFrameOk[0] = 1;
  5210. - pConcealChannelInfo->prevFrameOk[1] = 1;
  5211. -
  5212. - pConcealChannelInfo->cntFadeFrames = 0;
  5213. - pConcealChannelInfo->cntValidFrames = 0;
  5214. - pConcealChannelInfo->fade_old = (FIXP_DBL)MAXVAL_DBL;
  5215. - pConcealChannelInfo->winGrpOffset[0] = 0;
  5216. - pConcealChannelInfo->winGrpOffset[1] = 0;
  5217. - pConcealChannelInfo->attGrpOffset[0] = 0;
  5218. - pConcealChannelInfo->attGrpOffset[1] = 0;
  5219. -}
  5220. -
  5221. -/*!
  5222. - \brief Set error concealment parameters
  5223. -
  5224. - \param concealParams
  5225. - \param method
  5226. - \param fadeOutSlope
  5227. - \param fadeInSlope
  5228. - \param muteRelease
  5229. - \param comfNoiseLevel
  5230. -*/
  5231. -AAC_DECODER_ERROR
  5232. -CConcealment_SetParams(CConcealParams *concealParams, int method,
  5233. - int fadeOutSlope, int fadeInSlope, int muteRelease,
  5234. - FIXP_DBL comfNoiseLevel) {
  5235. - /* set concealment technique */
  5236. - if (method != AACDEC_CONCEAL_PARAM_NOT_SPECIFIED) {
  5237. - switch ((CConcealmentMethod)method) {
  5238. - case ConcealMethodMute:
  5239. - case ConcealMethodNoise:
  5240. - case ConcealMethodInter:
  5241. - /* Be sure to enable delay adjustment of SBR decoder! */
  5242. - if (concealParams == NULL) {
  5243. - return AAC_DEC_INVALID_HANDLE;
  5244. - } else {
  5245. - /* set param */
  5246. - concealParams->method = (CConcealmentMethod)method;
  5247. - }
  5248. - break;
  5249. -
  5250. - default:
  5251. - return AAC_DEC_SET_PARAM_FAIL;
  5252. - }
  5253. - }
  5254. -
  5255. - /* set number of frames for fade-out slope */
  5256. - if (fadeOutSlope != AACDEC_CONCEAL_PARAM_NOT_SPECIFIED) {
  5257. - if ((fadeOutSlope < CONCEAL_MAX_NUM_FADE_FACTORS) && (fadeOutSlope >= 0)) {
  5258. - if (concealParams == NULL) {
  5259. - return AAC_DEC_INVALID_HANDLE;
  5260. - } else {
  5261. - /* set param */
  5262. - concealParams->numFadeOutFrames = fadeOutSlope;
  5263. - }
  5264. - } else {
  5265. - return AAC_DEC_SET_PARAM_FAIL;
  5266. - }
  5267. - }
  5268. -
  5269. - /* set number of frames for fade-in slope */
  5270. - if (fadeInSlope != AACDEC_CONCEAL_PARAM_NOT_SPECIFIED) {
  5271. - if ((fadeInSlope < CONCEAL_MAX_NUM_FADE_FACTORS) && (fadeInSlope >= 0)) {
  5272. - if (concealParams == NULL) {
  5273. - return AAC_DEC_INVALID_HANDLE;
  5274. - } else {
  5275. - /* set param */
  5276. - concealParams->numFadeInFrames = fadeInSlope;
  5277. - }
  5278. - } else {
  5279. - return AAC_DEC_SET_PARAM_FAIL;
  5280. - }
  5281. - }
  5282. -
  5283. - /* set number of error-free frames after which the muting will be released */
  5284. - if (muteRelease != AACDEC_CONCEAL_PARAM_NOT_SPECIFIED) {
  5285. - if ((muteRelease < (CONCEAL_MAX_NUM_FADE_FACTORS << 1)) &&
  5286. - (muteRelease >= 0)) {
  5287. - if (concealParams == NULL) {
  5288. - return AAC_DEC_INVALID_HANDLE;
  5289. - } else {
  5290. - /* set param */
  5291. - concealParams->numMuteReleaseFrames = muteRelease;
  5292. - }
  5293. - } else {
  5294. - return AAC_DEC_SET_PARAM_FAIL;
  5295. - }
  5296. - }
  5297. -
  5298. - /* set confort noise level which will be inserted while in state 'muting' */
  5299. - if (comfNoiseLevel != (FIXP_DBL)AACDEC_CONCEAL_PARAM_NOT_SPECIFIED) {
  5300. - if ((comfNoiseLevel < (FIXP_DBL)0) ||
  5301. - (comfNoiseLevel > (FIXP_DBL)MAXVAL_DBL)) {
  5302. - return AAC_DEC_SET_PARAM_FAIL;
  5303. - }
  5304. - if (concealParams == NULL) {
  5305. - return AAC_DEC_INVALID_HANDLE;
  5306. - } else {
  5307. - concealParams->comfortNoiseLevel = (FIXP_DBL)comfNoiseLevel;
  5308. - }
  5309. - }
  5310. -
  5311. - return (AAC_DEC_OK);
  5312. -}
  5313. -
  5314. -/*!
  5315. - \brief Set fade-out/in attenuation factor vectors
  5316. -
  5317. - \param concealParams
  5318. - \param fadeOutAttenuationVector
  5319. - \param fadeInAttenuationVector
  5320. -
  5321. - \return 0 if OK all other values indicate errors
  5322. -*/
  5323. -AAC_DECODER_ERROR
  5324. -CConcealment_SetAttenuation(CConcealParams *concealParams,
  5325. - const SHORT *fadeOutAttenuationVector,
  5326. - const SHORT *fadeInAttenuationVector) {
  5327. - if ((fadeOutAttenuationVector == NULL) && (fadeInAttenuationVector == NULL)) {
  5328. - return AAC_DEC_SET_PARAM_FAIL;
  5329. - }
  5330. -
  5331. - /* Fade-out factors */
  5332. - if (fadeOutAttenuationVector != NULL) {
  5333. - int i;
  5334. -
  5335. - /* check quantized factors first */
  5336. - for (i = 0; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
  5337. - if ((fadeOutAttenuationVector[i] < 0) ||
  5338. - (fadeOutAttenuationVector[i] > CONCEAL_MAX_QUANT_FACTOR)) {
  5339. - return AAC_DEC_SET_PARAM_FAIL;
  5340. - }
  5341. - }
  5342. - if (concealParams == NULL) {
  5343. - return AAC_DEC_INVALID_HANDLE;
  5344. - }
  5345. -
  5346. - /* now dequantize factors */
  5347. - for (i = 0; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
  5348. - concealParams->fadeOutFactor[i] =
  5349. - FX_DBL2FX_SGL(fLdPow(CONCEAL_MIN_ATTENUATION_FACTOR_025_LD, 0,
  5350. - (FIXP_DBL)((INT)(FL2FXCONST_DBL(1.0 / 2.0) >>
  5351. - (CONCEAL_PARAMETER_BITS - 1)) *
  5352. - (INT)fadeOutAttenuationVector[i]),
  5353. - CONCEAL_PARAMETER_BITS));
  5354. - }
  5355. - }
  5356. -
  5357. - /* Fade-in factors */
  5358. - if (fadeInAttenuationVector != NULL) {
  5359. - int i;
  5360. -
  5361. - /* check quantized factors first */
  5362. - for (i = 0; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
  5363. - if ((fadeInAttenuationVector[i] < 0) ||
  5364. - (fadeInAttenuationVector[i] > CONCEAL_MAX_QUANT_FACTOR)) {
  5365. - return AAC_DEC_SET_PARAM_FAIL;
  5366. - }
  5367. - }
  5368. - if (concealParams == NULL) {
  5369. - return AAC_DEC_INVALID_HANDLE;
  5370. - }
  5371. -
  5372. - /* now dequantize factors */
  5373. - for (i = 0; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
  5374. - concealParams->fadeInFactor[i] = FX_DBL2FX_SGL(
  5375. - fLdPow(CONCEAL_MIN_ATTENUATION_FACTOR_025_LD, 0,
  5376. - (FIXP_DBL)((INT)(FIXP_ONE >> CONCEAL_PARAMETER_BITS) *
  5377. - (INT)fadeInAttenuationVector[i]),
  5378. - CONCEAL_PARAMETER_BITS));
  5379. - }
  5380. - }
  5381. -
  5382. - return (AAC_DEC_OK);
  5383. -}
  5384. -
  5385. -/*!
  5386. - \brief Get state of concealment module.
  5387. -
  5388. - \param pConcealChannelInfo
  5389. -
  5390. - \return Concealment state.
  5391. -*/
  5392. -CConcealmentState CConcealment_GetState(CConcealmentInfo *pConcealChannelInfo) {
  5393. - CConcealmentState state = ConcealState_Ok;
  5394. -
  5395. - if (pConcealChannelInfo != NULL) {
  5396. - state = pConcealChannelInfo->concealState;
  5397. - }
  5398. -
  5399. - return (state);
  5400. -}
  5401. -
  5402. -/*!
  5403. - \brief Store data for concealment techniques applied later
  5404. -
  5405. - Interface function to store data for different concealment strategies
  5406. - */
  5407. -void CConcealment_Store(
  5408. - CConcealmentInfo *hConcealmentInfo,
  5409. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  5410. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
  5411. - UCHAR nbDiv = NB_DIV;
  5412. -
  5413. - if (!(pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_LPD &&
  5414. - pAacDecoderChannelInfo->data.usac.mod[nbDiv - 1] == 0))
  5415. -
  5416. - {
  5417. - FIXP_DBL *pSpectralCoefficient =
  5418. - SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
  5419. - SHORT *pSpecScale = pAacDecoderChannelInfo->specScale;
  5420. - CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
  5421. -
  5422. - SHORT tSpecScale[8];
  5423. - UCHAR tWindowShape;
  5424. - BLOCK_TYPE tWindowSequence;
  5425. -
  5426. - /* store old window infos for swapping */
  5427. - tWindowSequence = hConcealmentInfo->windowSequence;
  5428. - tWindowShape = hConcealmentInfo->windowShape;
  5429. -
  5430. - /* store old scale factors for swapping */
  5431. - FDKmemcpy(tSpecScale, hConcealmentInfo->specScale, 8 * sizeof(SHORT));
  5432. -
  5433. - /* store new window infos */
  5434. - hConcealmentInfo->windowSequence = GetWindowSequence(pIcsInfo);
  5435. - hConcealmentInfo->windowShape = GetWindowShape(pIcsInfo);
  5436. - hConcealmentInfo->lastWinGrpLen =
  5437. - *(GetWindowGroupLengthTable(pIcsInfo) + GetWindowGroups(pIcsInfo) - 1);
  5438. -
  5439. - /* store new scale factors */
  5440. - FDKmemcpy(hConcealmentInfo->specScale, pSpecScale, 8 * sizeof(SHORT));
  5441. -
  5442. - if (hConcealmentInfo->pConcealParams->method < ConcealMethodInter) {
  5443. - /* store new spectral bins */
  5444. -#if (CNCL_FRACT_BITS == DFRACT_BITS)
  5445. - FDKmemcpy(hConcealmentInfo->spectralCoefficient, pSpectralCoefficient,
  5446. - 1024 * sizeof(FIXP_CNCL));
  5447. -#else
  5448. - FIXP_CNCL *RESTRICT pCncl =
  5449. - &hConcealmentInfo->spectralCoefficient[1024 - 1];
  5450. - FIXP_DBL *RESTRICT pSpec = &pSpectralCoefficient[1024 - 1];
  5451. - int i;
  5452. - for (i = 1024; i != 0; i--) {
  5453. - *pCncl-- = FX_DBL2FX_CNCL(*pSpec--);
  5454. - }
  5455. -#endif
  5456. - } else {
  5457. - /* swap spectral data */
  5458. -#if (FIXP_CNCL == FIXP_DBL)
  5459. - C_ALLOC_SCRATCH_START(pSpecTmp, FIXP_DBL, 1024);
  5460. - FDKmemcpy(pSpecTmp, pSpectralCoefficient, 1024 * sizeof(FIXP_DBL));
  5461. - FDKmemcpy(pSpectralCoefficient, hConcealmentInfo->spectralCoefficient,
  5462. - 1024 * sizeof(FIXP_DBL));
  5463. - FDKmemcpy(hConcealmentInfo->spectralCoefficient, pSpecTmp,
  5464. - 1024 * sizeof(FIXP_DBL));
  5465. - C_ALLOC_SCRATCH_END(pSpecTmp, FIXP_DBL, 1024);
  5466. -#else
  5467. - FIXP_CNCL *RESTRICT pCncl =
  5468. - &hConcealmentInfo->spectralCoefficient[1024 - 1];
  5469. - FIXP_DBL *RESTRICT pSpec = &pSpectralCoefficient[1024 - 1];
  5470. - FIXP_DBL tSpec;
  5471. -
  5472. - for (int i = 1024; i != 0; i--) {
  5473. - tSpec = *pSpec;
  5474. - *pSpec-- = FX_CNCL2FX_DBL(*pCncl);
  5475. - *pCncl-- = FX_DBL2FX_CNCL(tSpec);
  5476. - }
  5477. -#endif
  5478. -
  5479. - /* complete swapping of window infos */
  5480. - pIcsInfo->WindowSequence = tWindowSequence;
  5481. - pIcsInfo->WindowShape = tWindowShape;
  5482. -
  5483. - /* complete swapping of scale factors */
  5484. - FDKmemcpy(pSpecScale, tSpecScale, 8 * sizeof(SHORT));
  5485. - }
  5486. - }
  5487. -
  5488. - if (pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_LPD) {
  5489. - /* Store LSF4 */
  5490. - FDKmemcpy(hConcealmentInfo->lsf4, pAacDecoderStaticChannelInfo->lpc4_lsf,
  5491. - sizeof(hConcealmentInfo->lsf4));
  5492. - /* Store TCX gain */
  5493. - hConcealmentInfo->last_tcx_gain =
  5494. - pAacDecoderStaticChannelInfo->last_tcx_gain;
  5495. - hConcealmentInfo->last_tcx_gain_e =
  5496. - pAacDecoderStaticChannelInfo->last_tcx_gain_e;
  5497. - }
  5498. -}
  5499. -
  5500. -/*!
  5501. - \brief Apply concealment
  5502. -
  5503. - Interface function to different concealment strategies
  5504. - */
  5505. -int CConcealment_Apply(
  5506. - CConcealmentInfo *hConcealmentInfo,
  5507. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  5508. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  5509. - const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
  5510. - const UCHAR lastLpdMode, const int frameOk, const UINT flags) {
  5511. - int appliedProcessing = 0;
  5512. - const int mute_release_active =
  5513. - frameOk && (hConcealmentInfo->concealState >= ConcealState_Mute) &&
  5514. - (hConcealmentInfo->cntValidFrames + 1 <=
  5515. - hConcealmentInfo->pConcealParams->numMuteReleaseFrames);
  5516. -
  5517. - if (hConcealmentInfo->windowShape == CONCEAL_NOT_DEFINED) {
  5518. - /* Initialize window_shape with same value as in the current (parsed) frame.
  5519. - Because section 4.6.11.3.2 (Windowing and block switching) of ISO/IEC
  5520. - 14496-3:2009 says: For the first raw_data_block() to be decoded the
  5521. - window_shape of the left and right half of the window are identical. */
  5522. - hConcealmentInfo->windowShape = pAacDecoderChannelInfo->icsInfo.WindowShape;
  5523. - }
  5524. -
  5525. - if (frameOk && !mute_release_active) {
  5526. - /* Update render mode if frameOk except for ongoing mute release state. */
  5527. - hConcealmentInfo->lastRenderMode =
  5528. - (SCHAR)pAacDecoderChannelInfo->renderMode;
  5529. -
  5530. - /* Rescue current data for concealment in future frames */
  5531. - CConcealment_Store(hConcealmentInfo, pAacDecoderChannelInfo,
  5532. - pAacDecoderStaticChannelInfo);
  5533. - /* Reset index to random sign vector to make sign calculation frame agnostic
  5534. - (only depends on number of subsequently concealed spectral blocks) */
  5535. - hConcealmentInfo->iRandomPhase = 0;
  5536. - } else {
  5537. - if (hConcealmentInfo->lastRenderMode == AACDEC_RENDER_INVALID) {
  5538. - hConcealmentInfo->lastRenderMode = AACDEC_RENDER_IMDCT;
  5539. - }
  5540. - pAacDecoderChannelInfo->renderMode =
  5541. - (AACDEC_RENDER_MODE)hConcealmentInfo->lastRenderMode;
  5542. - }
  5543. -
  5544. - /* hand current frame status to the state machine */
  5545. - CConcealment_UpdateState(hConcealmentInfo, frameOk,
  5546. - pAacDecoderStaticChannelInfo, samplesPerFrame,
  5547. - pAacDecoderChannelInfo);
  5548. -
  5549. - {
  5550. - if (!frameOk && pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_IMDCT) {
  5551. - /* LPC extrapolation */
  5552. - CLpc_Conceal(pAacDecoderChannelInfo->data.usac.lsp_coeff,
  5553. - pAacDecoderStaticChannelInfo->lpc4_lsf,
  5554. - pAacDecoderStaticChannelInfo->lsf_adaptive_mean,
  5555. - hConcealmentInfo->lastRenderMode == AACDEC_RENDER_IMDCT);
  5556. - FDKmemcpy(hConcealmentInfo->lsf4, pAacDecoderStaticChannelInfo->lpc4_lsf,
  5557. - sizeof(pAacDecoderStaticChannelInfo->lpc4_lsf));
  5558. - }
  5559. -
  5560. - /* Create data for signal rendering according to the selected concealment
  5561. - * method and decoder operating mode. */
  5562. -
  5563. - if ((!frameOk || mute_release_active) &&
  5564. - (pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_LPD)) {
  5565. - /* Restore old LSF4 */
  5566. - FDKmemcpy(pAacDecoderStaticChannelInfo->lpc4_lsf, hConcealmentInfo->lsf4,
  5567. - sizeof(pAacDecoderStaticChannelInfo->lpc4_lsf));
  5568. - /* Restore old TCX gain */
  5569. - pAacDecoderStaticChannelInfo->last_tcx_gain =
  5570. - hConcealmentInfo->last_tcx_gain;
  5571. - pAacDecoderStaticChannelInfo->last_tcx_gain_e =
  5572. - hConcealmentInfo->last_tcx_gain_e;
  5573. - }
  5574. -
  5575. - if (!(pAacDecoderChannelInfo->renderMode == AACDEC_RENDER_LPD &&
  5576. - pAacDecoderStaticChannelInfo->last_lpd_mode == 0)) {
  5577. - switch (hConcealmentInfo->pConcealParams->method) {
  5578. - default:
  5579. - case ConcealMethodMute:
  5580. - if (!frameOk) {
  5581. - /* Mute spectral data in case of errors */
  5582. - FDKmemclear(pAacDecoderChannelInfo->pSpectralCoefficient,
  5583. - samplesPerFrame * sizeof(FIXP_DBL));
  5584. - /* Set last window shape */
  5585. - pAacDecoderChannelInfo->icsInfo.WindowShape =
  5586. - hConcealmentInfo->windowShape;
  5587. - appliedProcessing = 1;
  5588. - }
  5589. - break;
  5590. -
  5591. - case ConcealMethodNoise:
  5592. - /* Noise substitution error concealment technique */
  5593. - appliedProcessing = CConcealment_ApplyNoise(
  5594. - hConcealmentInfo, pAacDecoderChannelInfo,
  5595. - pAacDecoderStaticChannelInfo, pSamplingRateInfo, samplesPerFrame,
  5596. - flags);
  5597. - break;
  5598. -
  5599. - case ConcealMethodInter:
  5600. - /* Energy interpolation concealment based on 3GPP */
  5601. - appliedProcessing = CConcealment_ApplyInter(
  5602. - hConcealmentInfo, pAacDecoderChannelInfo, pSamplingRateInfo,
  5603. - samplesPerFrame, 0, /* don't use tonal improvement */
  5604. - frameOk, mute_release_active);
  5605. - break;
  5606. - }
  5607. - } else if (!frameOk || mute_release_active) {
  5608. - /* simply restore the buffer */
  5609. - FIXP_DBL *pSpectralCoefficient =
  5610. - SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
  5611. - SHORT *pSpecScale = pAacDecoderChannelInfo->specScale;
  5612. - CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
  5613. -#if (CNCL_FRACT_BITS != DFRACT_BITS)
  5614. - FIXP_CNCL *RESTRICT pCncl =
  5615. - &hConcealmentInfo->spectralCoefficient[1024 - 1];
  5616. - FIXP_DBL *RESTRICT pSpec = &pSpectralCoefficient[1024 - 1];
  5617. - int i;
  5618. -#endif
  5619. -
  5620. - /* restore window infos (gri) do we need that? */
  5621. - pIcsInfo->WindowSequence = hConcealmentInfo->windowSequence;
  5622. - pIcsInfo->WindowShape = hConcealmentInfo->windowShape;
  5623. -
  5624. - if (hConcealmentInfo->concealState != ConcealState_Mute) {
  5625. - /* restore scale factors */
  5626. - FDKmemcpy(pSpecScale, hConcealmentInfo->specScale, 8 * sizeof(SHORT));
  5627. -
  5628. - /* restore spectral bins */
  5629. -#if (CNCL_FRACT_BITS == DFRACT_BITS)
  5630. - FDKmemcpy(pSpectralCoefficient, hConcealmentInfo->spectralCoefficient,
  5631. - 1024 * sizeof(FIXP_DBL));
  5632. -#else
  5633. - for (i = 1024; i != 0; i--) {
  5634. - *pSpec-- = FX_CNCL2FX_DBL(*pCncl--);
  5635. - }
  5636. -#endif
  5637. - } else {
  5638. - /* clear scale factors */
  5639. - FDKmemclear(pSpecScale, 8 * sizeof(SHORT));
  5640. -
  5641. - /* clear buffer */
  5642. - FDKmemclear(pSpectralCoefficient, 1024 * sizeof(FIXP_CNCL));
  5643. - }
  5644. - }
  5645. - }
  5646. - /* update history */
  5647. - hConcealmentInfo->prevFrameOk[0] = hConcealmentInfo->prevFrameOk[1];
  5648. - hConcealmentInfo->prevFrameOk[1] = frameOk;
  5649. -
  5650. - return mute_release_active ? -1 : appliedProcessing;
  5651. -}
  5652. -
  5653. -/*!
  5654. -\brief Apply concealment noise substitution
  5655. -
  5656. - In case of frame lost this function produces a noisy frame with respect to the
  5657. - energies values of past frame.
  5658. - */
  5659. -static int CConcealment_ApplyNoise(
  5660. - CConcealmentInfo *pConcealmentInfo,
  5661. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  5662. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  5663. - const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
  5664. - const UINT flags) {
  5665. - FIXP_DBL *pSpectralCoefficient =
  5666. - SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
  5667. - CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
  5668. -
  5669. - int appliedProcessing = 0;
  5670. -
  5671. - FDK_ASSERT(pConcealmentInfo != NULL);
  5672. - FDK_ASSERT((samplesPerFrame >= 120) && (samplesPerFrame <= 1024));
  5673. -
  5674. - switch (pConcealmentInfo->concealState) {
  5675. - case ConcealState_Ok:
  5676. - /* Nothing to do here! */
  5677. - break;
  5678. -
  5679. - case ConcealState_Single:
  5680. - case ConcealState_FadeOut:
  5681. - appliedProcessing = CConcealment_ApplyFadeOut(
  5682. - /*mode =*/1, pConcealmentInfo, pAacDecoderStaticChannelInfo,
  5683. - samplesPerFrame, pAacDecoderChannelInfo);
  5684. - break;
  5685. -
  5686. - case ConcealState_Mute: {
  5687. - /* set dummy window parameters */
  5688. - pIcsInfo->Valid = 0; /* Trigger the generation of a consitent IcsInfo */
  5689. - pIcsInfo->WindowShape =
  5690. - pConcealmentInfo->windowShape; /* Prevent an invalid WindowShape
  5691. - (required for F/T transform) */
  5692. - pIcsInfo->WindowSequence =
  5693. - CConcealment_GetWinSeq(pConcealmentInfo->windowSequence);
  5694. - pConcealmentInfo->windowSequence =
  5695. - pIcsInfo->WindowSequence; /* Store for next frame
  5696. - (spectrum in concealment
  5697. - buffer can't be used at
  5698. - all) */
  5699. -
  5700. - /* mute spectral data */
  5701. - FDKmemclear(pSpectralCoefficient, samplesPerFrame * sizeof(FIXP_DBL));
  5702. - FDKmemclear(pConcealmentInfo->spectralCoefficient,
  5703. - samplesPerFrame * sizeof(FIXP_DBL));
  5704. -
  5705. - appliedProcessing = 1;
  5706. - } break;
  5707. -
  5708. - case ConcealState_FadeIn: {
  5709. - /* TimeDomainFading: */
  5710. - /* Attenuation of signal is done in CConcealment_TDFading() */
  5711. -
  5712. - appliedProcessing = 1;
  5713. - } break;
  5714. -
  5715. - default:
  5716. - /* we shouldn't come here anyway */
  5717. - FDK_ASSERT(0);
  5718. - break;
  5719. - }
  5720. -
  5721. - return appliedProcessing;
  5722. -}
  5723. -
  5724. -/*!
  5725. - \brief Apply concealment interpolation
  5726. -
  5727. - The function swaps the data from the current and the previous frame. If an
  5728. - error has occured, frame interpolation is performed to restore the missing
  5729. - frame. In case of multiple faulty frames, fade-in and fade-out is applied.
  5730. -*/
  5731. -static int CConcealment_ApplyInter(
  5732. - CConcealmentInfo *pConcealmentInfo,
  5733. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  5734. - const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
  5735. - const int improveTonal, const int frameOk, const int mute_release_active) {
  5736. -#if defined(FDK_ASSERT_ENABLE)
  5737. - CConcealParams *pConcealCommonData = pConcealmentInfo->pConcealParams;
  5738. -#endif
  5739. -
  5740. - FIXP_DBL *pSpectralCoefficient =
  5741. - SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
  5742. - CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
  5743. - SHORT *pSpecScale = pAacDecoderChannelInfo->specScale;
  5744. -
  5745. - int sfbEnergyPrev[64];
  5746. - int sfbEnergyAct[64];
  5747. -
  5748. - int i, appliedProcessing = 0;
  5749. -
  5750. - /* clear/init */
  5751. - FDKmemclear(sfbEnergyPrev, 64 * sizeof(int));
  5752. - FDKmemclear(sfbEnergyAct, 64 * sizeof(int));
  5753. -
  5754. - if (!frameOk || mute_release_active) {
  5755. - /* Restore last frame from concealment buffer */
  5756. - pIcsInfo->WindowShape = pConcealmentInfo->windowShape;
  5757. - pIcsInfo->WindowSequence = pConcealmentInfo->windowSequence;
  5758. -
  5759. - /* Restore spectral data */
  5760. - for (i = 0; i < samplesPerFrame; i++) {
  5761. - pSpectralCoefficient[i] =
  5762. - FX_CNCL2FX_DBL(pConcealmentInfo->spectralCoefficient[i]);
  5763. - }
  5764. -
  5765. - /* Restore scale factors */
  5766. - FDKmemcpy(pSpecScale, pConcealmentInfo->specScale, 8 * sizeof(SHORT));
  5767. - }
  5768. -
  5769. - /* if previous frame was not ok */
  5770. - if (!pConcealmentInfo->prevFrameOk[1] || mute_release_active) {
  5771. - /* if current frame (f_n) is ok and the last but one frame (f_(n-2))
  5772. - was ok, too, then interpolate both frames in order to generate
  5773. - the current output frame (f_(n-1)). Otherwise, use the last stored
  5774. - frame (f_(n-2) or f_(n-3) or ...). */
  5775. - if (frameOk && pConcealmentInfo->prevFrameOk[0] && !mute_release_active) {
  5776. - appliedProcessing = 1;
  5777. -
  5778. - /* Interpolate both frames in order to generate the current output frame
  5779. - * (f_(n-1)). */
  5780. - if (pIcsInfo->WindowSequence == BLOCK_SHORT) {
  5781. - /* f_(n-2) == BLOCK_SHORT */
  5782. - /* short--??????--short, short--??????--long interpolation */
  5783. - /* short--short---short, short---long---long interpolation */
  5784. -
  5785. - int wnd;
  5786. -
  5787. - if (pConcealmentInfo->windowSequence ==
  5788. - BLOCK_SHORT) { /* f_n == BLOCK_SHORT */
  5789. - /* short--short---short interpolation */
  5790. -
  5791. - int scaleFactorBandsTotal =
  5792. - pSamplingRateInfo->NumberOfScaleFactorBands_Short;
  5793. - const SHORT *pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Short;
  5794. - pIcsInfo->WindowShape = (samplesPerFrame <= 512) ? 2 : 1;
  5795. - pIcsInfo->WindowSequence = BLOCK_SHORT;
  5796. -
  5797. - for (wnd = 0; wnd < 8; wnd++) {
  5798. - CConcealment_CalcBandEnergy(
  5799. - &pSpectralCoefficient[wnd *
  5800. - (samplesPerFrame / 8)], /* spec_(n-2) */
  5801. - pSamplingRateInfo, BLOCK_SHORT, CConcealment_NoExpand,
  5802. - sfbEnergyPrev);
  5803. -
  5804. - CConcealment_CalcBandEnergy(
  5805. - &pConcealmentInfo->spectralCoefficient[wnd * (samplesPerFrame /
  5806. - 8)], /* spec_n */
  5807. - pSamplingRateInfo, BLOCK_SHORT, CConcealment_NoExpand,
  5808. - sfbEnergyAct);
  5809. -
  5810. - CConcealment_InterpolateBuffer(
  5811. - &pSpectralCoefficient[wnd *
  5812. - (samplesPerFrame / 8)], /* spec_(n-1) */
  5813. - &pSpecScale[wnd], &pConcealmentInfo->specScale[wnd],
  5814. - &pSpecScale[wnd], sfbEnergyPrev, sfbEnergyAct,
  5815. - scaleFactorBandsTotal, pSfbOffset);
  5816. - }
  5817. - } else { /* f_n != BLOCK_SHORT */
  5818. - /* short---long---long interpolation */
  5819. -
  5820. - int scaleFactorBandsTotal =
  5821. - pSamplingRateInfo->NumberOfScaleFactorBands_Long;
  5822. - const SHORT *pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Long;
  5823. - SHORT specScaleOut;
  5824. -
  5825. - CConcealment_CalcBandEnergy(
  5826. - &pSpectralCoefficient[samplesPerFrame -
  5827. - (samplesPerFrame /
  5828. - 8)], /* [wnd] spec_(n-2) */
  5829. - pSamplingRateInfo, BLOCK_SHORT, CConcealment_Expand,
  5830. - sfbEnergyAct);
  5831. -
  5832. - CConcealment_CalcBandEnergy(
  5833. - pConcealmentInfo->spectralCoefficient, /* spec_n */
  5834. - pSamplingRateInfo, BLOCK_LONG, CConcealment_NoExpand,
  5835. - sfbEnergyPrev);
  5836. -
  5837. - pIcsInfo->WindowShape = 0;
  5838. - pIcsInfo->WindowSequence = BLOCK_STOP;
  5839. -
  5840. - for (i = 0; i < samplesPerFrame; i++) {
  5841. - pSpectralCoefficient[i] =
  5842. - pConcealmentInfo->spectralCoefficient[i]; /* spec_n */
  5843. - }
  5844. -
  5845. - for (i = 0; i < 8; i++) { /* search for max(specScale) */
  5846. - if (pSpecScale[i] > pSpecScale[0]) {
  5847. - pSpecScale[0] = pSpecScale[i];
  5848. - }
  5849. - }
  5850. -
  5851. - CConcealment_InterpolateBuffer(
  5852. - pSpectralCoefficient, /* spec_(n-1) */
  5853. - &pConcealmentInfo->specScale[0], &pSpecScale[0], &specScaleOut,
  5854. - sfbEnergyPrev, sfbEnergyAct, scaleFactorBandsTotal, pSfbOffset);
  5855. -
  5856. - pSpecScale[0] = specScaleOut;
  5857. - }
  5858. - } else {
  5859. - /* long--??????--short, long--??????--long interpolation */
  5860. - /* long---long---short, long---long---long interpolation */
  5861. -
  5862. - int scaleFactorBandsTotal =
  5863. - pSamplingRateInfo->NumberOfScaleFactorBands_Long;
  5864. - const SHORT *pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Long;
  5865. - SHORT specScaleAct = pConcealmentInfo->specScale[0];
  5866. -
  5867. - CConcealment_CalcBandEnergy(pSpectralCoefficient, /* spec_(n-2) */
  5868. - pSamplingRateInfo, BLOCK_LONG,
  5869. - CConcealment_NoExpand, sfbEnergyPrev);
  5870. -
  5871. - if (pConcealmentInfo->windowSequence ==
  5872. - BLOCK_SHORT) { /* f_n == BLOCK_SHORT */
  5873. - /* long---long---short interpolation */
  5874. -
  5875. - pIcsInfo->WindowShape = (samplesPerFrame <= 512) ? 2 : 1;
  5876. - pIcsInfo->WindowSequence = BLOCK_START;
  5877. -
  5878. - for (i = 1; i < 8; i++) { /* search for max(specScale) */
  5879. - if (pConcealmentInfo->specScale[i] > specScaleAct) {
  5880. - specScaleAct = pConcealmentInfo->specScale[i];
  5881. - }
  5882. - }
  5883. -
  5884. - /* Expand first short spectrum */
  5885. - CConcealment_CalcBandEnergy(
  5886. - pConcealmentInfo->spectralCoefficient, /* spec_n */
  5887. - pSamplingRateInfo, BLOCK_SHORT, CConcealment_Expand, /* !!! */
  5888. - sfbEnergyAct);
  5889. - } else {
  5890. - /* long---long---long interpolation */
  5891. -
  5892. - pIcsInfo->WindowShape = 0;
  5893. - pIcsInfo->WindowSequence = BLOCK_LONG;
  5894. -
  5895. - CConcealment_CalcBandEnergy(
  5896. - pConcealmentInfo->spectralCoefficient, /* spec_n */
  5897. - pSamplingRateInfo, BLOCK_LONG, CConcealment_NoExpand,
  5898. - sfbEnergyAct);
  5899. - }
  5900. -
  5901. - CConcealment_InterpolateBuffer(
  5902. - pSpectralCoefficient, /* spec_(n-1) */
  5903. - &pSpecScale[0], &specScaleAct, &pSpecScale[0], sfbEnergyPrev,
  5904. - sfbEnergyAct, scaleFactorBandsTotal, pSfbOffset);
  5905. - }
  5906. - }
  5907. -
  5908. - /* Noise substitution of sign of the output spectral coefficients */
  5909. - CConcealment_ApplyRandomSign(pConcealmentInfo->iRandomPhase,
  5910. - pSpectralCoefficient, samplesPerFrame);
  5911. - /* Increment random phase index to avoid repetition artifacts. */
  5912. - pConcealmentInfo->iRandomPhase =
  5913. - (pConcealmentInfo->iRandomPhase + 1) & (AAC_NF_NO_RANDOM_VAL - 1);
  5914. - }
  5915. -
  5916. - /* scale spectrum according to concealment state */
  5917. - switch (pConcealmentInfo->concealState) {
  5918. - case ConcealState_Single:
  5919. - appliedProcessing = 1;
  5920. - break;
  5921. -
  5922. - case ConcealState_FadeOut: {
  5923. - FDK_ASSERT(pConcealmentInfo->cntFadeFrames >= 0);
  5924. - FDK_ASSERT(pConcealmentInfo->cntFadeFrames <
  5925. - CONCEAL_MAX_NUM_FADE_FACTORS);
  5926. - FDK_ASSERT(pConcealmentInfo->cntFadeFrames <
  5927. - pConcealCommonData->numFadeOutFrames);
  5928. -
  5929. - /* TimeDomainFading: */
  5930. - /* Attenuation of signal is done in CConcealment_TDFading() */
  5931. -
  5932. - appliedProcessing = 1;
  5933. - } break;
  5934. -
  5935. - case ConcealState_FadeIn: {
  5936. - FDK_ASSERT(pConcealmentInfo->cntFadeFrames >= 0);
  5937. - FDK_ASSERT(pConcealmentInfo->cntFadeFrames <
  5938. - CONCEAL_MAX_NUM_FADE_FACTORS);
  5939. - FDK_ASSERT(pConcealmentInfo->cntFadeFrames <
  5940. - pConcealCommonData->numFadeInFrames);
  5941. -
  5942. - /* TimeDomainFading: */
  5943. - /* Attenuation of signal is done in CConcealment_TDFading() */
  5944. -
  5945. - appliedProcessing = 1;
  5946. - } break;
  5947. -
  5948. - case ConcealState_Mute: {
  5949. - /* set dummy window parameters */
  5950. - pIcsInfo->Valid = 0; /* Trigger the generation of a consitent IcsInfo */
  5951. - pIcsInfo->WindowShape =
  5952. - pConcealmentInfo->windowShape; /* Prevent an invalid WindowShape
  5953. - (required for F/T transform) */
  5954. - pIcsInfo->WindowSequence =
  5955. - CConcealment_GetWinSeq(pConcealmentInfo->windowSequence);
  5956. - pConcealmentInfo->windowSequence =
  5957. - pIcsInfo->WindowSequence; /* Store for next frame
  5958. - (spectrum in concealment
  5959. - buffer can't be used at
  5960. - all) */
  5961. -
  5962. - /* mute spectral data */
  5963. - FDKmemclear(pSpectralCoefficient, samplesPerFrame * sizeof(FIXP_DBL));
  5964. -
  5965. - appliedProcessing = 1;
  5966. - } break;
  5967. -
  5968. - default:
  5969. - /* nothing to do here */
  5970. - break;
  5971. - }
  5972. -
  5973. - return appliedProcessing;
  5974. -}
  5975. -
  5976. -/*!
  5977. - \brief Calculate the spectral energy
  5978. -
  5979. - The function calculates band-wise the spectral energy. This is used for
  5980. - frame interpolation.
  5981. -*/
  5982. -static void CConcealment_CalcBandEnergy(
  5983. - FIXP_DBL *spectrum, const SamplingRateInfo *pSamplingRateInfo,
  5984. - const int blockType, CConcealmentExpandType expandType, int *sfbEnergy) {
  5985. - const SHORT *pSfbOffset;
  5986. - int line, sfb, scaleFactorBandsTotal = 0;
  5987. -
  5988. - /* In the following calculations, enAccu is initialized with LSB-value in
  5989. - * order to avoid zero energy-level */
  5990. -
  5991. - line = 0;
  5992. -
  5993. - switch (blockType) {
  5994. - case BLOCK_LONG:
  5995. - case BLOCK_START:
  5996. - case BLOCK_STOP:
  5997. -
  5998. - if (expandType == CConcealment_NoExpand) {
  5999. - /* standard long calculation */
  6000. - scaleFactorBandsTotal =
  6001. - pSamplingRateInfo->NumberOfScaleFactorBands_Long;
  6002. - pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Long;
  6003. -
  6004. - for (sfb = 0; sfb < scaleFactorBandsTotal; sfb++) {
  6005. - FIXP_DBL enAccu = (FIXP_DBL)(LONG)1;
  6006. - int sfbScale =
  6007. - (sizeof(LONG) << 3) -
  6008. - CntLeadingZeros(pSfbOffset[sfb + 1] - pSfbOffset[sfb]) - 1;
  6009. - /* scaling depends on sfb width. */
  6010. - for (; line < pSfbOffset[sfb + 1]; line++) {
  6011. - enAccu += fPow2Div2(*(spectrum + line)) >> sfbScale;
  6012. - }
  6013. - *(sfbEnergy + sfb) = CntLeadingZeros(enAccu) - 1;
  6014. - }
  6015. - } else {
  6016. - /* compress long to short */
  6017. - scaleFactorBandsTotal =
  6018. - pSamplingRateInfo->NumberOfScaleFactorBands_Short;
  6019. - pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Short;
  6020. -
  6021. - for (sfb = 0; sfb < scaleFactorBandsTotal; sfb++) {
  6022. - FIXP_DBL enAccu = (FIXP_DBL)(LONG)1;
  6023. - int sfbScale =
  6024. - (sizeof(LONG) << 3) -
  6025. - CntLeadingZeros(pSfbOffset[sfb + 1] - pSfbOffset[sfb]) - 1;
  6026. - /* scaling depends on sfb width. */
  6027. - for (; line < pSfbOffset[sfb + 1] << 3; line++) {
  6028. - enAccu +=
  6029. - (enAccu + (fPow2Div2(*(spectrum + line)) >> sfbScale)) >> 3;
  6030. - }
  6031. - *(sfbEnergy + sfb) = CntLeadingZeros(enAccu) - 1;
  6032. - }
  6033. - }
  6034. - break;
  6035. -
  6036. - case BLOCK_SHORT:
  6037. -
  6038. - if (expandType == CConcealment_NoExpand) {
  6039. - /* standard short calculation */
  6040. - scaleFactorBandsTotal =
  6041. - pSamplingRateInfo->NumberOfScaleFactorBands_Short;
  6042. - pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Short;
  6043. -
  6044. - for (sfb = 0; sfb < scaleFactorBandsTotal; sfb++) {
  6045. - FIXP_DBL enAccu = (FIXP_DBL)(LONG)1;
  6046. - int sfbScale =
  6047. - (sizeof(LONG) << 3) -
  6048. - CntLeadingZeros(pSfbOffset[sfb + 1] - pSfbOffset[sfb]) - 1;
  6049. - /* scaling depends on sfb width. */
  6050. - for (; line < pSfbOffset[sfb + 1]; line++) {
  6051. - enAccu += fPow2Div2(*(spectrum + line)) >> sfbScale;
  6052. - }
  6053. - *(sfbEnergy + sfb) = CntLeadingZeros(enAccu) - 1;
  6054. - }
  6055. - } else {
  6056. - /* expand short to long spectrum */
  6057. - scaleFactorBandsTotal =
  6058. - pSamplingRateInfo->NumberOfScaleFactorBands_Long;
  6059. - pSfbOffset = pSamplingRateInfo->ScaleFactorBands_Long;
  6060. -
  6061. - for (sfb = 0; sfb < scaleFactorBandsTotal; sfb++) {
  6062. - FIXP_DBL enAccu = (FIXP_DBL)(LONG)1;
  6063. - int sfbScale =
  6064. - (sizeof(LONG) << 3) -
  6065. - CntLeadingZeros(pSfbOffset[sfb + 1] - pSfbOffset[sfb]) - 1;
  6066. - /* scaling depends on sfb width. */
  6067. - for (; line < pSfbOffset[sfb + 1]; line++) {
  6068. - enAccu += fPow2Div2(*(spectrum + (line >> 3))) >> sfbScale;
  6069. - }
  6070. - *(sfbEnergy + sfb) = CntLeadingZeros(enAccu) - 1;
  6071. - }
  6072. - }
  6073. - break;
  6074. - }
  6075. -}
  6076. -
  6077. -/*!
  6078. - \brief Interpolate buffer
  6079. -
  6080. - The function creates the interpolated spectral data according to the
  6081. - energy of the last good frame and the current (good) frame.
  6082. -*/
  6083. -static void CConcealment_InterpolateBuffer(FIXP_DBL *spectrum,
  6084. - SHORT *pSpecScalePrv,
  6085. - SHORT *pSpecScaleAct,
  6086. - SHORT *pSpecScaleOut, int *enPrv,
  6087. - int *enAct, int sfbCnt,
  6088. - const SHORT *pSfbOffset) {
  6089. - int sfb, line = 0;
  6090. - int fac_shift;
  6091. - int fac_mod;
  6092. - FIXP_DBL accu;
  6093. -
  6094. - for (sfb = 0; sfb < sfbCnt; sfb++) {
  6095. - fac_shift =
  6096. - enPrv[sfb] - enAct[sfb] + ((*pSpecScaleAct - *pSpecScalePrv) << 1);
  6097. - fac_mod = fac_shift & 3;
  6098. - fac_shift = (fac_shift >> 2) + 1;
  6099. - fac_shift += *pSpecScalePrv - fixMax(*pSpecScalePrv, *pSpecScaleAct);
  6100. -
  6101. - for (; line < pSfbOffset[sfb + 1]; line++) {
  6102. - accu = fMult(*(spectrum + line), facMod4Table[fac_mod]);
  6103. - if (fac_shift < 0) {
  6104. - accu >>= -fac_shift;
  6105. - } else {
  6106. - accu <<= fac_shift;
  6107. - }
  6108. - *(spectrum + line) = accu;
  6109. - }
  6110. - }
  6111. - *pSpecScaleOut = fixMax(*pSpecScalePrv, *pSpecScaleAct);
  6112. -}
  6113. -
  6114. -/*!
  6115. - \brief Find next fading frame in case of changing fading direction
  6116. -
  6117. - \param pConcealCommonData Pointer to the concealment common data structure.
  6118. - \param actFadeIndex Last index used for fading
  6119. - \param direction Direction of change: 0 : change from FADE-OUT to FADE-IN, 1
  6120. - : change from FADE-IN to FADE-OUT
  6121. -
  6122. - This function determines the next fading index to be used for the fading
  6123. - direction to be changed to.
  6124. -*/
  6125. -
  6126. -static INT findEquiFadeFrame(CConcealParams *pConcealCommonData,
  6127. - INT actFadeIndex, int direction) {
  6128. - FIXP_SGL *pFactor;
  6129. - FIXP_SGL referenceVal;
  6130. - FIXP_SGL minDiff = (FIXP_SGL)MAXVAL_SGL;
  6131. -
  6132. - INT nextFadeIndex = 0;
  6133. -
  6134. - int i;
  6135. -
  6136. - /* init depending on direction */
  6137. - if (direction == 0) { /* FADE-OUT => FADE-IN */
  6138. - if (actFadeIndex < 0) {
  6139. - referenceVal = (FIXP_SGL)MAXVAL_SGL;
  6140. - } else {
  6141. - referenceVal = pConcealCommonData->fadeOutFactor[actFadeIndex] >> 1;
  6142. - }
  6143. - pFactor = pConcealCommonData->fadeInFactor;
  6144. - } else { /* FADE-IN => FADE-OUT */
  6145. - if (actFadeIndex < 0) {
  6146. - referenceVal = (FIXP_SGL)MAXVAL_SGL;
  6147. - } else {
  6148. - referenceVal = pConcealCommonData->fadeInFactor[actFadeIndex] >> 1;
  6149. - }
  6150. - pFactor = pConcealCommonData->fadeOutFactor;
  6151. - }
  6152. -
  6153. - /* search for minimum difference */
  6154. - for (i = 0; i < CONCEAL_MAX_NUM_FADE_FACTORS; i++) {
  6155. - FIXP_SGL diff = fixp_abs((pFactor[i] >> 1) - referenceVal);
  6156. - if (diff < minDiff) {
  6157. - minDiff = diff;
  6158. - nextFadeIndex = i;
  6159. - }
  6160. - }
  6161. -
  6162. - /* check and adjust depending on direction */
  6163. - if (direction == 0) { /* FADE-OUT => FADE-IN */
  6164. - if (nextFadeIndex > pConcealCommonData->numFadeInFrames) {
  6165. - nextFadeIndex = fMax(pConcealCommonData->numFadeInFrames - 1, 0);
  6166. - }
  6167. - if (((pFactor[nextFadeIndex] >> 1) <= referenceVal) &&
  6168. - (nextFadeIndex > 0)) {
  6169. - nextFadeIndex -= 1;
  6170. - }
  6171. - } else { /* FADE-IN => FADE-OUT */
  6172. - if (((pFactor[nextFadeIndex] >> 1) >= referenceVal) &&
  6173. - (nextFadeIndex < CONCEAL_MAX_NUM_FADE_FACTORS - 1)) {
  6174. - nextFadeIndex += 1;
  6175. - }
  6176. - }
  6177. -
  6178. - return (nextFadeIndex);
  6179. -}
  6180. -
  6181. -/*!
  6182. - \brief Update the concealment state
  6183. -
  6184. - The function updates the state of the concealment state-machine. The
  6185. - states are: mute, fade-in, fade-out, interpolate and frame-ok.
  6186. -*/
  6187. -static void CConcealment_UpdateState(
  6188. - CConcealmentInfo *pConcealmentInfo, int frameOk,
  6189. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  6190. - const int samplesPerFrame, CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
  6191. - CConcealParams *pConcealCommonData = pConcealmentInfo->pConcealParams;
  6192. -
  6193. - switch (pConcealCommonData->method) {
  6194. - case ConcealMethodNoise: {
  6195. - if (pConcealmentInfo->concealState != ConcealState_Ok) {
  6196. - /* count the valid frames during concealment process */
  6197. - if (frameOk) {
  6198. - pConcealmentInfo->cntValidFrames += 1;
  6199. - } else {
  6200. - pConcealmentInfo->cntValidFrames = 0;
  6201. - }
  6202. - }
  6203. -
  6204. - /* -- STATE MACHINE for Noise Substitution -- */
  6205. - switch (pConcealmentInfo->concealState) {
  6206. - case ConcealState_Ok:
  6207. - if (!frameOk) {
  6208. - pConcealmentInfo->cntFadeFrames = 0;
  6209. - pConcealmentInfo->cntValidFrames = 0;
  6210. - pConcealmentInfo->attGrpOffset[0] = 0;
  6211. - pConcealmentInfo->attGrpOffset[1] = 0;
  6212. - pConcealmentInfo->winGrpOffset[0] = 0;
  6213. - pConcealmentInfo->winGrpOffset[1] = 0;
  6214. - if (pConcealCommonData->numFadeOutFrames > 0) {
  6215. - /* change to state SINGLE-FRAME-LOSS */
  6216. - pConcealmentInfo->concealState = ConcealState_Single;
  6217. - /* mode 0 just updates the Fading counter */
  6218. - CConcealment_ApplyFadeOut(
  6219. - /*mode =*/0, pConcealmentInfo, pAacDecoderStaticChannelInfo,
  6220. - samplesPerFrame, pAacDecoderChannelInfo);
  6221. -
  6222. - } else {
  6223. - /* change to state MUTE */
  6224. - pConcealmentInfo->concealState = ConcealState_Mute;
  6225. - }
  6226. - }
  6227. - break;
  6228. -
  6229. - case ConcealState_Single: /* Just a pre-stage before fade-out begins.
  6230. - Stay here only one frame! */
  6231. - if (frameOk) {
  6232. - /* change to state OK */
  6233. - pConcealmentInfo->concealState = ConcealState_Ok;
  6234. - } else {
  6235. - if (pConcealmentInfo->cntFadeFrames >=
  6236. - pConcealCommonData->numFadeOutFrames) {
  6237. - /* change to state MUTE */
  6238. - pConcealmentInfo->concealState = ConcealState_Mute;
  6239. - } else {
  6240. - /* change to state FADE-OUT */
  6241. - pConcealmentInfo->concealState = ConcealState_FadeOut;
  6242. - /* mode 0 just updates the Fading counter */
  6243. - CConcealment_ApplyFadeOut(
  6244. - /*mode =*/0, pConcealmentInfo, pAacDecoderStaticChannelInfo,
  6245. - samplesPerFrame, pAacDecoderChannelInfo);
  6246. - }
  6247. - }
  6248. - break;
  6249. -
  6250. - case ConcealState_FadeOut:
  6251. - if (pConcealmentInfo->cntValidFrames >
  6252. - pConcealCommonData->numMuteReleaseFrames) {
  6253. - if (pConcealCommonData->numFadeInFrames > 0) {
  6254. - /* change to state FADE-IN */
  6255. - pConcealmentInfo->concealState = ConcealState_FadeIn;
  6256. - pConcealmentInfo->cntFadeFrames = findEquiFadeFrame(
  6257. - pConcealCommonData, pConcealmentInfo->cntFadeFrames,
  6258. - 0 /* FadeOut -> FadeIn */);
  6259. - } else {
  6260. - /* change to state OK */
  6261. - pConcealmentInfo->concealState = ConcealState_Ok;
  6262. - }
  6263. - } else {
  6264. - if (frameOk) {
  6265. - /* we have good frame information but stay fully in concealment -
  6266. - * reset winGrpOffset/attGrpOffset */
  6267. - pConcealmentInfo->winGrpOffset[0] = 0;
  6268. - pConcealmentInfo->winGrpOffset[1] = 0;
  6269. - pConcealmentInfo->attGrpOffset[0] = 0;
  6270. - pConcealmentInfo->attGrpOffset[1] = 0;
  6271. - }
  6272. - if (pConcealmentInfo->cntFadeFrames >=
  6273. - pConcealCommonData->numFadeOutFrames) {
  6274. - /* change to state MUTE */
  6275. - pConcealmentInfo->concealState = ConcealState_Mute;
  6276. - } else /* Stay in FADE-OUT */
  6277. - {
  6278. - /* mode 0 just updates the Fading counter */
  6279. - CConcealment_ApplyFadeOut(
  6280. - /*mode =*/0, pConcealmentInfo, pAacDecoderStaticChannelInfo,
  6281. - samplesPerFrame, pAacDecoderChannelInfo);
  6282. - }
  6283. - }
  6284. - break;
  6285. -
  6286. - case ConcealState_Mute:
  6287. - if (pConcealmentInfo->cntValidFrames >
  6288. - pConcealCommonData->numMuteReleaseFrames) {
  6289. - if (pConcealCommonData->numFadeInFrames > 0) {
  6290. - /* change to state FADE-IN */
  6291. - pConcealmentInfo->concealState = ConcealState_FadeIn;
  6292. - pConcealmentInfo->cntFadeFrames =
  6293. - pConcealCommonData->numFadeInFrames - 1;
  6294. - } else {
  6295. - /* change to state OK */
  6296. - pConcealmentInfo->concealState = ConcealState_Ok;
  6297. - }
  6298. - } else {
  6299. - if (frameOk) {
  6300. - /* we have good frame information but stay fully in concealment -
  6301. - * reset winGrpOffset/attGrpOffset */
  6302. - pConcealmentInfo->winGrpOffset[0] = 0;
  6303. - pConcealmentInfo->winGrpOffset[1] = 0;
  6304. - pConcealmentInfo->attGrpOffset[0] = 0;
  6305. - pConcealmentInfo->attGrpOffset[1] = 0;
  6306. - }
  6307. - }
  6308. - break;
  6309. -
  6310. - case ConcealState_FadeIn:
  6311. - pConcealmentInfo->cntFadeFrames -= 1;
  6312. - if (frameOk) {
  6313. - if (pConcealmentInfo->cntFadeFrames < 0) {
  6314. - /* change to state OK */
  6315. - pConcealmentInfo->concealState = ConcealState_Ok;
  6316. - }
  6317. - } else {
  6318. - if (pConcealCommonData->numFadeOutFrames > 0) {
  6319. - /* change to state FADE-OUT */
  6320. - pConcealmentInfo->concealState = ConcealState_FadeOut;
  6321. - pConcealmentInfo->cntFadeFrames = findEquiFadeFrame(
  6322. - pConcealCommonData, pConcealmentInfo->cntFadeFrames + 1,
  6323. - 1 /* FadeIn -> FadeOut */);
  6324. - pConcealmentInfo->winGrpOffset[0] = 0;
  6325. - pConcealmentInfo->winGrpOffset[1] = 0;
  6326. - pConcealmentInfo->attGrpOffset[0] = 0;
  6327. - pConcealmentInfo->attGrpOffset[1] = 0;
  6328. -
  6329. - pConcealmentInfo
  6330. - ->cntFadeFrames--; /* decrease because
  6331. - CConcealment_ApplyFadeOut() will
  6332. - increase, accordingly */
  6333. - /* mode 0 just updates the Fading counter */
  6334. - CConcealment_ApplyFadeOut(
  6335. - /*mode =*/0, pConcealmentInfo, pAacDecoderStaticChannelInfo,
  6336. - samplesPerFrame, pAacDecoderChannelInfo);
  6337. - } else {
  6338. - /* change to state MUTE */
  6339. - pConcealmentInfo->concealState = ConcealState_Mute;
  6340. - }
  6341. - }
  6342. - break;
  6343. -
  6344. - default:
  6345. - FDK_ASSERT(0);
  6346. - break;
  6347. - }
  6348. - } break;
  6349. -
  6350. - case ConcealMethodInter:
  6351. - case ConcealMethodTonal: {
  6352. - if (pConcealmentInfo->concealState != ConcealState_Ok) {
  6353. - /* count the valid frames during concealment process */
  6354. - if (pConcealmentInfo->prevFrameOk[1] ||
  6355. - (pConcealmentInfo->prevFrameOk[0] &&
  6356. - !pConcealmentInfo->prevFrameOk[1] && frameOk)) {
  6357. - /* The frame is OK even if it can be estimated by the energy
  6358. - * interpolation algorithm */
  6359. - pConcealmentInfo->cntValidFrames += 1;
  6360. - } else {
  6361. - pConcealmentInfo->cntValidFrames = 0;
  6362. - }
  6363. - }
  6364. -
  6365. - /* -- STATE MACHINE for energy interpolation -- */
  6366. - switch (pConcealmentInfo->concealState) {
  6367. - case ConcealState_Ok:
  6368. - if (!(pConcealmentInfo->prevFrameOk[1] ||
  6369. - (pConcealmentInfo->prevFrameOk[0] &&
  6370. - !pConcealmentInfo->prevFrameOk[1] && frameOk))) {
  6371. - if (pConcealCommonData->numFadeOutFrames > 0) {
  6372. - /* Fade out only if the energy interpolation algorithm can not be
  6373. - * applied! */
  6374. - pConcealmentInfo->concealState = ConcealState_FadeOut;
  6375. - } else {
  6376. - /* change to state MUTE */
  6377. - pConcealmentInfo->concealState = ConcealState_Mute;
  6378. - }
  6379. - pConcealmentInfo->cntFadeFrames = 0;
  6380. - pConcealmentInfo->cntValidFrames = 0;
  6381. - }
  6382. - break;
  6383. -
  6384. - case ConcealState_Single:
  6385. - pConcealmentInfo->concealState = ConcealState_Ok;
  6386. - break;
  6387. -
  6388. - case ConcealState_FadeOut:
  6389. - pConcealmentInfo->cntFadeFrames += 1;
  6390. -
  6391. - if (pConcealmentInfo->cntValidFrames >
  6392. - pConcealCommonData->numMuteReleaseFrames) {
  6393. - if (pConcealCommonData->numFadeInFrames > 0) {
  6394. - /* change to state FADE-IN */
  6395. - pConcealmentInfo->concealState = ConcealState_FadeIn;
  6396. - pConcealmentInfo->cntFadeFrames = findEquiFadeFrame(
  6397. - pConcealCommonData, pConcealmentInfo->cntFadeFrames - 1,
  6398. - 0 /* FadeOut -> FadeIn */);
  6399. - } else {
  6400. - /* change to state OK */
  6401. - pConcealmentInfo->concealState = ConcealState_Ok;
  6402. - }
  6403. - } else {
  6404. - if (pConcealmentInfo->cntFadeFrames >=
  6405. - pConcealCommonData->numFadeOutFrames) {
  6406. - /* change to state MUTE */
  6407. - pConcealmentInfo->concealState = ConcealState_Mute;
  6408. - }
  6409. - }
  6410. - break;
  6411. -
  6412. - case ConcealState_Mute:
  6413. - if (pConcealmentInfo->cntValidFrames >
  6414. - pConcealCommonData->numMuteReleaseFrames) {
  6415. - if (pConcealCommonData->numFadeInFrames > 0) {
  6416. - /* change to state FADE-IN */
  6417. - pConcealmentInfo->concealState = ConcealState_FadeIn;
  6418. - pConcealmentInfo->cntFadeFrames =
  6419. - pConcealCommonData->numFadeInFrames - 1;
  6420. - } else {
  6421. - /* change to state OK */
  6422. - pConcealmentInfo->concealState = ConcealState_Ok;
  6423. - }
  6424. - }
  6425. - break;
  6426. -
  6427. - case ConcealState_FadeIn:
  6428. - pConcealmentInfo->cntFadeFrames -=
  6429. - 1; /* used to address the fade-in factors */
  6430. -
  6431. - if (frameOk || pConcealmentInfo->prevFrameOk[1]) {
  6432. - if (pConcealmentInfo->cntFadeFrames < 0) {
  6433. - /* change to state OK */
  6434. - pConcealmentInfo->concealState = ConcealState_Ok;
  6435. - }
  6436. - } else {
  6437. - if (pConcealCommonData->numFadeOutFrames > 0) {
  6438. - /* change to state FADE-OUT */
  6439. - pConcealmentInfo->concealState = ConcealState_FadeOut;
  6440. - pConcealmentInfo->cntFadeFrames = findEquiFadeFrame(
  6441. - pConcealCommonData, pConcealmentInfo->cntFadeFrames + 1,
  6442. - 1 /* FadeIn -> FadeOut */);
  6443. - } else {
  6444. - /* change to state MUTE */
  6445. - pConcealmentInfo->concealState = ConcealState_Mute;
  6446. - }
  6447. - }
  6448. - break;
  6449. - } /* End switch(pConcealmentInfo->concealState) */
  6450. - } break;
  6451. -
  6452. - default:
  6453. - /* Don't need a state machine for other concealment methods. */
  6454. - break;
  6455. - }
  6456. -}
  6457. -
  6458. -/*!
  6459. -\brief Randomizes the sign of the spectral data
  6460. -
  6461. - The function toggles the sign of the spectral data randomly. This is
  6462. - useful to ensure the quality of the concealed frames.
  6463. - */
  6464. -static void CConcealment_ApplyRandomSign(int randomPhase, FIXP_DBL *spec,
  6465. - int samplesPerFrame) {
  6466. - int i;
  6467. - USHORT packedSign = 0;
  6468. -
  6469. - /* random table 512x16bit has been reduced to 512 packed sign bits = 32x16 bit
  6470. - */
  6471. -
  6472. - /* read current packed sign word */
  6473. - packedSign = AacDec_randomSign[randomPhase >> 4];
  6474. - packedSign >>= (randomPhase & 0xf);
  6475. -
  6476. - for (i = 0; i < samplesPerFrame; i++) {
  6477. - if ((randomPhase & 0xf) == 0) {
  6478. - packedSign = AacDec_randomSign[randomPhase >> 4];
  6479. - }
  6480. -
  6481. - if (packedSign & 0x1) {
  6482. - spec[i] = -spec[i];
  6483. - }
  6484. - packedSign >>= 1;
  6485. -
  6486. - randomPhase = (randomPhase + 1) & (AAC_NF_NO_RANDOM_VAL - 1);
  6487. - }
  6488. -}
  6489. -
  6490. -/*!
  6491. - \brief Get fadeing factor for current concealment state.
  6492. -
  6493. - The function returns the state (ok or not) of the previous frame.
  6494. - If called before the function CConcealment_Apply() set the fBeforeApply
  6495. - flag to get the correct value.
  6496. -
  6497. - \return Frame OK flag of previous frame.
  6498. - */
  6499. -int CConcealment_GetLastFrameOk(CConcealmentInfo *hConcealmentInfo,
  6500. - const int fBeforeApply) {
  6501. - int prevFrameOk = 1;
  6502. -
  6503. - if (hConcealmentInfo != NULL) {
  6504. - prevFrameOk = hConcealmentInfo->prevFrameOk[fBeforeApply & 0x1];
  6505. - }
  6506. -
  6507. - return prevFrameOk;
  6508. -}
  6509. -
  6510. -/*!
  6511. - \brief Get the number of delay frames introduced by concealment technique.
  6512. -
  6513. - \return Number of delay frames.
  6514. - */
  6515. -UINT CConcealment_GetDelay(CConcealParams *pConcealCommonData) {
  6516. - UINT frameDelay = 0;
  6517. -
  6518. - if (pConcealCommonData != NULL) {
  6519. - switch (pConcealCommonData->method) {
  6520. - case ConcealMethodTonal:
  6521. - case ConcealMethodInter:
  6522. - frameDelay = 1;
  6523. - break;
  6524. - default:
  6525. - break;
  6526. - }
  6527. - }
  6528. -
  6529. - return frameDelay;
  6530. -}
  6531. -
  6532. -static int CConcealment_ApplyFadeOut(
  6533. - int mode, CConcealmentInfo *pConcealmentInfo,
  6534. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  6535. - const int samplesPerFrame, CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
  6536. - /* mode 1 = apply RandomSign and mute spectral coefficients if necessary, *
  6537. - * mode 0 = Update cntFadeFrames */
  6538. -
  6539. - /* restore frequency coefficients from buffer with a specific muting */
  6540. - int srcWin, dstWin, numWindows = 1;
  6541. - int windowLen = samplesPerFrame;
  6542. - int srcGrpStart = 0;
  6543. - int winIdxStride = 1;
  6544. - int numWinGrpPerFac, attIdx, attIdxStride;
  6545. - int i;
  6546. - int appliedProcessing = 0;
  6547. -
  6548. - CIcsInfo *pIcsInfo = &pAacDecoderChannelInfo->icsInfo;
  6549. - FIXP_DBL *pSpectralCoefficient =
  6550. - SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient);
  6551. - SHORT *pSpecScale = pAacDecoderChannelInfo->specScale;
  6552. -
  6553. - /* set old window parameters */
  6554. - if (pConcealmentInfo->lastRenderMode == AACDEC_RENDER_LPD) {
  6555. - switch (pAacDecoderStaticChannelInfo->last_lpd_mode) {
  6556. - case 1:
  6557. - numWindows = 4;
  6558. - srcGrpStart = 3;
  6559. - windowLen = samplesPerFrame >> 2;
  6560. - break;
  6561. - case 2:
  6562. - numWindows = 2;
  6563. - srcGrpStart = 1;
  6564. - windowLen = samplesPerFrame >> 1;
  6565. - winIdxStride = 2;
  6566. - break;
  6567. - case 3:
  6568. - numWindows = 1;
  6569. - srcGrpStart = 0;
  6570. - windowLen = samplesPerFrame;
  6571. - winIdxStride = 4;
  6572. - break;
  6573. - }
  6574. - pConcealmentInfo->lastWinGrpLen = 1;
  6575. - } else {
  6576. - pIcsInfo->WindowShape = pConcealmentInfo->windowShape;
  6577. - pIcsInfo->WindowSequence = pConcealmentInfo->windowSequence;
  6578. -
  6579. - if (pConcealmentInfo->windowSequence == BLOCK_SHORT) {
  6580. - /* short block handling */
  6581. - numWindows = 8;
  6582. - windowLen = samplesPerFrame >> 3;
  6583. - srcGrpStart = numWindows - pConcealmentInfo->lastWinGrpLen;
  6584. - }
  6585. - }
  6586. -
  6587. - attIdxStride =
  6588. - fMax(1, (int)(numWindows / (pConcealmentInfo->lastWinGrpLen + 1)));
  6589. -
  6590. - /* load last state */
  6591. - attIdx = pConcealmentInfo->cntFadeFrames;
  6592. - numWinGrpPerFac = pConcealmentInfo->attGrpOffset[mode];
  6593. - srcWin = srcGrpStart + pConcealmentInfo->winGrpOffset[mode];
  6594. -
  6595. - FDK_ASSERT((srcGrpStart * windowLen + windowLen) <= samplesPerFrame);
  6596. - FDK_ASSERT((srcWin * windowLen + windowLen) <= 1024);
  6597. -
  6598. - for (dstWin = 0; dstWin < numWindows; dstWin += 1) {
  6599. - FIXP_CNCL *pCncl =
  6600. - pConcealmentInfo->spectralCoefficient + (srcWin * windowLen);
  6601. - FIXP_DBL *pOut = pSpectralCoefficient + (dstWin * windowLen);
  6602. -
  6603. - if (mode == 1) {
  6604. - /* mute if attIdx gets large enaugh */
  6605. - if (attIdx > pConcealmentInfo->pConcealParams->numFadeOutFrames) {
  6606. - FDKmemclear(pCncl, sizeof(FIXP_DBL) * windowLen);
  6607. - }
  6608. -
  6609. - /* restore frequency coefficients from buffer - attenuation is done later
  6610. - */
  6611. - for (i = 0; i < windowLen; i++) {
  6612. - pOut[i] = pCncl[i];
  6613. - }
  6614. -
  6615. - /* apply random change of sign for spectral coefficients */
  6616. - CConcealment_ApplyRandomSign(pConcealmentInfo->iRandomPhase, pOut,
  6617. - windowLen);
  6618. -
  6619. - /* Increment random phase index to avoid repetition artifacts. */
  6620. - pConcealmentInfo->iRandomPhase =
  6621. - (pConcealmentInfo->iRandomPhase + 1) & (AAC_NF_NO_RANDOM_VAL - 1);
  6622. -
  6623. - /* set old scale factors */
  6624. - pSpecScale[dstWin * winIdxStride] =
  6625. - pConcealmentInfo->specScale[srcWin * winIdxStride];
  6626. - }
  6627. -
  6628. - srcWin += 1;
  6629. -
  6630. - if (srcWin >= numWindows) {
  6631. - /* end of sequence -> rewind to first window of group */
  6632. - srcWin = srcGrpStart;
  6633. - numWinGrpPerFac += 1;
  6634. - if (numWinGrpPerFac >= attIdxStride) {
  6635. - numWinGrpPerFac = 0;
  6636. - attIdx += 1;
  6637. - }
  6638. - }
  6639. - }
  6640. -
  6641. - /* store current state */
  6642. -
  6643. - pConcealmentInfo->winGrpOffset[mode] = srcWin - srcGrpStart;
  6644. - FDK_ASSERT((pConcealmentInfo->winGrpOffset[mode] >= 0) &&
  6645. - (pConcealmentInfo->winGrpOffset[mode] < 8));
  6646. - pConcealmentInfo->attGrpOffset[mode] = numWinGrpPerFac;
  6647. - FDK_ASSERT((pConcealmentInfo->attGrpOffset[mode] >= 0) &&
  6648. - (pConcealmentInfo->attGrpOffset[mode] < attIdxStride));
  6649. -
  6650. - if (mode == 0) {
  6651. - pConcealmentInfo->cntFadeFrames = attIdx;
  6652. - }
  6653. -
  6654. - appliedProcessing = 1;
  6655. -
  6656. - return appliedProcessing;
  6657. -}
  6658. -
  6659. -/*!
  6660. - \brief Do Time domain fading (TDFading) in concealment case
  6661. -
  6662. - In case of concealment, this function takes care of the fading, after time
  6663. -domain signal has been rendered by the respective signal rendering functions.
  6664. - The fading out in case of ACELP decoding is not done by this function but by
  6665. -the ACELP decoder for the first concealed frame if CONCEAL_CORE_IGNORANT_FADE is
  6666. -not set.
  6667. -
  6668. - TimeDomain fading never creates jumps in energy / discontinuities, it always
  6669. -does a continuous fading. To achieve this, fading is always done from a starting
  6670. -point to a target point, while the starting point is always determined to be the
  6671. -last target point. By varying the target point of a fading, the fading slope can
  6672. -be controlled.
  6673. -
  6674. - This principle is applied to the fading within a frame and the fading from
  6675. -frame to frame.
  6676. -
  6677. - One frame is divided into 8 subframes to obtain 8 parts of fading slopes
  6678. -within a frame, each maybe with its own gradient.
  6679. -
  6680. - Workflow:
  6681. - 1.) Determine Fading behavior and end-of-frame target fading level, based on
  6682. -concealmentState (determined by CConcealment_UpdateState()) and the core mode.
  6683. - - By _DEFAULT_,
  6684. - The target fading level is determined by fadeOutFactor[cntFadeFrames]
  6685. -in case of fadeOut, or fadeInFactor[cntFadeFrames] in case of fadeIn.
  6686. - --> fading type is FADE_TIMEDOMAIN in this case. Target fading level
  6687. -is determined by fading index cntFadeFrames.
  6688. -
  6689. - - If concealmentState is signalling a _MUTED SIGNAL_,
  6690. - TDFading decays to 0 within 1/8th of a frame if numFadeOutFrames == 0.
  6691. - --> fading type is FADE_TIMEDOMAIN_TOSPECTRALMUTE in this case.
  6692. -
  6693. - - If concealmentState is signalling the _END OF MUTING_,
  6694. - TDFading fades to target fading level within 1/8th of a frame if
  6695. -numFadeInFrames == 0.
  6696. - --> fading type is FADE_TIMEDOMAIN_FROMSPECTRALMUTE in this case.
  6697. -Target fading level is determined by fading index cntFadeFrames.
  6698. -
  6699. -#ifndef CONCEAL_CORE_IGNORANT_FADE
  6700. - - In case of an _ACELP FADEOUT_,
  6701. - TDFading leaves fading control to ACELP decoder for 1/2 frame.
  6702. - --> fading type is FADE_ACELPDOMAIN in this case.
  6703. -#endif
  6704. -
  6705. - 2.) Render fading levels within current frame and do the final fading:
  6706. - Map Fading slopes to fading levels and apply to time domain signal.
  6707. -
  6708. -
  6709. -*/
  6710. -
  6711. -INT CConcealment_TDFading(
  6712. - int len, CAacDecoderStaticChannelInfo **ppAacDecoderStaticChannelInfo,
  6713. - FIXP_PCM *pcmdata, FIXP_PCM *pcmdata_1) {
  6714. - /*
  6715. - Do the fading in Time domain based on concealment states and core mode
  6716. - */
  6717. - FIXP_DBL fadeStop, attMute = (FIXP_DBL)0;
  6718. - int idx = 0, ii;
  6719. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo =
  6720. - *ppAacDecoderStaticChannelInfo;
  6721. - CConcealmentInfo *pConcealmentInfo =
  6722. - &pAacDecoderStaticChannelInfo->concealmentInfo;
  6723. - CConcealParams *pConcealParams = pConcealmentInfo->pConcealParams;
  6724. - const CConcealmentState concealState = pConcealmentInfo->concealState;
  6725. - TDfadingType fadingType;
  6726. - FIXP_DBL fadingStations[9] = {0};
  6727. - int fadingSteps[8] = {0};
  6728. - const FIXP_DBL fadeStart =
  6729. - pConcealmentInfo
  6730. - ->fade_old; /* start fading at last end-of-frame attenuation */
  6731. - FIXP_SGL *fadeFactor = pConcealParams->fadeOutFactor;
  6732. - const INT cntFadeFrames = pConcealmentInfo->cntFadeFrames;
  6733. - int TDFadeOutStopBeforeMute = 1;
  6734. - int TDFadeInStopBeforeFullLevel = 1;
  6735. -
  6736. - /*
  6737. - determine Fading behaviour (end-of-frame attenuation and fading type) (1.)
  6738. - */
  6739. -
  6740. - switch (concealState) {
  6741. - case ConcealState_Single:
  6742. - case ConcealState_Mute:
  6743. - case ConcealState_FadeOut:
  6744. - idx = (pConcealParams->method == ConcealMethodNoise) ? cntFadeFrames - 1
  6745. - : cntFadeFrames;
  6746. - fadingType = FADE_TIMEDOMAIN;
  6747. -
  6748. - if (concealState == ConcealState_Mute ||
  6749. - (cntFadeFrames + TDFadeOutStopBeforeMute) >
  6750. - pConcealmentInfo->pConcealParams->numFadeOutFrames) {
  6751. - fadingType = FADE_TIMEDOMAIN_TOSPECTRALMUTE;
  6752. - }
  6753. -
  6754. - break;
  6755. - case ConcealState_FadeIn:
  6756. - idx = cntFadeFrames;
  6757. - idx -= TDFadeInStopBeforeFullLevel;
  6758. - FDK_FALLTHROUGH;
  6759. - case ConcealState_Ok:
  6760. - fadeFactor = pConcealParams->fadeInFactor;
  6761. - idx = (concealState == ConcealState_Ok) ? -1 : idx;
  6762. - fadingType = (pConcealmentInfo->concealState_old == ConcealState_Mute)
  6763. - ? FADE_TIMEDOMAIN_FROMSPECTRALMUTE
  6764. - : FADE_TIMEDOMAIN;
  6765. - break;
  6766. - default:
  6767. - FDK_ASSERT(0);
  6768. - fadingType = FADE_TIMEDOMAIN_TOSPECTRALMUTE;
  6769. - break;
  6770. - }
  6771. -
  6772. - /* determine Target end-of-frame fading level and fading slope */
  6773. - switch (fadingType) {
  6774. - case FADE_TIMEDOMAIN_FROMSPECTRALMUTE:
  6775. - fadeStop =
  6776. - (idx < 0) ? (FIXP_DBL)MAXVAL_DBL : FX_SGL2FX_DBL(fadeFactor[idx]);
  6777. - if (pConcealmentInfo->pConcealParams->numFadeInFrames == 0) {
  6778. - /* do step as fast as possible */
  6779. - fadingSteps[0] = 1;
  6780. - break;
  6781. - }
  6782. - CConcealment_TDFading_doLinearFadingSteps(&fadingSteps[0]);
  6783. - break;
  6784. - case FADE_TIMEDOMAIN:
  6785. - fadeStop =
  6786. - (idx < 0) ? (FIXP_DBL)MAXVAL_DBL : FX_SGL2FX_DBL(fadeFactor[idx]);
  6787. - CConcealment_TDFading_doLinearFadingSteps(&fadingSteps[0]);
  6788. - break;
  6789. - case FADE_TIMEDOMAIN_TOSPECTRALMUTE:
  6790. - fadeStop = attMute;
  6791. - if (pConcealmentInfo->pConcealParams->numFadeOutFrames == 0) {
  6792. - /* do step as fast as possible */
  6793. - fadingSteps[0] = 1;
  6794. - break;
  6795. - }
  6796. - CConcealment_TDFading_doLinearFadingSteps(&fadingSteps[0]);
  6797. - break;
  6798. - }
  6799. -
  6800. - /*
  6801. - Render fading levels within current frame and do the final fading (2.)
  6802. - */
  6803. -
  6804. - len >>= 3;
  6805. - CConcealment_TDFadeFillFadingStations(fadingStations, fadingSteps, fadeStop,
  6806. - fadeStart, fadingType);
  6807. -
  6808. - if ((fadingStations[8] != (FIXP_DBL)MAXVAL_DBL) ||
  6809. - (fadingStations[7] != (FIXP_DBL)MAXVAL_DBL) ||
  6810. - (fadingStations[6] != (FIXP_DBL)MAXVAL_DBL) ||
  6811. - (fadingStations[5] != (FIXP_DBL)MAXVAL_DBL) ||
  6812. - (fadingStations[4] != (FIXP_DBL)MAXVAL_DBL) ||
  6813. - (fadingStations[3] != (FIXP_DBL)MAXVAL_DBL) ||
  6814. - (fadingStations[2] != (FIXP_DBL)MAXVAL_DBL) ||
  6815. - (fadingStations[1] != (FIXP_DBL)MAXVAL_DBL) ||
  6816. - (fadingStations[0] !=
  6817. - (FIXP_DBL)MAXVAL_DBL)) /* if there's something to fade */
  6818. - {
  6819. - int start = 0;
  6820. - for (ii = 0; ii < 8; ii++) {
  6821. - CConcealment_TDFadePcmAtt(start, len, fadingStations[ii],
  6822. - fadingStations[ii + 1], pcmdata);
  6823. - start += len;
  6824. - }
  6825. - }
  6826. - CConcealment_TDNoise_Apply(pConcealmentInfo, len, pcmdata);
  6827. -
  6828. - /* Save end-of-frame attenuation and fading type */
  6829. - pConcealmentInfo->lastFadingType = fadingType;
  6830. - pConcealmentInfo->fade_old = fadeStop;
  6831. - pConcealmentInfo->concealState_old = concealState;
  6832. -
  6833. - return 1;
  6834. -}
  6835. -
  6836. -/* attenuate pcmdata in Time Domain Fading process */
  6837. -static void CConcealment_TDFadePcmAtt(int start, int len, FIXP_DBL fadeStart,
  6838. - FIXP_DBL fadeStop, FIXP_PCM *pcmdata) {
  6839. - int i;
  6840. - FIXP_DBL dStep;
  6841. - FIXP_DBL dGain;
  6842. - FIXP_DBL dGain_apply;
  6843. - int bitshift = (DFRACT_BITS - SAMPLE_BITS);
  6844. -
  6845. - /* set start energy */
  6846. - dGain = fadeStart;
  6847. - /* determine energy steps from sample to sample */
  6848. - dStep = (FIXP_DBL)((int)((fadeStart >> 1) - (fadeStop >> 1)) / len) << 1;
  6849. -
  6850. - for (i = start; i < (start + len); i++) {
  6851. - dGain -= dStep;
  6852. - /* prevent gain from getting negative due to possible fixpoint inaccuracies
  6853. - */
  6854. - dGain_apply = fMax((FIXP_DBL)0, dGain);
  6855. - /* finally, attenuate samples */
  6856. - pcmdata[i] = (FIXP_PCM)((fMult(pcmdata[i], (dGain_apply))) >> bitshift);
  6857. - }
  6858. -}
  6859. -
  6860. -/*
  6861. -\brief Fill FadingStations
  6862. -
  6863. -The fadingstations are the attenuation factors, being applied to its dedicated
  6864. -portions of pcm data. They are calculated using the fadingsteps. One fadingstep
  6865. -is the weighted contribution to the fading slope within its dedicated portion of
  6866. -pcm data.
  6867. -
  6868. -*Fadingsteps : 0 0 0 1 0 1 2 0
  6869. -
  6870. - |<- 1 Frame pcm data ->|
  6871. - fadeStart-->|__________ |
  6872. - ^ ^ ^ ^ \____ |
  6873. - Attenuation : | | | | ^ ^\__ |
  6874. - | | | | | | ^\ |
  6875. - | | | | | | | \___|<-- fadeStop
  6876. - | | | | | | | ^ ^
  6877. - | | | | | | | | |
  6878. -Fadingstations: [0][1][2][3][4][5][6][7][8]
  6879. -
  6880. -(Fadingstations "[0]" is "[8] from previous frame", therefore its not meaningful
  6881. -to be edited)
  6882. -
  6883. -*/
  6884. -static void CConcealment_TDFadeFillFadingStations(FIXP_DBL *fadingStations,
  6885. - int *fadingSteps,
  6886. - FIXP_DBL fadeStop,
  6887. - FIXP_DBL fadeStart,
  6888. - TDfadingType fadingType) {
  6889. - int i;
  6890. - INT fadingSteps_sum = 0;
  6891. - INT fadeDiff;
  6892. -
  6893. - fadingSteps_sum = fadingSteps[0] + fadingSteps[1] + fadingSteps[2] +
  6894. - fadingSteps[3] + fadingSteps[4] + fadingSteps[5] +
  6895. - fadingSteps[6] + fadingSteps[7];
  6896. - fadeDiff = ((INT)(fadeStop - fadeStart) / fMax(fadingSteps_sum, (INT)1));
  6897. - fadingStations[0] = fadeStart;
  6898. - for (i = 1; i < 8; i++) {
  6899. - fadingStations[i] =
  6900. - fadingStations[i - 1] + (FIXP_DBL)(fadeDiff * fadingSteps[i - 1]);
  6901. - }
  6902. - fadingStations[8] = fadeStop;
  6903. -}
  6904. -
  6905. -static void CConcealment_TDFading_doLinearFadingSteps(int *fadingSteps) {
  6906. - fadingSteps[0] = fadingSteps[1] = fadingSteps[2] = fadingSteps[3] =
  6907. - fadingSteps[4] = fadingSteps[5] = fadingSteps[6] = fadingSteps[7] = 1;
  6908. -}
  6909. -
  6910. -/* end of TimeDomainFading functions */
  6911. -
  6912. -/* derived from int UsacRandomSign() */
  6913. -static int CConcealment_TDNoise_Random(ULONG *seed) {
  6914. - *seed = (ULONG)(((UINT64)(*seed) * 69069) + 5);
  6915. - return (int)(*seed);
  6916. -}
  6917. -
  6918. -static void CConcealment_TDNoise_Apply(CConcealmentInfo *const pConcealmentInfo,
  6919. - const int len, FIXP_PCM *const pcmdata) {
  6920. - FIXP_PCM *states = pConcealmentInfo->TDNoiseStates;
  6921. - FIXP_PCM noiseVal;
  6922. - FIXP_DBL noiseValLong;
  6923. - FIXP_SGL *coef = pConcealmentInfo->TDNoiseCoef;
  6924. - FIXP_DBL TDNoiseAtt;
  6925. - ULONG seed = pConcealmentInfo->TDNoiseSeed =
  6926. - (ULONG)CConcealment_TDNoise_Random(&pConcealmentInfo->TDNoiseSeed) + 1;
  6927. -
  6928. - TDNoiseAtt = pConcealmentInfo->pConcealParams->comfortNoiseLevel;
  6929. -
  6930. - int ii;
  6931. -
  6932. - if ((pConcealmentInfo->concealState != ConcealState_Ok ||
  6933. - pConcealmentInfo->concealState_old != ConcealState_Ok) &&
  6934. - TDNoiseAtt != (FIXP_DBL)0) {
  6935. - for (ii = 0; ii < (len << 3); ii++) {
  6936. - /* create filtered noise */
  6937. - states[2] = states[1];
  6938. - states[1] = states[0];
  6939. - states[0] = ((FIXP_PCM)CConcealment_TDNoise_Random(&seed));
  6940. - noiseValLong = fMult(states[0], coef[0]) + fMult(states[1], coef[1]) +
  6941. - fMult(states[2], coef[2]);
  6942. - noiseVal = FX_DBL2FX_PCM(fMult(noiseValLong, TDNoiseAtt));
  6943. -
  6944. - /* add filtered noise - check for clipping, before */
  6945. - if (noiseVal > (FIXP_PCM)0 &&
  6946. - pcmdata[ii] > (FIXP_PCM)MAXVAL_FIXP_PCM - noiseVal) {
  6947. - noiseVal = noiseVal * (FIXP_PCM)-1;
  6948. - } else if (noiseVal < (FIXP_PCM)0 &&
  6949. - pcmdata[ii] < (FIXP_PCM)MINVAL_FIXP_PCM - noiseVal) {
  6950. - noiseVal = noiseVal * (FIXP_PCM)-1;
  6951. - }
  6952. -
  6953. - pcmdata[ii] += noiseVal;
  6954. - }
  6955. - }
  6956. -}
  6957. diff --git a/libAACdec/src/conceal.h b/libAACdec/src/conceal.h
  6958. deleted file mode 100644
  6959. index e01a796..0000000
  6960. --- a/libAACdec/src/conceal.h
  6961. +++ /dev/null
  6962. @@ -1,152 +0,0 @@
  6963. -/* -----------------------------------------------------------------------------
  6964. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  6965. -
  6966. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  6967. -Forschung e.V. All rights reserved.
  6968. -
  6969. - 1. INTRODUCTION
  6970. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  6971. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  6972. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  6973. -a wide variety of Android devices.
  6974. -
  6975. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  6976. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  6977. -full-bandwidth communications codec by independent studies and is widely
  6978. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  6979. -specifications.
  6980. -
  6981. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  6982. -those of Fraunhofer) may be obtained through Via Licensing
  6983. -(www.vialicensing.com) or through the respective patent owners individually for
  6984. -the purpose of encoding or decoding bit streams in products that are compliant
  6985. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  6986. -Android devices already license these patent claims through Via Licensing or
  6987. -directly from the patent owners, and therefore FDK AAC Codec software may
  6988. -already be covered under those patent licenses when it is used for those
  6989. -licensed purposes only.
  6990. -
  6991. -Commercially-licensed AAC software libraries, including floating-point versions
  6992. -with enhanced sound quality, are also available from Fraunhofer. Users are
  6993. -encouraged to check the Fraunhofer website for additional applications
  6994. -information and documentation.
  6995. -
  6996. -2. COPYRIGHT LICENSE
  6997. -
  6998. -Redistribution and use in source and binary forms, with or without modification,
  6999. -are permitted without payment of copyright license fees provided that you
  7000. -satisfy the following conditions:
  7001. -
  7002. -You must retain the complete text of this software license in redistributions of
  7003. -the FDK AAC Codec or your modifications thereto in source code form.
  7004. -
  7005. -You must retain the complete text of this software license in the documentation
  7006. -and/or other materials provided with redistributions of the FDK AAC Codec or
  7007. -your modifications thereto in binary form. You must make available free of
  7008. -charge copies of the complete source code of the FDK AAC Codec and your
  7009. -modifications thereto to recipients of copies in binary form.
  7010. -
  7011. -The name of Fraunhofer may not be used to endorse or promote products derived
  7012. -from this library without prior written permission.
  7013. -
  7014. -You may not charge copyright license fees for anyone to use, copy or distribute
  7015. -the FDK AAC Codec software or your modifications thereto.
  7016. -
  7017. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  7018. -that you changed the software and the date of any change. For modified versions
  7019. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  7020. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  7021. -AAC Codec Library for Android."
  7022. -
  7023. -3. NO PATENT LICENSE
  7024. -
  7025. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  7026. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  7027. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  7028. -software.
  7029. -
  7030. -You may use this FDK AAC Codec software or modifications thereto only for
  7031. -purposes that are authorized by appropriate patent licenses.
  7032. -
  7033. -4. DISCLAIMER
  7034. -
  7035. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  7036. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  7037. -including but not limited to the implied warranties of merchantability and
  7038. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  7039. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  7040. -or consequential damages, including but not limited to procurement of substitute
  7041. -goods or services; loss of use, data, or profits, or business interruption,
  7042. -however caused and on any theory of liability, whether in contract, strict
  7043. -liability, or tort (including negligence), arising in any way out of the use of
  7044. -this software, even if advised of the possibility of such damage.
  7045. -
  7046. -5. CONTACT INFORMATION
  7047. -
  7048. -Fraunhofer Institute for Integrated Circuits IIS
  7049. -Attention: Audio and Multimedia Departments - FDK AAC LL
  7050. -Am Wolfsmantel 33
  7051. -91058 Erlangen, Germany
  7052. -
  7053. -www.iis.fraunhofer.de/amm
  7054. -amm-info@iis.fraunhofer.de
  7055. ------------------------------------------------------------------------------ */
  7056. -
  7057. -/**************************** AAC decoder library ******************************
  7058. -
  7059. - Author(s): Josef Hoepfl
  7060. -
  7061. - Description: independent channel concealment
  7062. -
  7063. -*******************************************************************************/
  7064. -
  7065. -#ifndef CONCEAL_H
  7066. -#define CONCEAL_H
  7067. -
  7068. -#include "channelinfo.h"
  7069. -
  7070. -#define AACDEC_CONCEAL_PARAM_NOT_SPECIFIED (0xFFFE)
  7071. -
  7072. -void CConcealment_InitCommonData(CConcealParams *pConcealCommonData);
  7073. -
  7074. -void CConcealment_InitChannelData(CConcealmentInfo *hConcealmentInfo,
  7075. - CConcealParams *pConcealCommonData,
  7076. - AACDEC_RENDER_MODE initRenderMode,
  7077. - int samplesPerFrame);
  7078. -
  7079. -CConcealmentMethod CConcealment_GetMethod(CConcealParams *pConcealCommonData);
  7080. -
  7081. -UINT CConcealment_GetDelay(CConcealParams *pConcealCommonData);
  7082. -
  7083. -AAC_DECODER_ERROR
  7084. -CConcealment_SetParams(CConcealParams *concealParams, int method,
  7085. - int fadeOutSlope, int fadeInSlope, int muteRelease,
  7086. - FIXP_DBL comfNoiseLevel);
  7087. -
  7088. -CConcealmentState CConcealment_GetState(CConcealmentInfo *hConcealmentInfo);
  7089. -
  7090. -AAC_DECODER_ERROR
  7091. -CConcealment_SetAttenuation(CConcealParams *concealParams,
  7092. - const SHORT *fadeOutAttenuationVector,
  7093. - const SHORT *fadeInAttenuationVector);
  7094. -
  7095. -void CConcealment_Store(
  7096. - CConcealmentInfo *hConcealmentInfo,
  7097. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  7098. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo);
  7099. -
  7100. -int CConcealment_Apply(
  7101. - CConcealmentInfo *hConcealmentInfo,
  7102. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  7103. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  7104. - const SamplingRateInfo *pSamplingRateInfo, const int samplesPerFrame,
  7105. - const UCHAR lastLpdMode, const int FrameOk, const UINT flags);
  7106. -
  7107. -int CConcealment_GetLastFrameOk(CConcealmentInfo *hConcealmentInfo,
  7108. - const int fBeforeApply);
  7109. -
  7110. -INT CConcealment_TDFading(
  7111. - int len, CAacDecoderStaticChannelInfo **ppAacDecoderStaticChannelInfo,
  7112. - FIXP_PCM *pcmdata, FIXP_PCM *pcmdata_1);
  7113. -
  7114. -#endif /* #ifndef CONCEAL_H */
  7115. diff --git a/libAACdec/src/conceal_types.h b/libAACdec/src/conceal_types.h
  7116. deleted file mode 100644
  7117. index d90374e..0000000
  7118. --- a/libAACdec/src/conceal_types.h
  7119. +++ /dev/null
  7120. @@ -1,203 +0,0 @@
  7121. -/* -----------------------------------------------------------------------------
  7122. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  7123. -
  7124. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  7125. -Forschung e.V. All rights reserved.
  7126. -
  7127. - 1. INTRODUCTION
  7128. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  7129. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  7130. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  7131. -a wide variety of Android devices.
  7132. -
  7133. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  7134. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  7135. -full-bandwidth communications codec by independent studies and is widely
  7136. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  7137. -specifications.
  7138. -
  7139. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  7140. -those of Fraunhofer) may be obtained through Via Licensing
  7141. -(www.vialicensing.com) or through the respective patent owners individually for
  7142. -the purpose of encoding or decoding bit streams in products that are compliant
  7143. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  7144. -Android devices already license these patent claims through Via Licensing or
  7145. -directly from the patent owners, and therefore FDK AAC Codec software may
  7146. -already be covered under those patent licenses when it is used for those
  7147. -licensed purposes only.
  7148. -
  7149. -Commercially-licensed AAC software libraries, including floating-point versions
  7150. -with enhanced sound quality, are also available from Fraunhofer. Users are
  7151. -encouraged to check the Fraunhofer website for additional applications
  7152. -information and documentation.
  7153. -
  7154. -2. COPYRIGHT LICENSE
  7155. -
  7156. -Redistribution and use in source and binary forms, with or without modification,
  7157. -are permitted without payment of copyright license fees provided that you
  7158. -satisfy the following conditions:
  7159. -
  7160. -You must retain the complete text of this software license in redistributions of
  7161. -the FDK AAC Codec or your modifications thereto in source code form.
  7162. -
  7163. -You must retain the complete text of this software license in the documentation
  7164. -and/or other materials provided with redistributions of the FDK AAC Codec or
  7165. -your modifications thereto in binary form. You must make available free of
  7166. -charge copies of the complete source code of the FDK AAC Codec and your
  7167. -modifications thereto to recipients of copies in binary form.
  7168. -
  7169. -The name of Fraunhofer may not be used to endorse or promote products derived
  7170. -from this library without prior written permission.
  7171. -
  7172. -You may not charge copyright license fees for anyone to use, copy or distribute
  7173. -the FDK AAC Codec software or your modifications thereto.
  7174. -
  7175. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  7176. -that you changed the software and the date of any change. For modified versions
  7177. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  7178. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  7179. -AAC Codec Library for Android."
  7180. -
  7181. -3. NO PATENT LICENSE
  7182. -
  7183. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  7184. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  7185. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  7186. -software.
  7187. -
  7188. -You may use this FDK AAC Codec software or modifications thereto only for
  7189. -purposes that are authorized by appropriate patent licenses.
  7190. -
  7191. -4. DISCLAIMER
  7192. -
  7193. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  7194. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  7195. -including but not limited to the implied warranties of merchantability and
  7196. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  7197. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  7198. -or consequential damages, including but not limited to procurement of substitute
  7199. -goods or services; loss of use, data, or profits, or business interruption,
  7200. -however caused and on any theory of liability, whether in contract, strict
  7201. -liability, or tort (including negligence), arising in any way out of the use of
  7202. -this software, even if advised of the possibility of such damage.
  7203. -
  7204. -5. CONTACT INFORMATION
  7205. -
  7206. -Fraunhofer Institute for Integrated Circuits IIS
  7207. -Attention: Audio and Multimedia Departments - FDK AAC LL
  7208. -Am Wolfsmantel 33
  7209. -91058 Erlangen, Germany
  7210. -
  7211. -www.iis.fraunhofer.de/amm
  7212. -amm-info@iis.fraunhofer.de
  7213. ------------------------------------------------------------------------------ */
  7214. -
  7215. -/**************************** AAC decoder library ******************************
  7216. -
  7217. - Author(s): Christian Griebel
  7218. -
  7219. - Description: Error concealment structs and types
  7220. -
  7221. -*******************************************************************************/
  7222. -
  7223. -#ifndef CONCEAL_TYPES_H
  7224. -#define CONCEAL_TYPES_H
  7225. -
  7226. -#include "machine_type.h"
  7227. -#include "common_fix.h"
  7228. -
  7229. -#include "rvlc_info.h"
  7230. -
  7231. -#include "usacdec_lpc.h"
  7232. -
  7233. -#define CONCEAL_MAX_NUM_FADE_FACTORS (32)
  7234. -
  7235. -#define FIXP_CNCL FIXP_DBL
  7236. -#define FL2FXCONST_CNCL FL2FXCONST_DBL
  7237. -#define FX_DBL2FX_CNCL
  7238. -#define FX_CNCL2FX_DBL
  7239. -#define CNCL_FRACT_BITS DFRACT_BITS
  7240. -
  7241. -/* Warning: Do not ever change these values. */
  7242. -typedef enum {
  7243. - ConcealMethodNone = -1,
  7244. - ConcealMethodMute = 0,
  7245. - ConcealMethodNoise = 1,
  7246. - ConcealMethodInter = 2,
  7247. - ConcealMethodTonal = 3
  7248. -
  7249. -} CConcealmentMethod;
  7250. -
  7251. -typedef enum {
  7252. - ConcealState_Ok,
  7253. - ConcealState_Single,
  7254. - ConcealState_FadeIn,
  7255. - ConcealState_Mute,
  7256. - ConcealState_FadeOut
  7257. -
  7258. -} CConcealmentState;
  7259. -
  7260. -typedef struct {
  7261. - FIXP_SGL fadeOutFactor[CONCEAL_MAX_NUM_FADE_FACTORS];
  7262. - FIXP_SGL fadeInFactor[CONCEAL_MAX_NUM_FADE_FACTORS];
  7263. -
  7264. - CConcealmentMethod method;
  7265. -
  7266. - int numFadeOutFrames;
  7267. - int numFadeInFrames;
  7268. - int numMuteReleaseFrames;
  7269. - FIXP_DBL comfortNoiseLevel;
  7270. -
  7271. -} CConcealParams;
  7272. -
  7273. -typedef enum {
  7274. - FADE_TIMEDOMAIN_TOSPECTRALMUTE = 1,
  7275. - FADE_TIMEDOMAIN_FROMSPECTRALMUTE,
  7276. - FADE_TIMEDOMAIN
  7277. -} TDfadingType;
  7278. -
  7279. -typedef struct {
  7280. - CConcealParams *pConcealParams;
  7281. -
  7282. - FIXP_CNCL spectralCoefficient[1024];
  7283. - SHORT specScale[8];
  7284. -
  7285. - INT iRandomPhase;
  7286. - INT prevFrameOk[2];
  7287. - INT cntValidFrames;
  7288. - INT cntFadeFrames; /* State for signal fade-in/out */
  7289. - /* States for signal fade-out of frames with more than one window/subframe -
  7290. - [0] used by Update CntFadeFrames mode of CConcealment_ApplyFadeOut, [1] used
  7291. - by FadeOut mode */
  7292. - int winGrpOffset[2]; /* State for signal fade-out of frames with more than one
  7293. - window/subframe */
  7294. - int attGrpOffset[2]; /* State for faster signal fade-out of frames with
  7295. - transient signal parts */
  7296. -
  7297. - SCHAR lastRenderMode;
  7298. -
  7299. - UCHAR windowShape;
  7300. - BLOCK_TYPE windowSequence;
  7301. - UCHAR lastWinGrpLen;
  7302. -
  7303. - CConcealmentState concealState;
  7304. - CConcealmentState concealState_old;
  7305. - FIXP_DBL fade_old; /* last fading factor */
  7306. - TDfadingType lastFadingType; /* last fading type */
  7307. -
  7308. - SHORT aRvlcPreviousScaleFactor[RVLC_MAX_SFB]; /* needed once per channel */
  7309. - UCHAR aRvlcPreviousCodebook[RVLC_MAX_SFB]; /* needed once per channel */
  7310. - SCHAR rvlcPreviousScaleFactorOK;
  7311. - SCHAR rvlcPreviousBlockType;
  7312. -
  7313. - FIXP_LPC lsf4[M_LP_FILTER_ORDER];
  7314. - FIXP_DBL last_tcx_gain;
  7315. - INT last_tcx_gain_e;
  7316. - ULONG TDNoiseSeed;
  7317. - FIXP_PCM TDNoiseStates[3];
  7318. - FIXP_SGL TDNoiseCoef[3];
  7319. - FIXP_SGL TDNoiseAtt;
  7320. -
  7321. -} CConcealmentInfo;
  7322. -
  7323. -#endif /* #ifndef CONCEAL_TYPES_H */
  7324. diff --git a/libAACdec/src/rvlc.cpp b/libAACdec/src/rvlc.cpp
  7325. deleted file mode 100644
  7326. index b7a9be1..0000000
  7327. --- a/libAACdec/src/rvlc.cpp
  7328. +++ /dev/null
  7329. @@ -1,1217 +0,0 @@
  7330. -/* -----------------------------------------------------------------------------
  7331. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  7332. -
  7333. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  7334. -Forschung e.V. All rights reserved.
  7335. -
  7336. - 1. INTRODUCTION
  7337. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  7338. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  7339. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  7340. -a wide variety of Android devices.
  7341. -
  7342. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  7343. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  7344. -full-bandwidth communications codec by independent studies and is widely
  7345. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  7346. -specifications.
  7347. -
  7348. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  7349. -those of Fraunhofer) may be obtained through Via Licensing
  7350. -(www.vialicensing.com) or through the respective patent owners individually for
  7351. -the purpose of encoding or decoding bit streams in products that are compliant
  7352. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  7353. -Android devices already license these patent claims through Via Licensing or
  7354. -directly from the patent owners, and therefore FDK AAC Codec software may
  7355. -already be covered under those patent licenses when it is used for those
  7356. -licensed purposes only.
  7357. -
  7358. -Commercially-licensed AAC software libraries, including floating-point versions
  7359. -with enhanced sound quality, are also available from Fraunhofer. Users are
  7360. -encouraged to check the Fraunhofer website for additional applications
  7361. -information and documentation.
  7362. -
  7363. -2. COPYRIGHT LICENSE
  7364. -
  7365. -Redistribution and use in source and binary forms, with or without modification,
  7366. -are permitted without payment of copyright license fees provided that you
  7367. -satisfy the following conditions:
  7368. -
  7369. -You must retain the complete text of this software license in redistributions of
  7370. -the FDK AAC Codec or your modifications thereto in source code form.
  7371. -
  7372. -You must retain the complete text of this software license in the documentation
  7373. -and/or other materials provided with redistributions of the FDK AAC Codec or
  7374. -your modifications thereto in binary form. You must make available free of
  7375. -charge copies of the complete source code of the FDK AAC Codec and your
  7376. -modifications thereto to recipients of copies in binary form.
  7377. -
  7378. -The name of Fraunhofer may not be used to endorse or promote products derived
  7379. -from this library without prior written permission.
  7380. -
  7381. -You may not charge copyright license fees for anyone to use, copy or distribute
  7382. -the FDK AAC Codec software or your modifications thereto.
  7383. -
  7384. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  7385. -that you changed the software and the date of any change. For modified versions
  7386. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  7387. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  7388. -AAC Codec Library for Android."
  7389. -
  7390. -3. NO PATENT LICENSE
  7391. -
  7392. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  7393. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  7394. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  7395. -software.
  7396. -
  7397. -You may use this FDK AAC Codec software or modifications thereto only for
  7398. -purposes that are authorized by appropriate patent licenses.
  7399. -
  7400. -4. DISCLAIMER
  7401. -
  7402. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  7403. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  7404. -including but not limited to the implied warranties of merchantability and
  7405. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  7406. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  7407. -or consequential damages, including but not limited to procurement of substitute
  7408. -goods or services; loss of use, data, or profits, or business interruption,
  7409. -however caused and on any theory of liability, whether in contract, strict
  7410. -liability, or tort (including negligence), arising in any way out of the use of
  7411. -this software, even if advised of the possibility of such damage.
  7412. -
  7413. -5. CONTACT INFORMATION
  7414. -
  7415. -Fraunhofer Institute for Integrated Circuits IIS
  7416. -Attention: Audio and Multimedia Departments - FDK AAC LL
  7417. -Am Wolfsmantel 33
  7418. -91058 Erlangen, Germany
  7419. -
  7420. -www.iis.fraunhofer.de/amm
  7421. -amm-info@iis.fraunhofer.de
  7422. ------------------------------------------------------------------------------ */
  7423. -
  7424. -/**************************** AAC decoder library ******************************
  7425. -
  7426. - Author(s):
  7427. -
  7428. - Description:
  7429. -
  7430. -*******************************************************************************/
  7431. -
  7432. -/*!
  7433. - \file
  7434. - \brief RVLC Decoder
  7435. - \author Robert Weidner
  7436. -*/
  7437. -
  7438. -#include "rvlc.h"
  7439. -
  7440. -#include "block.h"
  7441. -
  7442. -#include "aac_rom.h"
  7443. -#include "rvlcbit.h"
  7444. -#include "rvlcconceal.h"
  7445. -#include "aacdec_hcr.h"
  7446. -
  7447. -/*---------------------------------------------------------------------------------------------
  7448. - function: rvlcInit
  7449. -
  7450. - description: init RVLC by data from channelinfo, which was decoded
  7451. -previously and set up pointers
  7452. ------------------------------------------------------------------------------------------------
  7453. - input: - pointer rvlc structure
  7454. - - pointer channel info structure
  7455. - - pointer bitstream structure
  7456. ------------------------------------------------------------------------------------------------
  7457. - return: -
  7458. ---------------------------------------------------------------------------------------------
  7459. -*/
  7460. -
  7461. -static void rvlcInit(CErRvlcInfo *pRvlc,
  7462. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  7463. - HANDLE_FDK_BITSTREAM bs) {
  7464. - /* RVLC common initialization part 2 of 2 */
  7465. - SHORT *pScfEsc = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfEsc;
  7466. - SHORT *pScfFwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd;
  7467. - SHORT *pScfBwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd;
  7468. - SHORT *pScaleFactor = pAacDecoderChannelInfo->pDynData->aScaleFactor;
  7469. - int bnds;
  7470. -
  7471. - pAacDecoderChannelInfo->pDynData->specificTo.aac.rvlcIntensityUsed = 0;
  7472. -
  7473. - pRvlc->numDecodedEscapeWordsEsc = 0;
  7474. - pRvlc->numDecodedEscapeWordsFwd = 0;
  7475. - pRvlc->numDecodedEscapeWordsBwd = 0;
  7476. -
  7477. - pRvlc->intensity_used = 0;
  7478. - pRvlc->errorLogRvlc = 0;
  7479. -
  7480. - pRvlc->conceal_max = CONCEAL_MAX_INIT;
  7481. - pRvlc->conceal_min = CONCEAL_MIN_INIT;
  7482. -
  7483. - pRvlc->conceal_max_esc = CONCEAL_MAX_INIT;
  7484. - pRvlc->conceal_min_esc = CONCEAL_MIN_INIT;
  7485. -
  7486. - pRvlc->pHuffTreeRvlcEscape = aHuffTreeRvlcEscape;
  7487. - pRvlc->pHuffTreeRvlCodewds = aHuffTreeRvlCodewds;
  7488. -
  7489. - /* init scf arrays (for savety (in case of there are only zero codebooks)) */
  7490. - for (bnds = 0; bnds < RVLC_MAX_SFB; bnds++) {
  7491. - pScfFwd[bnds] = 0;
  7492. - pScfBwd[bnds] = 0;
  7493. - pScfEsc[bnds] = 0;
  7494. - pScaleFactor[bnds] = 0;
  7495. - }
  7496. -
  7497. - /* set base bitstream ptr to the RVL-coded part (start of RVLC data (ESC 2))
  7498. - */
  7499. - FDKsyncCache(bs);
  7500. - pRvlc->bsAnchor = (INT)FDKgetValidBits(bs);
  7501. -
  7502. - pRvlc->bitstreamIndexRvlFwd =
  7503. - 0; /* first bit within RVL coded block as start address for forward
  7504. - decoding */
  7505. - pRvlc->bitstreamIndexRvlBwd =
  7506. - pRvlc->length_of_rvlc_sf - 1; /* last bit within RVL coded block as start
  7507. - address for backward decoding */
  7508. -
  7509. - /* skip RVLC-bitstream-part -- pointing now to escapes (if present) or to TNS
  7510. - * data (if present) */
  7511. - FDKpushFor(bs, pRvlc->length_of_rvlc_sf);
  7512. -
  7513. - if (pRvlc->sf_escapes_present != 0) {
  7514. - /* locate internal bitstream ptr at escapes (which is the second part) */
  7515. - FDKsyncCache(bs);
  7516. - pRvlc->bitstreamIndexEsc = pRvlc->bsAnchor - (INT)FDKgetValidBits(bs);
  7517. -
  7518. - /* skip escapeRVLC-bitstream-part -- pointing to TNS data (if present) to
  7519. - * make decoder continue */
  7520. - /* decoding of RVLC should work despite this second pushFor during
  7521. - * initialization because */
  7522. - /* bitstream initialization is valid for both ESC2 data parts (RVL-coded
  7523. - * values and ESC-coded values) */
  7524. - FDKpushFor(bs, pRvlc->length_of_rvlc_escapes);
  7525. - }
  7526. -}
  7527. -
  7528. -/*---------------------------------------------------------------------------------------------
  7529. - function: rvlcCheckIntensityCb
  7530. -
  7531. - description: Check if a intensity codebook is used in the current channel.
  7532. ------------------------------------------------------------------------------------------------
  7533. - input: - pointer rvlc structure
  7534. - - pointer channel info structure
  7535. ------------------------------------------------------------------------------------------------
  7536. - output: - intensity_used: 0 no intensity codebook is used
  7537. - 1 intensity codebook is used
  7538. ------------------------------------------------------------------------------------------------
  7539. - return: -
  7540. ---------------------------------------------------------------------------------------------
  7541. -*/
  7542. -
  7543. -static void rvlcCheckIntensityCb(
  7544. - CErRvlcInfo *pRvlc, CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
  7545. - int group, band, bnds;
  7546. -
  7547. - pRvlc->intensity_used = 0;
  7548. -
  7549. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  7550. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  7551. - bnds = 16 * group + band;
  7552. - if ((pAacDecoderChannelInfo->pDynData->aCodeBook[bnds] ==
  7553. - INTENSITY_HCB) ||
  7554. - (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds] ==
  7555. - INTENSITY_HCB2)) {
  7556. - pRvlc->intensity_used = 1;
  7557. - break;
  7558. - }
  7559. - }
  7560. - }
  7561. -}
  7562. -
  7563. -/*---------------------------------------------------------------------------------------------
  7564. - function: rvlcDecodeEscapeWord
  7565. -
  7566. - description: Decode a huffman coded RVLC Escape-word. This value is part
  7567. -of a DPCM coded scalefactor.
  7568. ------------------------------------------------------------------------------------------------
  7569. - input: - pointer rvlc structure
  7570. ------------------------------------------------------------------------------------------------
  7571. - return: - a single RVLC-Escape value which had to be applied to a
  7572. -DPCM value (which has a absolute value of 7)
  7573. ---------------------------------------------------------------------------------------------
  7574. -*/
  7575. -
  7576. -static SCHAR rvlcDecodeEscapeWord(CErRvlcInfo *pRvlc, HANDLE_FDK_BITSTREAM bs) {
  7577. - int i;
  7578. - SCHAR value;
  7579. - UCHAR carryBit;
  7580. - UINT treeNode;
  7581. - UINT branchValue;
  7582. - UINT branchNode;
  7583. -
  7584. - INT *pBitstreamIndexEsc;
  7585. - const UINT *pEscTree;
  7586. -
  7587. - pEscTree = pRvlc->pHuffTreeRvlcEscape;
  7588. - pBitstreamIndexEsc = &(pRvlc->bitstreamIndexEsc);
  7589. - treeNode = *pEscTree; /* init at starting node */
  7590. -
  7591. - for (i = MAX_LEN_RVLC_ESCAPE_WORD - 1; i >= 0; i--) {
  7592. - carryBit =
  7593. - rvlcReadBitFromBitstream(bs, /* get next bit */
  7594. - pRvlc->bsAnchor, pBitstreamIndexEsc, FWD);
  7595. -
  7596. - CarryBitToBranchValue(carryBit, /* huffman decoding, do a single step in
  7597. - huffman decoding tree */
  7598. - treeNode, &branchValue, &branchNode);
  7599. -
  7600. - if ((branchNode & TEST_BIT_10) ==
  7601. - TEST_BIT_10) { /* test bit 10 ; if set --> a RVLC-escape-word is
  7602. - completely decoded */
  7603. - value = (SCHAR)branchNode & CLR_BIT_10;
  7604. - pRvlc->length_of_rvlc_escapes -= (MAX_LEN_RVLC_ESCAPE_WORD - i);
  7605. -
  7606. - if (pRvlc->length_of_rvlc_escapes < 0) {
  7607. - pRvlc->errorLogRvlc |= RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID;
  7608. - value = -1;
  7609. - }
  7610. -
  7611. - return value;
  7612. - } else {
  7613. - treeNode = *(
  7614. - pEscTree +
  7615. - branchValue); /* update treeNode for further step in decoding tree */
  7616. - }
  7617. - }
  7618. -
  7619. - pRvlc->errorLogRvlc |= RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID;
  7620. -
  7621. - return -1; /* should not be reached */
  7622. -}
  7623. -
  7624. -/*---------------------------------------------------------------------------------------------
  7625. - function: rvlcDecodeEscapes
  7626. -
  7627. - description: Decodes all huffman coded RVLC Escape Words.
  7628. - Here a difference to the pseudo-code-implementation from
  7629. -standard can be found. A while loop (and not two nested for loops) is used for
  7630. -two reasons:
  7631. -
  7632. - 1. The plain huffman encoded escapes are decoded before the
  7633. -RVL-coded scalefactors. Therefore the escapes are present in the second step
  7634. - when decoding the RVL-coded-scalefactor values in forward
  7635. -and backward direction.
  7636. -
  7637. - When the RVL-coded scalefactors are decoded and there a
  7638. -escape is needed, then it is just taken out of the array in ascending order.
  7639. -
  7640. - 2. It's faster.
  7641. ------------------------------------------------------------------------------------------------
  7642. - input: - pointer rvlc structure
  7643. - - handle to FDK bitstream
  7644. ------------------------------------------------------------------------------------------------
  7645. - return: - 0 ok the decoded escapes seem to be valid
  7646. - - 1 error there was a error detected during decoding escapes
  7647. - --> all escapes are invalid
  7648. ---------------------------------------------------------------------------------------------
  7649. -*/
  7650. -
  7651. -static void rvlcDecodeEscapes(CErRvlcInfo *pRvlc, SHORT *pEsc,
  7652. - HANDLE_FDK_BITSTREAM bs) {
  7653. - SCHAR escWord;
  7654. - SCHAR escCnt = 0;
  7655. - SHORT *pEscBitCntSum;
  7656. -
  7657. - pEscBitCntSum = &(pRvlc->length_of_rvlc_escapes);
  7658. -
  7659. - /* Decode all RVLC-Escape words with a plain Huffman-Decoder */
  7660. - while (*pEscBitCntSum > 0) {
  7661. - escWord = rvlcDecodeEscapeWord(pRvlc, bs);
  7662. -
  7663. - if (escWord >= 0) {
  7664. - pEsc[escCnt] = escWord;
  7665. - escCnt++;
  7666. - } else {
  7667. - pRvlc->errorLogRvlc |= RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID;
  7668. - pRvlc->numDecodedEscapeWordsEsc = escCnt;
  7669. -
  7670. - return;
  7671. - }
  7672. - } /* all RVLC escapes decoded */
  7673. -
  7674. - pRvlc->numDecodedEscapeWordsEsc = escCnt;
  7675. -}
  7676. -
  7677. -/*---------------------------------------------------------------------------------------------
  7678. - function: decodeRVLCodeword
  7679. -
  7680. - description: Decodes a RVL-coded dpcm-word (-part).
  7681. ------------------------------------------------------------------------------------------------
  7682. - input: - FDK bitstream handle
  7683. - - pointer rvlc structure
  7684. ------------------------------------------------------------------------------------------------
  7685. - return: - a dpcm value which is within range [0,1,..,14] in case of
  7686. -no errors. The offset of 7 must be subtracted to get a valid dpcm scalefactor
  7687. -value. In case of errors a forbidden codeword is detected --> returning -1
  7688. ---------------------------------------------------------------------------------------------
  7689. -*/
  7690. -
  7691. -SCHAR decodeRVLCodeword(HANDLE_FDK_BITSTREAM bs, CErRvlcInfo *pRvlc) {
  7692. - int i;
  7693. - SCHAR value;
  7694. - UCHAR carryBit;
  7695. - UINT branchValue;
  7696. - UINT branchNode;
  7697. -
  7698. - const UINT *pRvlCodeTree = pRvlc->pHuffTreeRvlCodewds;
  7699. - UCHAR direction = pRvlc->direction;
  7700. - INT *pBitstrIndxRvl = pRvlc->pBitstrIndxRvl_RVL;
  7701. - UINT treeNode = *pRvlCodeTree;
  7702. -
  7703. - for (i = MAX_LEN_RVLC_CODE_WORD - 1; i >= 0; i--) {
  7704. - carryBit =
  7705. - rvlcReadBitFromBitstream(bs, /* get next bit */
  7706. - pRvlc->bsAnchor, pBitstrIndxRvl, direction);
  7707. -
  7708. - CarryBitToBranchValue(carryBit, /* huffman decoding, do a single step in
  7709. - huffman decoding tree */
  7710. - treeNode, &branchValue, &branchNode);
  7711. -
  7712. - if ((branchNode & TEST_BIT_10) ==
  7713. - TEST_BIT_10) { /* test bit 10 ; if set --> a
  7714. - RVLC-codeword is completely decoded
  7715. - */
  7716. - value = (SCHAR)(branchNode & CLR_BIT_10);
  7717. - *pRvlc->pRvlBitCnt_RVL -= (MAX_LEN_RVLC_CODE_WORD - i);
  7718. -
  7719. - /* check available bits for decoding */
  7720. - if (*pRvlc->pRvlBitCnt_RVL < 0) {
  7721. - if (direction == FWD) {
  7722. - pRvlc->errorLogRvlc |= RVLC_ERROR_RVL_SUM_BIT_COUNTER_BELOW_ZERO_FWD;
  7723. - } else {
  7724. - pRvlc->errorLogRvlc |= RVLC_ERROR_RVL_SUM_BIT_COUNTER_BELOW_ZERO_BWD;
  7725. - }
  7726. - value = -1; /* signalize an error in return value, because too many bits
  7727. - was decoded */
  7728. - }
  7729. -
  7730. - /* check max value of dpcm value */
  7731. - if (value > MAX_ALLOWED_DPCM_INDEX) {
  7732. - if (direction == FWD) {
  7733. - pRvlc->errorLogRvlc |= RVLC_ERROR_FORBIDDEN_CW_DETECTED_FWD;
  7734. - } else {
  7735. - pRvlc->errorLogRvlc |= RVLC_ERROR_FORBIDDEN_CW_DETECTED_BWD;
  7736. - }
  7737. - value = -1; /* signalize an error in return value, because a forbidden
  7738. - cw was detected*/
  7739. - }
  7740. -
  7741. - return value; /* return a dpcm value with offset +7 or an error status */
  7742. - } else {
  7743. - treeNode = *(
  7744. - pRvlCodeTree +
  7745. - branchValue); /* update treeNode for further step in decoding tree */
  7746. - }
  7747. - }
  7748. -
  7749. - return -1;
  7750. -}
  7751. -
  7752. -/*---------------------------------------------------------------------------------------------
  7753. - function: rvlcDecodeForward
  7754. -
  7755. - description: Decode RVL-coded codewords in forward direction.
  7756. ------------------------------------------------------------------------------------------------
  7757. - input: - pointer rvlc structure
  7758. - - pointer channel info structure
  7759. - - handle to FDK bitstream
  7760. ------------------------------------------------------------------------------------------------
  7761. - return: -
  7762. ---------------------------------------------------------------------------------------------
  7763. -*/
  7764. -
  7765. -static void rvlcDecodeForward(CErRvlcInfo *pRvlc,
  7766. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  7767. - HANDLE_FDK_BITSTREAM bs) {
  7768. - int band = 0;
  7769. - int group = 0;
  7770. - int bnds = 0;
  7771. -
  7772. - SHORT dpcm;
  7773. -
  7774. - SHORT factor =
  7775. - pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET;
  7776. - SHORT position = -SF_OFFSET;
  7777. - SHORT noisenrg = pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain -
  7778. - SF_OFFSET - 90 - 256;
  7779. -
  7780. - SHORT *pScfFwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd;
  7781. - SHORT *pScfEsc = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfEsc;
  7782. - UCHAR *pEscFwdCnt = &(pRvlc->numDecodedEscapeWordsFwd);
  7783. -
  7784. - pRvlc->pRvlBitCnt_RVL = &(pRvlc->length_of_rvlc_sf_fwd);
  7785. - pRvlc->pBitstrIndxRvl_RVL = &(pRvlc->bitstreamIndexRvlFwd);
  7786. -
  7787. - *pEscFwdCnt = 0;
  7788. - pRvlc->direction = FWD;
  7789. - pRvlc->noise_used = 0;
  7790. - pRvlc->sf_used = 0;
  7791. - pRvlc->lastScf = 0;
  7792. - pRvlc->lastNrg = 0;
  7793. - pRvlc->lastIs = 0;
  7794. -
  7795. - rvlcCheckIntensityCb(pRvlc, pAacDecoderChannelInfo);
  7796. -
  7797. - /* main loop fwd long */
  7798. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  7799. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  7800. - bnds = 16 * group + band;
  7801. -
  7802. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  7803. - case ZERO_HCB:
  7804. - pScfFwd[bnds] = 0;
  7805. - break;
  7806. -
  7807. - case INTENSITY_HCB2:
  7808. - case INTENSITY_HCB:
  7809. - /* store dpcm_is_position */
  7810. - dpcm = decodeRVLCodeword(bs, pRvlc);
  7811. - if (dpcm < 0) {
  7812. - pRvlc->conceal_max = bnds;
  7813. - return;
  7814. - }
  7815. - dpcm -= TABLE_OFFSET;
  7816. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  7817. - if (pRvlc->length_of_rvlc_escapes) {
  7818. - pRvlc->conceal_max = bnds;
  7819. - return;
  7820. - } else {
  7821. - if (dpcm == MIN_RVL) {
  7822. - dpcm -= *pScfEsc++;
  7823. - } else {
  7824. - dpcm += *pScfEsc++;
  7825. - }
  7826. - (*pEscFwdCnt)++;
  7827. - if (pRvlc->conceal_max_esc == CONCEAL_MAX_INIT) {
  7828. - pRvlc->conceal_max_esc = bnds;
  7829. - }
  7830. - }
  7831. - }
  7832. - position += dpcm;
  7833. - pScfFwd[bnds] = position;
  7834. - pRvlc->lastIs = position;
  7835. - break;
  7836. -
  7837. - case NOISE_HCB:
  7838. - if (pRvlc->noise_used == 0) {
  7839. - pRvlc->noise_used = 1;
  7840. - pRvlc->first_noise_band = bnds;
  7841. - noisenrg += pRvlc->dpcm_noise_nrg;
  7842. - pScfFwd[bnds] = 100 + noisenrg;
  7843. - pRvlc->lastNrg = noisenrg;
  7844. - } else {
  7845. - dpcm = decodeRVLCodeword(bs, pRvlc);
  7846. - if (dpcm < 0) {
  7847. - pRvlc->conceal_max = bnds;
  7848. - return;
  7849. - }
  7850. - dpcm -= TABLE_OFFSET;
  7851. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  7852. - if (pRvlc->length_of_rvlc_escapes) {
  7853. - pRvlc->conceal_max = bnds;
  7854. - return;
  7855. - } else {
  7856. - if (dpcm == MIN_RVL) {
  7857. - dpcm -= *pScfEsc++;
  7858. - } else {
  7859. - dpcm += *pScfEsc++;
  7860. - }
  7861. - (*pEscFwdCnt)++;
  7862. - if (pRvlc->conceal_max_esc == CONCEAL_MAX_INIT) {
  7863. - pRvlc->conceal_max_esc = bnds;
  7864. - }
  7865. - }
  7866. - }
  7867. - noisenrg += dpcm;
  7868. - pScfFwd[bnds] = 100 + noisenrg;
  7869. - pRvlc->lastNrg = noisenrg;
  7870. - }
  7871. - pAacDecoderChannelInfo->data.aac.PnsData.pnsUsed[bnds] = 1;
  7872. - break;
  7873. -
  7874. - default:
  7875. - pRvlc->sf_used = 1;
  7876. - dpcm = decodeRVLCodeword(bs, pRvlc);
  7877. - if (dpcm < 0) {
  7878. - pRvlc->conceal_max = bnds;
  7879. - return;
  7880. - }
  7881. - dpcm -= TABLE_OFFSET;
  7882. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  7883. - if (pRvlc->length_of_rvlc_escapes) {
  7884. - pRvlc->conceal_max = bnds;
  7885. - return;
  7886. - } else {
  7887. - if (dpcm == MIN_RVL) {
  7888. - dpcm -= *pScfEsc++;
  7889. - } else {
  7890. - dpcm += *pScfEsc++;
  7891. - }
  7892. - (*pEscFwdCnt)++;
  7893. - if (pRvlc->conceal_max_esc == CONCEAL_MAX_INIT) {
  7894. - pRvlc->conceal_max_esc = bnds;
  7895. - }
  7896. - }
  7897. - }
  7898. - factor += dpcm;
  7899. - pScfFwd[bnds] = factor;
  7900. - pRvlc->lastScf = factor;
  7901. - break;
  7902. - }
  7903. - }
  7904. - }
  7905. -
  7906. - /* postfetch fwd long */
  7907. - if (pRvlc->intensity_used) {
  7908. - dpcm = decodeRVLCodeword(bs, pRvlc); /* dpcm_is_last_position */
  7909. - if (dpcm < 0) {
  7910. - pRvlc->conceal_max = bnds;
  7911. - return;
  7912. - }
  7913. - dpcm -= TABLE_OFFSET;
  7914. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  7915. - if (pRvlc->length_of_rvlc_escapes) {
  7916. - pRvlc->conceal_max = bnds;
  7917. - return;
  7918. - } else {
  7919. - if (dpcm == MIN_RVL) {
  7920. - dpcm -= *pScfEsc++;
  7921. - } else {
  7922. - dpcm += *pScfEsc++;
  7923. - }
  7924. - (*pEscFwdCnt)++;
  7925. - if (pRvlc->conceal_max_esc == CONCEAL_MAX_INIT) {
  7926. - pRvlc->conceal_max_esc = bnds;
  7927. - }
  7928. - }
  7929. - }
  7930. - pRvlc->dpcm_is_last_position = dpcm;
  7931. - }
  7932. -}
  7933. -
  7934. -/*---------------------------------------------------------------------------------------------
  7935. - function: rvlcDecodeBackward
  7936. -
  7937. - description: Decode RVL-coded codewords in backward direction.
  7938. ------------------------------------------------------------------------------------------------
  7939. - input: - pointer rvlc structure
  7940. - - pointer channel info structure
  7941. - - handle FDK bitstream
  7942. ------------------------------------------------------------------------------------------------
  7943. - return: -
  7944. ---------------------------------------------------------------------------------------------
  7945. -*/
  7946. -
  7947. -static void rvlcDecodeBackward(CErRvlcInfo *pRvlc,
  7948. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  7949. - HANDLE_FDK_BITSTREAM bs) {
  7950. - SHORT band, group, dpcm, offset;
  7951. - SHORT bnds = pRvlc->maxSfbTransmitted - 1;
  7952. -
  7953. - SHORT factor = pRvlc->rev_global_gain - SF_OFFSET;
  7954. - SHORT position = pRvlc->dpcm_is_last_position - SF_OFFSET;
  7955. - SHORT noisenrg = pRvlc->rev_global_gain + pRvlc->dpcm_noise_last_position -
  7956. - SF_OFFSET - 90 - 256;
  7957. -
  7958. - SHORT *pScfBwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd;
  7959. - SHORT *pScfEsc = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfEsc;
  7960. - UCHAR *pEscEscCnt = &(pRvlc->numDecodedEscapeWordsEsc);
  7961. - UCHAR *pEscBwdCnt = &(pRvlc->numDecodedEscapeWordsBwd);
  7962. -
  7963. - pRvlc->pRvlBitCnt_RVL = &(pRvlc->length_of_rvlc_sf_bwd);
  7964. - pRvlc->pBitstrIndxRvl_RVL = &(pRvlc->bitstreamIndexRvlBwd);
  7965. -
  7966. - *pEscBwdCnt = 0;
  7967. - pRvlc->direction = BWD;
  7968. - pScfEsc += *pEscEscCnt - 1; /* set pScfEsc to last entry */
  7969. - pRvlc->firstScf = 0;
  7970. - pRvlc->firstNrg = 0;
  7971. - pRvlc->firstIs = 0;
  7972. -
  7973. - /* prefetch long BWD */
  7974. - if (pRvlc->intensity_used) {
  7975. - dpcm = decodeRVLCodeword(bs, pRvlc); /* dpcm_is_last_position */
  7976. - if (dpcm < 0) {
  7977. - pRvlc->dpcm_is_last_position = 0;
  7978. - pRvlc->conceal_min = bnds;
  7979. - return;
  7980. - }
  7981. - dpcm -= TABLE_OFFSET;
  7982. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  7983. - if (pRvlc->length_of_rvlc_escapes) {
  7984. - pRvlc->conceal_min = bnds;
  7985. - return;
  7986. - } else {
  7987. - if (dpcm == MIN_RVL) {
  7988. - dpcm -= *pScfEsc--;
  7989. - } else {
  7990. - dpcm += *pScfEsc--;
  7991. - }
  7992. - (*pEscBwdCnt)++;
  7993. - if (pRvlc->conceal_min_esc == CONCEAL_MIN_INIT) {
  7994. - pRvlc->conceal_min_esc = bnds;
  7995. - }
  7996. - }
  7997. - }
  7998. - pRvlc->dpcm_is_last_position = dpcm;
  7999. - }
  8000. -
  8001. - /* main loop long BWD */
  8002. - for (group = pRvlc->numWindowGroups - 1; group >= 0; group--) {
  8003. - for (band = pRvlc->maxSfbTransmitted - 1; band >= 0; band--) {
  8004. - bnds = 16 * group + band;
  8005. - if ((band == 0) && (pRvlc->numWindowGroups != 1))
  8006. - offset = 16 - pRvlc->maxSfbTransmitted + 1;
  8007. - else
  8008. - offset = 1;
  8009. -
  8010. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  8011. - case ZERO_HCB:
  8012. - pScfBwd[bnds] = 0;
  8013. - break;
  8014. -
  8015. - case INTENSITY_HCB2:
  8016. - case INTENSITY_HCB:
  8017. - /* store dpcm_is_position */
  8018. - dpcm = decodeRVLCodeword(bs, pRvlc);
  8019. - if (dpcm < 0) {
  8020. - pScfBwd[bnds] = position;
  8021. - pRvlc->conceal_min = fMax(0, bnds - offset);
  8022. - return;
  8023. - }
  8024. - dpcm -= TABLE_OFFSET;
  8025. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  8026. - if (pRvlc->length_of_rvlc_escapes) {
  8027. - pScfBwd[bnds] = position;
  8028. - pRvlc->conceal_min = fMax(0, bnds - offset);
  8029. - return;
  8030. - } else {
  8031. - if (dpcm == MIN_RVL) {
  8032. - dpcm -= *pScfEsc--;
  8033. - } else {
  8034. - dpcm += *pScfEsc--;
  8035. - }
  8036. - (*pEscBwdCnt)++;
  8037. - if (pRvlc->conceal_min_esc == CONCEAL_MIN_INIT) {
  8038. - pRvlc->conceal_min_esc = fMax(0, bnds - offset);
  8039. - }
  8040. - }
  8041. - }
  8042. - pScfBwd[bnds] = position;
  8043. - position -= dpcm;
  8044. - pRvlc->firstIs = position;
  8045. - break;
  8046. -
  8047. - case NOISE_HCB:
  8048. - if (bnds == pRvlc->first_noise_band) {
  8049. - pScfBwd[bnds] =
  8050. - pRvlc->dpcm_noise_nrg +
  8051. - pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain -
  8052. - SF_OFFSET - 90 - 256;
  8053. - pRvlc->firstNrg = pScfBwd[bnds];
  8054. - } else {
  8055. - dpcm = decodeRVLCodeword(bs, pRvlc);
  8056. - if (dpcm < 0) {
  8057. - pScfBwd[bnds] = noisenrg;
  8058. - pRvlc->conceal_min = fMax(0, bnds - offset);
  8059. - return;
  8060. - }
  8061. - dpcm -= TABLE_OFFSET;
  8062. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  8063. - if (pRvlc->length_of_rvlc_escapes) {
  8064. - pScfBwd[bnds] = noisenrg;
  8065. - pRvlc->conceal_min = fMax(0, bnds - offset);
  8066. - return;
  8067. - } else {
  8068. - if (dpcm == MIN_RVL) {
  8069. - dpcm -= *pScfEsc--;
  8070. - } else {
  8071. - dpcm += *pScfEsc--;
  8072. - }
  8073. - (*pEscBwdCnt)++;
  8074. - if (pRvlc->conceal_min_esc == CONCEAL_MIN_INIT) {
  8075. - pRvlc->conceal_min_esc = fMax(0, bnds - offset);
  8076. - }
  8077. - }
  8078. - }
  8079. - pScfBwd[bnds] = noisenrg;
  8080. - noisenrg -= dpcm;
  8081. - pRvlc->firstNrg = noisenrg;
  8082. - }
  8083. - break;
  8084. -
  8085. - default:
  8086. - dpcm = decodeRVLCodeword(bs, pRvlc);
  8087. - if (dpcm < 0) {
  8088. - pScfBwd[bnds] = factor;
  8089. - pRvlc->conceal_min = fMax(0, bnds - offset);
  8090. - return;
  8091. - }
  8092. - dpcm -= TABLE_OFFSET;
  8093. - if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
  8094. - if (pRvlc->length_of_rvlc_escapes) {
  8095. - pScfBwd[bnds] = factor;
  8096. - pRvlc->conceal_min = fMax(0, bnds - offset);
  8097. - return;
  8098. - } else {
  8099. - if (dpcm == MIN_RVL) {
  8100. - dpcm -= *pScfEsc--;
  8101. - } else {
  8102. - dpcm += *pScfEsc--;
  8103. - }
  8104. - (*pEscBwdCnt)++;
  8105. - if (pRvlc->conceal_min_esc == CONCEAL_MIN_INIT) {
  8106. - pRvlc->conceal_min_esc = fMax(0, bnds - offset);
  8107. - }
  8108. - }
  8109. - }
  8110. - pScfBwd[bnds] = factor;
  8111. - factor -= dpcm;
  8112. - pRvlc->firstScf = factor;
  8113. - break;
  8114. - }
  8115. - }
  8116. - }
  8117. -}
  8118. -
  8119. -/*---------------------------------------------------------------------------------------------
  8120. - function: rvlcFinalErrorDetection
  8121. -
  8122. - description: Call RVLC concealment if error was detected in decoding
  8123. -process
  8124. ------------------------------------------------------------------------------------------------
  8125. - input: - pointer rvlc structure
  8126. - - pointer channel info structure
  8127. ------------------------------------------------------------------------------------------------
  8128. - return: -
  8129. ---------------------------------------------------------------------------------------------
  8130. -*/
  8131. -
  8132. -static void rvlcFinalErrorDetection(
  8133. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  8134. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
  8135. - CErRvlcInfo *pRvlc =
  8136. - &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
  8137. - UCHAR ErrorStatusComplete = 0;
  8138. - UCHAR ErrorStatusLengthFwd = 0;
  8139. - UCHAR ErrorStatusLengthBwd = 0;
  8140. - UCHAR ErrorStatusLengthEscapes = 0;
  8141. - UCHAR ErrorStatusFirstScf = 0;
  8142. - UCHAR ErrorStatusLastScf = 0;
  8143. - UCHAR ErrorStatusFirstNrg = 0;
  8144. - UCHAR ErrorStatusLastNrg = 0;
  8145. - UCHAR ErrorStatusFirstIs = 0;
  8146. - UCHAR ErrorStatusLastIs = 0;
  8147. - UCHAR ErrorStatusForbiddenCwFwd = 0;
  8148. - UCHAR ErrorStatusForbiddenCwBwd = 0;
  8149. - UCHAR ErrorStatusNumEscapesFwd = 0;
  8150. - UCHAR ErrorStatusNumEscapesBwd = 0;
  8151. - UCHAR ConcealStatus = 1;
  8152. - UCHAR currentBlockType; /* short: 0, not short: 1*/
  8153. -
  8154. - pAacDecoderChannelInfo->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK = 1;
  8155. -
  8156. - /* invalid escape words, bit counter unequal zero, forbidden codeword detected
  8157. - */
  8158. - if (pRvlc->errorLogRvlc & RVLC_ERROR_FORBIDDEN_CW_DETECTED_FWD)
  8159. - ErrorStatusForbiddenCwFwd = 1;
  8160. -
  8161. - if (pRvlc->errorLogRvlc & RVLC_ERROR_FORBIDDEN_CW_DETECTED_BWD)
  8162. - ErrorStatusForbiddenCwBwd = 1;
  8163. -
  8164. - /* bit counter forward unequal zero */
  8165. - if (pRvlc->length_of_rvlc_sf_fwd) ErrorStatusLengthFwd = 1;
  8166. -
  8167. - /* bit counter backward unequal zero */
  8168. - if (pRvlc->length_of_rvlc_sf_bwd) ErrorStatusLengthBwd = 1;
  8169. -
  8170. - /* bit counter escape sequences unequal zero */
  8171. - if (pRvlc->sf_escapes_present)
  8172. - if (pRvlc->length_of_rvlc_escapes) ErrorStatusLengthEscapes = 1;
  8173. -
  8174. - if (pRvlc->sf_used) {
  8175. - /* first decoded scf does not match to global gain in backward direction */
  8176. - if (pRvlc->firstScf !=
  8177. - (pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET))
  8178. - ErrorStatusFirstScf = 1;
  8179. -
  8180. - /* last decoded scf does not match to rev global gain in forward direction
  8181. - */
  8182. - if (pRvlc->lastScf != (pRvlc->rev_global_gain - SF_OFFSET))
  8183. - ErrorStatusLastScf = 1;
  8184. - }
  8185. -
  8186. - if (pRvlc->noise_used) {
  8187. - /* first decoded nrg does not match to dpcm_noise_nrg in backward direction
  8188. - */
  8189. - if (pRvlc->firstNrg !=
  8190. - (pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain +
  8191. - pRvlc->dpcm_noise_nrg - SF_OFFSET - 90 - 256))
  8192. - ErrorStatusFirstNrg = 1;
  8193. -
  8194. - /* last decoded nrg does not match to dpcm_noise_last_position in forward
  8195. - * direction */
  8196. - if (pRvlc->lastNrg !=
  8197. - (pRvlc->rev_global_gain + pRvlc->dpcm_noise_last_position - SF_OFFSET -
  8198. - 90 - 256))
  8199. - ErrorStatusLastNrg = 1;
  8200. - }
  8201. -
  8202. - if (pRvlc->intensity_used) {
  8203. - /* first decoded is position does not match in backward direction */
  8204. - if (pRvlc->firstIs != (-SF_OFFSET)) ErrorStatusFirstIs = 1;
  8205. -
  8206. - /* last decoded is position does not match in forward direction */
  8207. - if (pRvlc->lastIs != (pRvlc->dpcm_is_last_position - SF_OFFSET))
  8208. - ErrorStatusLastIs = 1;
  8209. - }
  8210. -
  8211. - /* decoded escapes and used escapes in forward direction do not fit */
  8212. - if ((pRvlc->numDecodedEscapeWordsFwd != pRvlc->numDecodedEscapeWordsEsc) &&
  8213. - (pRvlc->conceal_max == CONCEAL_MAX_INIT)) {
  8214. - ErrorStatusNumEscapesFwd = 1;
  8215. - }
  8216. -
  8217. - /* decoded escapes and used escapes in backward direction do not fit */
  8218. - if ((pRvlc->numDecodedEscapeWordsBwd != pRvlc->numDecodedEscapeWordsEsc) &&
  8219. - (pRvlc->conceal_min == CONCEAL_MIN_INIT)) {
  8220. - ErrorStatusNumEscapesBwd = 1;
  8221. - }
  8222. -
  8223. - if (ErrorStatusLengthEscapes ||
  8224. - (((pRvlc->conceal_max == CONCEAL_MAX_INIT) &&
  8225. - (pRvlc->numDecodedEscapeWordsFwd != pRvlc->numDecodedEscapeWordsEsc) &&
  8226. - (ErrorStatusLastScf || ErrorStatusLastNrg || ErrorStatusLastIs))
  8227. -
  8228. - &&
  8229. -
  8230. - ((pRvlc->conceal_min == CONCEAL_MIN_INIT) &&
  8231. - (pRvlc->numDecodedEscapeWordsBwd != pRvlc->numDecodedEscapeWordsEsc) &&
  8232. - (ErrorStatusFirstScf || ErrorStatusFirstNrg || ErrorStatusFirstIs))) ||
  8233. - ((pRvlc->conceal_max == CONCEAL_MAX_INIT) &&
  8234. - ((pRvlc->rev_global_gain - SF_OFFSET - pRvlc->lastScf) < -15)) ||
  8235. - ((pRvlc->conceal_min == CONCEAL_MIN_INIT) &&
  8236. - ((pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET -
  8237. - pRvlc->firstScf) < -15))) {
  8238. - if ((pRvlc->conceal_max == CONCEAL_MAX_INIT) ||
  8239. - (pRvlc->conceal_min == CONCEAL_MIN_INIT)) {
  8240. - pRvlc->conceal_max = 0;
  8241. - pRvlc->conceal_min = fMax(
  8242. - 0, (pRvlc->numWindowGroups - 1) * 16 + pRvlc->maxSfbTransmitted - 1);
  8243. - } else {
  8244. - pRvlc->conceal_max = fMin(pRvlc->conceal_max, pRvlc->conceal_max_esc);
  8245. - pRvlc->conceal_min = fMax(pRvlc->conceal_min, pRvlc->conceal_min_esc);
  8246. - }
  8247. - }
  8248. -
  8249. - ErrorStatusComplete = ErrorStatusLastScf || ErrorStatusFirstScf ||
  8250. - ErrorStatusLastNrg || ErrorStatusFirstNrg ||
  8251. - ErrorStatusLastIs || ErrorStatusFirstIs ||
  8252. - ErrorStatusForbiddenCwFwd ||
  8253. - ErrorStatusForbiddenCwBwd || ErrorStatusLengthFwd ||
  8254. - ErrorStatusLengthBwd || ErrorStatusLengthEscapes ||
  8255. - ErrorStatusNumEscapesFwd || ErrorStatusNumEscapesBwd;
  8256. -
  8257. - currentBlockType =
  8258. - (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) ? 0
  8259. - : 1;
  8260. -
  8261. - if (!ErrorStatusComplete) {
  8262. - int band;
  8263. - int group;
  8264. - int bnds;
  8265. - int lastSfbIndex;
  8266. -
  8267. - lastSfbIndex = (pRvlc->numWindowGroups > 1) ? 16 : 64;
  8268. -
  8269. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  8270. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  8271. - bnds = 16 * group + band;
  8272. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  8273. - pAacDecoderStaticChannelInfo->concealmentInfo
  8274. - .aRvlcPreviousScaleFactor[bnds] =
  8275. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  8276. - }
  8277. - }
  8278. -
  8279. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  8280. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  8281. - bnds = 16 * group + band;
  8282. - pAacDecoderStaticChannelInfo->concealmentInfo
  8283. - .aRvlcPreviousCodebook[bnds] =
  8284. - pAacDecoderChannelInfo->pDynData->aCodeBook[bnds];
  8285. - }
  8286. - for (; band < lastSfbIndex; band++) {
  8287. - bnds = 16 * group + band;
  8288. - FDK_ASSERT(bnds >= 0 && bnds < RVLC_MAX_SFB);
  8289. - pAacDecoderStaticChannelInfo->concealmentInfo
  8290. - .aRvlcPreviousCodebook[bnds] = ZERO_HCB;
  8291. - }
  8292. - }
  8293. - } else {
  8294. - int band;
  8295. - int group;
  8296. -
  8297. - /* A single bit error was detected in decoding of dpcm values. It also could
  8298. - be an error with more bits in decoding of escapes and dpcm values whereby
  8299. - an illegal codeword followed not directly after the corrupted bits but
  8300. - just after decoding some more (wrong) scalefactors. Use the smaller
  8301. - scalefactor from forward decoding, backward decoding and previous frame.
  8302. - */
  8303. - if (((pRvlc->conceal_min != CONCEAL_MIN_INIT) ||
  8304. - (pRvlc->conceal_max != CONCEAL_MAX_INIT)) &&
  8305. - (pRvlc->conceal_min <= pRvlc->conceal_max) &&
  8306. - (pAacDecoderStaticChannelInfo->concealmentInfo.rvlcPreviousBlockType ==
  8307. - currentBlockType) &&
  8308. - pAacDecoderStaticChannelInfo->concealmentInfo
  8309. - .rvlcPreviousScaleFactorOK &&
  8310. - pRvlc->sf_concealment && ConcealStatus) {
  8311. - BidirectionalEstimation_UseScfOfPrevFrameAsReference(
  8312. - pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo);
  8313. - ConcealStatus = 0;
  8314. - }
  8315. -
  8316. - /* A single bit error was detected in decoding of dpcm values. It also could
  8317. - be an error with more bits in decoding of escapes and dpcm values whereby
  8318. - an illegal codeword followed not directly after the corrupted bits but
  8319. - just after decoding some more (wrong) scalefactors. Use the smaller
  8320. - scalefactor from forward and backward decoding. */
  8321. - if ((pRvlc->conceal_min <= pRvlc->conceal_max) &&
  8322. - ((pRvlc->conceal_min != CONCEAL_MIN_INIT) ||
  8323. - (pRvlc->conceal_max != CONCEAL_MAX_INIT)) &&
  8324. - !(pAacDecoderStaticChannelInfo->concealmentInfo
  8325. - .rvlcPreviousScaleFactorOK &&
  8326. - pRvlc->sf_concealment &&
  8327. - (pAacDecoderStaticChannelInfo->concealmentInfo
  8328. - .rvlcPreviousBlockType == currentBlockType)) &&
  8329. - ConcealStatus) {
  8330. - BidirectionalEstimation_UseLowerScfOfCurrentFrame(pAacDecoderChannelInfo);
  8331. - ConcealStatus = 0;
  8332. - }
  8333. -
  8334. - /* No errors were detected in decoding of escapes and dpcm values however
  8335. - the first and last value of a group (is,nrg,sf) is incorrect */
  8336. - if ((pRvlc->conceal_min <= pRvlc->conceal_max) &&
  8337. - ((ErrorStatusLastScf && ErrorStatusFirstScf) ||
  8338. - (ErrorStatusLastNrg && ErrorStatusFirstNrg) ||
  8339. - (ErrorStatusLastIs && ErrorStatusFirstIs)) &&
  8340. - !(ErrorStatusForbiddenCwFwd || ErrorStatusForbiddenCwBwd ||
  8341. - ErrorStatusLengthEscapes) &&
  8342. - ConcealStatus) {
  8343. - StatisticalEstimation(pAacDecoderChannelInfo);
  8344. - ConcealStatus = 0;
  8345. - }
  8346. -
  8347. - /* A error with more bits in decoding of escapes and dpcm values was
  8348. - detected. Use the smaller scalefactor from forward decoding, backward
  8349. - decoding and previous frame. */
  8350. - if ((pRvlc->conceal_min <= pRvlc->conceal_max) &&
  8351. - pAacDecoderStaticChannelInfo->concealmentInfo
  8352. - .rvlcPreviousScaleFactorOK &&
  8353. - pRvlc->sf_concealment &&
  8354. - (pAacDecoderStaticChannelInfo->concealmentInfo.rvlcPreviousBlockType ==
  8355. - currentBlockType) &&
  8356. - ConcealStatus) {
  8357. - PredictiveInterpolation(pAacDecoderChannelInfo,
  8358. - pAacDecoderStaticChannelInfo);
  8359. - ConcealStatus = 0;
  8360. - }
  8361. -
  8362. - /* Call frame concealment, because no better strategy was found. Setting the
  8363. - scalefactors to zero is done for debugging purposes */
  8364. - if (ConcealStatus) {
  8365. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  8366. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  8367. - pAacDecoderChannelInfo->pDynData->aScaleFactor[16 * group + band] = 0;
  8368. - }
  8369. - }
  8370. - pAacDecoderChannelInfo->pDynData->specificTo.aac
  8371. - .rvlcCurrentScaleFactorOK = 0;
  8372. - }
  8373. - }
  8374. -}
  8375. -
  8376. -/*---------------------------------------------------------------------------------------------
  8377. - function: CRvlc_Read
  8378. -
  8379. - description: Read RVLC ESC1 data (side info) from bitstream.
  8380. ------------------------------------------------------------------------------------------------
  8381. - input: - pointer rvlc structure
  8382. - - pointer channel info structure
  8383. - - pointer bitstream structure
  8384. ------------------------------------------------------------------------------------------------
  8385. - return: -
  8386. ---------------------------------------------------------------------------------------------
  8387. -*/
  8388. -
  8389. -void CRvlc_Read(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  8390. - HANDLE_FDK_BITSTREAM bs) {
  8391. - CErRvlcInfo *pRvlc =
  8392. - &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
  8393. -
  8394. - int group, band;
  8395. -
  8396. - /* RVLC long specific initialization Init part 1 of 2 */
  8397. - pRvlc->numWindowGroups = GetWindowGroups(&pAacDecoderChannelInfo->icsInfo);
  8398. - pRvlc->maxSfbTransmitted =
  8399. - GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->icsInfo);
  8400. - pRvlc->noise_used = 0; /* noise detection */
  8401. - pRvlc->dpcm_noise_nrg = 0; /* only for debugging */
  8402. - pRvlc->dpcm_noise_last_position = 0; /* only for debugging */
  8403. - pRvlc->length_of_rvlc_escapes =
  8404. - -1; /* default value is used for error detection and concealment */
  8405. -
  8406. - /* read only error sensitivity class 1 data (ESC 1 - data) */
  8407. - pRvlc->sf_concealment = FDKreadBits(bs, 1); /* #1 */
  8408. - pRvlc->rev_global_gain = FDKreadBits(bs, 8); /* #2 */
  8409. -
  8410. - if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) {
  8411. - pRvlc->length_of_rvlc_sf = FDKreadBits(bs, 11); /* #3 */
  8412. - } else {
  8413. - pRvlc->length_of_rvlc_sf = FDKreadBits(bs, 9); /* #3 */
  8414. - }
  8415. -
  8416. - /* check if noise codebook is used */
  8417. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  8418. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  8419. - if (pAacDecoderChannelInfo->pDynData->aCodeBook[16 * group + band] ==
  8420. - NOISE_HCB) {
  8421. - pRvlc->noise_used = 1;
  8422. - break;
  8423. - }
  8424. - }
  8425. - }
  8426. -
  8427. - if (pRvlc->noise_used)
  8428. - pRvlc->dpcm_noise_nrg = FDKreadBits(bs, 9); /* #4 PNS */
  8429. -
  8430. - pRvlc->sf_escapes_present = FDKreadBits(bs, 1); /* #5 */
  8431. -
  8432. - if (pRvlc->sf_escapes_present) {
  8433. - pRvlc->length_of_rvlc_escapes = FDKreadBits(bs, 8); /* #6 */
  8434. - }
  8435. -
  8436. - if (pRvlc->noise_used) {
  8437. - pRvlc->dpcm_noise_last_position = FDKreadBits(bs, 9); /* #7 PNS */
  8438. - pRvlc->length_of_rvlc_sf -= 9;
  8439. - }
  8440. -
  8441. - pRvlc->length_of_rvlc_sf_fwd = pRvlc->length_of_rvlc_sf;
  8442. - pRvlc->length_of_rvlc_sf_bwd = pRvlc->length_of_rvlc_sf;
  8443. -}
  8444. -
  8445. -/*---------------------------------------------------------------------------------------------
  8446. - function: CRvlc_Decode
  8447. -
  8448. - description: Decode rvlc data
  8449. - The function reads both the escape sequences and the
  8450. -scalefactors in forward and backward direction. If an error occured during
  8451. -decoding process which can not be concealed with the rvlc concealment frame
  8452. -concealment will be initiated. Then the element "rvlcCurrentScaleFactorOK" in
  8453. -the decoder channel info is set to 0 otherwise it is set to 1.
  8454. ------------------------------------------------------------------------------------------------
  8455. - input: - pointer rvlc structure
  8456. - - pointer channel info structure
  8457. - - pointer to persistent channel info structure
  8458. - - pointer bitstream structure
  8459. ------------------------------------------------------------------------------------------------
  8460. - return: ErrorStatus = AAC_DEC_OK
  8461. ---------------------------------------------------------------------------------------------
  8462. -*/
  8463. -
  8464. -void CRvlc_Decode(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  8465. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  8466. - HANDLE_FDK_BITSTREAM bs) {
  8467. - CErRvlcInfo *pRvlc =
  8468. - &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
  8469. - INT bitCntOffst;
  8470. - INT saveBitCnt;
  8471. -
  8472. - rvlcInit(pRvlc, pAacDecoderChannelInfo, bs);
  8473. -
  8474. - /* save bitstream position */
  8475. - saveBitCnt = (INT)FDKgetValidBits(bs);
  8476. -
  8477. - if (pRvlc->sf_escapes_present)
  8478. - rvlcDecodeEscapes(
  8479. - pRvlc, pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfEsc, bs);
  8480. -
  8481. - rvlcDecodeForward(pRvlc, pAacDecoderChannelInfo, bs);
  8482. - rvlcDecodeBackward(pRvlc, pAacDecoderChannelInfo, bs);
  8483. - rvlcFinalErrorDetection(pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo);
  8484. -
  8485. - pAacDecoderChannelInfo->pDynData->specificTo.aac.rvlcIntensityUsed =
  8486. - pRvlc->intensity_used;
  8487. - pAacDecoderChannelInfo->data.aac.PnsData.PnsActive = pRvlc->noise_used;
  8488. -
  8489. - /* restore bitstream position */
  8490. - bitCntOffst = (INT)FDKgetValidBits(bs) - saveBitCnt;
  8491. - if (bitCntOffst) {
  8492. - FDKpushBiDirectional(bs, bitCntOffst);
  8493. - }
  8494. -}
  8495. -
  8496. -void CRvlc_ElementCheck(
  8497. - CAacDecoderChannelInfo *pAacDecoderChannelInfo[],
  8498. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo[],
  8499. - const UINT flags, const INT elChannels) {
  8500. - int ch;
  8501. -
  8502. - /* Required for MPS residuals. */
  8503. - if (pAacDecoderStaticChannelInfo == NULL) {
  8504. - return;
  8505. - }
  8506. -
  8507. - /* RVLC specific sanity checks */
  8508. - if ((flags & AC_ER_RVLC) && (elChannels == 2)) { /* to be reviewed */
  8509. - if (((pAacDecoderChannelInfo[0]
  8510. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK == 0) ||
  8511. - (pAacDecoderChannelInfo[1]
  8512. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK == 0)) &&
  8513. - pAacDecoderChannelInfo[0]->pComData->jointStereoData.MsMaskPresent) {
  8514. - pAacDecoderChannelInfo[0]
  8515. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK = 0;
  8516. - pAacDecoderChannelInfo[1]
  8517. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK = 0;
  8518. - }
  8519. -
  8520. - if ((pAacDecoderChannelInfo[0]
  8521. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK == 0) &&
  8522. - (pAacDecoderChannelInfo[1]
  8523. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK == 1) &&
  8524. - (pAacDecoderChannelInfo[1]
  8525. - ->pDynData->specificTo.aac.rvlcIntensityUsed == 1)) {
  8526. - pAacDecoderChannelInfo[1]
  8527. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK = 0;
  8528. - }
  8529. - }
  8530. -
  8531. - for (ch = 0; ch < elChannels; ch++) {
  8532. - pAacDecoderStaticChannelInfo[ch]->concealmentInfo.rvlcPreviousBlockType =
  8533. - (GetWindowSequence(&pAacDecoderChannelInfo[ch]->icsInfo) == BLOCK_SHORT)
  8534. - ? 0
  8535. - : 1;
  8536. - if (flags & AC_ER_RVLC) {
  8537. - pAacDecoderStaticChannelInfo[ch]
  8538. - ->concealmentInfo.rvlcPreviousScaleFactorOK =
  8539. - pAacDecoderChannelInfo[ch]
  8540. - ->pDynData->specificTo.aac.rvlcCurrentScaleFactorOK;
  8541. - } else {
  8542. - pAacDecoderStaticChannelInfo[ch]
  8543. - ->concealmentInfo.rvlcPreviousScaleFactorOK = 0;
  8544. - }
  8545. - }
  8546. -}
  8547. diff --git a/libAACdec/src/rvlc.h b/libAACdec/src/rvlc.h
  8548. deleted file mode 100644
  8549. index 9c60d51..0000000
  8550. --- a/libAACdec/src/rvlc.h
  8551. +++ /dev/null
  8552. @@ -1,153 +0,0 @@
  8553. -/* -----------------------------------------------------------------------------
  8554. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  8555. -
  8556. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  8557. -Forschung e.V. All rights reserved.
  8558. -
  8559. - 1. INTRODUCTION
  8560. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  8561. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  8562. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  8563. -a wide variety of Android devices.
  8564. -
  8565. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  8566. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  8567. -full-bandwidth communications codec by independent studies and is widely
  8568. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  8569. -specifications.
  8570. -
  8571. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  8572. -those of Fraunhofer) may be obtained through Via Licensing
  8573. -(www.vialicensing.com) or through the respective patent owners individually for
  8574. -the purpose of encoding or decoding bit streams in products that are compliant
  8575. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  8576. -Android devices already license these patent claims through Via Licensing or
  8577. -directly from the patent owners, and therefore FDK AAC Codec software may
  8578. -already be covered under those patent licenses when it is used for those
  8579. -licensed purposes only.
  8580. -
  8581. -Commercially-licensed AAC software libraries, including floating-point versions
  8582. -with enhanced sound quality, are also available from Fraunhofer. Users are
  8583. -encouraged to check the Fraunhofer website for additional applications
  8584. -information and documentation.
  8585. -
  8586. -2. COPYRIGHT LICENSE
  8587. -
  8588. -Redistribution and use in source and binary forms, with or without modification,
  8589. -are permitted without payment of copyright license fees provided that you
  8590. -satisfy the following conditions:
  8591. -
  8592. -You must retain the complete text of this software license in redistributions of
  8593. -the FDK AAC Codec or your modifications thereto in source code form.
  8594. -
  8595. -You must retain the complete text of this software license in the documentation
  8596. -and/or other materials provided with redistributions of the FDK AAC Codec or
  8597. -your modifications thereto in binary form. You must make available free of
  8598. -charge copies of the complete source code of the FDK AAC Codec and your
  8599. -modifications thereto to recipients of copies in binary form.
  8600. -
  8601. -The name of Fraunhofer may not be used to endorse or promote products derived
  8602. -from this library without prior written permission.
  8603. -
  8604. -You may not charge copyright license fees for anyone to use, copy or distribute
  8605. -the FDK AAC Codec software or your modifications thereto.
  8606. -
  8607. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  8608. -that you changed the software and the date of any change. For modified versions
  8609. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  8610. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  8611. -AAC Codec Library for Android."
  8612. -
  8613. -3. NO PATENT LICENSE
  8614. -
  8615. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  8616. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  8617. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  8618. -software.
  8619. -
  8620. -You may use this FDK AAC Codec software or modifications thereto only for
  8621. -purposes that are authorized by appropriate patent licenses.
  8622. -
  8623. -4. DISCLAIMER
  8624. -
  8625. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  8626. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  8627. -including but not limited to the implied warranties of merchantability and
  8628. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  8629. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  8630. -or consequential damages, including but not limited to procurement of substitute
  8631. -goods or services; loss of use, data, or profits, or business interruption,
  8632. -however caused and on any theory of liability, whether in contract, strict
  8633. -liability, or tort (including negligence), arising in any way out of the use of
  8634. -this software, even if advised of the possibility of such damage.
  8635. -
  8636. -5. CONTACT INFORMATION
  8637. -
  8638. -Fraunhofer Institute for Integrated Circuits IIS
  8639. -Attention: Audio and Multimedia Departments - FDK AAC LL
  8640. -Am Wolfsmantel 33
  8641. -91058 Erlangen, Germany
  8642. -
  8643. -www.iis.fraunhofer.de/amm
  8644. -amm-info@iis.fraunhofer.de
  8645. ------------------------------------------------------------------------------ */
  8646. -
  8647. -/**************************** AAC decoder library ******************************
  8648. -
  8649. - Author(s):
  8650. -
  8651. - Description:
  8652. -
  8653. -*******************************************************************************/
  8654. -
  8655. -/*!
  8656. - \file
  8657. - \brief Defines structures and prototypes for RVLC
  8658. - \author Robert Weidner
  8659. -*/
  8660. -
  8661. -#ifndef RVLC_H
  8662. -#define RVLC_H
  8663. -
  8664. -#include "aacdecoder.h"
  8665. -#include "channel.h"
  8666. -#include "rvlc_info.h"
  8667. -
  8668. -/* ------------------------------------------------------------------- */
  8669. -/* errorLogRvlc: A word of 32 bits used for logging possible errors */
  8670. -/* within RVLC in case of distorted bitstreams. */
  8671. -/* ------------------------------------------------------------------- */
  8672. -#define RVLC_ERROR_ALL_ESCAPE_WORDS_INVALID \
  8673. - 0x80000000 /* ESC-Dec During RVLC-Escape-decoding there have been more \
  8674. - bits decoded as there are available */
  8675. -#define RVLC_ERROR_RVL_SUM_BIT_COUNTER_BELOW_ZERO_FWD \
  8676. - 0x40000000 /* RVL-Dec negative sum-bitcounter during RVL-fwd-decoding \
  8677. - (long+shrt) */
  8678. -#define RVLC_ERROR_RVL_SUM_BIT_COUNTER_BELOW_ZERO_BWD \
  8679. - 0x20000000 /* RVL-Dec negative sum-bitcounter during RVL-fwd-decoding \
  8680. - (long+shrt) */
  8681. -#define RVLC_ERROR_FORBIDDEN_CW_DETECTED_FWD \
  8682. - 0x08000000 /* RVL-Dec forbidden codeword detected fwd (long+shrt) */
  8683. -#define RVLC_ERROR_FORBIDDEN_CW_DETECTED_BWD \
  8684. - 0x04000000 /* RVL-Dec forbidden codeword detected bwd (long+shrt) */
  8685. -
  8686. -void CRvlc_Read(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  8687. - HANDLE_FDK_BITSTREAM bs);
  8688. -
  8689. -void CRvlc_Decode(CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  8690. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo,
  8691. - HANDLE_FDK_BITSTREAM bs);
  8692. -
  8693. -/**
  8694. - * \brief performe sanity checks to the channel data corresponding to one
  8695. - * channel element.
  8696. - * \param pAacDecoderChannelInfo
  8697. - * \param pAacDecoderStaticChannelInfo
  8698. - * \param elChannels amount of channels of the channel element.
  8699. - */
  8700. -void CRvlc_ElementCheck(
  8701. - CAacDecoderChannelInfo *pAacDecoderChannelInfo[],
  8702. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo[],
  8703. - const UINT flags, const INT elChannels);
  8704. -
  8705. -#endif /* RVLC_H */
  8706. diff --git a/libAACdec/src/rvlc_info.h b/libAACdec/src/rvlc_info.h
  8707. deleted file mode 100644
  8708. index e7b3b99..0000000
  8709. --- a/libAACdec/src/rvlc_info.h
  8710. +++ /dev/null
  8711. @@ -1,204 +0,0 @@
  8712. -/* -----------------------------------------------------------------------------
  8713. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  8714. -
  8715. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  8716. -Forschung e.V. All rights reserved.
  8717. -
  8718. - 1. INTRODUCTION
  8719. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  8720. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  8721. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  8722. -a wide variety of Android devices.
  8723. -
  8724. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  8725. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  8726. -full-bandwidth communications codec by independent studies and is widely
  8727. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  8728. -specifications.
  8729. -
  8730. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  8731. -those of Fraunhofer) may be obtained through Via Licensing
  8732. -(www.vialicensing.com) or through the respective patent owners individually for
  8733. -the purpose of encoding or decoding bit streams in products that are compliant
  8734. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  8735. -Android devices already license these patent claims through Via Licensing or
  8736. -directly from the patent owners, and therefore FDK AAC Codec software may
  8737. -already be covered under those patent licenses when it is used for those
  8738. -licensed purposes only.
  8739. -
  8740. -Commercially-licensed AAC software libraries, including floating-point versions
  8741. -with enhanced sound quality, are also available from Fraunhofer. Users are
  8742. -encouraged to check the Fraunhofer website for additional applications
  8743. -information and documentation.
  8744. -
  8745. -2. COPYRIGHT LICENSE
  8746. -
  8747. -Redistribution and use in source and binary forms, with or without modification,
  8748. -are permitted without payment of copyright license fees provided that you
  8749. -satisfy the following conditions:
  8750. -
  8751. -You must retain the complete text of this software license in redistributions of
  8752. -the FDK AAC Codec or your modifications thereto in source code form.
  8753. -
  8754. -You must retain the complete text of this software license in the documentation
  8755. -and/or other materials provided with redistributions of the FDK AAC Codec or
  8756. -your modifications thereto in binary form. You must make available free of
  8757. -charge copies of the complete source code of the FDK AAC Codec and your
  8758. -modifications thereto to recipients of copies in binary form.
  8759. -
  8760. -The name of Fraunhofer may not be used to endorse or promote products derived
  8761. -from this library without prior written permission.
  8762. -
  8763. -You may not charge copyright license fees for anyone to use, copy or distribute
  8764. -the FDK AAC Codec software or your modifications thereto.
  8765. -
  8766. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  8767. -that you changed the software and the date of any change. For modified versions
  8768. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  8769. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  8770. -AAC Codec Library for Android."
  8771. -
  8772. -3. NO PATENT LICENSE
  8773. -
  8774. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  8775. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  8776. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  8777. -software.
  8778. -
  8779. -You may use this FDK AAC Codec software or modifications thereto only for
  8780. -purposes that are authorized by appropriate patent licenses.
  8781. -
  8782. -4. DISCLAIMER
  8783. -
  8784. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  8785. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  8786. -including but not limited to the implied warranties of merchantability and
  8787. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  8788. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  8789. -or consequential damages, including but not limited to procurement of substitute
  8790. -goods or services; loss of use, data, or profits, or business interruption,
  8791. -however caused and on any theory of liability, whether in contract, strict
  8792. -liability, or tort (including negligence), arising in any way out of the use of
  8793. -this software, even if advised of the possibility of such damage.
  8794. -
  8795. -5. CONTACT INFORMATION
  8796. -
  8797. -Fraunhofer Institute for Integrated Circuits IIS
  8798. -Attention: Audio and Multimedia Departments - FDK AAC LL
  8799. -Am Wolfsmantel 33
  8800. -91058 Erlangen, Germany
  8801. -
  8802. -www.iis.fraunhofer.de/amm
  8803. -amm-info@iis.fraunhofer.de
  8804. ------------------------------------------------------------------------------ */
  8805. -
  8806. -/**************************** AAC decoder library ******************************
  8807. -
  8808. - Author(s):
  8809. -
  8810. - Description:
  8811. -
  8812. -*******************************************************************************/
  8813. -
  8814. -/*!
  8815. - \file
  8816. - \brief Defines structures for RVLC
  8817. - \author Robert Weidner
  8818. -*/
  8819. -#ifndef RVLC_INFO_H
  8820. -#define RVLC_INFO_H
  8821. -
  8822. -#define FWD 0 /* bitstream decoding direction forward (RVL coded part) */
  8823. -#define BWD 1 /* bitstream decoding direction backward (RVL coded part) */
  8824. -
  8825. -#define MAX_RVL 7 /* positive RVLC escape */
  8826. -#define MIN_RVL -7 /* negative RVLC escape */
  8827. -#define MAX_ALLOWED_DPCM_INDEX \
  8828. - 14 /* the maximum allowed index of a decoded dpcm value (offset \
  8829. - 'TABLE_OFFSET' incl --> must be subtracted) */
  8830. -#define TABLE_OFFSET \
  8831. - 7 /* dpcm offset of valid output values of rvl table decoding, the rvl table \
  8832. - ouly returns positive values, therefore the offset */
  8833. -#define MAX_LEN_RVLC_CODE_WORD 9 /* max length of a RVL codeword in bits */
  8834. -#define MAX_LEN_RVLC_ESCAPE_WORD \
  8835. - 20 /* max length of huffman coded RVLC escape word in bits */
  8836. -
  8837. -#define DPCM_NOISE_NRG_BITS 9
  8838. -#define SF_OFFSET 100 /* offset for correcting scf value */
  8839. -
  8840. -#define CONCEAL_MAX_INIT 1311 /* arbitrary value */
  8841. -#define CONCEAL_MIN_INIT -1311 /* arbitrary value */
  8842. -
  8843. -#define RVLC_MAX_SFB ((8) * (16))
  8844. -
  8845. -/* sideinfo of RVLC */
  8846. -typedef struct {
  8847. - /* ------- ESC 1 Data: --------- */ /* order of RVLC-bitstream components in
  8848. - bitstream (RVLC-initialization), every
  8849. - component appears only once in
  8850. - bitstream */
  8851. - INT sf_concealment; /* 1 */
  8852. - INT rev_global_gain; /* 2 */
  8853. - SHORT length_of_rvlc_sf; /* 3 */ /* original value, gets modified
  8854. - (subtract 9) in case of noise
  8855. - (PNS); is kept for later use */
  8856. - INT dpcm_noise_nrg; /* 4 optional */
  8857. - INT sf_escapes_present; /* 5 */
  8858. - SHORT length_of_rvlc_escapes; /* 6 optional */
  8859. - INT dpcm_noise_last_position; /* 7 optional */
  8860. -
  8861. - INT dpcm_is_last_position;
  8862. -
  8863. - SHORT length_of_rvlc_sf_fwd; /* length_of_rvlc_sf used for forward decoding */
  8864. - SHORT
  8865. - length_of_rvlc_sf_bwd; /* length_of_rvlc_sf used for backward decoding */
  8866. -
  8867. - /* for RVL-Codeword decoder to distinguish between fwd and bwd decoding */
  8868. - SHORT *pRvlBitCnt_RVL;
  8869. - INT *pBitstrIndxRvl_RVL;
  8870. -
  8871. - UCHAR numWindowGroups;
  8872. - UCHAR maxSfbTransmitted;
  8873. - UCHAR first_noise_group;
  8874. - UCHAR first_noise_band;
  8875. - UCHAR direction;
  8876. -
  8877. - /* bitstream indices */
  8878. - INT bsAnchor; /* hcr bit buffer reference index */
  8879. - INT bitstreamIndexRvlFwd; /* base address of RVL-coded-scalefactor data (ESC
  8880. - 2) for forward decoding */
  8881. - INT bitstreamIndexRvlBwd; /* base address of RVL-coded-scalefactor data (ESC
  8882. - 2) for backward decoding */
  8883. - INT bitstreamIndexEsc; /* base address where RVLC-escapes start (ESC 2) */
  8884. -
  8885. - /* decoding trees */
  8886. - const UINT *pHuffTreeRvlCodewds;
  8887. - const UINT *pHuffTreeRvlcEscape;
  8888. -
  8889. - /* escape counters */
  8890. - UCHAR numDecodedEscapeWordsFwd; /* when decoding RVL-codes forward */
  8891. - UCHAR numDecodedEscapeWordsBwd; /* when decoding RVL-codes backward */
  8892. - UCHAR numDecodedEscapeWordsEsc; /* when decoding the escape-Words */
  8893. -
  8894. - SCHAR noise_used;
  8895. - SCHAR intensity_used;
  8896. - SCHAR sf_used;
  8897. -
  8898. - SHORT firstScf;
  8899. - SHORT lastScf;
  8900. - SHORT firstNrg;
  8901. - SHORT lastNrg;
  8902. - SHORT firstIs;
  8903. - SHORT lastIs;
  8904. -
  8905. - /* ------ RVLC error detection ------ */
  8906. - UINT errorLogRvlc; /* store RVLC errors */
  8907. - SHORT conceal_min; /* is set at backward decoding */
  8908. - SHORT conceal_max; /* is set at forward decoding */
  8909. - SHORT conceal_min_esc; /* is set at backward decoding */
  8910. - SHORT conceal_max_esc; /* is set at forward decoding */
  8911. -} CErRvlcInfo;
  8912. -
  8913. -typedef CErRvlcInfo RVLC_INFO; /* temp */
  8914. -
  8915. -#endif /* RVLC_INFO_H */
  8916. diff --git a/libAACdec/src/rvlcbit.cpp b/libAACdec/src/rvlcbit.cpp
  8917. deleted file mode 100644
  8918. index b0c4596..0000000
  8919. --- a/libAACdec/src/rvlcbit.cpp
  8920. +++ /dev/null
  8921. @@ -1,148 +0,0 @@
  8922. -/* -----------------------------------------------------------------------------
  8923. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  8924. -
  8925. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  8926. -Forschung e.V. All rights reserved.
  8927. -
  8928. - 1. INTRODUCTION
  8929. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  8930. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  8931. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  8932. -a wide variety of Android devices.
  8933. -
  8934. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  8935. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  8936. -full-bandwidth communications codec by independent studies and is widely
  8937. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  8938. -specifications.
  8939. -
  8940. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  8941. -those of Fraunhofer) may be obtained through Via Licensing
  8942. -(www.vialicensing.com) or through the respective patent owners individually for
  8943. -the purpose of encoding or decoding bit streams in products that are compliant
  8944. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  8945. -Android devices already license these patent claims through Via Licensing or
  8946. -directly from the patent owners, and therefore FDK AAC Codec software may
  8947. -already be covered under those patent licenses when it is used for those
  8948. -licensed purposes only.
  8949. -
  8950. -Commercially-licensed AAC software libraries, including floating-point versions
  8951. -with enhanced sound quality, are also available from Fraunhofer. Users are
  8952. -encouraged to check the Fraunhofer website for additional applications
  8953. -information and documentation.
  8954. -
  8955. -2. COPYRIGHT LICENSE
  8956. -
  8957. -Redistribution and use in source and binary forms, with or without modification,
  8958. -are permitted without payment of copyright license fees provided that you
  8959. -satisfy the following conditions:
  8960. -
  8961. -You must retain the complete text of this software license in redistributions of
  8962. -the FDK AAC Codec or your modifications thereto in source code form.
  8963. -
  8964. -You must retain the complete text of this software license in the documentation
  8965. -and/or other materials provided with redistributions of the FDK AAC Codec or
  8966. -your modifications thereto in binary form. You must make available free of
  8967. -charge copies of the complete source code of the FDK AAC Codec and your
  8968. -modifications thereto to recipients of copies in binary form.
  8969. -
  8970. -The name of Fraunhofer may not be used to endorse or promote products derived
  8971. -from this library without prior written permission.
  8972. -
  8973. -You may not charge copyright license fees for anyone to use, copy or distribute
  8974. -the FDK AAC Codec software or your modifications thereto.
  8975. -
  8976. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  8977. -that you changed the software and the date of any change. For modified versions
  8978. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  8979. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  8980. -AAC Codec Library for Android."
  8981. -
  8982. -3. NO PATENT LICENSE
  8983. -
  8984. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  8985. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  8986. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  8987. -software.
  8988. -
  8989. -You may use this FDK AAC Codec software or modifications thereto only for
  8990. -purposes that are authorized by appropriate patent licenses.
  8991. -
  8992. -4. DISCLAIMER
  8993. -
  8994. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  8995. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  8996. -including but not limited to the implied warranties of merchantability and
  8997. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  8998. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  8999. -or consequential damages, including but not limited to procurement of substitute
  9000. -goods or services; loss of use, data, or profits, or business interruption,
  9001. -however caused and on any theory of liability, whether in contract, strict
  9002. -liability, or tort (including negligence), arising in any way out of the use of
  9003. -this software, even if advised of the possibility of such damage.
  9004. -
  9005. -5. CONTACT INFORMATION
  9006. -
  9007. -Fraunhofer Institute for Integrated Circuits IIS
  9008. -Attention: Audio and Multimedia Departments - FDK AAC LL
  9009. -Am Wolfsmantel 33
  9010. -91058 Erlangen, Germany
  9011. -
  9012. -www.iis.fraunhofer.de/amm
  9013. -amm-info@iis.fraunhofer.de
  9014. ------------------------------------------------------------------------------ */
  9015. -
  9016. -/**************************** AAC decoder library ******************************
  9017. -
  9018. - Author(s):
  9019. -
  9020. - Description:
  9021. -
  9022. -*******************************************************************************/
  9023. -
  9024. -/*!
  9025. - \file
  9026. - \brief RVLC bitstream reading
  9027. - \author Robert Weidner
  9028. -*/
  9029. -
  9030. -#include "rvlcbit.h"
  9031. -
  9032. -/*---------------------------------------------------------------------------------------------
  9033. - function: rvlcReadBitFromBitstream
  9034. -
  9035. - description: This function returns a bit from the bitstream according to
  9036. -read direction. It is called very often, therefore it makes sense to inline it
  9037. -(runtime).
  9038. ------------------------------------------------------------------------------------------------
  9039. - input: - bitstream
  9040. - - pPosition
  9041. - - readDirection
  9042. ------------------------------------------------------------------------------------------------
  9043. - return: - bit from bitstream
  9044. ---------------------------------------------------------------------------------------------
  9045. -*/
  9046. -
  9047. -UCHAR rvlcReadBitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  9048. - INT *pPosition, UCHAR readDirection) {
  9049. - UINT bit;
  9050. - INT readBitOffset = (INT)FDKgetValidBits(bs) - bsAnchor + *pPosition;
  9051. -
  9052. - if (readBitOffset) {
  9053. - FDKpushBiDirectional(bs, readBitOffset);
  9054. - }
  9055. -
  9056. - if (readDirection == FWD) {
  9057. - bit = FDKreadBits(bs, 1);
  9058. -
  9059. - *pPosition += 1;
  9060. - } else {
  9061. - /* to be replaced with a brother function of FDKreadBits() */
  9062. - bit = FDKreadBits(bs, 1);
  9063. - FDKpushBack(bs, 2);
  9064. -
  9065. - *pPosition -= 1;
  9066. - }
  9067. -
  9068. - return (bit);
  9069. -}
  9070. diff --git a/libAACdec/src/rvlcbit.h b/libAACdec/src/rvlcbit.h
  9071. deleted file mode 100644
  9072. index 2578453..0000000
  9073. --- a/libAACdec/src/rvlcbit.h
  9074. +++ /dev/null
  9075. @@ -1,111 +0,0 @@
  9076. -/* -----------------------------------------------------------------------------
  9077. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  9078. -
  9079. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  9080. -Forschung e.V. All rights reserved.
  9081. -
  9082. - 1. INTRODUCTION
  9083. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  9084. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  9085. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  9086. -a wide variety of Android devices.
  9087. -
  9088. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  9089. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  9090. -full-bandwidth communications codec by independent studies and is widely
  9091. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  9092. -specifications.
  9093. -
  9094. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  9095. -those of Fraunhofer) may be obtained through Via Licensing
  9096. -(www.vialicensing.com) or through the respective patent owners individually for
  9097. -the purpose of encoding or decoding bit streams in products that are compliant
  9098. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  9099. -Android devices already license these patent claims through Via Licensing or
  9100. -directly from the patent owners, and therefore FDK AAC Codec software may
  9101. -already be covered under those patent licenses when it is used for those
  9102. -licensed purposes only.
  9103. -
  9104. -Commercially-licensed AAC software libraries, including floating-point versions
  9105. -with enhanced sound quality, are also available from Fraunhofer. Users are
  9106. -encouraged to check the Fraunhofer website for additional applications
  9107. -information and documentation.
  9108. -
  9109. -2. COPYRIGHT LICENSE
  9110. -
  9111. -Redistribution and use in source and binary forms, with or without modification,
  9112. -are permitted without payment of copyright license fees provided that you
  9113. -satisfy the following conditions:
  9114. -
  9115. -You must retain the complete text of this software license in redistributions of
  9116. -the FDK AAC Codec or your modifications thereto in source code form.
  9117. -
  9118. -You must retain the complete text of this software license in the documentation
  9119. -and/or other materials provided with redistributions of the FDK AAC Codec or
  9120. -your modifications thereto in binary form. You must make available free of
  9121. -charge copies of the complete source code of the FDK AAC Codec and your
  9122. -modifications thereto to recipients of copies in binary form.
  9123. -
  9124. -The name of Fraunhofer may not be used to endorse or promote products derived
  9125. -from this library without prior written permission.
  9126. -
  9127. -You may not charge copyright license fees for anyone to use, copy or distribute
  9128. -the FDK AAC Codec software or your modifications thereto.
  9129. -
  9130. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  9131. -that you changed the software and the date of any change. For modified versions
  9132. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  9133. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  9134. -AAC Codec Library for Android."
  9135. -
  9136. -3. NO PATENT LICENSE
  9137. -
  9138. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  9139. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  9140. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  9141. -software.
  9142. -
  9143. -You may use this FDK AAC Codec software or modifications thereto only for
  9144. -purposes that are authorized by appropriate patent licenses.
  9145. -
  9146. -4. DISCLAIMER
  9147. -
  9148. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  9149. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  9150. -including but not limited to the implied warranties of merchantability and
  9151. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  9152. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  9153. -or consequential damages, including but not limited to procurement of substitute
  9154. -goods or services; loss of use, data, or profits, or business interruption,
  9155. -however caused and on any theory of liability, whether in contract, strict
  9156. -liability, or tort (including negligence), arising in any way out of the use of
  9157. -this software, even if advised of the possibility of such damage.
  9158. -
  9159. -5. CONTACT INFORMATION
  9160. -
  9161. -Fraunhofer Institute for Integrated Circuits IIS
  9162. -Attention: Audio and Multimedia Departments - FDK AAC LL
  9163. -Am Wolfsmantel 33
  9164. -91058 Erlangen, Germany
  9165. -
  9166. -www.iis.fraunhofer.de/amm
  9167. -amm-info@iis.fraunhofer.de
  9168. ------------------------------------------------------------------------------ */
  9169. -
  9170. -/**************************** AAC decoder library ******************************
  9171. -
  9172. - Author(s): Robert Weidner (DSP Solutions)
  9173. -
  9174. - Description: RVLC Decoder: Bitstream reading
  9175. -
  9176. -*******************************************************************************/
  9177. -
  9178. -#ifndef RVLCBIT_H
  9179. -#define RVLCBIT_H
  9180. -
  9181. -#include "rvlc.h"
  9182. -
  9183. -UCHAR rvlcReadBitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,
  9184. - INT *pPosition, UCHAR readDirection);
  9185. -
  9186. -#endif /* RVLCBIT_H */
  9187. diff --git a/libAACdec/src/rvlcconceal.cpp b/libAACdec/src/rvlcconceal.cpp
  9188. deleted file mode 100644
  9189. index 77fda68..0000000
  9190. --- a/libAACdec/src/rvlcconceal.cpp
  9191. +++ /dev/null
  9192. @@ -1,787 +0,0 @@
  9193. -/* -----------------------------------------------------------------------------
  9194. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  9195. -
  9196. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  9197. -Forschung e.V. All rights reserved.
  9198. -
  9199. - 1. INTRODUCTION
  9200. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  9201. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  9202. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  9203. -a wide variety of Android devices.
  9204. -
  9205. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  9206. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  9207. -full-bandwidth communications codec by independent studies and is widely
  9208. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  9209. -specifications.
  9210. -
  9211. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  9212. -those of Fraunhofer) may be obtained through Via Licensing
  9213. -(www.vialicensing.com) or through the respective patent owners individually for
  9214. -the purpose of encoding or decoding bit streams in products that are compliant
  9215. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  9216. -Android devices already license these patent claims through Via Licensing or
  9217. -directly from the patent owners, and therefore FDK AAC Codec software may
  9218. -already be covered under those patent licenses when it is used for those
  9219. -licensed purposes only.
  9220. -
  9221. -Commercially-licensed AAC software libraries, including floating-point versions
  9222. -with enhanced sound quality, are also available from Fraunhofer. Users are
  9223. -encouraged to check the Fraunhofer website for additional applications
  9224. -information and documentation.
  9225. -
  9226. -2. COPYRIGHT LICENSE
  9227. -
  9228. -Redistribution and use in source and binary forms, with or without modification,
  9229. -are permitted without payment of copyright license fees provided that you
  9230. -satisfy the following conditions:
  9231. -
  9232. -You must retain the complete text of this software license in redistributions of
  9233. -the FDK AAC Codec or your modifications thereto in source code form.
  9234. -
  9235. -You must retain the complete text of this software license in the documentation
  9236. -and/or other materials provided with redistributions of the FDK AAC Codec or
  9237. -your modifications thereto in binary form. You must make available free of
  9238. -charge copies of the complete source code of the FDK AAC Codec and your
  9239. -modifications thereto to recipients of copies in binary form.
  9240. -
  9241. -The name of Fraunhofer may not be used to endorse or promote products derived
  9242. -from this library without prior written permission.
  9243. -
  9244. -You may not charge copyright license fees for anyone to use, copy or distribute
  9245. -the FDK AAC Codec software or your modifications thereto.
  9246. -
  9247. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  9248. -that you changed the software and the date of any change. For modified versions
  9249. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  9250. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  9251. -AAC Codec Library for Android."
  9252. -
  9253. -3. NO PATENT LICENSE
  9254. -
  9255. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  9256. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  9257. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  9258. -software.
  9259. -
  9260. -You may use this FDK AAC Codec software or modifications thereto only for
  9261. -purposes that are authorized by appropriate patent licenses.
  9262. -
  9263. -4. DISCLAIMER
  9264. -
  9265. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  9266. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  9267. -including but not limited to the implied warranties of merchantability and
  9268. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  9269. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  9270. -or consequential damages, including but not limited to procurement of substitute
  9271. -goods or services; loss of use, data, or profits, or business interruption,
  9272. -however caused and on any theory of liability, whether in contract, strict
  9273. -liability, or tort (including negligence), arising in any way out of the use of
  9274. -this software, even if advised of the possibility of such damage.
  9275. -
  9276. -5. CONTACT INFORMATION
  9277. -
  9278. -Fraunhofer Institute for Integrated Circuits IIS
  9279. -Attention: Audio and Multimedia Departments - FDK AAC LL
  9280. -Am Wolfsmantel 33
  9281. -91058 Erlangen, Germany
  9282. -
  9283. -www.iis.fraunhofer.de/amm
  9284. -amm-info@iis.fraunhofer.de
  9285. ------------------------------------------------------------------------------ */
  9286. -
  9287. -/**************************** AAC decoder library ******************************
  9288. -
  9289. - Author(s):
  9290. -
  9291. - Description:
  9292. -
  9293. -*******************************************************************************/
  9294. -
  9295. -/*!
  9296. - \file
  9297. - \brief rvlc concealment
  9298. - \author Josef Hoepfl
  9299. -*/
  9300. -
  9301. -#include "rvlcconceal.h"
  9302. -
  9303. -#include "block.h"
  9304. -#include "rvlc.h"
  9305. -
  9306. -/*---------------------------------------------------------------------------------------------
  9307. - function: calcRefValFwd
  9308. -
  9309. - description: The function determines the scalefactor which is closed to the
  9310. -scalefactorband conceal_min. The same is done for intensity data and noise
  9311. -energies.
  9312. ------------------------------------------------------------------------------------------------
  9313. - output: - reference value scf
  9314. - - reference value internsity data
  9315. - - reference value noise energy
  9316. ------------------------------------------------------------------------------------------------
  9317. - return: -
  9318. ---------------------------------------------------------------------------------------------
  9319. -*/
  9320. -
  9321. -static void calcRefValFwd(CErRvlcInfo *pRvlc,
  9322. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  9323. - int *refIsFwd, int *refNrgFwd, int *refScfFwd) {
  9324. - int band, bnds, group, startBand;
  9325. - int idIs, idNrg, idScf;
  9326. - int conceal_min, conceal_group_min;
  9327. - int MaximumScaleFactorBands;
  9328. -
  9329. - if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT)
  9330. - MaximumScaleFactorBands = 16;
  9331. - else
  9332. - MaximumScaleFactorBands = 64;
  9333. -
  9334. - conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
  9335. - conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
  9336. -
  9337. - /* calculate first reference value for approach in forward direction */
  9338. - idIs = idNrg = idScf = 1;
  9339. -
  9340. - /* set reference values */
  9341. - *refIsFwd = -SF_OFFSET;
  9342. - *refNrgFwd = pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain -
  9343. - SF_OFFSET - 90 - 256;
  9344. - *refScfFwd =
  9345. - pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET;
  9346. -
  9347. - startBand = conceal_min - 1;
  9348. - for (group = conceal_group_min; group >= 0; group--) {
  9349. - for (band = startBand; band >= 0; band--) {
  9350. - bnds = 16 * group + band;
  9351. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  9352. - case ZERO_HCB:
  9353. - break;
  9354. - case INTENSITY_HCB:
  9355. - case INTENSITY_HCB2:
  9356. - if (idIs) {
  9357. - *refIsFwd =
  9358. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9359. - idIs = 0; /* reference value has been set */
  9360. - }
  9361. - break;
  9362. - case NOISE_HCB:
  9363. - if (idNrg) {
  9364. - *refNrgFwd =
  9365. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9366. - idNrg = 0; /* reference value has been set */
  9367. - }
  9368. - break;
  9369. - default:
  9370. - if (idScf) {
  9371. - *refScfFwd =
  9372. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9373. - idScf = 0; /* reference value has been set */
  9374. - }
  9375. - break;
  9376. - }
  9377. - }
  9378. - startBand = pRvlc->maxSfbTransmitted - 1;
  9379. - }
  9380. -}
  9381. -
  9382. -/*---------------------------------------------------------------------------------------------
  9383. - function: calcRefValBwd
  9384. -
  9385. - description: The function determines the scalefactor which is closed to the
  9386. -scalefactorband conceal_max. The same is done for intensity data and noise
  9387. -energies.
  9388. ------------------------------------------------------------------------------------------------
  9389. - output: - reference value scf
  9390. - - reference value internsity data
  9391. - - reference value noise energy
  9392. ------------------------------------------------------------------------------------------------
  9393. - return: -
  9394. ---------------------------------------------------------------------------------------------
  9395. -*/
  9396. -
  9397. -static void calcRefValBwd(CErRvlcInfo *pRvlc,
  9398. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  9399. - int *refIsBwd, int *refNrgBwd, int *refScfBwd) {
  9400. - int band, bnds, group, startBand;
  9401. - int idIs, idNrg, idScf;
  9402. - int conceal_max, conceal_group_max;
  9403. - int MaximumScaleFactorBands;
  9404. -
  9405. - if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT)
  9406. - MaximumScaleFactorBands = 16;
  9407. - else
  9408. - MaximumScaleFactorBands = 64;
  9409. -
  9410. - conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
  9411. - conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
  9412. -
  9413. - /* calculate first reference value for approach in backward direction */
  9414. - idIs = idNrg = idScf = 1;
  9415. -
  9416. - /* set reference values */
  9417. - *refIsBwd = pRvlc->dpcm_is_last_position - SF_OFFSET;
  9418. - *refNrgBwd = pRvlc->rev_global_gain + pRvlc->dpcm_noise_last_position -
  9419. - SF_OFFSET - 90 - 256 + pRvlc->dpcm_noise_nrg;
  9420. - *refScfBwd = pRvlc->rev_global_gain - SF_OFFSET;
  9421. -
  9422. - startBand = conceal_max + 1;
  9423. -
  9424. - /* if needed, re-set reference values */
  9425. - for (group = conceal_group_max; group < pRvlc->numWindowGroups; group++) {
  9426. - for (band = startBand; band < pRvlc->maxSfbTransmitted; band++) {
  9427. - bnds = 16 * group + band;
  9428. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  9429. - case ZERO_HCB:
  9430. - break;
  9431. - case INTENSITY_HCB:
  9432. - case INTENSITY_HCB2:
  9433. - if (idIs) {
  9434. - *refIsBwd =
  9435. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9436. - idIs = 0; /* reference value has been set */
  9437. - }
  9438. - break;
  9439. - case NOISE_HCB:
  9440. - if (idNrg) {
  9441. - *refNrgBwd =
  9442. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9443. - idNrg = 0; /* reference value has been set */
  9444. - }
  9445. - break;
  9446. - default:
  9447. - if (idScf) {
  9448. - *refScfBwd =
  9449. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9450. - idScf = 0; /* reference value has been set */
  9451. - }
  9452. - break;
  9453. - }
  9454. - }
  9455. - startBand = 0;
  9456. - }
  9457. -}
  9458. -
  9459. -/*---------------------------------------------------------------------------------------------
  9460. - function: BidirectionalEstimation_UseLowerScfOfCurrentFrame
  9461. -
  9462. - description: This approach by means of bidirectional estimation is generally
  9463. -performed when a single bit error has been detected, the bit error can be
  9464. -isolated between 'conceal_min' and 'conceal_max' and the 'sf_concealment' flag
  9465. -is not set. The sets of scalefactors decoded in forward and backward direction
  9466. -are compared with each other. The smaller scalefactor will be considered as the
  9467. -correct one respectively. The reconstruction of the scalefactors with this
  9468. -approach archieve good results in audio quality. The strategy must be applied to
  9469. -scalefactors, intensity data and noise energy seperately.
  9470. ------------------------------------------------------------------------------------------------
  9471. - output: Concealed scalefactor, noise energy and intensity data between
  9472. -conceal_min and conceal_max
  9473. ------------------------------------------------------------------------------------------------
  9474. - return: -
  9475. ---------------------------------------------------------------------------------------------
  9476. -*/
  9477. -
  9478. -void BidirectionalEstimation_UseLowerScfOfCurrentFrame(
  9479. - CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
  9480. - CErRvlcInfo *pRvlc =
  9481. - &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
  9482. - int band, bnds, startBand, endBand, group;
  9483. - int conceal_min, conceal_max;
  9484. - int conceal_group_min, conceal_group_max;
  9485. - int MaximumScaleFactorBands;
  9486. -
  9487. - if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) {
  9488. - MaximumScaleFactorBands = 16;
  9489. - } else {
  9490. - MaximumScaleFactorBands = 64;
  9491. - }
  9492. -
  9493. - /* If an error was detected just in forward or backward direction, set the
  9494. - corresponding border for concealment to a appropriate scalefactor band. The
  9495. - border is set to first or last sfb respectively, because the error will
  9496. - possibly not follow directly after the corrupt bit but just after decoding
  9497. - some more (wrong) scalefactors. */
  9498. - if (pRvlc->conceal_min == CONCEAL_MIN_INIT) pRvlc->conceal_min = 0;
  9499. -
  9500. - if (pRvlc->conceal_max == CONCEAL_MAX_INIT)
  9501. - pRvlc->conceal_max =
  9502. - (pRvlc->numWindowGroups - 1) * 16 + pRvlc->maxSfbTransmitted - 1;
  9503. -
  9504. - conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
  9505. - conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
  9506. - conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
  9507. - conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
  9508. -
  9509. - if (pRvlc->conceal_min == pRvlc->conceal_max) {
  9510. - int refIsFwd, refNrgFwd, refScfFwd;
  9511. - int refIsBwd, refNrgBwd, refScfBwd;
  9512. -
  9513. - bnds = pRvlc->conceal_min;
  9514. - calcRefValFwd(pRvlc, pAacDecoderChannelInfo, &refIsFwd, &refNrgFwd,
  9515. - &refScfFwd);
  9516. - calcRefValBwd(pRvlc, pAacDecoderChannelInfo, &refIsBwd, &refNrgBwd,
  9517. - &refScfBwd);
  9518. -
  9519. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  9520. - case ZERO_HCB:
  9521. - break;
  9522. - case INTENSITY_HCB:
  9523. - case INTENSITY_HCB2:
  9524. - if (refIsFwd < refIsBwd)
  9525. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refIsFwd;
  9526. - else
  9527. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refIsBwd;
  9528. - break;
  9529. - case NOISE_HCB:
  9530. - if (refNrgFwd < refNrgBwd)
  9531. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refNrgFwd;
  9532. - else
  9533. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refNrgBwd;
  9534. - break;
  9535. - default:
  9536. - if (refScfFwd < refScfBwd)
  9537. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refScfFwd;
  9538. - else
  9539. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refScfBwd;
  9540. - break;
  9541. - }
  9542. - } else {
  9543. - pAacDecoderChannelInfo->pComData->overlay.aac
  9544. - .aRvlcScfFwd[pRvlc->conceal_max] =
  9545. - pAacDecoderChannelInfo->pComData->overlay.aac
  9546. - .aRvlcScfBwd[pRvlc->conceal_max];
  9547. - pAacDecoderChannelInfo->pComData->overlay.aac
  9548. - .aRvlcScfBwd[pRvlc->conceal_min] =
  9549. - pAacDecoderChannelInfo->pComData->overlay.aac
  9550. - .aRvlcScfFwd[pRvlc->conceal_min];
  9551. -
  9552. - /* consider the smaller of the forward and backward decoded value as the
  9553. - * correct one */
  9554. - startBand = conceal_min;
  9555. - if (conceal_group_min == conceal_group_max)
  9556. - endBand = conceal_max;
  9557. - else
  9558. - endBand = pRvlc->maxSfbTransmitted - 1;
  9559. -
  9560. - for (group = conceal_group_min; group <= conceal_group_max; group++) {
  9561. - for (band = startBand; band <= endBand; band++) {
  9562. - bnds = 16 * group + band;
  9563. - if (pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds] <
  9564. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds])
  9565. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9566. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9567. - else
  9568. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9569. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9570. - }
  9571. - startBand = 0;
  9572. - if ((group + 1) == conceal_group_max) endBand = conceal_max;
  9573. - }
  9574. - }
  9575. -
  9576. - /* now copy all data to the output buffer which needs not to be concealed */
  9577. - if (conceal_group_min == 0)
  9578. - endBand = conceal_min;
  9579. - else
  9580. - endBand = pRvlc->maxSfbTransmitted;
  9581. - for (group = 0; group <= conceal_group_min; group++) {
  9582. - for (band = 0; band < endBand; band++) {
  9583. - bnds = 16 * group + band;
  9584. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9585. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9586. - }
  9587. - if ((group + 1) == conceal_group_min) endBand = conceal_min;
  9588. - }
  9589. -
  9590. - startBand = conceal_max + 1;
  9591. - for (group = conceal_group_max; group < pRvlc->numWindowGroups; group++) {
  9592. - for (band = startBand; band < pRvlc->maxSfbTransmitted; band++) {
  9593. - bnds = 16 * group + band;
  9594. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9595. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9596. - }
  9597. - startBand = 0;
  9598. - }
  9599. -}
  9600. -
  9601. -/*---------------------------------------------------------------------------------------------
  9602. - function: BidirectionalEstimation_UseScfOfPrevFrameAsReference
  9603. -
  9604. - description: This approach by means of bidirectional estimation is generally
  9605. -performed when a single bit error has been detected, the bit error can be
  9606. -isolated between 'conceal_min' and 'conceal_max', the 'sf_concealment' flag is
  9607. -set and the previous frame has the same block type as the current frame. The
  9608. -scalefactor decoded in forward and backward direction and the scalefactor of the
  9609. -previous frame are compared with each other. The smaller scalefactor will be
  9610. -considered as the correct one. At this the codebook of the previous and current
  9611. -frame must be of the same set (scf, nrg, is) in each scalefactorband. Otherwise
  9612. -the scalefactor of the previous frame is not considered in the minimum
  9613. -calculation. The reconstruction of the scalefactors with this approach archieve
  9614. -good results in audio quality. The strategy must be applied to scalefactors,
  9615. -intensity data and noise energy seperately.
  9616. ------------------------------------------------------------------------------------------------
  9617. - output: Concealed scalefactor, noise energy and intensity data between
  9618. -conceal_min and conceal_max
  9619. ------------------------------------------------------------------------------------------------
  9620. - return: -
  9621. ---------------------------------------------------------------------------------------------
  9622. -*/
  9623. -
  9624. -void BidirectionalEstimation_UseScfOfPrevFrameAsReference(
  9625. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  9626. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
  9627. - CErRvlcInfo *pRvlc =
  9628. - &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
  9629. - int band, bnds, startBand, endBand, group;
  9630. - int conceal_min, conceal_max;
  9631. - int conceal_group_min, conceal_group_max;
  9632. - int MaximumScaleFactorBands;
  9633. - SHORT commonMin;
  9634. -
  9635. - if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) {
  9636. - MaximumScaleFactorBands = 16;
  9637. - } else {
  9638. - MaximumScaleFactorBands = 64;
  9639. - }
  9640. -
  9641. - /* If an error was detected just in forward or backward direction, set the
  9642. - corresponding border for concealment to a appropriate scalefactor band. The
  9643. - border is set to first or last sfb respectively, because the error will
  9644. - possibly not follow directly after the corrupt bit but just after decoding
  9645. - some more (wrong) scalefactors. */
  9646. - if (pRvlc->conceal_min == CONCEAL_MIN_INIT) pRvlc->conceal_min = 0;
  9647. -
  9648. - if (pRvlc->conceal_max == CONCEAL_MAX_INIT)
  9649. - pRvlc->conceal_max =
  9650. - (pRvlc->numWindowGroups - 1) * 16 + pRvlc->maxSfbTransmitted - 1;
  9651. -
  9652. - conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
  9653. - conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
  9654. - conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
  9655. - conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
  9656. -
  9657. - pAacDecoderChannelInfo->pComData->overlay.aac
  9658. - .aRvlcScfFwd[pRvlc->conceal_max] =
  9659. - pAacDecoderChannelInfo->pComData->overlay.aac
  9660. - .aRvlcScfBwd[pRvlc->conceal_max];
  9661. - pAacDecoderChannelInfo->pComData->overlay.aac
  9662. - .aRvlcScfBwd[pRvlc->conceal_min] =
  9663. - pAacDecoderChannelInfo->pComData->overlay.aac
  9664. - .aRvlcScfFwd[pRvlc->conceal_min];
  9665. -
  9666. - /* consider the smaller of the forward and backward decoded value as the
  9667. - * correct one */
  9668. - startBand = conceal_min;
  9669. - if (conceal_group_min == conceal_group_max)
  9670. - endBand = conceal_max;
  9671. - else
  9672. - endBand = pRvlc->maxSfbTransmitted - 1;
  9673. -
  9674. - for (group = conceal_group_min; group <= conceal_group_max; group++) {
  9675. - for (band = startBand; band <= endBand; band++) {
  9676. - bnds = 16 * group + band;
  9677. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  9678. - case ZERO_HCB:
  9679. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
  9680. - break;
  9681. -
  9682. - case INTENSITY_HCB:
  9683. - case INTENSITY_HCB2:
  9684. - if ((pAacDecoderStaticChannelInfo->concealmentInfo
  9685. - .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB) ||
  9686. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9687. - .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB2)) {
  9688. - commonMin = fMin(
  9689. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9690. - pAacDecoderChannelInfo->pComData->overlay.aac
  9691. - .aRvlcScfBwd[bnds]);
  9692. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9693. - fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
  9694. - .aRvlcPreviousScaleFactor[bnds]);
  9695. - } else {
  9696. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = fMin(
  9697. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9698. - pAacDecoderChannelInfo->pComData->overlay.aac
  9699. - .aRvlcScfBwd[bnds]);
  9700. - }
  9701. - break;
  9702. -
  9703. - case NOISE_HCB:
  9704. - if (pAacDecoderStaticChannelInfo->concealmentInfo
  9705. - .aRvlcPreviousCodebook[bnds] == NOISE_HCB) {
  9706. - commonMin = fMin(
  9707. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9708. - pAacDecoderChannelInfo->pComData->overlay.aac
  9709. - .aRvlcScfBwd[bnds]);
  9710. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9711. - fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
  9712. - .aRvlcPreviousScaleFactor[bnds]);
  9713. - } else {
  9714. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = fMin(
  9715. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9716. - pAacDecoderChannelInfo->pComData->overlay.aac
  9717. - .aRvlcScfBwd[bnds]);
  9718. - }
  9719. - break;
  9720. -
  9721. - default:
  9722. - if ((pAacDecoderStaticChannelInfo->concealmentInfo
  9723. - .aRvlcPreviousCodebook[bnds] != ZERO_HCB) &&
  9724. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9725. - .aRvlcPreviousCodebook[bnds] != NOISE_HCB) &&
  9726. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9727. - .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB) &&
  9728. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9729. - .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB2)) {
  9730. - commonMin = fMin(
  9731. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9732. - pAacDecoderChannelInfo->pComData->overlay.aac
  9733. - .aRvlcScfBwd[bnds]);
  9734. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9735. - fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
  9736. - .aRvlcPreviousScaleFactor[bnds]);
  9737. - } else {
  9738. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = fMin(
  9739. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9740. - pAacDecoderChannelInfo->pComData->overlay.aac
  9741. - .aRvlcScfBwd[bnds]);
  9742. - }
  9743. - break;
  9744. - }
  9745. - }
  9746. - startBand = 0;
  9747. - if ((group + 1) == conceal_group_max) endBand = conceal_max;
  9748. - }
  9749. -
  9750. - /* now copy all data to the output buffer which needs not to be concealed */
  9751. - if (conceal_group_min == 0)
  9752. - endBand = conceal_min;
  9753. - else
  9754. - endBand = pRvlc->maxSfbTransmitted;
  9755. - for (group = 0; group <= conceal_group_min; group++) {
  9756. - for (band = 0; band < endBand; band++) {
  9757. - bnds = 16 * group + band;
  9758. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9759. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9760. - }
  9761. - if ((group + 1) == conceal_group_min) endBand = conceal_min;
  9762. - }
  9763. -
  9764. - startBand = conceal_max + 1;
  9765. - for (group = conceal_group_max; group < pRvlc->numWindowGroups; group++) {
  9766. - for (band = startBand; band < pRvlc->maxSfbTransmitted; band++) {
  9767. - bnds = 16 * group + band;
  9768. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9769. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9770. - }
  9771. - startBand = 0;
  9772. - }
  9773. -}
  9774. -
  9775. -/*---------------------------------------------------------------------------------------------
  9776. - function: StatisticalEstimation
  9777. -
  9778. - description: This approach by means of statistical estimation is generally
  9779. -performed when both the start value and the end value are different and no
  9780. -further errors have been detected. Considering the forward and backward decoded
  9781. -scalefactors, the set with the lower scalefactors in sum will be considered as
  9782. -the correct one. The scalefactors are differentially encoded. Normally it would
  9783. -reach to compare one pair of the forward and backward decoded scalefactors to
  9784. -specify the lower set. But having detected no further errors does not
  9785. -necessarily mean the absence of errors. Therefore all scalefactors decoded in
  9786. -forward and backward direction are summed up seperately. The set with the lower
  9787. -sum will be used. The strategy must be applied to scalefactors, intensity data
  9788. -and noise energy seperately.
  9789. ------------------------------------------------------------------------------------------------
  9790. - output: Concealed scalefactor, noise energy and intensity data
  9791. ------------------------------------------------------------------------------------------------
  9792. - return: -
  9793. ---------------------------------------------------------------------------------------------
  9794. -*/
  9795. -
  9796. -void StatisticalEstimation(CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
  9797. - CErRvlcInfo *pRvlc =
  9798. - &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
  9799. - int band, bnds, group;
  9800. - int sumIsFwd, sumIsBwd; /* sum of intensity data forward/backward */
  9801. - int sumNrgFwd, sumNrgBwd; /* sum of noise energy data forward/backward */
  9802. - int sumScfFwd, sumScfBwd; /* sum of scalefactor data forward/backward */
  9803. - int useIsFwd, useNrgFwd, useScfFwd; /* the flags signals the elements which
  9804. - are used for the final result */
  9805. -
  9806. - sumIsFwd = sumIsBwd = sumNrgFwd = sumNrgBwd = sumScfFwd = sumScfBwd = 0;
  9807. - useIsFwd = useNrgFwd = useScfFwd = 0;
  9808. -
  9809. - /* calculate sum of each group (scf,nrg,is) of forward and backward direction
  9810. - */
  9811. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  9812. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  9813. - bnds = 16 * group + band;
  9814. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  9815. - case ZERO_HCB:
  9816. - break;
  9817. -
  9818. - case INTENSITY_HCB:
  9819. - case INTENSITY_HCB2:
  9820. - sumIsFwd +=
  9821. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9822. - sumIsBwd +=
  9823. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9824. - break;
  9825. -
  9826. - case NOISE_HCB:
  9827. - sumNrgFwd +=
  9828. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9829. - sumNrgBwd +=
  9830. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9831. - break;
  9832. -
  9833. - default:
  9834. - sumScfFwd +=
  9835. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9836. - sumScfBwd +=
  9837. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9838. - break;
  9839. - }
  9840. - }
  9841. - }
  9842. -
  9843. - /* find for each group (scf,nrg,is) the correct direction */
  9844. - if (sumIsFwd < sumIsBwd) useIsFwd = 1;
  9845. -
  9846. - if (sumNrgFwd < sumNrgBwd) useNrgFwd = 1;
  9847. -
  9848. - if (sumScfFwd < sumScfBwd) useScfFwd = 1;
  9849. -
  9850. - /* conceal each group (scf,nrg,is) */
  9851. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  9852. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  9853. - bnds = 16 * group + band;
  9854. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  9855. - case ZERO_HCB:
  9856. - break;
  9857. -
  9858. - case INTENSITY_HCB:
  9859. - case INTENSITY_HCB2:
  9860. - if (useIsFwd)
  9861. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9862. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9863. - else
  9864. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9865. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9866. - break;
  9867. -
  9868. - case NOISE_HCB:
  9869. - if (useNrgFwd)
  9870. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9871. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9872. - else
  9873. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9874. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9875. - break;
  9876. -
  9877. - default:
  9878. - if (useScfFwd)
  9879. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9880. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
  9881. - else
  9882. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9883. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
  9884. - break;
  9885. - }
  9886. - }
  9887. - }
  9888. -}
  9889. -
  9890. -/*---------------------------------------------------------------------------------------------
  9891. - description: Approach by means of predictive interpolation
  9892. - This approach by means of predictive estimation is generally
  9893. -performed when the error cannot be isolated between 'conceal_min' and
  9894. -'conceal_max', the 'sf_concealment' flag is set and the previous frame has the
  9895. -same block type as the current frame. Check for each scalefactorband if the same
  9896. -type of data (scalefactor, internsity data, noise energies) is transmitted. If
  9897. -so use the scalefactor (intensity data, noise energy) in the current frame.
  9898. -Otherwise set the scalefactor (intensity data, noise energy) for this
  9899. -scalefactorband to zero.
  9900. ------------------------------------------------------------------------------------------------
  9901. - output: Concealed scalefactor, noise energy and intensity data
  9902. ------------------------------------------------------------------------------------------------
  9903. - return: -
  9904. ---------------------------------------------------------------------------------------------
  9905. -*/
  9906. -
  9907. -void PredictiveInterpolation(
  9908. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  9909. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
  9910. - CErRvlcInfo *pRvlc =
  9911. - &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
  9912. - int band, bnds, group;
  9913. - SHORT commonMin;
  9914. -
  9915. - for (group = 0; group < pRvlc->numWindowGroups; group++) {
  9916. - for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
  9917. - bnds = 16 * group + band;
  9918. - switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
  9919. - case ZERO_HCB:
  9920. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
  9921. - break;
  9922. -
  9923. - case INTENSITY_HCB:
  9924. - case INTENSITY_HCB2:
  9925. - if ((pAacDecoderStaticChannelInfo->concealmentInfo
  9926. - .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB) ||
  9927. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9928. - .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB2)) {
  9929. - commonMin = fMin(
  9930. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9931. - pAacDecoderChannelInfo->pComData->overlay.aac
  9932. - .aRvlcScfBwd[bnds]);
  9933. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9934. - fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
  9935. - .aRvlcPreviousScaleFactor[bnds]);
  9936. - } else {
  9937. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = -110;
  9938. - }
  9939. - break;
  9940. -
  9941. - case NOISE_HCB:
  9942. - if (pAacDecoderStaticChannelInfo->concealmentInfo
  9943. - .aRvlcPreviousCodebook[bnds] == NOISE_HCB) {
  9944. - commonMin = fMin(
  9945. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9946. - pAacDecoderChannelInfo->pComData->overlay.aac
  9947. - .aRvlcScfBwd[bnds]);
  9948. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9949. - fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
  9950. - .aRvlcPreviousScaleFactor[bnds]);
  9951. - } else {
  9952. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = -110;
  9953. - }
  9954. - break;
  9955. -
  9956. - default:
  9957. - if ((pAacDecoderStaticChannelInfo->concealmentInfo
  9958. - .aRvlcPreviousCodebook[bnds] != ZERO_HCB) &&
  9959. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9960. - .aRvlcPreviousCodebook[bnds] != NOISE_HCB) &&
  9961. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9962. - .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB) &&
  9963. - (pAacDecoderStaticChannelInfo->concealmentInfo
  9964. - .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB2)) {
  9965. - commonMin = fMin(
  9966. - pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
  9967. - pAacDecoderChannelInfo->pComData->overlay.aac
  9968. - .aRvlcScfBwd[bnds]);
  9969. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
  9970. - fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
  9971. - .aRvlcPreviousScaleFactor[bnds]);
  9972. - } else {
  9973. - pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
  9974. - }
  9975. - break;
  9976. - }
  9977. - }
  9978. - }
  9979. -}
  9980. diff --git a/libAACdec/src/rvlcconceal.h b/libAACdec/src/rvlcconceal.h
  9981. deleted file mode 100644
  9982. index 8e2062e..0000000
  9983. --- a/libAACdec/src/rvlcconceal.h
  9984. +++ /dev/null
  9985. @@ -1,127 +0,0 @@
  9986. -/* -----------------------------------------------------------------------------
  9987. -Software License for The Fraunhofer FDK AAC Codec Library for Android
  9988. -
  9989. -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
  9990. -Forschung e.V. All rights reserved.
  9991. -
  9992. - 1. INTRODUCTION
  9993. -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  9994. -that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  9995. -scheme for digital audio. This FDK AAC Codec software is intended to be used on
  9996. -a wide variety of Android devices.
  9997. -
  9998. -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  9999. -general perceptual audio codecs. AAC-ELD is considered the best-performing
  10000. -full-bandwidth communications codec by independent studies and is widely
  10001. -deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  10002. -specifications.
  10003. -
  10004. -Patent licenses for necessary patent claims for the FDK AAC Codec (including
  10005. -those of Fraunhofer) may be obtained through Via Licensing
  10006. -(www.vialicensing.com) or through the respective patent owners individually for
  10007. -the purpose of encoding or decoding bit streams in products that are compliant
  10008. -with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  10009. -Android devices already license these patent claims through Via Licensing or
  10010. -directly from the patent owners, and therefore FDK AAC Codec software may
  10011. -already be covered under those patent licenses when it is used for those
  10012. -licensed purposes only.
  10013. -
  10014. -Commercially-licensed AAC software libraries, including floating-point versions
  10015. -with enhanced sound quality, are also available from Fraunhofer. Users are
  10016. -encouraged to check the Fraunhofer website for additional applications
  10017. -information and documentation.
  10018. -
  10019. -2. COPYRIGHT LICENSE
  10020. -
  10021. -Redistribution and use in source and binary forms, with or without modification,
  10022. -are permitted without payment of copyright license fees provided that you
  10023. -satisfy the following conditions:
  10024. -
  10025. -You must retain the complete text of this software license in redistributions of
  10026. -the FDK AAC Codec or your modifications thereto in source code form.
  10027. -
  10028. -You must retain the complete text of this software license in the documentation
  10029. -and/or other materials provided with redistributions of the FDK AAC Codec or
  10030. -your modifications thereto in binary form. You must make available free of
  10031. -charge copies of the complete source code of the FDK AAC Codec and your
  10032. -modifications thereto to recipients of copies in binary form.
  10033. -
  10034. -The name of Fraunhofer may not be used to endorse or promote products derived
  10035. -from this library without prior written permission.
  10036. -
  10037. -You may not charge copyright license fees for anyone to use, copy or distribute
  10038. -the FDK AAC Codec software or your modifications thereto.
  10039. -
  10040. -Your modified versions of the FDK AAC Codec must carry prominent notices stating
  10041. -that you changed the software and the date of any change. For modified versions
  10042. -of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  10043. -must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  10044. -AAC Codec Library for Android."
  10045. -
  10046. -3. NO PATENT LICENSE
  10047. -
  10048. -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  10049. -limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  10050. -Fraunhofer provides no warranty of patent non-infringement with respect to this
  10051. -software.
  10052. -
  10053. -You may use this FDK AAC Codec software or modifications thereto only for
  10054. -purposes that are authorized by appropriate patent licenses.
  10055. -
  10056. -4. DISCLAIMER
  10057. -
  10058. -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  10059. -holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  10060. -including but not limited to the implied warranties of merchantability and
  10061. -fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  10062. -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  10063. -or consequential damages, including but not limited to procurement of substitute
  10064. -goods or services; loss of use, data, or profits, or business interruption,
  10065. -however caused and on any theory of liability, whether in contract, strict
  10066. -liability, or tort (including negligence), arising in any way out of the use of
  10067. -this software, even if advised of the possibility of such damage.
  10068. -
  10069. -5. CONTACT INFORMATION
  10070. -
  10071. -Fraunhofer Institute for Integrated Circuits IIS
  10072. -Attention: Audio and Multimedia Departments - FDK AAC LL
  10073. -Am Wolfsmantel 33
  10074. -91058 Erlangen, Germany
  10075. -
  10076. -www.iis.fraunhofer.de/amm
  10077. -amm-info@iis.fraunhofer.de
  10078. ------------------------------------------------------------------------------ */
  10079. -
  10080. -/**************************** AAC decoder library ******************************
  10081. -
  10082. - Author(s):
  10083. -
  10084. - Description:
  10085. -
  10086. -*******************************************************************************/
  10087. -
  10088. -/*!
  10089. - \file
  10090. - \brief rvlc concealment
  10091. - \author Josef Hoepfl
  10092. -*/
  10093. -
  10094. -#ifndef RVLCCONCEAL_H
  10095. -#define RVLCCONCEAL_H
  10096. -
  10097. -#include "rvlc.h"
  10098. -
  10099. -void BidirectionalEstimation_UseLowerScfOfCurrentFrame(
  10100. - CAacDecoderChannelInfo *pAacDecoderChannelInfo);
  10101. -
  10102. -void BidirectionalEstimation_UseScfOfPrevFrameAsReference(
  10103. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  10104. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo);
  10105. -
  10106. -void StatisticalEstimation(CAacDecoderChannelInfo *pAacDecoderChannelInfo);
  10107. -
  10108. -void PredictiveInterpolation(
  10109. - CAacDecoderChannelInfo *pAacDecoderChannelInfo,
  10110. - CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo);
  10111. -
  10112. -#endif /* RVLCCONCEAL_H */
  10113. diff --git a/libAACdec/src/usacdec_lpd.cpp b/libAACdec/src/usacdec_lpd.cpp
  10114. index 2110172..fcf7a76 100644
  10115. --- a/libAACdec/src/usacdec_lpd.cpp
  10116. +++ b/libAACdec/src/usacdec_lpd.cpp
  10117. @@ -111,8 +111,6 @@ amm-info@iis.fraunhofer.de
  10118. #include "usacdec_acelp.h"
  10119. #include "overlapadd.h"
  10120. -#include "conceal.h"
  10121. -
  10122. #include "block.h"
  10123. #define SF_PITCH_TRACK 6
  10124. @@ -1210,8 +1208,7 @@ AAC_DECODER_ERROR CLpdChannelStream_Read(
  10125. : &lg_table_ccfl[1][lg_table_offset];
  10126. int last_lpc_lost = pAacDecoderStaticChannelInfo->last_lpc_lost;
  10127. - int last_frame_ok = CConcealment_GetLastFrameOk(
  10128. - &pAacDecoderStaticChannelInfo->concealmentInfo, 1);
  10129. + int last_frame_ok = 1;
  10130. INT i_offset;
  10131. UINT samplingRate;
  10132. @@ -1392,13 +1389,7 @@ AAC_DECODER_ERROR CLpdChannelStream_Read(
  10133. }
  10134. }
  10135. - if (!CConcealment_GetLastFrameOk(
  10136. - &pAacDecoderStaticChannelInfo->concealmentInfo, 1)) {
  10137. - E_LPC_f_lsp_a_conversion(
  10138. - pAacDecoderChannelInfo->data.usac.lsp_coeff[0],
  10139. - pAacDecoderChannelInfo->data.usac.lp_coeff[0],
  10140. - &pAacDecoderChannelInfo->data.usac.lp_coeff_exp[0]);
  10141. - } else if (pAacDecoderStaticChannelInfo->last_lpd_mode != 0) {
  10142. + if (pAacDecoderStaticChannelInfo->last_lpd_mode != 0) {
  10143. if (pAacDecoderStaticChannelInfo->last_lpd_mode == 255) {
  10144. /* We need it for TCX decoding or ACELP excitation update */
  10145. E_LPC_f_lsp_a_conversion(
  10146. @@ -1426,9 +1417,7 @@ AAC_DECODER_ERROR CLpdChannelStream_Read(
  10147. FD_SHORT;
  10148. pAacDecoderChannelInfo->data.usac.lpd_mode_last = 255;
  10149. - if ((pAacDecoderStaticChannelInfo->last_core_mode != FD_SHORT) &&
  10150. - CConcealment_GetLastFrameOk(
  10151. - &pAacDecoderStaticChannelInfo->concealmentInfo, 1)) {
  10152. + if ((pAacDecoderStaticChannelInfo->last_core_mode != FD_SHORT)) {
  10153. /* USAC Conformance document:
  10154. short_fac_flag shall be encoded with a value of 1 if the
  10155. window_sequence of the previous frame was 2 (EIGHT_SHORT_SEQUENCE).
  10156. @@ -1604,8 +1593,7 @@ AAC_DECODER_ERROR CLpd_RenderTimeSignal(
  10157. return AAC_DEC_UNKNOWN;
  10158. }
  10159. - last_frame_lost = !CConcealment_GetLastFrameOk(
  10160. - &pAacDecoderStaticChannelInfo->concealmentInfo, 0);
  10161. + last_frame_lost = 0;
  10162. /* Maintain LPD mode from previous frame */
  10163. if ((pAacDecoderStaticChannelInfo->last_core_mode == FD_LONG) ||
  10164. --
  10165. cgit v1.1