coef2sam.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*****************************************************************************
  2. **
  3. ** ITU-T G.722.1 (2005-05) - Fixed point implementation for main body and Annex C
  4. ** > Software Release 2.1 (2008-06)
  5. ** (Simple repackaging; no change from 2005-05 Release 2.0 code)
  6. **
  7. ** © 2004 Polycom, Inc.
  8. **
  9. ** All rights reserved.
  10. **
  11. *****************************************************************************/
  12. /*****************************************************************************
  13. * Filename: rmlt_coefs_to_samples.c
  14. *
  15. * Purpose: Convert Reversed MLT (Modulated Lapped Transform)
  16. * Coefficients to Samples
  17. *
  18. * The "Reversed MLT" is an overlapped block transform which uses
  19. * even symmetry * on the left, odd symmetry on the right and a
  20. * Type IV DCT as the block transform. * It is thus similar to a
  21. * MLT which uses odd symmetry on the left, even symmetry * on the
  22. * right and a Type IV DST as the block transform. In fact, it is
  23. * equivalent * to reversing the order of the samples, performing
  24. * an MLT and then negating all * the even-numbered coefficients.
  25. *
  26. *****************************************************************************/
  27. /***************************************************************************
  28. Include files
  29. ***************************************************************************/
  30. #include "defs.h"
  31. #include "tables.h"
  32. #include "count.h"
  33. /***************************************************************************
  34. Function: rmlt_coefs_to_samples
  35. Syntax: void rmlt_coefs_to_samples(Word16 *coefs,
  36. Word16 *old_samples,
  37. Word16 *out_samples,
  38. Word16 dct_length,
  39. Word16 mag_shift)
  40. inputs: Word16 *coefs
  41. Word16 *old_samples
  42. Word16 dct_length
  43. Word16 mag_shift
  44. outputs: Word16 *out_samples
  45. Description: Converts the mlt_coefs to samples
  46. Design Notes:
  47. WMOPS: 7kHz | 24kbit | 32kbit
  48. -------|--------------|----------------
  49. AVG | 1.91 | 1.91
  50. -------|--------------|----------------
  51. MAX | 1.91 | 1.91
  52. -------|--------------|----------------
  53. 14kHz | 24kbit | 32kbit | 48kbit
  54. -------|--------------|----------------|----------------
  55. AVG | 3.97 | 3.97 | 3.97
  56. -------|--------------|----------------|----------------
  57. MAX | 3.97 | 3.97 | 3.97
  58. -------|--------------|----------------|----------------
  59. ***************************************************************************/
  60. void rmlt_coefs_to_samples(Word16 *coefs,
  61. Word16 *old_samples,
  62. Word16 *out_samples,
  63. Word16 dct_length,
  64. Word16 mag_shift)
  65. {
  66. Word16 index, vals_left;
  67. Word16 new_samples[MAX_DCT_LENGTH];
  68. Word16 *new_ptr, *old_ptr;
  69. Word16 *win_new, *win_old;
  70. Word16 *out_ptr;
  71. Word16 half_dct_size;
  72. Word32 sum;
  73. half_dct_size = shr_nocheck(dct_length,1);
  74. /* Perform a Type IV (inverse) DCT on the coefficients */
  75. dct_type_iv_s(coefs, new_samples, dct_length);
  76. test();
  77. if (mag_shift > 0)
  78. {
  79. for(index=0;index<dct_length;index++)
  80. {
  81. new_samples[index] = shr_nocheck(new_samples[index],mag_shift);
  82. move16();
  83. }
  84. }
  85. else
  86. {
  87. test();
  88. if (mag_shift < 0)
  89. {
  90. mag_shift = negate(mag_shift);
  91. for(index=0;index<dct_length;index++)
  92. {
  93. new_samples[index] = shl_nocheck(new_samples[index],mag_shift);
  94. move16();
  95. }
  96. }
  97. }
  98. /* Get the first half of the windowed samples */
  99. out_ptr = out_samples;
  100. move16();
  101. test();
  102. if (dct_length==DCT_LENGTH)
  103. {
  104. win_new = rmlt_to_samples_window;
  105. move16();
  106. win_old = rmlt_to_samples_window + dct_length;
  107. move16();
  108. }
  109. else
  110. {
  111. win_new = max_rmlt_to_samples_window;
  112. move16();
  113. win_old = max_rmlt_to_samples_window + dct_length;
  114. move16();
  115. }
  116. old_ptr = old_samples;
  117. move16();
  118. new_ptr = new_samples + half_dct_size;
  119. move16();
  120. for (vals_left = half_dct_size; vals_left > 0; vals_left--)
  121. {
  122. sum = 0L;
  123. move32();
  124. sum = L_mac(sum,*win_new++, *--new_ptr);
  125. sum = L_mac(sum,*--win_old, *old_ptr++);
  126. *out_ptr++ = itu_round(L_shl_nocheck(sum,2));
  127. move16();
  128. }
  129. /* Get the second half of the windowed samples */
  130. for (vals_left = half_dct_size; vals_left > 0; vals_left--)
  131. {
  132. sum = 0L;
  133. move32();
  134. sum = L_mac(sum,*win_new++, *new_ptr++);
  135. sum = L_mac(sum,negate(*--win_old), *--old_ptr);
  136. *out_ptr++ = itu_round(L_shl_nocheck(sum,2));
  137. move16();
  138. }
  139. /* Save the second half of the new samples for */
  140. /* next time, when they will be the old samples. */
  141. /* pointer arithmetic */
  142. new_ptr = new_samples + half_dct_size;
  143. move16();
  144. old_ptr = old_samples;
  145. move16();
  146. for (vals_left = half_dct_size; vals_left > 0; vals_left--)
  147. {
  148. *old_ptr++ = *new_ptr++;
  149. move16();
  150. }
  151. }