FDK_trigFcts.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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): Haricharan Lakshman, Manuel Jander
  64. Description: Trigonometric functions fixed point fractional implementation.
  65. ******************************************************************************/
  66. #include "common_fix.h"
  67. #include "FDK_tools_rom.h"
  68. /* Fixed point precision definitions */
  69. #define Q(format) ((FIXP_DBL)(((LONG)1) << (format)))
  70. #ifndef M_PI
  71. #define M_PI (3.14159265358979323846f)
  72. #endif
  73. /*!
  74. * Inverse tangent function.
  75. */
  76. // --- fixp_atan() ----
  77. #define Q_ATANINP (25) // Input in q25, Output in q30
  78. #define Q_ATANOUT (30)
  79. #define ATI_SF ((DFRACT_BITS-1)-Q_ATANINP) // 6
  80. #define ATI_SCALE ((float)(1<<ATI_SF)) //
  81. #define ATO_SF ((DFRACT_BITS-1)-Q_ATANOUT) // 1 ] -pi/2 .. pi/2 [
  82. #define ATO_SCALE ((float)(1<<ATO_SF)) //
  83. // --- fixp_atan2() ---
  84. #define Q_ATAN2OUT (29)
  85. #define AT2O_SF ((DFRACT_BITS-1)-Q_ATAN2OUT) // 2 ] -pi .. pi ]
  86. #define AT2O_SCALE ((float)(1<<AT2O_SF)) //
  87. // --------------------
  88. FIXP_DBL fixp_atan(FIXP_DBL x);
  89. FIXP_DBL fixp_atan2(FIXP_DBL y, FIXP_DBL x);
  90. FIXP_DBL fixp_cos(FIXP_DBL x, int scale);
  91. FIXP_DBL fixp_sin(FIXP_DBL x, int scale);
  92. #define FIXP_COS_SIN
  93. #include "FDK_tools_rom.h"
  94. #define SINETAB SineTable512
  95. #define LD 9
  96. #ifndef FUNCTION_inline_fixp_cos_sin
  97. #define FUNCTION_inline_fixp_cos_sin
  98. /*
  99. * Calculates coarse lookup index and sign for sine.
  100. * Returns delta x residual.
  101. */
  102. static inline FIXP_DBL fixp_sin_cos_residual_inline(FIXP_DBL x, int scale, FIXP_DBL *sine, FIXP_DBL *cosine)
  103. {
  104. FIXP_DBL residual;
  105. int s;
  106. int shift = (31-scale-LD-1);
  107. int ssign = 1;
  108. int csign = 1;
  109. residual = fMult(x, FL2FXCONST_DBL(1.0/M_PI));
  110. s = ((LONG)residual) >> shift;
  111. residual &= ( (1<<shift) - 1 );
  112. residual = fMult(residual, FL2FXCONST_DBL(M_PI/4.0)) << 2;
  113. residual <<= scale;
  114. /* Sine sign symmetry */
  115. if (s & ((1<<LD)<<1) ) {
  116. ssign = -ssign;
  117. }
  118. /* Cosine sign symmetry */
  119. if ( (s + (1<<LD)) & ((1<<LD)<<1) ) {
  120. csign = -csign;
  121. }
  122. s = fAbs(s);
  123. s &= (((1<<LD)<<1)-1); /* Modulo PI */
  124. if (s > (1<<LD)) {
  125. s = ((1<<LD)<<1) - s;
  126. }
  127. {
  128. LONG sl, cl;
  129. /* Because of packed table */
  130. if (s > (1<<(LD-1))) {
  131. FIXP_STP tmp;
  132. /* Cosine/Sine simetry for angles greater than PI/4 */
  133. s = (1<<LD)-s;
  134. tmp = SINETAB[s];
  135. sl = (LONG)tmp.v.re;
  136. cl = (LONG)tmp.v.im;
  137. } else {
  138. FIXP_STP tmp;
  139. tmp = SINETAB[s];
  140. sl = (LONG)tmp.v.im;
  141. cl = (LONG)tmp.v.re;
  142. }
  143. #ifdef SINETABLE_16BIT
  144. *sine = (FIXP_DBL)((sl * ssign) << (DFRACT_BITS-FRACT_BITS));
  145. *cosine = (FIXP_DBL)((cl * csign) << (DFRACT_BITS-FRACT_BITS));
  146. #else
  147. *sine = (FIXP_DBL)(sl * ssign);
  148. *cosine = (FIXP_DBL)(cl * csign);
  149. #endif
  150. }
  151. return residual;
  152. }
  153. /**
  154. * \brief Calculate cosine and sine value each of 2 angles different angle values.
  155. * \param x1 first angle value
  156. * \param x2 second angle value
  157. * \param scale exponent of x1 and x2
  158. * \param out pointer to 4 FIXP_DBL locations, were the values cos(x1), sin(x1), cos(x2), sin(x2)
  159. * will be stored into.
  160. */
  161. static inline void inline_fixp_cos_sin (FIXP_DBL x1, FIXP_DBL x2, const int scale, FIXP_DBL *out)
  162. {
  163. FIXP_DBL residual, error0, error1, sine, cosine;
  164. residual = fixp_sin_cos_residual_inline(x1, scale, &sine, &cosine);
  165. error0 = fMultDiv2(sine, residual);
  166. error1 = fMultDiv2(cosine, residual);
  167. *out++ = cosine - (error0<<1);
  168. *out++ = sine + (error1<<1);
  169. residual = fixp_sin_cos_residual_inline(x2, scale, &sine, &cosine);
  170. error0 = fMultDiv2(sine, residual);
  171. error1 = fMultDiv2(cosine, residual);
  172. *out++ = cosine - (error0<<1);
  173. *out++ = sine + (error1<<1);
  174. }
  175. #endif