diff options
Diffstat (limited to 'lib/rbcodec/codecs/libopus/celt/pitch.c')
-rw-r--r-- | lib/rbcodec/codecs/libopus/celt/pitch.c | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/lib/rbcodec/codecs/libopus/celt/pitch.c b/lib/rbcodec/codecs/libopus/celt/pitch.c index ee56a434f0..872582a48a 100644 --- a/lib/rbcodec/codecs/libopus/celt/pitch.c +++ b/lib/rbcodec/codecs/libopus/celt/pitch.c | |||
@@ -102,11 +102,9 @@ static void find_best_pitch(opus_val32 *xcorr, opus_val16 *y, int len, | |||
102 | } | 102 | } |
103 | } | 103 | } |
104 | 104 | ||
105 | static void celt_fir5(const opus_val16 *x, | 105 | static void celt_fir5(opus_val16 *x, |
106 | const opus_val16 *num, | 106 | const opus_val16 *num, |
107 | opus_val16 *y, | 107 | int N) |
108 | int N, | ||
109 | opus_val16 *mem) | ||
110 | { | 108 | { |
111 | int i; | 109 | int i; |
112 | opus_val16 num0, num1, num2, num3, num4; | 110 | opus_val16 num0, num1, num2, num3, num4; |
@@ -116,11 +114,11 @@ static void celt_fir5(const opus_val16 *x, | |||
116 | num2=num[2]; | 114 | num2=num[2]; |
117 | num3=num[3]; | 115 | num3=num[3]; |
118 | num4=num[4]; | 116 | num4=num[4]; |
119 | mem0=mem[0]; | 117 | mem0=0; |
120 | mem1=mem[1]; | 118 | mem1=0; |
121 | mem2=mem[2]; | 119 | mem2=0; |
122 | mem3=mem[3]; | 120 | mem3=0; |
123 | mem4=mem[4]; | 121 | mem4=0; |
124 | for (i=0;i<N;i++) | 122 | for (i=0;i<N;i++) |
125 | { | 123 | { |
126 | opus_val32 sum = SHL32(EXTEND32(x[i]), SIG_SHIFT); | 124 | opus_val32 sum = SHL32(EXTEND32(x[i]), SIG_SHIFT); |
@@ -134,13 +132,8 @@ static void celt_fir5(const opus_val16 *x, | |||
134 | mem2 = mem1; | 132 | mem2 = mem1; |
135 | mem1 = mem0; | 133 | mem1 = mem0; |
136 | mem0 = x[i]; | 134 | mem0 = x[i]; |
137 | y[i] = ROUND16(sum, SIG_SHIFT); | 135 | x[i] = ROUND16(sum, SIG_SHIFT); |
138 | } | 136 | } |
139 | mem[0]=mem0; | ||
140 | mem[1]=mem1; | ||
141 | mem[2]=mem2; | ||
142 | mem[3]=mem3; | ||
143 | mem[4]=mem4; | ||
144 | } | 137 | } |
145 | 138 | ||
146 | 139 | ||
@@ -150,7 +143,7 @@ void pitch_downsample(celt_sig * OPUS_RESTRICT x[], opus_val16 * OPUS_RESTRICT x | |||
150 | int i; | 143 | int i; |
151 | opus_val32 ac[5]; | 144 | opus_val32 ac[5]; |
152 | opus_val16 tmp=Q15ONE; | 145 | opus_val16 tmp=Q15ONE; |
153 | opus_val16 lpc[4], mem[5]={0,0,0,0,0}; | 146 | opus_val16 lpc[4]; |
154 | opus_val16 lpc2[5]; | 147 | opus_val16 lpc2[5]; |
155 | opus_val16 c1 = QCONST16(.8f,15); | 148 | opus_val16 c1 = QCONST16(.8f,15); |
156 | #ifdef FIXED_POINT | 149 | #ifdef FIXED_POINT |
@@ -211,28 +204,33 @@ void pitch_downsample(celt_sig * OPUS_RESTRICT x[], opus_val16 * OPUS_RESTRICT x | |||
211 | lpc2[2] = lpc[2] + MULT16_16_Q15(c1,lpc[1]); | 204 | lpc2[2] = lpc[2] + MULT16_16_Q15(c1,lpc[1]); |
212 | lpc2[3] = lpc[3] + MULT16_16_Q15(c1,lpc[2]); | 205 | lpc2[3] = lpc[3] + MULT16_16_Q15(c1,lpc[2]); |
213 | lpc2[4] = MULT16_16_Q15(c1,lpc[3]); | 206 | lpc2[4] = MULT16_16_Q15(c1,lpc[3]); |
214 | celt_fir5(x_lp, lpc2, x_lp, len>>1, mem); | 207 | celt_fir5(x_lp, lpc2, len>>1); |
215 | } | 208 | } |
216 | 209 | ||
217 | #if 0 /* This is a simple version of the pitch correlation that should work | 210 | /* Pure C implementation. */ |
218 | well on DSPs like Blackfin and TI C5x/C6x */ | ||
219 | |||
220 | #ifdef FIXED_POINT | 211 | #ifdef FIXED_POINT |
221 | opus_val32 | 212 | opus_val32 |
222 | #else | 213 | #else |
223 | void | 214 | void |
224 | #endif | 215 | #endif |
225 | celt_pitch_xcorr(opus_val16 *x, opus_val16 *y, opus_val32 *xcorr, int len, int max_pitch) | 216 | celt_pitch_xcorr_c(const opus_val16 *_x, const opus_val16 *_y, |
217 | opus_val32 *xcorr, int len, int max_pitch, int arch) | ||
226 | { | 218 | { |
219 | |||
220 | #if 0 /* This is a simple version of the pitch correlation that should work | ||
221 | well on DSPs like Blackfin and TI C5x/C6x */ | ||
227 | int i, j; | 222 | int i, j; |
228 | #ifdef FIXED_POINT | 223 | #ifdef FIXED_POINT |
229 | opus_val32 maxcorr=1; | 224 | opus_val32 maxcorr=1; |
230 | #endif | 225 | #endif |
226 | #if !defined(OVERRIDE_PITCH_XCORR) | ||
227 | (void)arch; | ||
228 | #endif | ||
231 | for (i=0;i<max_pitch;i++) | 229 | for (i=0;i<max_pitch;i++) |
232 | { | 230 | { |
233 | opus_val32 sum = 0; | 231 | opus_val32 sum = 0; |
234 | for (j=0;j<len;j++) | 232 | for (j=0;j<len;j++) |
235 | sum = MAC16_16(sum, x[j],y[i+j]); | 233 | sum = MAC16_16(sum, _x[j], _y[i+j]); |
236 | xcorr[i] = sum; | 234 | xcorr[i] = sum; |
237 | #ifdef FIXED_POINT | 235 | #ifdef FIXED_POINT |
238 | maxcorr = MAX32(maxcorr, sum); | 236 | maxcorr = MAX32(maxcorr, sum); |
@@ -241,17 +239,8 @@ celt_pitch_xcorr(opus_val16 *x, opus_val16 *y, opus_val32 *xcorr, int len, int m | |||
241 | #ifdef FIXED_POINT | 239 | #ifdef FIXED_POINT |
242 | return maxcorr; | 240 | return maxcorr; |
243 | #endif | 241 | #endif |
244 | } | ||
245 | 242 | ||
246 | #else /* Unrolled version of the pitch correlation -- runs faster on x86 and ARM */ | 243 | #else /* Unrolled version of the pitch correlation -- runs faster on x86 and ARM */ |
247 | |||
248 | #ifdef FIXED_POINT | ||
249 | opus_val32 | ||
250 | #else | ||
251 | void | ||
252 | #endif | ||
253 | celt_pitch_xcorr_c(const opus_val16 *_x, const opus_val16 *_y, opus_val32 *xcorr, int len, int max_pitch) | ||
254 | { | ||
255 | int i; | 244 | int i; |
256 | /*The EDSP version requires that max_pitch is at least 1, and that _x is | 245 | /*The EDSP version requires that max_pitch is at least 1, and that _x is |
257 | 32-bit aligned. | 246 | 32-bit aligned. |
@@ -260,11 +249,11 @@ celt_pitch_xcorr_c(const opus_val16 *_x, const opus_val16 *_y, opus_val32 *xcorr | |||
260 | opus_val32 maxcorr=1; | 249 | opus_val32 maxcorr=1; |
261 | #endif | 250 | #endif |
262 | celt_assert(max_pitch>0); | 251 | celt_assert(max_pitch>0); |
263 | celt_assert((((unsigned char *)_x-(unsigned char *)NULL)&3)==0); | 252 | celt_sig_assert((((unsigned char *)_x-(unsigned char *)NULL)&3)==0); |
264 | for (i=0;i<max_pitch-3;i+=4) | 253 | for (i=0;i<max_pitch-3;i+=4) |
265 | { | 254 | { |
266 | opus_val32 sum[4]={0,0,0,0}; | 255 | opus_val32 sum[4]={0,0,0,0}; |
267 | xcorr_kernel(_x, _y+i, sum, len); | 256 | xcorr_kernel(_x, _y+i, sum, len, arch); |
268 | xcorr[i]=sum[0]; | 257 | xcorr[i]=sum[0]; |
269 | xcorr[i+1]=sum[1]; | 258 | xcorr[i+1]=sum[1]; |
270 | xcorr[i+2]=sum[2]; | 259 | xcorr[i+2]=sum[2]; |
@@ -280,7 +269,7 @@ celt_pitch_xcorr_c(const opus_val16 *_x, const opus_val16 *_y, opus_val32 *xcorr | |||
280 | for (;i<max_pitch;i++) | 269 | for (;i<max_pitch;i++) |
281 | { | 270 | { |
282 | opus_val32 sum; | 271 | opus_val32 sum; |
283 | sum = celt_inner_prod(_x, _y+i, len); | 272 | sum = celt_inner_prod(_x, _y+i, len, arch); |
284 | xcorr[i] = sum; | 273 | xcorr[i] = sum; |
285 | #ifdef FIXED_POINT | 274 | #ifdef FIXED_POINT |
286 | maxcorr = MAX32(maxcorr, sum); | 275 | maxcorr = MAX32(maxcorr, sum); |
@@ -289,9 +278,9 @@ celt_pitch_xcorr_c(const opus_val16 *_x, const opus_val16 *_y, opus_val32 *xcorr | |||
289 | #ifdef FIXED_POINT | 278 | #ifdef FIXED_POINT |
290 | return maxcorr; | 279 | return maxcorr; |
291 | #endif | 280 | #endif |
281 | #endif | ||
292 | } | 282 | } |
293 | 283 | ||
294 | #endif | ||
295 | void pitch_search(const opus_val16 * OPUS_RESTRICT x_lp, opus_val16 * OPUS_RESTRICT y, | 284 | void pitch_search(const opus_val16 * OPUS_RESTRICT x_lp, opus_val16 * OPUS_RESTRICT y, |
296 | int len, int max_pitch, int *pitch, int arch) | 285 | int len, int max_pitch, int *pitch, int arch) |
297 | { | 286 | { |
@@ -369,7 +358,7 @@ void pitch_search(const opus_val16 * OPUS_RESTRICT x_lp, opus_val16 * OPUS_RESTR | |||
369 | for (j=0;j<len>>1;j++) | 358 | for (j=0;j<len>>1;j++) |
370 | sum += SHR32(MULT16_16(x_lp[j],y[i+j]), shift); | 359 | sum += SHR32(MULT16_16(x_lp[j],y[i+j]), shift); |
371 | #else | 360 | #else |
372 | sum = celt_inner_prod(x_lp, y+i, len>>1); | 361 | sum = celt_inner_prod(x_lp, y+i, len>>1, arch); |
373 | #endif | 362 | #endif |
374 | xcorr[i] = MAX32(-1, sum); | 363 | xcorr[i] = MAX32(-1, sum); |
375 | #ifdef FIXED_POINT | 364 | #ifdef FIXED_POINT |
@@ -403,10 +392,44 @@ void pitch_search(const opus_val16 * OPUS_RESTRICT x_lp, opus_val16 * OPUS_RESTR | |||
403 | RESTORE_STACK; | 392 | RESTORE_STACK; |
404 | } | 393 | } |
405 | 394 | ||
406 | #if 0 | 395 | #ifdef FIXED_POINT |
396 | static opus_val16 compute_pitch_gain(opus_val32 xy, opus_val32 xx, opus_val32 yy) | ||
397 | { | ||
398 | opus_val32 x2y2; | ||
399 | int sx, sy, shift; | ||
400 | opus_val32 g; | ||
401 | opus_val16 den; | ||
402 | if (xy == 0 || xx == 0 || yy == 0) | ||
403 | return 0; | ||
404 | sx = celt_ilog2(xx)-14; | ||
405 | sy = celt_ilog2(yy)-14; | ||
406 | shift = sx + sy; | ||
407 | x2y2 = SHR32(MULT16_16(VSHR32(xx, sx), VSHR32(yy, sy)), 14); | ||
408 | if (shift & 1) { | ||
409 | if (x2y2 < 32768) | ||
410 | { | ||
411 | x2y2 <<= 1; | ||
412 | shift--; | ||
413 | } else { | ||
414 | x2y2 >>= 1; | ||
415 | shift++; | ||
416 | } | ||
417 | } | ||
418 | den = celt_rsqrt_norm(x2y2); | ||
419 | g = MULT16_32_Q15(den, xy); | ||
420 | g = VSHR32(g, (shift>>1)-1); | ||
421 | return EXTRACT16(MIN32(g, Q15ONE)); | ||
422 | } | ||
423 | #else | ||
424 | static opus_val16 compute_pitch_gain(opus_val32 xy, opus_val32 xx, opus_val32 yy) | ||
425 | { | ||
426 | return xy/celt_sqrt(1+xx*yy); | ||
427 | } | ||
428 | #endif | ||
429 | |||
407 | static const int second_check[16] = {0, 0, 3, 2, 3, 2, 5, 2, 3, 2, 3, 2, 5, 2, 3, 2}; | 430 | static const int second_check[16] = {0, 0, 3, 2, 3, 2, 5, 2, 3, 2, 3, 2, 5, 2, 3, 2}; |
408 | opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod, | 431 | opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod, |
409 | int N, int *T0_, int prev_period, opus_val16 prev_gain) | 432 | int N, int *T0_, int prev_period, opus_val16 prev_gain, int arch) |
410 | { | 433 | { |
411 | int k, i, T, T0; | 434 | int k, i, T, T0; |
412 | opus_val16 g, g0; | 435 | opus_val16 g, g0; |
@@ -431,7 +454,7 @@ opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod, | |||
431 | 454 | ||
432 | T = T0 = *T0_; | 455 | T = T0 = *T0_; |
433 | ALLOC(yy_lookup, maxperiod+1, opus_val32); | 456 | ALLOC(yy_lookup, maxperiod+1, opus_val32); |
434 | dual_inner_prod(x, x, x-T0, N, &xx, &xy); | 457 | dual_inner_prod(x, x, x-T0, N, &xx, &xy, arch); |
435 | yy_lookup[0] = xx; | 458 | yy_lookup[0] = xx; |
436 | yy=xx; | 459 | yy=xx; |
437 | for (i=1;i<=maxperiod;i++) | 460 | for (i=1;i<=maxperiod;i++) |
@@ -442,18 +465,7 @@ opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod, | |||
442 | yy = yy_lookup[T0]; | 465 | yy = yy_lookup[T0]; |
443 | best_xy = xy; | 466 | best_xy = xy; |
444 | best_yy = yy; | 467 | best_yy = yy; |
445 | #ifdef FIXED_POINT | 468 | g = g0 = compute_pitch_gain(xy, xx, yy); |
446 | { | ||
447 | opus_val32 x2y2; | ||
448 | int sh, t; | ||
449 | x2y2 = 1+HALF32(MULT32_32_Q31(xx,yy)); | ||
450 | sh = celt_ilog2(x2y2)>>1; | ||
451 | t = VSHR32(x2y2, 2*(sh-7)); | ||
452 | g = g0 = VSHR32(MULT16_32_Q15(celt_rsqrt_norm(t), xy),sh+1); | ||
453 | } | ||
454 | #else | ||
455 | g = g0 = xy/celt_sqrt(1+xx*yy); | ||
456 | #endif | ||
457 | /* Look for any pitch at T/k */ | 469 | /* Look for any pitch at T/k */ |
458 | for (k=2;k<=15;k++) | 470 | for (k=2;k<=15;k++) |
459 | { | 471 | { |
@@ -475,25 +487,14 @@ opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod, | |||
475 | { | 487 | { |
476 | T1b = celt_udiv(2*second_check[k]*T0+k, 2*k); | 488 | T1b = celt_udiv(2*second_check[k]*T0+k, 2*k); |
477 | } | 489 | } |
478 | dual_inner_prod(x, &x[-T1], &x[-T1b], N, &xy, &xy2); | 490 | dual_inner_prod(x, &x[-T1], &x[-T1b], N, &xy, &xy2, arch); |
479 | xy += xy2; | 491 | xy = HALF32(xy + xy2); |
480 | yy = yy_lookup[T1] + yy_lookup[T1b]; | 492 | yy = HALF32(yy_lookup[T1] + yy_lookup[T1b]); |
481 | #ifdef FIXED_POINT | 493 | g1 = compute_pitch_gain(xy, xx, yy); |
482 | { | ||
483 | opus_val32 x2y2; | ||
484 | int sh, t; | ||
485 | x2y2 = 1+MULT32_32_Q31(xx,yy); | ||
486 | sh = celt_ilog2(x2y2)>>1; | ||
487 | t = VSHR32(x2y2, 2*(sh-7)); | ||
488 | g1 = VSHR32(MULT16_32_Q15(celt_rsqrt_norm(t), xy),sh+1); | ||
489 | } | ||
490 | #else | ||
491 | g1 = xy/celt_sqrt(1+2.f*xx*1.f*yy); | ||
492 | #endif | ||
493 | if (abs(T1-prev_period)<=1) | 494 | if (abs(T1-prev_period)<=1) |
494 | cont = prev_gain; | 495 | cont = prev_gain; |
495 | else if (abs(T1-prev_period)<=2 && 5*k*k < T0) | 496 | else if (abs(T1-prev_period)<=2 && 5*k*k < T0) |
496 | cont = HALF32(prev_gain); | 497 | cont = HALF16(prev_gain); |
497 | else | 498 | else |
498 | cont = 0; | 499 | cont = 0; |
499 | thresh = MAX16(QCONST16(.3f,15), MULT16_16_Q15(QCONST16(.7f,15),g0)-cont); | 500 | thresh = MAX16(QCONST16(.3f,15), MULT16_16_Q15(QCONST16(.7f,15),g0)-cont); |
@@ -518,7 +519,7 @@ opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod, | |||
518 | pg = SHR32(frac_div32(best_xy,best_yy+1),16); | 519 | pg = SHR32(frac_div32(best_xy,best_yy+1),16); |
519 | 520 | ||
520 | for (k=0;k<3;k++) | 521 | for (k=0;k<3;k++) |
521 | xcorr[k] = celt_inner_prod(x, x-(T+k-1), N); | 522 | xcorr[k] = celt_inner_prod(x, x-(T+k-1), N, arch); |
522 | if ((xcorr[2]-xcorr[0]) > MULT16_32_Q15(QCONST16(.7f,15),xcorr[1]-xcorr[0])) | 523 | if ((xcorr[2]-xcorr[0]) > MULT16_32_Q15(QCONST16(.7f,15),xcorr[1]-xcorr[0])) |
523 | offset = 1; | 524 | offset = 1; |
524 | else if ((xcorr[0]-xcorr[2]) > MULT16_32_Q15(QCONST16(.7f,15),xcorr[1]-xcorr[2])) | 525 | else if ((xcorr[0]-xcorr[2]) > MULT16_32_Q15(QCONST16(.7f,15),xcorr[1]-xcorr[2])) |
@@ -534,4 +535,3 @@ opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod, | |||
534 | RESTORE_STACK; | 535 | RESTORE_STACK; |
535 | return pg; | 536 | return pg; |
536 | } | 537 | } |
537 | #endif | ||