scale.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /* -----------------------------------------------------------------------------------------------------------
  2. Software License for The Fraunhofer FDK AAC Codec Library for Android
  3. © Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
  4. All rights reserved.
  5. 1. INTRODUCTION
  6. The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
  7. the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
  8. This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
  9. AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
  10. audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
  11. independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
  12. of the MPEG specifications.
  13. Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
  14. may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
  15. individually for the purpose of encoding or decoding bit streams in products that are compliant with
  16. the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
  17. these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
  18. software may already be covered under those patent licenses when it is used for those licensed purposes only.
  19. Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
  20. are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
  21. applications information and documentation.
  22. 2. COPYRIGHT LICENSE
  23. Redistribution and use in source and binary forms, with or without modification, are permitted without
  24. payment of copyright license fees provided that you satisfy the following conditions:
  25. You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
  26. your modifications thereto in source code form.
  27. You must retain the complete text of this software license in the documentation and/or other materials
  28. provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
  29. You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
  30. modifications thereto to recipients of copies in binary form.
  31. The name of Fraunhofer may not be used to endorse or promote products derived from this library without
  32. prior written permission.
  33. You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
  34. software or your modifications thereto.
  35. Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
  36. and the date of any change. For modified versions of the FDK AAC Codec, the term
  37. "Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
  38. "Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
  39. 3. NO PATENT LICENSE
  40. NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
  41. ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
  42. respect to this software.
  43. You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
  44. by appropriate patent licenses.
  45. 4. DISCLAIMER
  46. This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
  47. "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
  48. of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  49. CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
  50. including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
  51. or business interruption, however caused and on any theory of liability, whether in contract, strict
  52. liability, or tort (including negligence), arising in any way out of the use of this software, even if
  53. advised of the possibility of such damage.
  54. 5. CONTACT INFORMATION
  55. Fraunhofer Institute for Integrated Circuits IIS
  56. Attention: Audio and Multimedia Departments - FDK AAC LL
  57. Am Wolfsmantel 33
  58. 91058 Erlangen, Germany
  59. www.iis.fraunhofer.de/amm
  60. [email protected]
  61. ----------------------------------------------------------------------------------------------------------- */
  62. /*************************** Fraunhofer IIS FDK Tools **********************
  63. Author(s):
  64. Description: Scaling operations
  65. ******************************************************************************/
  66. #ifndef SCALE_H
  67. #define SCALE_H
  68. #include "common_fix.h"
  69. #include "genericStds.h"
  70. #include "fixminmax.h"
  71. #define SCALE_INLINE inline
  72. #if defined(__arm__) /* cppp replaced: elif */
  73. #include "arm/scale.h"
  74. #elif defined(__mips__) /* cppp replaced: elif */
  75. #include "mips/scale.h"
  76. #endif
  77. #include "../src/scale.cpp"
  78. #ifndef FUNCTION_scaleValue
  79. /*!
  80. *
  81. * \brief Multiply input by \f$ 2^{scalefactor} \f$
  82. *
  83. * \return Scaled input
  84. *
  85. */
  86. #define FUNCTION_scaleValue
  87. inline
  88. FIXP_DBL scaleValue(const FIXP_DBL value, /*!< Value */
  89. INT scalefactor /*!< Scalefactor */
  90. )
  91. {
  92. if(scalefactor > 0)
  93. return (value<<scalefactor);
  94. else
  95. return (value>>(-scalefactor));
  96. }
  97. #endif
  98. #ifndef FUNCTION_scaleValueSaturate
  99. /*!
  100. *
  101. * \brief Multiply input by \f$ 2^{scalefactor} \f$
  102. * \param value The value to be scaled.
  103. * \param the shift amount
  104. * \return \f$ value * 2^scalefactor \f$
  105. *
  106. */
  107. #define FUNCTION_scaleValueSaturate
  108. inline
  109. FIXP_DBL scaleValueSaturate(
  110. const FIXP_DBL value,
  111. INT scalefactor
  112. )
  113. {
  114. if(scalefactor > 0) {
  115. if (fNorm(value) < scalefactor && value != (FIXP_DBL)0) {
  116. if (value > (FIXP_DBL)0) {
  117. return (FIXP_DBL)MAXVAL_DBL;
  118. } else {
  119. return (FIXP_DBL)MINVAL_DBL;
  120. }
  121. } else {
  122. return (value<<scalefactor);
  123. }
  124. } else {
  125. if (-(DFRACT_BITS-1) > scalefactor) {
  126. return (FIXP_DBL)0;
  127. } else {
  128. return (value>>(-scalefactor));
  129. }
  130. }
  131. }
  132. #endif
  133. #ifndef FUNCTION_scaleValueInPlace
  134. /*!
  135. *
  136. * \brief Multiply input by \f$ 2^{scalefactor} \f$ in place
  137. *
  138. * \return void
  139. *
  140. */
  141. #define FUNCTION_scaleValueInPlace
  142. inline
  143. void scaleValueInPlace(
  144. FIXP_DBL *value, /*!< Value */
  145. INT scalefactor /*!< Scalefactor */
  146. )
  147. {
  148. INT newscale;
  149. /* Note: The assignment inside the if conditional allows combining a load with the compare to zero (on ARM and maybe others) */
  150. if ((newscale = (scalefactor)) >= 0) {
  151. *(value) <<= newscale;
  152. } else {
  153. *(value) >>= -newscale;
  154. }
  155. }
  156. #endif
  157. /*!
  158. *
  159. * \brief Scale input value by 2^{scale} and saturate output to 2^{dBits-1}
  160. * \return scaled and saturated value
  161. *
  162. * This macro scales src value right or left and applies saturation to (2^dBits)-1
  163. * maxima output.
  164. */
  165. #ifndef SATURATE_RIGHT_SHIFT
  166. #define SATURATE_RIGHT_SHIFT(src, scale, dBits) \
  167. ( (((LONG)(src)>>(scale)) > (LONG)(((1U)<<((dBits)-1))-1)) ? (LONG)(((1U)<<((dBits)-1))-1) \
  168. : (((LONG)(src)>>(scale)) < ~((LONG)(((1U)<<((dBits)-1))-1))) ? ~((LONG)(((1U)<<((dBits)-1))-1)) \
  169. : ((LONG)(src) >> (scale)) )
  170. #endif
  171. #ifndef SATURATE_LEFT_SHIFT
  172. #define SATURATE_LEFT_SHIFT(src, scale, dBits) \
  173. ( ((LONG)(src) > ((LONG)(((1U)<<((dBits)-1))-1)>>(scale))) ? (LONG)(((1U)<<((dBits)-1))-1) \
  174. : ((LONG)(src) < ~((LONG)(((1U)<<((dBits)-1))-1)>>(scale))) ? ~((LONG)(((1U)<<((dBits)-1))-1)) \
  175. : ((LONG)(src) << (scale)) )
  176. #endif
  177. #ifndef SATURATE_SHIFT
  178. #define SATURATE_SHIFT(src, scale, dBits) \
  179. ( ((scale) < 0) \
  180. ? SATURATE_LEFT_SHIFT((src), -(scale), (dBits)) \
  181. : SATURATE_RIGHT_SHIFT((src), (scale), (dBits)) )
  182. #endif
  183. /*
  184. * Alternative shift and saturate left, saturates to -0.99999 instead of -1.0000
  185. * to avoid problems when inverting the sign of the result.
  186. */
  187. #ifndef SATURATE_LEFT_SHIFT_ALT
  188. #define SATURATE_LEFT_SHIFT_ALT(src, scale, dBits) \
  189. ( ((LONG)(src) > ((LONG)(((1U)<<((dBits)-1))-1)>>(scale))) ? (LONG)(((1U)<<((dBits)-1))-1) \
  190. : ((LONG)(src) < ~((LONG)(((1U)<<((dBits)-1))-2)>>(scale))) ? ~((LONG)(((1U)<<((dBits)-1))-2)) \
  191. : ((LONG)(src) << (scale)) )
  192. #endif
  193. #ifndef SATURATE_RIGHT_SHIFT_ALT
  194. #define SATURATE_RIGHT_SHIFT_ALT(src, scale, dBits) \
  195. ( (((LONG)(src)>>(scale)) > (LONG)(((1U)<<((dBits)-1))-1)) ? (LONG)(((1U)<<((dBits)-1))-1) \
  196. : (((LONG)(src)>>(scale)) < ~((LONG)(((1U)<<((dBits)-1))-2))) ? ~((LONG)(((1U)<<((dBits)-1))-2)) \
  197. : ((LONG)(src) >> (scale)) )
  198. #endif
  199. #ifndef SATURATE_INT_PCM_RIGHT_SHIFT
  200. #define SATURATE_INT_PCM_RIGHT_SHIFT(src, scale) SATURATE_RIGHT_SHIFT(src, scale, SAMPLE_BITS)
  201. #endif
  202. #ifndef SATURATE_INT_PCM_LEFT_SHIFT
  203. #define SATURATE_INT_PCM_LEFT_SHIFT(src, scale) SATURATE_LEFT_SHIFT(src, scale, SAMPLE_BITS)
  204. #endif
  205. #endif /* #ifndef SCALE_H */