123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- /*
- ********************************************************************************
- *
- * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
- * R99 Version 3.3.0
- * REL-4 Version 4.1.0
- *
- ********************************************************************************
- *
- * File : autocorr.c
- *
- ********************************************************************************
- */
- /*
- ********************************************************************************
- * MODULE INCLUDE FILE AND VERSION ID
- ********************************************************************************
- */
- #include "autocorr.h"
- const char autocorr_id[] = "@(#)$Id $" autocorr_h;
-
- /*
- ********************************************************************************
- * INCLUDE FILES
- ********************************************************************************
- */
- #include "typedef.h"
- #include "basic_op.h"
- #include "oper_32b.h"
- #include "count.h"
- #include "cnst.h"
- /*
- ********************************************************************************
- * LOCAL VARIABLES AND TABLES
- ********************************************************************************
- */
-
- /*
- ********************************************************************************
- * PUBLIC PROGRAM CODE
- ********************************************************************************
- */
- /*
- **************************************************************************
- *
- * Function : autocorr
- * Purpose : Compute autocorrelations of signal with windowing
- *
- **************************************************************************
- */
- Word16 Autocorr (
- Word16 x[], /* (i) : Input signal (L_WINDOW) */
- Word16 m, /* (i) : LPC order */
- Word16 r_h[], /* (o) : Autocorrelations (msb) */
- Word16 r_l[], /* (o) : Autocorrelations (lsb) */
- const Word16 wind[] /* (i) : window for LPC analysis (L_WINDOW) */
- )
- {
- Word16 i, j, norm;
- Word16 y[L_WINDOW];
- Word32 sum;
- Word16 overfl, overfl_shft;
- /* Windowing of signal */
- for (i = 0; i < L_WINDOW; i++)
- {
- y[i] = mult_r_ex (x[i], wind[i]); move16 ();
- }
- /* Compute r[0] and test for overflow */
- overfl_shft = 0; move16 ();
- do
- {
- overfl = 0; move16 ();
- sum = 0L; move32 ();
- for (i = 0; i < L_WINDOW; i++)
- {
- sum = L_mac_ex (sum, y[i], y[i]);
- }
- /* If overflow divide y[] by 4 */
- test ();
- if (L_sub_ex (sum, MAX_32) == 0L)
- {
- overfl_shft = add_ex (overfl_shft, 4);
- overfl = 1; move16 (); /* Set the overflow flag */
- for (i = 0; i < L_WINDOW; i++)
- {
- y[i] = shr_ex (y[i], 2); move16 ();
- }
- }
- test ();
- }
- while (overfl != 0);
- sum = L_add_ex (sum, 1L); /* Avoid the case of all zeros */
- /* Normalization of r[0] */
- norm = norm_l_ex (sum);
- sum = L_shl_ex (sum, norm);
- L_Extract (sum, &r_h[0], &r_l[0]); /* Put in DPF format (see oper_32b) */
- /* r[1] to r[m] */
- for (i = 1; i <= m; i++)
- {
- sum = 0; move32 ();
- for (j = 0; j < L_WINDOW - i; j++)
- {
- sum = L_mac_ex (sum, y[j], y[j + i]);
- }
- sum = L_shl_ex (sum, norm);
- L_Extract (sum, &r_h[i], &r_l[i]);
- }
- norm = sub_ex (norm, overfl_shft);
- return norm;
- }
|