Jean-Marc Valin | 6c3788c | 2010-06-20 22:48:50 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2009-2010 Xiph.Org Foundation |
| 2 | Written by Jean-Marc Valin */ |
| 3 | /* |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, are permitted provided that the following conditions |
| 6 | are met: |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 7 | |
Jean-Marc Valin | 6c3788c | 2010-06-20 22:48:50 -0400 | [diff] [blame] | 8 | - Redistributions of source code must retain the above copyright |
| 9 | notice, this list of conditions and the following disclaimer. |
| 10 | |
| 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 | |
Jean-Marc Valin | 6c3788c | 2010-06-20 22:48:50 -0400 | [diff] [blame] | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
Jean-Marc Valin | cb05e7c | 2012-04-20 16:40:24 -0400 | [diff] [blame] | 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
| 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
Jean-Marc Valin | 6c3788c | 2010-06-20 22:48:50 -0400 | [diff] [blame] | 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #ifdef HAVE_CONFIG_H |
| 29 | #include "config.h" |
Jean-Marc Valin | d69c1cb | 2009-12-28 00:34:29 -0500 | [diff] [blame] | 30 | #endif |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 31 | |
Jean-Marc Valin | 2779df7 | 2011-10-04 13:26:53 -0400 | [diff] [blame] | 32 | #include "celt_lpc.h" |
Jean-Marc Valin | 6c3788c | 2010-06-20 22:48:50 -0400 | [diff] [blame] | 33 | #include "stack_alloc.h" |
| 34 | #include "mathops.h" |
Jean-Marc Valin | e8e57a3 | 2013-05-25 02:14:25 -0400 | [diff] [blame] | 35 | #include "pitch.h" |
Jean-Marc Valin | 3a9699e | 2010-06-17 00:35:26 -0400 | [diff] [blame] | 36 | |
Jean-Marc Valin | 7b7f071 | 2010-06-17 20:10:02 -0400 | [diff] [blame] | 37 | void _celt_lpc( |
Jean-Marc Valin | ff5f722 | 2011-07-29 18:59:12 -0400 | [diff] [blame] | 38 | opus_val16 *_lpc, /* out: [0...p-1] LPC coefficients */ |
| 39 | const opus_val32 *ac, /* in: [0...p] autocorrelation values */ |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 40 | int p |
| 41 | ) |
| 42 | { |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 43 | int i, j; |
Jean-Marc Valin | ff5f722 | 2011-07-29 18:59:12 -0400 | [diff] [blame] | 44 | opus_val32 r; |
| 45 | opus_val32 error = ac[0]; |
Jean-Marc Valin | 74128be | 2010-01-01 09:33:17 -0500 | [diff] [blame] | 46 | #ifdef FIXED_POINT |
Jean-Marc Valin | ff5f722 | 2011-07-29 18:59:12 -0400 | [diff] [blame] | 47 | opus_val32 lpc[LPC_ORDER]; |
Jean-Marc Valin | 74128be | 2010-01-01 09:33:17 -0500 | [diff] [blame] | 48 | #else |
| 49 | float *lpc = _lpc; |
| 50 | #endif |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 51 | |
Jean-Marc Valin | b66080a | 2016-06-20 12:11:05 -0400 | [diff] [blame] | 52 | OPUS_CLEAR(lpc, p); |
Jean-Marc Valin | 456eab2 | 2010-06-16 22:38:57 -0400 | [diff] [blame] | 53 | if (ac[0] != 0) |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 54 | { |
Jean-Marc Valin | 456eab2 | 2010-06-16 22:38:57 -0400 | [diff] [blame] | 55 | for (i = 0; i < p; i++) { |
| 56 | /* Sum up this iteration's reflection coefficient */ |
Jean-Marc Valin | ff5f722 | 2011-07-29 18:59:12 -0400 | [diff] [blame] | 57 | opus_val32 rr = 0; |
Jean-Marc Valin | 456eab2 | 2010-06-16 22:38:57 -0400 | [diff] [blame] | 58 | for (j = 0; j < i; j++) |
| 59 | rr += MULT32_32_Q31(lpc[j],ac[i - j]); |
| 60 | rr += SHR32(ac[i + 1],3); |
Jean-Marc Valin | bd82ca8 | 2010-06-17 00:11:54 -0400 | [diff] [blame] | 61 | r = -frac_div32(SHL32(rr,3), error); |
Jean-Marc Valin | 456eab2 | 2010-06-16 22:38:57 -0400 | [diff] [blame] | 62 | /* Update LPC coefficients and total error */ |
| 63 | lpc[i] = SHR32(r,3); |
| 64 | for (j = 0; j < (i+1)>>1; j++) |
| 65 | { |
Jean-Marc Valin | ff5f722 | 2011-07-29 18:59:12 -0400 | [diff] [blame] | 66 | opus_val32 tmp1, tmp2; |
Jean-Marc Valin | 456eab2 | 2010-06-16 22:38:57 -0400 | [diff] [blame] | 67 | tmp1 = lpc[j]; |
| 68 | tmp2 = lpc[i-1-j]; |
| 69 | lpc[j] = tmp1 + MULT32_32_Q31(r,tmp2); |
| 70 | lpc[i-1-j] = tmp2 + MULT32_32_Q31(r,tmp1); |
| 71 | } |
| 72 | |
| 73 | error = error - MULT32_32_Q31(MULT32_32_Q31(r,r),error); |
Jean-Marc Valin | bd82ca8 | 2010-06-17 00:11:54 -0400 | [diff] [blame] | 74 | /* Bail out once we get 30 dB gain */ |
| 75 | #ifdef FIXED_POINT |
| 76 | if (error<SHR32(ac[0],10)) |
Jean-Marc Valin | 456eab2 | 2010-06-16 22:38:57 -0400 | [diff] [blame] | 77 | break; |
Jean-Marc Valin | bd82ca8 | 2010-06-17 00:11:54 -0400 | [diff] [blame] | 78 | #else |
Gregory Maxwell | 60c316b | 2010-11-04 20:14:19 -0400 | [diff] [blame] | 79 | if (error<.001f*ac[0]) |
Jean-Marc Valin | bd82ca8 | 2010-06-17 00:11:54 -0400 | [diff] [blame] | 80 | break; |
| 81 | #endif |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 82 | } |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 83 | } |
Jean-Marc Valin | 303b3b6 | 2009-12-30 22:40:24 -0500 | [diff] [blame] | 84 | #ifdef FIXED_POINT |
| 85 | for (i=0;i<p;i++) |
Jean-Marc Valin | 456eab2 | 2010-06-16 22:38:57 -0400 | [diff] [blame] | 86 | _lpc[i] = ROUND16(lpc[i],16); |
Jean-Marc Valin | 303b3b6 | 2009-12-30 22:40:24 -0500 | [diff] [blame] | 87 | #endif |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 88 | } |
| 89 | |
xiangmingzhu | c95c9a0 | 2014-04-30 15:48:07 +0800 | [diff] [blame] | 90 | |
| 91 | void celt_fir_c( |
Linfeng Zhang | 783ad76 | 2016-06-16 16:21:02 -0700 | [diff] [blame] | 92 | const opus_val16 *x, |
Jean-Marc Valin | ff5f722 | 2011-07-29 18:59:12 -0400 | [diff] [blame] | 93 | const opus_val16 *num, |
Linfeng Zhang | 783ad76 | 2016-06-16 16:21:02 -0700 | [diff] [blame] | 94 | opus_val16 *y, |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 95 | int N, |
| 96 | int ord, |
xiangmingzhu | c95c9a0 | 2014-04-30 15:48:07 +0800 | [diff] [blame] | 97 | int arch) |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 98 | { |
| 99 | int i,j; |
Jean-Marc Valin | e2374a8 | 2013-05-25 04:25:54 -0400 | [diff] [blame] | 100 | VARDECL(opus_val16, rnum); |
Jean-Marc Valin | e2374a8 | 2013-05-25 04:25:54 -0400 | [diff] [blame] | 101 | SAVE_STACK; |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 102 | |
Jean-Marc Valin | e2374a8 | 2013-05-25 04:25:54 -0400 | [diff] [blame] | 103 | ALLOC(rnum, ord, opus_val16); |
Jean-Marc Valin | e2374a8 | 2013-05-25 04:25:54 -0400 | [diff] [blame] | 104 | for(i=0;i<ord;i++) |
| 105 | rnum[i] = num[ord-i-1]; |
Jean-Marc Valin | e2374a8 | 2013-05-25 04:25:54 -0400 | [diff] [blame] | 106 | for (i=0;i<N-3;i+=4) |
| 107 | { |
Jean-Marc Valin | ad15578 | 2017-02-18 17:04:24 -0500 | [diff] [blame] | 108 | opus_val32 sum[4]; |
| 109 | sum[0] = SHL32(EXTEND32(x[i ]), SIG_SHIFT); |
| 110 | sum[1] = SHL32(EXTEND32(x[i+1]), SIG_SHIFT), |
| 111 | sum[2] = SHL32(EXTEND32(x[i+2]), SIG_SHIFT); |
| 112 | sum[3] = SHL32(EXTEND32(x[i+3]), SIG_SHIFT); |
Linfeng Zhang | 783ad76 | 2016-06-16 16:21:02 -0700 | [diff] [blame] | 113 | xcorr_kernel(rnum, x+i-ord, sum, ord, arch); |
Jean-Marc Valin | 414eef5 | 2017-02-17 19:28:28 -0500 | [diff] [blame] | 114 | y[i ] = ROUND16(sum[0], SIG_SHIFT); |
| 115 | y[i+1] = ROUND16(sum[1], SIG_SHIFT); |
| 116 | y[i+2] = ROUND16(sum[2], SIG_SHIFT); |
| 117 | y[i+3] = ROUND16(sum[3], SIG_SHIFT); |
Jean-Marc Valin | e2374a8 | 2013-05-25 04:25:54 -0400 | [diff] [blame] | 118 | } |
| 119 | for (;i<N;i++) |
| 120 | { |
Jean-Marc Valin | 414eef5 | 2017-02-17 19:28:28 -0500 | [diff] [blame] | 121 | opus_val32 sum = SHL32(EXTEND32(x[i]), SIG_SHIFT); |
Jean-Marc Valin | e2374a8 | 2013-05-25 04:25:54 -0400 | [diff] [blame] | 122 | for (j=0;j<ord;j++) |
Linfeng Zhang | 783ad76 | 2016-06-16 16:21:02 -0700 | [diff] [blame] | 123 | sum = MAC16_16(sum,rnum[j],x[i+j-ord]); |
Jean-Marc Valin | 414eef5 | 2017-02-17 19:28:28 -0500 | [diff] [blame] | 124 | y[i] = ROUND16(sum, SIG_SHIFT); |
Jean-Marc Valin | e2374a8 | 2013-05-25 04:25:54 -0400 | [diff] [blame] | 125 | } |
Jean-Marc Valin | 0fa5fa8 | 2013-05-25 18:50:01 -0400 | [diff] [blame] | 126 | RESTORE_STACK; |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 127 | } |
| 128 | |
Jean-Marc Valin | 531cf59 | 2013-05-25 07:41:55 -0400 | [diff] [blame] | 129 | void celt_iir(const opus_val32 *_x, |
Jean-Marc Valin | ff5f722 | 2011-07-29 18:59:12 -0400 | [diff] [blame] | 130 | const opus_val16 *den, |
Jean-Marc Valin | 531cf59 | 2013-05-25 07:41:55 -0400 | [diff] [blame] | 131 | opus_val32 *_y, |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 132 | int N, |
| 133 | int ord, |
xiangmingzhu | c95c9a0 | 2014-04-30 15:48:07 +0800 | [diff] [blame] | 134 | opus_val16 *mem, |
| 135 | int arch) |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 136 | { |
Jean-Marc Valin | 531cf59 | 2013-05-25 07:41:55 -0400 | [diff] [blame] | 137 | #ifdef SMALL_FOOTPRINT |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 138 | int i,j; |
Timothy B. Terriberry | 020a0a4 | 2014-10-03 21:11:51 -0700 | [diff] [blame] | 139 | (void)arch; |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 140 | for (i=0;i<N;i++) |
| 141 | { |
Jean-Marc Valin | 531cf59 | 2013-05-25 07:41:55 -0400 | [diff] [blame] | 142 | opus_val32 sum = _x[i]; |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 143 | for (j=0;j<ord;j++) |
| 144 | { |
Jean-Marc Valin | 74128be | 2010-01-01 09:33:17 -0500 | [diff] [blame] | 145 | sum -= MULT16_16(den[j],mem[j]); |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 146 | } |
| 147 | for (j=ord-1;j>=1;j--) |
| 148 | { |
| 149 | mem[j]=mem[j-1]; |
| 150 | } |
Jean-Marc Valin | a0bd7d3 | 2016-07-22 09:13:00 -0400 | [diff] [blame] | 151 | mem[0] = SROUND16(sum, SIG_SHIFT); |
Jean-Marc Valin | 531cf59 | 2013-05-25 07:41:55 -0400 | [diff] [blame] | 152 | _y[i] = sum; |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 153 | } |
Jean-Marc Valin | 531cf59 | 2013-05-25 07:41:55 -0400 | [diff] [blame] | 154 | #else |
| 155 | int i,j; |
| 156 | VARDECL(opus_val16, rden); |
| 157 | VARDECL(opus_val16, y); |
| 158 | SAVE_STACK; |
| 159 | |
| 160 | celt_assert((ord&3)==0); |
| 161 | ALLOC(rden, ord, opus_val16); |
| 162 | ALLOC(y, N+ord, opus_val16); |
| 163 | for(i=0;i<ord;i++) |
| 164 | rden[i] = den[ord-i-1]; |
| 165 | for(i=0;i<ord;i++) |
| 166 | y[i] = -mem[ord-i-1]; |
| 167 | for(;i<N+ord;i++) |
| 168 | y[i]=0; |
| 169 | for (i=0;i<N-3;i+=4) |
| 170 | { |
Jean-Marc Valin | 068cbd8 | 2013-05-26 20:08:35 -0400 | [diff] [blame] | 171 | /* Unroll by 4 as if it were an FIR filter */ |
Jean-Marc Valin | 0fed074 | 2013-05-26 20:29:44 -0400 | [diff] [blame] | 172 | opus_val32 sum[4]; |
| 173 | sum[0]=_x[i]; |
| 174 | sum[1]=_x[i+1]; |
| 175 | sum[2]=_x[i+2]; |
| 176 | sum[3]=_x[i+3]; |
xiangmingzhu | c95c9a0 | 2014-04-30 15:48:07 +0800 | [diff] [blame] | 177 | xcorr_kernel(rden, y+i, sum, ord, arch); |
Jean-Marc Valin | 531cf59 | 2013-05-25 07:41:55 -0400 | [diff] [blame] | 178 | |
Jean-Marc Valin | 068cbd8 | 2013-05-26 20:08:35 -0400 | [diff] [blame] | 179 | /* Patch up the result to compensate for the fact that this is an IIR */ |
Jean-Marc Valin | a0bd7d3 | 2016-07-22 09:13:00 -0400 | [diff] [blame] | 180 | y[i+ord ] = -SROUND16(sum[0],SIG_SHIFT); |
Jean-Marc Valin | 068cbd8 | 2013-05-26 20:08:35 -0400 | [diff] [blame] | 181 | _y[i ] = sum[0]; |
| 182 | sum[1] = MAC16_16(sum[1], y[i+ord ], den[0]); |
Jean-Marc Valin | a0bd7d3 | 2016-07-22 09:13:00 -0400 | [diff] [blame] | 183 | y[i+ord+1] = -SROUND16(sum[1],SIG_SHIFT); |
Jean-Marc Valin | 068cbd8 | 2013-05-26 20:08:35 -0400 | [diff] [blame] | 184 | _y[i+1] = sum[1]; |
| 185 | sum[2] = MAC16_16(sum[2], y[i+ord+1], den[0]); |
| 186 | sum[2] = MAC16_16(sum[2], y[i+ord ], den[1]); |
Jean-Marc Valin | a0bd7d3 | 2016-07-22 09:13:00 -0400 | [diff] [blame] | 187 | y[i+ord+2] = -SROUND16(sum[2],SIG_SHIFT); |
Jean-Marc Valin | 068cbd8 | 2013-05-26 20:08:35 -0400 | [diff] [blame] | 188 | _y[i+2] = sum[2]; |
| 189 | |
| 190 | sum[3] = MAC16_16(sum[3], y[i+ord+2], den[0]); |
| 191 | sum[3] = MAC16_16(sum[3], y[i+ord+1], den[1]); |
| 192 | sum[3] = MAC16_16(sum[3], y[i+ord ], den[2]); |
Jean-Marc Valin | a0bd7d3 | 2016-07-22 09:13:00 -0400 | [diff] [blame] | 193 | y[i+ord+3] = -SROUND16(sum[3],SIG_SHIFT); |
Jean-Marc Valin | 068cbd8 | 2013-05-26 20:08:35 -0400 | [diff] [blame] | 194 | _y[i+3] = sum[3]; |
Jean-Marc Valin | 531cf59 | 2013-05-25 07:41:55 -0400 | [diff] [blame] | 195 | } |
| 196 | for (;i<N;i++) |
| 197 | { |
| 198 | opus_val32 sum = _x[i]; |
| 199 | for (j=0;j<ord;j++) |
| 200 | sum -= MULT16_16(rden[j],y[i+j]); |
Jean-Marc Valin | a0bd7d3 | 2016-07-22 09:13:00 -0400 | [diff] [blame] | 201 | y[i+ord] = SROUND16(sum,SIG_SHIFT); |
Jean-Marc Valin | 531cf59 | 2013-05-25 07:41:55 -0400 | [diff] [blame] | 202 | _y[i] = sum; |
| 203 | } |
| 204 | for(i=0;i<ord;i++) |
| 205 | mem[i] = _y[N-i-1]; |
Jean-Marc Valin | 0fa5fa8 | 2013-05-25 18:50:01 -0400 | [diff] [blame] | 206 | RESTORE_STACK; |
John Ridges | e50e808 | 2013-06-06 23:12:57 -0400 | [diff] [blame] | 207 | #endif |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 208 | } |
| 209 | |
Jean-Marc Valin | 6a7ee7f | 2013-08-28 17:55:34 -0400 | [diff] [blame] | 210 | int _celt_autocorr( |
Jean-Marc Valin | ff5f722 | 2011-07-29 18:59:12 -0400 | [diff] [blame] | 211 | const opus_val16 *x, /* in: [0...n-1] samples x */ |
| 212 | opus_val32 *ac, /* out: [0...lag-1] ac values */ |
| 213 | const opus_val16 *window, |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 214 | int overlap, |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 215 | int lag, |
Timothy B. Terriberry | 39386e0 | 2013-11-18 13:30:13 -0500 | [diff] [blame] | 216 | int n, |
| 217 | int arch |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 218 | ) |
| 219 | { |
Jean-Marc Valin | ff5f722 | 2011-07-29 18:59:12 -0400 | [diff] [blame] | 220 | opus_val32 d; |
Jean-Marc Valin | 6a7ee7f | 2013-08-28 17:55:34 -0400 | [diff] [blame] | 221 | int i, k; |
Jean-Marc Valin | e8e57a3 | 2013-05-25 02:14:25 -0400 | [diff] [blame] | 222 | int fastN=n-lag; |
Jean-Marc Valin | 6a7ee7f | 2013-08-28 17:55:34 -0400 | [diff] [blame] | 223 | int shift; |
| 224 | const opus_val16 *xptr; |
Jean-Marc Valin | ff5f722 | 2011-07-29 18:59:12 -0400 | [diff] [blame] | 225 | VARDECL(opus_val16, xx); |
Thorvald Natvig | b8002a0 | 2009-12-11 13:19:09 +0100 | [diff] [blame] | 226 | SAVE_STACK; |
Jean-Marc Valin | ff5f722 | 2011-07-29 18:59:12 -0400 | [diff] [blame] | 227 | ALLOC(xx, n, opus_val16); |
Gregory Maxwell | 5d5875a | 2011-10-03 21:07:39 -0400 | [diff] [blame] | 228 | celt_assert(n>0); |
| 229 | celt_assert(overlap>=0); |
Jean-Marc Valin | 6a7ee7f | 2013-08-28 17:55:34 -0400 | [diff] [blame] | 230 | if (overlap == 0) |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 231 | { |
Jean-Marc Valin | 6a7ee7f | 2013-08-28 17:55:34 -0400 | [diff] [blame] | 232 | xptr = x; |
| 233 | } else { |
| 234 | for (i=0;i<n;i++) |
| 235 | xx[i] = x[i]; |
| 236 | for (i=0;i<overlap;i++) |
| 237 | { |
| 238 | xx[i] = MULT16_16_Q15(x[i],window[i]); |
| 239 | xx[n-i-1] = MULT16_16_Q15(x[n-i-1],window[i]); |
| 240 | } |
| 241 | xptr = xx; |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 242 | } |
Jean-Marc Valin | 6a7ee7f | 2013-08-28 17:55:34 -0400 | [diff] [blame] | 243 | shift=0; |
Jean-Marc Valin | 456eab2 | 2010-06-16 22:38:57 -0400 | [diff] [blame] | 244 | #ifdef FIXED_POINT |
| 245 | { |
Timothy B. Terriberry | 85ede2c | 2013-05-22 15:26:12 -0700 | [diff] [blame] | 246 | opus_val32 ac0; |
Jean-Marc Valin | 6a7ee7f | 2013-08-28 17:55:34 -0400 | [diff] [blame] | 247 | ac0 = 1+(n<<7); |
| 248 | if (n&1) ac0 += SHR32(MULT16_16(xptr[0],xptr[0]),9); |
Timothy B. Terriberry | 85ede2c | 2013-05-22 15:26:12 -0700 | [diff] [blame] | 249 | for(i=(n&1);i<n;i+=2) |
| 250 | { |
Jean-Marc Valin | 6a7ee7f | 2013-08-28 17:55:34 -0400 | [diff] [blame] | 251 | ac0 += SHR32(MULT16_16(xptr[i],xptr[i]),9); |
| 252 | ac0 += SHR32(MULT16_16(xptr[i+1],xptr[i+1]),9); |
Timothy B. Terriberry | 85ede2c | 2013-05-22 15:26:12 -0700 | [diff] [blame] | 253 | } |
Jean-Marc Valin | 0da0d91 | 2010-06-17 07:32:20 -0400 | [diff] [blame] | 254 | |
Jean-Marc Valin | e1be192 | 2011-11-28 22:48:01 -0500 | [diff] [blame] | 255 | shift = celt_ilog2(ac0)-30+10; |
Jean-Marc Valin | 6a7ee7f | 2013-08-28 17:55:34 -0400 | [diff] [blame] | 256 | shift = (shift)/2; |
| 257 | if (shift>0) |
| 258 | { |
| 259 | for(i=0;i<n;i++) |
| 260 | xx[i] = PSHR32(xptr[i], shift); |
| 261 | xptr = xx; |
| 262 | } else |
| 263 | shift = 0; |
Jean-Marc Valin | 456eab2 | 2010-06-16 22:38:57 -0400 | [diff] [blame] | 264 | } |
| 265 | #endif |
Timothy B. Terriberry | 39386e0 | 2013-11-18 13:30:13 -0500 | [diff] [blame] | 266 | celt_pitch_xcorr(xptr, xptr, ac, fastN, lag+1, arch); |
Jean-Marc Valin | 6a7ee7f | 2013-08-28 17:55:34 -0400 | [diff] [blame] | 267 | for (k=0;k<=lag;k++) |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 268 | { |
Jean-Marc Valin | 6a7ee7f | 2013-08-28 17:55:34 -0400 | [diff] [blame] | 269 | for (i = k+fastN, d = 0; i < n; i++) |
| 270 | d = MAC16_16(d, xptr[i], xptr[i-k]); |
| 271 | ac[k] += d; |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 272 | } |
Jean-Marc Valin | 6a7ee7f | 2013-08-28 17:55:34 -0400 | [diff] [blame] | 273 | #ifdef FIXED_POINT |
| 274 | shift = 2*shift; |
| 275 | if (shift<=0) |
| 276 | ac[0] += SHL32((opus_int32)1, -shift); |
| 277 | if (ac[0] < 268435456) |
| 278 | { |
| 279 | int shift2 = 29 - EC_ILOG(ac[0]); |
| 280 | for (i=0;i<=lag;i++) |
| 281 | ac[i] = SHL32(ac[i], shift2); |
| 282 | shift -= shift2; |
| 283 | } else if (ac[0] >= 536870912) |
| 284 | { |
| 285 | int shift2=1; |
| 286 | if (ac[0] >= 1073741824) |
| 287 | shift2++; |
| 288 | for (i=0;i<=lag;i++) |
| 289 | ac[i] = SHR32(ac[i], shift2); |
| 290 | shift += shift2; |
| 291 | } |
| 292 | #endif |
Jean-Marc Valin | 456eab2 | 2010-06-16 22:38:57 -0400 | [diff] [blame] | 293 | |
Thorvald Natvig | b8002a0 | 2009-12-11 13:19:09 +0100 | [diff] [blame] | 294 | RESTORE_STACK; |
Jean-Marc Valin | 6a7ee7f | 2013-08-28 17:55:34 -0400 | [diff] [blame] | 295 | return shift; |
Jean-Marc Valin | e14fe90 | 2009-12-11 00:07:31 -0500 | [diff] [blame] | 296 | } |