pvmp3_alias_reduction.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /* ------------------------------------------------------------------
  2. * Copyright (C) 1998-2009 PacketVideo
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied.
  14. * See the License for the specific language governing permissions
  15. * and limitations under the License.
  16. * -------------------------------------------------------------------
  17. */
  18. /*
  19. ------------------------------------------------------------------------------
  20. PacketVideo Corp.
  21. MP3 Decoder Library
  22. Filename: pvmp3_alias_reduction.cpp
  23. Date: 09/21/2007
  24. ------------------------------------------------------------------------------
  25. REVISION HISTORY
  26. Description:
  27. ------------------------------------------------------------------------------
  28. INPUT AND OUTPUT DEFINITIONS
  29. Input
  30. int32 *input_buffer, Ptr to fequency lines of current channel
  31. struct gr_info_s *gr_info, structure with granuke information for the
  32. input
  33. mp3Header *info mp3 header information
  34. ------------------------------------------------------------------------------
  35. FUNCTION DESCRIPTION
  36. Alias Reduction
  37. Alias reduction before processing by the IMDCT
  38. Csi +
  39. >---------0---------0-------->
  40. \ / -
  41. Cai \ /
  42. \ /
  43. \ /
  44. \
  45. / \
  46. Cai / \
  47. / \ +
  48. >--------0---------0---------->
  49. Csi +
  50. Aliasing Butterfly
  51. Alias reduction is not applied to short blocks
  52. ------------------------------------------------------------------------------
  53. REQUIREMENTS
  54. ------------------------------------------------------------------------------
  55. REFERENCES
  56. [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
  57. ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
  58. ------------------------------------------------------------------------------
  59. PSEUDO-CODE
  60. 1 ci
  61. csi = ---------------- csi = ----------------
  62. sqrt( 1 + (ci^2)) sqrt( 1 + (ci^2))
  63. ci = -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037
  64. ------------------------------------------------------------------------------
  65. */
  66. /*----------------------------------------------------------------------------
  67. ; INCLUDES
  68. ----------------------------------------------------------------------------*/
  69. #include "pvmp3_alias_reduction.h"
  70. #include "pv_mp3dec_fxd_op.h"
  71. /*----------------------------------------------------------------------------
  72. ; MACROS
  73. ; Define module specific macros here
  74. ----------------------------------------------------------------------------*/
  75. /*----------------------------------------------------------------------------
  76. ; DEFINES
  77. ; Include all pre-processor statements here. Include conditional
  78. ; compile variables also.
  79. ----------------------------------------------------------------------------*/
  80. #define NUM_BUTTERFLIES 8
  81. #define Q31_fmt(a) (int32(double(0x7FFFFFFF)*a))
  82. /*----------------------------------------------------------------------------
  83. ; LOCAL FUNCTION DEFINITIONS
  84. ; Function Prototype declaration
  85. ----------------------------------------------------------------------------*/
  86. /*----------------------------------------------------------------------------
  87. ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
  88. ; Variable declaration - defined here and used outside this module
  89. ----------------------------------------------------------------------------*/
  90. const int32 c_signal [ NUM_BUTTERFLIES ] =
  91. {
  92. Q31_fmt(0.85749292571254f), Q31_fmt(0.88174199731771f),
  93. Q31_fmt(0.94962864910273f), Q31_fmt(0.98331459249179f),
  94. Q31_fmt(0.99551781606759f), Q31_fmt(0.99916055817815f),
  95. Q31_fmt(0.99989919524445f), Q31_fmt(0.99999315507028f)
  96. };
  97. const int32 c_alias [ NUM_BUTTERFLIES ] =
  98. {
  99. Q31_fmt(-0.51449575542753f), Q31_fmt(-0.47173196856497f),
  100. Q31_fmt(-0.31337745420390f), Q31_fmt(-0.18191319961098f),
  101. Q31_fmt(-0.09457419252642f), Q31_fmt(-0.04096558288530f),
  102. Q31_fmt(-0.01419856857247f), Q31_fmt(-0.00369997467376f)
  103. };
  104. /*----------------------------------------------------------------------------
  105. ; EXTERNAL FUNCTION REFERENCES
  106. ; Declare functions defined elsewhere and referenced in this module
  107. ----------------------------------------------------------------------------*/
  108. /*----------------------------------------------------------------------------
  109. ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
  110. ; Declare variables used in this module but defined elsewhere
  111. ----------------------------------------------------------------------------*/
  112. /*----------------------------------------------------------------------------
  113. ; FUNCTION CODE
  114. ----------------------------------------------------------------------------*/
  115. void pvmp3_alias_reduction(int32 *input_buffer, /* Ptr to spec values of current channel */
  116. granuleInfo *gr_info,
  117. int32 *used_freq_lines,
  118. mp3Header *info)
  119. {
  120. int32 *ptr1;
  121. int32 *ptr2;
  122. int32 *ptr3;
  123. int32 *ptr4;
  124. const int32 *ptr_csi;
  125. const int32 *ptr_csa;
  126. int32 sblim;
  127. int32 i, j;
  128. *used_freq_lines = fxp_mul32_Q32(*used_freq_lines << 16, (int32)(0x7FFFFFFF / (float)18 - 1.0f)) >> 15;
  129. if (gr_info->window_switching_flag && gr_info->block_type == 2)
  130. {
  131. if (gr_info->mixed_block_flag)
  132. {
  133. sblim = ((info->version_x == MPEG_2_5) && (info->sampling_frequency == 2)) ? 3 : 1;
  134. }
  135. else
  136. {
  137. return; /* illegal parameter */
  138. }
  139. }
  140. else
  141. {
  142. sblim = *used_freq_lines + 1;
  143. if (sblim > SUBBANDS_NUMBER - 1)
  144. {
  145. sblim = SUBBANDS_NUMBER - 1; /* default */
  146. }
  147. }
  148. ptr3 = &input_buffer[17];
  149. ptr4 = &input_buffer[18];
  150. ptr_csi = c_signal;
  151. ptr_csa = c_alias;
  152. /* NUM_BUTTERFLIES (=8) butterflies between each pair of sub-bands*/
  153. for (i = NUM_BUTTERFLIES >> 1; i != 0; i--)
  154. {
  155. int32 csi1 = *ptr_csi++;
  156. int32 csi2 = *ptr_csi++;
  157. int32 csa1 = *ptr_csa++;
  158. int32 csa2 = *ptr_csa++;
  159. ptr1 = ptr3;
  160. ptr3 -= 2;
  161. ptr2 = ptr4;
  162. ptr4 += 2;
  163. /*
  164. * "sblim" alias-reduction operations between each
  165. * pair of sub-bands
  166. */
  167. for (j = sblim >> 1; j != 0; j--)
  168. {
  169. int32 y = *ptr2;
  170. int32 x = *ptr1 << 1;
  171. *ptr1-- = fxp_msb32_Q32(fxp_mul32_Q32(x, csi1), y << 1, csa1);
  172. *ptr2++ = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi1), x, csa1);
  173. y = *ptr2;
  174. x = *ptr1 << 1;
  175. *ptr1 = fxp_msb32_Q32(fxp_mul32_Q32(x, csi2), y << 1, csa2);
  176. *ptr2 = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi2), x, csa2);
  177. ptr1 += 19;
  178. ptr2 += 17;
  179. y = *ptr2;
  180. x = *ptr1 << 1;
  181. *ptr1-- = fxp_msb32_Q32(fxp_mul32_Q32(x, csi1), y << 1, csa1);
  182. *ptr2++ = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi1), x, csa1);
  183. y = *ptr2;
  184. x = *ptr1 << 1;
  185. *ptr1 = fxp_msb32_Q32(fxp_mul32_Q32(x, csi2), y << 1, csa2);
  186. *ptr2 = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi2), x, csa2);
  187. ptr1 += 19;
  188. ptr2 += 17;
  189. }
  190. if (sblim & 1)
  191. {
  192. int32 x = *ptr1 << 1;
  193. int32 y = *ptr2;
  194. *ptr1-- = fxp_msb32_Q32(fxp_mul32_Q32(x, csi1), y << 1, csa1);
  195. *ptr2++ = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi1), x, csa1);
  196. x = *ptr1 << 1;
  197. y = *ptr2;
  198. *ptr1 = fxp_msb32_Q32(fxp_mul32_Q32(x, csi2), y << 1, csa2);
  199. *ptr2 = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi2), x, csa2);
  200. }
  201. }
  202. }