celt_mipsr1.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* Copyright (c) 2007-2008 CSIRO
  2. Copyright (c) 2007-2010 Xiph.Org Foundation
  3. Copyright (c) 2008 Gregory Maxwell
  4. Written by Jean-Marc Valin and Gregory Maxwell */
  5. /*
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions
  8. are met:
  9. - Redistributions of source code must retain the above copyright
  10. notice, this list of conditions and the following disclaimer.
  11. - Redistributions in binary form must reproduce the above copyright
  12. notice, this list of conditions and the following disclaimer in the
  13. documentation and/or other materials provided with the distribution.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  18. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef __CELT_MIPSR1_H__
  27. #define __CELT_MIPSR1_H__
  28. #ifdef HAVE_CONFIG_H
  29. #include "config.h"
  30. #endif
  31. #define CELT_C
  32. #include "os_support.h"
  33. #include "mdct.h"
  34. #include <math.h>
  35. #include "celt.h"
  36. #include "pitch.h"
  37. #include "bands.h"
  38. #include "modes.h"
  39. #include "entcode.h"
  40. #include "quant_bands.h"
  41. #include "rate.h"
  42. #include "stack_alloc.h"
  43. #include "mathops.h"
  44. #include "float_cast.h"
  45. #include <stdarg.h>
  46. #include "celt_lpc.h"
  47. #include "vq.h"
  48. #define OVERRIDE_COMB_FILTER_CONST
  49. #define OVERRIDE_comb_filter
  50. void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N,
  51. opus_val16 g0, opus_val16 g1, int tapset0, int tapset1,
  52. const opus_val16 *window, int overlap, int arch)
  53. {
  54. int i;
  55. opus_val32 x0, x1, x2, x3, x4;
  56. (void)arch;
  57. /* printf ("%d %d %f %f\n", T0, T1, g0, g1); */
  58. opus_val16 g00, g01, g02, g10, g11, g12;
  59. static const opus_val16 gains[3][3] = {
  60. {QCONST16(0.3066406250f, 15), QCONST16(0.2170410156f, 15), QCONST16(0.1296386719f, 15)},
  61. {QCONST16(0.4638671875f, 15), QCONST16(0.2680664062f, 15), QCONST16(0.f, 15)},
  62. {QCONST16(0.7998046875f, 15), QCONST16(0.1000976562f, 15), QCONST16(0.f, 15)}};
  63. if (g0==0 && g1==0)
  64. {
  65. /* OPT: Happens to work without the OPUS_MOVE(), but only because the current encoder already copies x to y */
  66. if (x!=y)
  67. OPUS_MOVE(y, x, N);
  68. return;
  69. }
  70. g00 = MULT16_16_P15(g0, gains[tapset0][0]);
  71. g01 = MULT16_16_P15(g0, gains[tapset0][1]);
  72. g02 = MULT16_16_P15(g0, gains[tapset0][2]);
  73. g10 = MULT16_16_P15(g1, gains[tapset1][0]);
  74. g11 = MULT16_16_P15(g1, gains[tapset1][1]);
  75. g12 = MULT16_16_P15(g1, gains[tapset1][2]);
  76. x1 = x[-T1+1];
  77. x2 = x[-T1 ];
  78. x3 = x[-T1-1];
  79. x4 = x[-T1-2];
  80. /* If the filter didn't change, we don't need the overlap */
  81. if (g0==g1 && T0==T1 && tapset0==tapset1)
  82. overlap=0;
  83. for (i=0;i<overlap;i++)
  84. {
  85. opus_val16 f;
  86. opus_val32 res;
  87. f = MULT16_16_Q15(window[i],window[i]);
  88. x0= x[i-T1+2];
  89. asm volatile("MULT $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15((Q15ONE-f),g00)), "r" ((int)x[i-T0]));
  90. asm volatile("MADD $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15((Q15ONE-f),g01)), "r" ((int)ADD32(x[i-T0-1],x[i-T0+1])));
  91. asm volatile("MADD $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15((Q15ONE-f),g02)), "r" ((int)ADD32(x[i-T0-2],x[i-T0+2])));
  92. asm volatile("MADD $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15(f,g10)), "r" ((int)x2));
  93. asm volatile("MADD $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15(f,g11)), "r" ((int)ADD32(x3,x1)));
  94. asm volatile("MADD $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15(f,g12)), "r" ((int)ADD32(x4,x0)));
  95. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (res): "i" (15));
  96. y[i] = x[i] + res;
  97. x4=x3;
  98. x3=x2;
  99. x2=x1;
  100. x1=x0;
  101. }
  102. x4 = x[i-T1-2];
  103. x3 = x[i-T1-1];
  104. x2 = x[i-T1];
  105. x1 = x[i-T1+1];
  106. if (g1==0)
  107. {
  108. /* OPT: Happens to work without the OPUS_MOVE(), but only because the current encoder already copies x to y */
  109. if (x!=y)
  110. OPUS_MOVE(y+overlap, x+overlap, N-overlap);
  111. return;
  112. }
  113. for (i=overlap;i<N;i++)
  114. {
  115. opus_val32 res;
  116. x0=x[i-T1+2];
  117. asm volatile("MULT $ac1, %0, %1" : : "r" ((int)g10), "r" ((int)x2));
  118. asm volatile("MADD $ac1, %0, %1" : : "r" ((int)g11), "r" ((int)ADD32(x3,x1)));
  119. asm volatile("MADD $ac1, %0, %1" : : "r" ((int)g12), "r" ((int)ADD32(x4,x0)));
  120. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (res): "i" (15));
  121. y[i] = x[i] + res;
  122. x4=x3;
  123. x3=x2;
  124. x2=x1;
  125. x1=x0;
  126. }
  127. }
  128. #endif /* __CELT_MIPSR1_H__ */