summaryrefslogtreecommitdiff
path: root/apps/codecs/libspeex/lsp.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libspeex/lsp.c')
-rw-r--r--apps/codecs/libspeex/lsp.c200
1 files changed, 100 insertions, 100 deletions
diff --git a/apps/codecs/libspeex/lsp.c b/apps/codecs/libspeex/lsp.c
index edf480e8bc..8408d782aa 100644
--- a/apps/codecs/libspeex/lsp.c
+++ b/apps/codecs/libspeex/lsp.c
@@ -1,8 +1,8 @@
1/*---------------------------------------------------------------------------*\ 1/*---------------------------------------------------------------------------*\
2Original copyright 2Original copyright
3 FILE........: lsp.c 3 FILE........: lsp.c
4 AUTHOR......: David Rowe 4 AUTHOR......: David Rowe
5 DATE CREATED: 24/2/93 5 DATE CREATED: 24/2/93
6 6
7Heavily modified by Jean-Marc Valin (c) 2002-2006 (fixed-point, 7Heavily modified by Jean-Marc Valin (c) 2002-2006 (fixed-point,
8 optimizations, additional functions, ...) 8 optimizations, additional functions, ...)
@@ -219,31 +219,31 @@ static float cheb_poly_eva(spx_word32_t *coef, spx_word16_t x, int m, char *stac
219 219
220 220
221int lpc_to_lsp (spx_coef_t *a,int lpcrdr,spx_lsp_t *freq,int nb,spx_word16_t delta, char *stack) 221int lpc_to_lsp (spx_coef_t *a,int lpcrdr,spx_lsp_t *freq,int nb,spx_word16_t delta, char *stack)
222/* float *a lpc coefficients */ 222/* float *a lpc coefficients */
223/* int lpcrdr order of LPC coefficients (10) */ 223/* int lpcrdr order of LPC coefficients (10) */
224/* float *freq LSP frequencies in the x domain */ 224/* float *freq LSP frequencies in the x domain */
225/* int nb number of sub-intervals (4) */ 225/* int nb number of sub-intervals (4) */
226/* float delta grid spacing interval (0.02) */ 226/* float delta grid spacing interval (0.02) */
227 227
228 228
229{ 229{
230 spx_word16_t temp_xr,xl,xr,xm=0; 230 spx_word16_t temp_xr,xl,xr,xm=0;
231 spx_word32_t psuml,psumr,psumm,temp_psumr/*,temp_qsumr*/; 231 spx_word32_t psuml,psumr,psumm,temp_psumr/*,temp_qsumr*/;
232 int i,j,m,flag,k; 232 int i,j,m,flag,k;
233 VARDECL(spx_word32_t *Q); /* ptrs for memory allocation */ 233 VARDECL(spx_word32_t *Q); /* ptrs for memory allocation */
234 VARDECL(spx_word32_t *P); 234 VARDECL(spx_word32_t *P);
235 VARDECL(spx_word16_t *Q16); /* ptrs for memory allocation */ 235 VARDECL(spx_word16_t *Q16); /* ptrs for memory allocation */
236 VARDECL(spx_word16_t *P16); 236 VARDECL(spx_word16_t *P16);
237 spx_word32_t *px; /* ptrs of respective P'(z) & Q'(z) */ 237 spx_word32_t *px; /* ptrs of respective P'(z) & Q'(z) */
238 spx_word32_t *qx; 238 spx_word32_t *qx;
239 spx_word32_t *p; 239 spx_word32_t *p;
240 spx_word32_t *q; 240 spx_word32_t *q;
241 spx_word16_t *pt; /* ptr used for cheb_poly_eval() 241 spx_word16_t *pt; /* ptr used for cheb_poly_eval()
242 whether P' or Q' */ 242 whether P' or Q' */
243 int roots=0; /* DR 8/2/94: number of roots found */ 243 int roots=0; /* DR 8/2/94: number of roots found */
244 flag = 1; /* program is searching for a root when, 244 flag = 1; /* program is searching for a root when,
245 1 else has found one */ 245 1 else has found one */
246 m = lpcrdr/2; /* order of P'(z) & Q'(z) polynomials */ 246 m = lpcrdr/2; /* order of P'(z) & Q'(z) polynomials */
247 247
248 /* Allocate memory space for polynomials */ 248 /* Allocate memory space for polynomials */
249 ALLOC(Q, (m+1), spx_word32_t); 249 ALLOC(Q, (m+1), spx_word32_t);
@@ -252,7 +252,7 @@ int lpc_to_lsp (spx_coef_t *a,int lpcrdr,spx_lsp_t *freq,int nb,spx_word16_t del
252 /* determine P'(z)'s and Q'(z)'s coefficients where 252 /* determine P'(z)'s and Q'(z)'s coefficients where
253 P'(z) = P(z)/(1 + z^(-1)) and Q'(z) = Q(z)/(1-z^(-1)) */ 253 P'(z) = P(z)/(1 + z^(-1)) and Q'(z) = Q(z)/(1-z^(-1)) */
254 254
255 px = P; /* initialise ptrs */ 255 px = P; /* initialise ptrs */
256 qx = Q; 256 qx = Q;
257 p = px; 257 p = px;
258 q = qx; 258 q = qx;
@@ -297,7 +297,7 @@ int lpc_to_lsp (spx_coef_t *a,int lpcrdr,spx_lsp_t *freq,int nb,spx_word16_t del
297 } 297 }
298#endif 298#endif
299 299
300 px = P; /* re-initialise ptrs */ 300 px = P; /* re-initialise ptrs */
301 qx = Q; 301 qx = Q;
302 302
303 /* now that we have computed P and Q convert to 16 bits to 303 /* now that we have computed P and Q convert to 16 bits to
@@ -313,20 +313,20 @@ int lpc_to_lsp (spx_coef_t *a,int lpcrdr,spx_lsp_t *freq,int nb,spx_word16_t del
313 } 313 }
314 314
315 /* Search for a zero in P'(z) polynomial first and then alternate to Q'(z). 315 /* Search for a zero in P'(z) polynomial first and then alternate to Q'(z).
316 Keep alternating between the two polynomials as each zero is found */ 316 Keep alternating between the two polynomials as each zero is found */
317 317
318 xr = 0; /* initialise xr to zero */ 318 xr = 0; /* initialise xr to zero */
319 xl = FREQ_SCALE; /* start at point xl = 1 */ 319 xl = FREQ_SCALE; /* start at point xl = 1 */
320 320
321 for(j=0;j<lpcrdr;j++){ 321 for(j=0;j<lpcrdr;j++){
322 if(j&1) /* determines whether P' or Q' is eval. */ 322 if(j&1) /* determines whether P' or Q' is eval. */
323 pt = Q16; 323 pt = Q16;
324 else 324 else
325 pt = P16; 325 pt = P16;
326 326
327 psuml = cheb_poly_eva(pt,xl,m,stack); /* evals poly. at xl */ 327 psuml = cheb_poly_eva(pt,xl,m,stack); /* evals poly. at xl */
328 flag = 1; 328 flag = 1;
329 while(flag && (xr >= -FREQ_SCALE)){ 329 while(flag && (xr >= -FREQ_SCALE)){
330 spx_word16_t dd; 330 spx_word16_t dd;
331 /* Modified by JMV to provide smaller steps around x=+-1 */ 331 /* Modified by JMV to provide smaller steps around x=+-1 */
332#ifdef FIXED_POINT 332#ifdef FIXED_POINT
@@ -338,10 +338,10 @@ int lpc_to_lsp (spx_coef_t *a,int lpcrdr,spx_lsp_t *freq,int nb,spx_word16_t del
338 if (fabs(psuml)<.2) 338 if (fabs(psuml)<.2)
339 dd *= .5; 339 dd *= .5;
340#endif 340#endif
341 xr = SUB16(xl, dd); /* interval spacing */ 341 xr = SUB16(xl, dd); /* interval spacing */
342 psumr = cheb_poly_eva(pt,xr,m,stack);/* poly(xl-delta_x) */ 342 psumr = cheb_poly_eva(pt,xr,m,stack);/* poly(xl-delta_x) */
343 temp_psumr = psumr; 343 temp_psumr = psumr;
344 temp_xr = xr; 344 temp_xr = xr;
345 345
346 /* if no sign change increment xr and re-evaluate poly(xr). Repeat til 346 /* if no sign change increment xr and re-evaluate poly(xr). Repeat til
347 sign change. 347 sign change.
@@ -350,41 +350,41 @@ int lpc_to_lsp (spx_coef_t *a,int lpcrdr,spx_lsp_t *freq,int nb,spx_word16_t del
350 interval the zero lies in. 350 interval the zero lies in.
351 If there is no sign change between poly(xm) and poly(xl) set interval 351 If there is no sign change between poly(xm) and poly(xl) set interval
352 between xm and xr else set interval between xl and xr and repeat till 352 between xm and xr else set interval between xl and xr and repeat till
353 root is located within the specified limits */ 353 root is located within the specified limits */
354 354
355 if(SIGN_CHANGE(psumr,psuml)) 355 if(SIGN_CHANGE(psumr,psuml))
356 { 356 {
357 roots++; 357 roots++;
358 358
359 psumm=psuml; 359 psumm=psuml;
360 for(k=0;k<=nb;k++){ 360 for(k=0;k<=nb;k++){
361#ifdef FIXED_POINT 361#ifdef FIXED_POINT
362 xm = ADD16(PSHR16(xl,1),PSHR16(xr,1)); /* bisect the interval */ 362 xm = ADD16(PSHR16(xl,1),PSHR16(xr,1)); /* bisect the interval */
363#else 363#else
364 xm = .5*(xl+xr); /* bisect the interval */ 364 xm = .5*(xl+xr); /* bisect the interval */
365#endif 365#endif
366 psumm=cheb_poly_eva(pt,xm,m,stack); 366 psumm=cheb_poly_eva(pt,xm,m,stack);
367 /*if(psumm*psuml>0.)*/ 367 /*if(psumm*psuml>0.)*/
368 if(!SIGN_CHANGE(psumm,psuml)) 368 if(!SIGN_CHANGE(psumm,psuml))
369 { 369 {
370 psuml=psumm; 370 psuml=psumm;
371 xl=xm; 371 xl=xm;
372 } else { 372 } else {
373 psumr=psumm; 373 psumr=psumm;
374 xr=xm; 374 xr=xm;
375 } 375 }
376 } 376 }
377 377
378 /* once zero is found, reset initial interval to xr */ 378 /* once zero is found, reset initial interval to xr */
379 freq[j] = X2ANGLE(xm); 379 freq[j] = X2ANGLE(xm);
380 xl = xm; 380 xl = xm;
381 flag = 0; /* reset flag for next search */ 381 flag = 0; /* reset flag for next search */
382 } 382 }
383 else{ 383 else{
384 psuml=temp_psumr; 384 psuml=temp_psumr;
385 xl=temp_xr; 385 xl=temp_xr;
386 } 386 }
387 } 387 }
388 } 388 }
389 return(roots); 389 return(roots);
390} 390}
@@ -393,10 +393,10 @@ int lpc_to_lsp (spx_coef_t *a,int lpcrdr,spx_lsp_t *freq,int nb,spx_word16_t del
393 393
394/*---------------------------------------------------------------------------*\ 394/*---------------------------------------------------------------------------*\
395 395
396 FUNCTION....: lsp_to_lpc() 396 FUNCTION....: lsp_to_lpc()
397 397
398 AUTHOR......: David Rowe 398 AUTHOR......: David Rowe
399 DATE CREATED: 24/2/93 399 DATE CREATED: 24/2/93
400 400
401 Converts LSP coefficients to LPC coefficients. 401 Converts LSP coefficients to LPC coefficients.
402 402
@@ -405,9 +405,9 @@ int lpc_to_lsp (spx_coef_t *a,int lpcrdr,spx_lsp_t *freq,int nb,spx_word16_t del
405#ifdef FIXED_POINT 405#ifdef FIXED_POINT
406 406
407void lsp_to_lpc(spx_lsp_t *freq,spx_coef_t *ak,int lpcrdr, char *stack) 407void lsp_to_lpc(spx_lsp_t *freq,spx_coef_t *ak,int lpcrdr, char *stack)
408/* float *freq array of LSP frequencies in the x domain */ 408/* float *freq array of LSP frequencies in the x domain */
409/* float *ak array of LPC coefficients */ 409/* float *ak array of LPC coefficients */
410/* int lpcrdr order of LPC coefficients */ 410/* int lpcrdr order of LPC coefficients */
411{ 411{
412 (void)stack; 412 (void)stack;
413 int i,j; 413 int i,j;
@@ -488,10 +488,10 @@ void lsp_to_lpc(spx_lsp_t *freq,spx_coef_t *ak,int lpcrdr, char *stack)
488 for(i=1;i<m;i++) { 488 for(i=1;i<m;i++) {
489 489
490 for(j=1;j<2*(i+1)-1;j++) { 490 for(j=1;j<2*(i+1)-1;j++) {
491 mult = MULT16_32_Q14(freqn[2*i],xp[i][j+1]); 491 mult = MULT16_32_Q14(freqn[2*i],xp[i][j+1]);
492 xp[i+1][j+2] = ADD32(SUB32(xp[i][j+2], mult), xp[i][j]); 492 xp[i+1][j+2] = ADD32(SUB32(xp[i][j+2], mult), xp[i][j]);
493 mult = MULT16_32_Q14(freqn[2*i+1],xq[i][j+1]); 493 mult = MULT16_32_Q14(freqn[2*i+1],xq[i][j+1]);
494 xq[i+1][j+2] = ADD32(SUB32(xq[i][j+2], mult), xq[i][j]); 494 xq[i+1][j+2] = ADD32(SUB32(xq[i][j+2], mult), xq[i][j]);
495 } 495 }
496 496
497 /* for last col xp[i][j+2] = xq[i][j+2] = 0 */ 497 /* for last col xp[i][j+2] = xq[i][j+2] = 0 */
@@ -525,9 +525,9 @@ void lsp_to_lpc(spx_lsp_t *freq,spx_coef_t *ak,int lpcrdr, char *stack)
525#else 525#else
526 526
527void lsp_to_lpc(spx_lsp_t *freq,spx_coef_t *ak,int lpcrdr, char *stack) 527void lsp_to_lpc(spx_lsp_t *freq,spx_coef_t *ak,int lpcrdr, char *stack)
528/* float *freq array of LSP frequencies in the x domain */ 528/* float *freq array of LSP frequencies in the x domain */
529/* float *ak array of LPC coefficients */ 529/* float *ak array of LPC coefficients */
530/* int lpcrdr order of LPC coefficients */ 530/* int lpcrdr order of LPC coefficients */
531 531
532 532
533{ 533{
@@ -543,8 +543,8 @@ void lsp_to_lpc(spx_lsp_t *freq,spx_coef_t *ak,int lpcrdr, char *stack)
543 543
544 /* initialise contents of array */ 544 /* initialise contents of array */
545 545
546 for(i=0;i<=4*m+1;i++){ /* set contents of buffer to 0 */ 546 for(i=0;i<=4*m+1;i++){ /* set contents of buffer to 0 */
547 *pw++ = 0.0; 547 *pw++ = 0.0;
548 } 548 }
549 549
550 /* Set pointers up */ 550 /* Set pointers up */
@@ -563,29 +563,29 @@ void lsp_to_lpc(spx_lsp_t *freq,spx_coef_t *ak,int lpcrdr, char *stack)
563 563
564 for(j=0;j<=lpcrdr;j++){ 564 for(j=0;j<=lpcrdr;j++){
565 int i2=0; 565 int i2=0;
566 for(i=0;i<m;i++,i2+=2){ 566 for(i=0;i<m;i++,i2+=2){
567 n1 = pw+(i*4); 567 n1 = pw+(i*4);
568 n2 = n1 + 1; 568 n2 = n1 + 1;
569 n3 = n2 + 1; 569 n3 = n2 + 1;
570 n4 = n3 + 1; 570 n4 = n3 + 1;
571 xout1 = xin1 - 2.f*x_freq[i2] * *n1 + *n2; 571 xout1 = xin1 - 2.f*x_freq[i2] * *n1 + *n2;
572 xout2 = xin2 - 2.f*x_freq[i2+1] * *n3 + *n4; 572 xout2 = xin2 - 2.f*x_freq[i2+1] * *n3 + *n4;
573 *n2 = *n1; 573 *n2 = *n1;
574 *n4 = *n3; 574 *n4 = *n3;
575 *n1 = xin1; 575 *n1 = xin1;
576 *n3 = xin2; 576 *n3 = xin2;
577 xin1 = xout1; 577 xin1 = xout1;
578 xin2 = xout2; 578 xin2 = xout2;
579 } 579 }
580 xout1 = xin1 + *(n4+1); 580 xout1 = xin1 + *(n4+1);
581 xout2 = xin2 - *(n4+2); 581 xout2 = xin2 - *(n4+2);
582 if (j>0) 582 if (j>0)
583 ak[j-1] = (xout1 + xout2)*0.5f; 583 ak[j-1] = (xout1 + xout2)*0.5f;
584 *(n4+1) = xin1; 584 *(n4+1) = xin1;
585 *(n4+2) = xin2; 585 *(n4+2) = xin2;
586 586
587 xin1 = 0.0; 587 xin1 = 0.0;
588 xin2 = 0.0; 588 xin2 = 0.0;
589 } 589 }
590 590
591} 591}