celt_mipsr1.h 4.9 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
  49. void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N,
  50. opus_val16 g0, opus_val16 g1, int tapset0, int tapset1,
  51. const opus_val16 *window, int overlap, int arch)
  52. {
  53. int i;
  54. opus_val32 x0, x1, x2, x3, x4;
  55. (void)arch;
  56. /* printf ("%d %d %f %f\n", T0, T1, g0, g1); */
  57. opus_val16 g00, g01, g02, g10, g11, g12;
  58. static const opus_val16 gains[3][3] = {
  59. {QCONST16(0.3066406250f, 15), QCONST16(0.2170410156f, 15), QCONST16(0.1296386719f, 15)},
  60. {QCONST16(0.4638671875f, 15), QCONST16(0.2680664062f, 15), QCONST16(0.f, 15)},
  61. {QCONST16(0.7998046875f, 15), QCONST16(0.1000976562f, 15), QCONST16(0.f, 15)}};
  62. if (g0==0 && g1==0)
  63. {
  64. /* OPT: Happens to work without the OPUS_MOVE(), but only because the current encoder already copies x to y */
  65. if (x!=y)
  66. OPUS_MOVE(y, x, N);
  67. return;
  68. }
  69. g00 = MULT16_16_P15(g0, gains[tapset0][0]);
  70. g01 = MULT16_16_P15(g0, gains[tapset0][1]);
  71. g02 = MULT16_16_P15(g0, gains[tapset0][2]);
  72. g10 = MULT16_16_P15(g1, gains[tapset1][0]);
  73. g11 = MULT16_16_P15(g1, gains[tapset1][1]);
  74. g12 = MULT16_16_P15(g1, gains[tapset1][2]);
  75. x1 = x[-T1+1];
  76. x2 = x[-T1 ];
  77. x3 = x[-T1-1];
  78. x4 = x[-T1-2];
  79. /* If the filter didn't change, we don't need the overlap */
  80. if (g0==g1 && T0==T1 && tapset0==tapset1)
  81. overlap=0;
  82. for (i=0;i<overlap;i++)
  83. {
  84. opus_val16 f;
  85. opus_val32 res;
  86. f = MULT16_16_Q15(window[i],window[i]);
  87. x0= x[i-T1+2];
  88. asm volatile("MULT $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15((Q15ONE-f),g00)), "r" ((int)x[i-T0]));
  89. 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])));
  90. 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])));
  91. asm volatile("MADD $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15(f,g10)), "r" ((int)x2));
  92. asm volatile("MADD $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15(f,g11)), "r" ((int)ADD32(x3,x1)));
  93. asm volatile("MADD $ac1, %0, %1" : : "r" ((int)MULT16_16_Q15(f,g12)), "r" ((int)ADD32(x4,x0)));
  94. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (res): "i" (15));
  95. y[i] = x[i] + res;
  96. x4=x3;
  97. x3=x2;
  98. x2=x1;
  99. x1=x0;
  100. }
  101. x4 = x[i-T1-2];
  102. x3 = x[i-T1-1];
  103. x2 = x[i-T1];
  104. x1 = x[i-T1+1];
  105. if (g1==0)
  106. {
  107. /* OPT: Happens to work without the OPUS_MOVE(), but only because the current encoder already copies x to y */
  108. if (x!=y)
  109. OPUS_MOVE(y+overlap, x+overlap, N-overlap);
  110. return;
  111. }
  112. for (i=overlap;i<N;i++)
  113. {
  114. opus_val32 res;
  115. x0=x[i-T1+2];
  116. asm volatile("MULT $ac1, %0, %1" : : "r" ((int)g10), "r" ((int)x2));
  117. asm volatile("MADD $ac1, %0, %1" : : "r" ((int)g11), "r" ((int)ADD32(x3,x1)));
  118. asm volatile("MADD $ac1, %0, %1" : : "r" ((int)g12), "r" ((int)ADD32(x4,x0)));
  119. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (res): "i" (15));
  120. y[i] = x[i] + res;
  121. x4=x3;
  122. x3=x2;
  123. x2=x1;
  124. x1=x0;
  125. }
  126. }
  127. #endif /* __CELT_MIPSR1_H__ */