resampler_private_up2_HQ.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /***********************************************************************
  2. Copyright (c) 2006-2011, Skype Limited. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. - Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. - Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. - Neither the name of Internet Society, IETF or IETF Trust, nor the
  12. names of specific contributors, may be used to endorse or promote
  13. products derived from this software without specific prior written
  14. permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  19. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. POSSIBILITY OF SUCH DAMAGE.
  26. ***********************************************************************/
  27. #ifdef HAVE_CONFIG_H
  28. #include "config.h"
  29. #endif
  30. #include "SigProc_FIX.h"
  31. #include "resampler_private.h"
  32. /* Upsample by a factor 2, high quality */
  33. /* Uses 2nd order allpass filters for the 2x upsampling, followed by a */
  34. /* notch filter just above Nyquist. */
  35. void silk_resampler_private_up2_HQ(
  36. opus_int32 *S, /* I/O Resampler state [ 6 ] */
  37. opus_int16 *out, /* O Output signal [ 2 * len ] */
  38. const opus_int16 *in, /* I Input signal [ len ] */
  39. opus_int32 len /* I Number of input samples */
  40. )
  41. {
  42. opus_int32 k;
  43. opus_int32 in32, out32_1, out32_2, Y, X;
  44. silk_assert( silk_resampler_up2_hq_0[ 0 ] > 0 );
  45. silk_assert( silk_resampler_up2_hq_0[ 1 ] > 0 );
  46. silk_assert( silk_resampler_up2_hq_0[ 2 ] < 0 );
  47. silk_assert( silk_resampler_up2_hq_1[ 0 ] > 0 );
  48. silk_assert( silk_resampler_up2_hq_1[ 1 ] > 0 );
  49. silk_assert( silk_resampler_up2_hq_1[ 2 ] < 0 );
  50. /* Internal variables and state are in Q10 format */
  51. for( k = 0; k < len; k++ ) {
  52. /* Convert to Q10 */
  53. in32 = silk_LSHIFT( (opus_int32)in[ k ], 10 );
  54. /* First all-pass section for even output sample */
  55. Y = silk_SUB32( in32, S[ 0 ] );
  56. X = silk_SMULWB( Y, silk_resampler_up2_hq_0[ 0 ] );
  57. out32_1 = silk_ADD32( S[ 0 ], X );
  58. S[ 0 ] = silk_ADD32( in32, X );
  59. /* Second all-pass section for even output sample */
  60. Y = silk_SUB32( out32_1, S[ 1 ] );
  61. X = silk_SMULWB( Y, silk_resampler_up2_hq_0[ 1 ] );
  62. out32_2 = silk_ADD32( S[ 1 ], X );
  63. S[ 1 ] = silk_ADD32( out32_1, X );
  64. /* Third all-pass section for even output sample */
  65. Y = silk_SUB32( out32_2, S[ 2 ] );
  66. X = silk_SMLAWB( Y, Y, silk_resampler_up2_hq_0[ 2 ] );
  67. out32_1 = silk_ADD32( S[ 2 ], X );
  68. S[ 2 ] = silk_ADD32( out32_2, X );
  69. /* Apply gain in Q15, convert back to int16 and store to output */
  70. out[ 2 * k ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( out32_1, 10 ) );
  71. /* First all-pass section for odd output sample */
  72. Y = silk_SUB32( in32, S[ 3 ] );
  73. X = silk_SMULWB( Y, silk_resampler_up2_hq_1[ 0 ] );
  74. out32_1 = silk_ADD32( S[ 3 ], X );
  75. S[ 3 ] = silk_ADD32( in32, X );
  76. /* Second all-pass section for odd output sample */
  77. Y = silk_SUB32( out32_1, S[ 4 ] );
  78. X = silk_SMULWB( Y, silk_resampler_up2_hq_1[ 1 ] );
  79. out32_2 = silk_ADD32( S[ 4 ], X );
  80. S[ 4 ] = silk_ADD32( out32_1, X );
  81. /* Third all-pass section for odd output sample */
  82. Y = silk_SUB32( out32_2, S[ 5 ] );
  83. X = silk_SMLAWB( Y, Y, silk_resampler_up2_hq_1[ 2 ] );
  84. out32_1 = silk_ADD32( S[ 5 ], X );
  85. S[ 5 ] = silk_ADD32( out32_2, X );
  86. /* Apply gain in Q15, convert back to int16 and store to output */
  87. out[ 2 * k + 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( out32_1, 10 ) );
  88. }
  89. }
  90. void silk_resampler_private_up2_HQ_wrapper(
  91. void *SS, /* I/O Resampler state (unused) */
  92. opus_int16 *out, /* O Output signal [ 2 * len ] */
  93. const opus_int16 *in, /* I Input signal [ len ] */
  94. opus_int32 len /* I Number of input samples */
  95. )
  96. {
  97. silk_resampler_state_struct *S = (silk_resampler_state_struct *)SS;
  98. silk_resampler_private_up2_HQ( S->sIIR, out, in, len );
  99. }