NSQ.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /***********************************************************************
  2. Copyright (c) 2014 Vidyo.
  3. Copyright (c) 2006-2011, Skype Limited. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. - Redistributions of source code must retain the above copyright notice,
  8. this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. - Neither the name of Internet Society, IETF or IETF Trust, nor the
  13. names of specific contributors, may be used to endorse or promote
  14. products derived from this software without specific prior written
  15. permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  20. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26. POSSIBILITY OF SUCH DAMAGE.
  27. ***********************************************************************/
  28. #ifndef SILK_NSQ_H
  29. #define SILK_NSQ_H
  30. #include "SigProc_FIX.h"
  31. #undef silk_short_prediction_create_arch_coef
  32. static OPUS_INLINE opus_int32 silk_noise_shape_quantizer_short_prediction_c(const opus_int32 *buf32, const opus_int16 *coef16, opus_int order)
  33. {
  34. opus_int32 out;
  35. silk_assert( order == 10 || order == 16 );
  36. /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */
  37. out = silk_RSHIFT( order, 1 );
  38. out = silk_SMLAWB( out, buf32[ 0 ], coef16[ 0 ] );
  39. out = silk_SMLAWB( out, buf32[ -1 ], coef16[ 1 ] );
  40. out = silk_SMLAWB( out, buf32[ -2 ], coef16[ 2 ] );
  41. out = silk_SMLAWB( out, buf32[ -3 ], coef16[ 3 ] );
  42. out = silk_SMLAWB( out, buf32[ -4 ], coef16[ 4 ] );
  43. out = silk_SMLAWB( out, buf32[ -5 ], coef16[ 5 ] );
  44. out = silk_SMLAWB( out, buf32[ -6 ], coef16[ 6 ] );
  45. out = silk_SMLAWB( out, buf32[ -7 ], coef16[ 7 ] );
  46. out = silk_SMLAWB( out, buf32[ -8 ], coef16[ 8 ] );
  47. out = silk_SMLAWB( out, buf32[ -9 ], coef16[ 9 ] );
  48. if( order == 16 )
  49. {
  50. out = silk_SMLAWB( out, buf32[ -10 ], coef16[ 10 ] );
  51. out = silk_SMLAWB( out, buf32[ -11 ], coef16[ 11 ] );
  52. out = silk_SMLAWB( out, buf32[ -12 ], coef16[ 12 ] );
  53. out = silk_SMLAWB( out, buf32[ -13 ], coef16[ 13 ] );
  54. out = silk_SMLAWB( out, buf32[ -14 ], coef16[ 14 ] );
  55. out = silk_SMLAWB( out, buf32[ -15 ], coef16[ 15 ] );
  56. }
  57. return out;
  58. }
  59. #define silk_noise_shape_quantizer_short_prediction(in, coef, coefRev, order, arch) ((void)arch,silk_noise_shape_quantizer_short_prediction_c(in, coef, order))
  60. static OPUS_INLINE opus_int32 silk_NSQ_noise_shape_feedback_loop_c(const opus_int32 *data0, opus_int32 *data1, const opus_int16 *coef, opus_int order)
  61. {
  62. opus_int32 out;
  63. opus_int32 tmp1, tmp2;
  64. opus_int j;
  65. tmp2 = data0[0];
  66. tmp1 = data1[0];
  67. data1[0] = tmp2;
  68. out = silk_RSHIFT(order, 1);
  69. out = silk_SMLAWB(out, tmp2, coef[0]);
  70. for (j = 2; j < order; j += 2) {
  71. tmp2 = data1[j - 1];
  72. data1[j - 1] = tmp1;
  73. out = silk_SMLAWB(out, tmp1, coef[j - 1]);
  74. tmp1 = data1[j + 0];
  75. data1[j + 0] = tmp2;
  76. out = silk_SMLAWB(out, tmp2, coef[j]);
  77. }
  78. data1[order - 1] = tmp1;
  79. out = silk_SMLAWB(out, tmp1, coef[order - 1]);
  80. /* Q11 -> Q12 */
  81. out = silk_LSHIFT32( out, 1 );
  82. return out;
  83. }
  84. #define silk_NSQ_noise_shape_feedback_loop(data0, data1, coef, order, arch) ((void)arch,silk_NSQ_noise_shape_feedback_loop_c(data0, data1, coef, order))
  85. #if defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
  86. #include "arm/NSQ_neon.h"
  87. #endif
  88. #endif /* SILK_NSQ_H */