Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: celt/pitch.c

Issue 882843002: Update to opus-HEAD-66611f1. (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/opus.git@master
Patch Set: Add the contents of Makefile.mips back. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « celt/pitch.h ('k') | celt/rate.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2007-2008 CSIRO 1 /* Copyright (c) 2007-2008 CSIRO
2 Copyright (c) 2007-2009 Xiph.Org Foundation 2 Copyright (c) 2007-2009 Xiph.Org Foundation
3 Written by Jean-Marc Valin */ 3 Written by Jean-Marc Valin */
4 /** 4 /**
5 @file pitch.c 5 @file pitch.c
6 @brief Pitch analysis 6 @brief Pitch analysis
7 */ 7 */
8 8
9 /* 9 /*
10 Redistribution and use in source and binary forms, with or without 10 Redistribution and use in source and binary forms, with or without
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 207 }
208 /* Add a zero */ 208 /* Add a zero */
209 lpc2[0] = lpc[0] + QCONST16(.8f,SIG_SHIFT); 209 lpc2[0] = lpc[0] + QCONST16(.8f,SIG_SHIFT);
210 lpc2[1] = lpc[1] + MULT16_16_Q15(c1,lpc[0]); 210 lpc2[1] = lpc[1] + MULT16_16_Q15(c1,lpc[0]);
211 lpc2[2] = lpc[2] + MULT16_16_Q15(c1,lpc[1]); 211 lpc2[2] = lpc[2] + MULT16_16_Q15(c1,lpc[1]);
212 lpc2[3] = lpc[3] + MULT16_16_Q15(c1,lpc[2]); 212 lpc2[3] = lpc[3] + MULT16_16_Q15(c1,lpc[2]);
213 lpc2[4] = MULT16_16_Q15(c1,lpc[3]); 213 lpc2[4] = MULT16_16_Q15(c1,lpc[3]);
214 celt_fir5(x_lp, lpc2, x_lp, len>>1, mem); 214 celt_fir5(x_lp, lpc2, x_lp, len>>1, mem);
215 } 215 }
216 216
217 #if 0 /* This is a simple version of the pitch correlation that should work 217 /* Pure C implementation. */
218 well on DSPs like Blackfin and TI C5x/C6x */
219
220 #ifdef FIXED_POINT 218 #ifdef FIXED_POINT
221 opus_val32 219 opus_val32
222 #else 220 #else
223 void 221 void
224 #endif 222 #endif
225 celt_pitch_xcorr(opus_val16 *x, opus_val16 *y, opus_val32 *xcorr, int len, int m ax_pitch) 223 #if defined(OVERRIDE_PITCH_XCORR)
224 celt_pitch_xcorr_c(const opus_val16 *_x, const opus_val16 *_y,
225 opus_val32 *xcorr, int len, int max_pitch)
226 #else
227 celt_pitch_xcorr(const opus_val16 *_x, const opus_val16 *_y,
228 opus_val32 *xcorr, int len, int max_pitch, int arch)
229 #endif
226 { 230 {
231
232 #if 0 /* This is a simple version of the pitch correlation that should work
233 well on DSPs like Blackfin and TI C5x/C6x */
227 int i, j; 234 int i, j;
228 #ifdef FIXED_POINT 235 #ifdef FIXED_POINT
229 opus_val32 maxcorr=1; 236 opus_val32 maxcorr=1;
230 #endif 237 #endif
238 #if !defined(OVERRIDE_PITCH_XCORR)
239 (void)arch;
240 #endif
231 for (i=0;i<max_pitch;i++) 241 for (i=0;i<max_pitch;i++)
232 { 242 {
233 opus_val32 sum = 0; 243 opus_val32 sum = 0;
234 for (j=0;j<len;j++) 244 for (j=0;j<len;j++)
235 sum = MAC16_16(sum, x[j],y[i+j]); 245 sum = MAC16_16(sum, _x[j], _y[i+j]);
236 xcorr[i] = sum; 246 xcorr[i] = sum;
237 #ifdef FIXED_POINT 247 #ifdef FIXED_POINT
238 maxcorr = MAX32(maxcorr, sum); 248 maxcorr = MAX32(maxcorr, sum);
239 #endif 249 #endif
240 } 250 }
241 #ifdef FIXED_POINT 251 #ifdef FIXED_POINT
242 return maxcorr; 252 return maxcorr;
243 #endif 253 #endif
244 }
245 254
246 #else /* Unrolled version of the pitch correlation -- runs faster on x86 and ARM */ 255 #else /* Unrolled version of the pitch correlation -- runs faster on x86 and ARM */
247 256 int i;
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,j;
256 /*The EDSP version requires that max_pitch is at least 1, and that _x is 257 /*The EDSP version requires that max_pitch is at least 1, and that _x is
257 32-bit aligned. 258 32-bit aligned.
258 Since it's hard to put asserts in assembly, put them here.*/ 259 Since it's hard to put asserts in assembly, put them here.*/
259 celt_assert(max_pitch>0);
260 celt_assert((((unsigned char *)_x-(unsigned char *)NULL)&3)==0);
261 #ifdef FIXED_POINT 260 #ifdef FIXED_POINT
262 opus_val32 maxcorr=1; 261 opus_val32 maxcorr=1;
263 #endif 262 #endif
263 celt_assert(max_pitch>0);
264 celt_assert((((unsigned char *)_x-(unsigned char *)NULL)&3)==0);
264 for (i=0;i<max_pitch-3;i+=4) 265 for (i=0;i<max_pitch-3;i+=4)
265 { 266 {
266 opus_val32 sum[4]={0,0,0,0}; 267 opus_val32 sum[4]={0,0,0,0};
267 xcorr_kernel(_x, _y+i, sum, len); 268 #if defined(OVERRIDE_PITCH_XCORR)
269 xcorr_kernel_c(_x, _y+i, sum, len);
270 #else
271 xcorr_kernel(_x, _y+i, sum, len, arch);
272 #endif
268 xcorr[i]=sum[0]; 273 xcorr[i]=sum[0];
269 xcorr[i+1]=sum[1]; 274 xcorr[i+1]=sum[1];
270 xcorr[i+2]=sum[2]; 275 xcorr[i+2]=sum[2];
271 xcorr[i+3]=sum[3]; 276 xcorr[i+3]=sum[3];
272 #ifdef FIXED_POINT 277 #ifdef FIXED_POINT
273 sum[0] = MAX32(sum[0], sum[1]); 278 sum[0] = MAX32(sum[0], sum[1]);
274 sum[2] = MAX32(sum[2], sum[3]); 279 sum[2] = MAX32(sum[2], sum[3]);
275 sum[0] = MAX32(sum[0], sum[2]); 280 sum[0] = MAX32(sum[0], sum[2]);
276 maxcorr = MAX32(maxcorr, sum[0]); 281 maxcorr = MAX32(maxcorr, sum[0]);
277 #endif 282 #endif
278 } 283 }
279 /* In case max_pitch isn't a multiple of 4, do non-unrolled version. */ 284 /* In case max_pitch isn't a multiple of 4, do non-unrolled version. */
280 for (;i<max_pitch;i++) 285 for (;i<max_pitch;i++)
281 { 286 {
282 opus_val32 sum = 0; 287 opus_val32 sum;
283 for (j=0;j<len;j++) 288 #if defined(OVERRIDE_PITCH_XCORR)
284 sum = MAC16_16(sum, _x[j],_y[i+j]); 289 sum = celt_inner_prod_c(_x, _y+i, len);
290 #else
291 sum = celt_inner_prod(_x, _y+i, len, arch);
292 #endif
285 xcorr[i] = sum; 293 xcorr[i] = sum;
286 #ifdef FIXED_POINT 294 #ifdef FIXED_POINT
287 maxcorr = MAX32(maxcorr, sum); 295 maxcorr = MAX32(maxcorr, sum);
288 #endif 296 #endif
289 } 297 }
290 #ifdef FIXED_POINT 298 #ifdef FIXED_POINT
291 return maxcorr; 299 return maxcorr;
292 #endif 300 #endif
301 #endif
293 } 302 }
294 303
295 #endif
296 void pitch_search(const opus_val16 * OPUS_RESTRICT x_lp, opus_val16 * OPUS_RESTR ICT y, 304 void pitch_search(const opus_val16 * OPUS_RESTRICT x_lp, opus_val16 * OPUS_RESTR ICT y,
297 int len, int max_pitch, int *pitch, int arch) 305 int len, int max_pitch, int *pitch, int arch)
298 { 306 {
299 int i, j; 307 int i, j;
300 int lag; 308 int lag;
301 int best_pitch[2]={0,0}; 309 int best_pitch[2]={0,0};
302 VARDECL(opus_val16, x_lp4); 310 VARDECL(opus_val16, x_lp4);
303 VARDECL(opus_val16, y_lp4); 311 VARDECL(opus_val16, y_lp4);
304 VARDECL(opus_val32, xcorr); 312 VARDECL(opus_val32, xcorr);
305 #ifdef FIXED_POINT 313 #ifdef FIXED_POINT
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 , 0, maxcorr 362 , 0, maxcorr
355 #endif 363 #endif
356 ); 364 );
357 365
358 /* Finer search with 2x decimation */ 366 /* Finer search with 2x decimation */
359 #ifdef FIXED_POINT 367 #ifdef FIXED_POINT
360 maxcorr=1; 368 maxcorr=1;
361 #endif 369 #endif
362 for (i=0;i<max_pitch>>1;i++) 370 for (i=0;i<max_pitch>>1;i++)
363 { 371 {
364 opus_val32 sum=0; 372 opus_val32 sum;
365 xcorr[i] = 0; 373 xcorr[i] = 0;
366 if (abs(i-2*best_pitch[0])>2 && abs(i-2*best_pitch[1])>2) 374 if (abs(i-2*best_pitch[0])>2 && abs(i-2*best_pitch[1])>2)
367 continue; 375 continue;
376 #ifdef FIXED_POINT
377 sum = 0;
368 for (j=0;j<len>>1;j++) 378 for (j=0;j<len>>1;j++)
369 sum += SHR32(MULT16_16(x_lp[j],y[i+j]), shift); 379 sum += SHR32(MULT16_16(x_lp[j],y[i+j]), shift);
380 #else
381 sum = celt_inner_prod_c(x_lp, y+i, len>>1);
382 #endif
370 xcorr[i] = MAX32(-1, sum); 383 xcorr[i] = MAX32(-1, sum);
371 #ifdef FIXED_POINT 384 #ifdef FIXED_POINT
372 maxcorr = MAX32(maxcorr, sum); 385 maxcorr = MAX32(maxcorr, sum);
373 #endif 386 #endif
374 } 387 }
375 find_best_pitch(xcorr, y, len>>1, max_pitch>>1, best_pitch 388 find_best_pitch(xcorr, y, len>>1, max_pitch>>1, best_pitch
376 #ifdef FIXED_POINT 389 #ifdef FIXED_POINT
377 , shift+1, maxcorr 390 , shift+1, maxcorr
378 #endif 391 #endif
379 ); 392 );
(...skipping 14 matching lines...) Expand all
394 } else { 407 } else {
395 offset = 0; 408 offset = 0;
396 } 409 }
397 *pitch = 2*best_pitch[0]-offset; 410 *pitch = 2*best_pitch[0]-offset;
398 411
399 RESTORE_STACK; 412 RESTORE_STACK;
400 } 413 }
401 414
402 static const int second_check[16] = {0, 0, 3, 2, 3, 2, 5, 2, 3, 2, 3, 2, 5, 2, 3 , 2}; 415 static const int second_check[16] = {0, 0, 3, 2, 3, 2, 5, 2, 3, 2, 3, 2, 5, 2, 3 , 2};
403 opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod, 416 opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod,
404 int N, int *T0_, int prev_period, opus_val16 prev_gain) 417 int N, int *T0_, int prev_period, opus_val16 prev_gain, int arch)
405 { 418 {
406 int k, i, T, T0; 419 int k, i, T, T0;
407 opus_val16 g, g0; 420 opus_val16 g, g0;
408 opus_val16 pg; 421 opus_val16 pg;
409 opus_val32 xy,xx,yy,xy2; 422 opus_val32 xy,xx,yy,xy2;
410 opus_val32 xcorr[3]; 423 opus_val32 xcorr[3];
411 opus_val32 best_xy, best_yy; 424 opus_val32 best_xy, best_yy;
412 int offset; 425 int offset;
413 int minperiod0; 426 int minperiod0;
414 VARDECL(opus_val32, yy_lookup); 427 VARDECL(opus_val32, yy_lookup);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 #else 462 #else
450 g = g0 = xy/celt_sqrt(1+xx*yy); 463 g = g0 = xy/celt_sqrt(1+xx*yy);
451 #endif 464 #endif
452 /* Look for any pitch at T/k */ 465 /* Look for any pitch at T/k */
453 for (k=2;k<=15;k++) 466 for (k=2;k<=15;k++)
454 { 467 {
455 int T1, T1b; 468 int T1, T1b;
456 opus_val16 g1; 469 opus_val16 g1;
457 opus_val16 cont=0; 470 opus_val16 cont=0;
458 opus_val16 thresh; 471 opus_val16 thresh;
459 T1 = (2*T0+k)/(2*k); 472 T1 = celt_udiv(2*T0+k, 2*k);
460 if (T1 < minperiod) 473 if (T1 < minperiod)
461 break; 474 break;
462 /* Look for another strong correlation at T1b */ 475 /* Look for another strong correlation at T1b */
463 if (k==2) 476 if (k==2)
464 { 477 {
465 if (T1+T0>maxperiod) 478 if (T1+T0>maxperiod)
466 T1b = T0; 479 T1b = T0;
467 else 480 else
468 T1b = T0+T1; 481 T1b = T0+T1;
469 } else 482 } else
470 { 483 {
471 T1b = (2*second_check[k]*T0+k)/(2*k); 484 T1b = celt_udiv(2*second_check[k]*T0+k, 2*k);
472 } 485 }
473 dual_inner_prod(x, &x[-T1], &x[-T1b], N, &xy, &xy2); 486 dual_inner_prod(x, &x[-T1], &x[-T1b], N, &xy, &xy2);
474 xy += xy2; 487 xy += xy2;
475 yy = yy_lookup[T1] + yy_lookup[T1b]; 488 yy = yy_lookup[T1] + yy_lookup[T1b];
476 #ifdef FIXED_POINT 489 #ifdef FIXED_POINT
477 { 490 {
478 opus_val32 x2y2; 491 opus_val32 x2y2;
479 int sh, t; 492 int sh, t;
480 x2y2 = 1+MULT32_32_Q31(xx,yy); 493 x2y2 = 1+MULT32_32_Q31(xx,yy);
481 sh = celt_ilog2(x2y2)>>1; 494 sh = celt_ilog2(x2y2)>>1;
(...skipping 24 matching lines...) Expand all
506 g = g1; 519 g = g1;
507 } 520 }
508 } 521 }
509 best_xy = MAX32(0, best_xy); 522 best_xy = MAX32(0, best_xy);
510 if (best_yy <= best_xy) 523 if (best_yy <= best_xy)
511 pg = Q15ONE; 524 pg = Q15ONE;
512 else 525 else
513 pg = SHR32(frac_div32(best_xy,best_yy+1),16); 526 pg = SHR32(frac_div32(best_xy,best_yy+1),16);
514 527
515 for (k=0;k<3;k++) 528 for (k=0;k<3;k++)
516 { 529 xcorr[k] = celt_inner_prod(x, x-(T+k-1), N, arch);
517 int T1 = T+k-1;
518 xy = 0;
519 for (i=0;i<N;i++)
520 xy = MAC16_16(xy, x[i], x[i-T1]);
521 xcorr[k] = xy;
522 }
523 if ((xcorr[2]-xcorr[0]) > MULT16_32_Q15(QCONST16(.7f,15),xcorr[1]-xcorr[0])) 530 if ((xcorr[2]-xcorr[0]) > MULT16_32_Q15(QCONST16(.7f,15),xcorr[1]-xcorr[0]))
524 offset = 1; 531 offset = 1;
525 else if ((xcorr[0]-xcorr[2]) > MULT16_32_Q15(QCONST16(.7f,15),xcorr[1]-xcorr[ 2])) 532 else if ((xcorr[0]-xcorr[2]) > MULT16_32_Q15(QCONST16(.7f,15),xcorr[1]-xcorr[ 2]))
526 offset = -1; 533 offset = -1;
527 else 534 else
528 offset = 0; 535 offset = 0;
529 if (pg > g) 536 if (pg > g)
530 pg = g; 537 pg = g;
531 *T0_ = 2*T+offset; 538 *T0_ = 2*T+offset;
532 539
533 if (*T0_<minperiod0) 540 if (*T0_<minperiod0)
534 *T0_=minperiod0; 541 *T0_=minperiod0;
535 RESTORE_STACK; 542 RESTORE_STACK;
536 return pg; 543 return pg;
537 } 544 }
OLDNEW
« no previous file with comments | « celt/pitch.h ('k') | celt/rate.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698