123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- /*
- *****************************************************************************
- *
- * 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 : lsp_avg.c
- * Purpose: : LSP averaging and history
- *
- *****************************************************************************
- */
-
-
- /*
- *****************************************************************************
- * MODULE INCLUDE FILE AND VERSION ID
- *****************************************************************************
- */
- #include "lsp_avg.h"
- const char lsp_avg_id[] = "@(#)$Id $" lsp_avg_h;
-
- /*
- *****************************************************************************
- * INCLUDE FILES
- *****************************************************************************
- */
- #include <stdlib.h>
- #include <stdio.h>
- #include "basic_op.h"
- #include "oper_32b.h"
- #include "count.h"
- #include "q_plsf_5.tab"
- #include "copy.h"
- /*
- *****************************************************************************
- * LOCAL VARIABLES AND TABLES
- *****************************************************************************
- */
- /*
- *****************************************************************************
- * PUBLIC PROGRAM CODE
- *****************************************************************************
- */
- /*
- **************************************************************************
- *
- * Function : lsp_avg_init
- * Purpose : Allocates memory and initializes state variables
- *
- **************************************************************************
- */
- int lsp_avg_init (lsp_avgState **state)
- {
- lsp_avgState* s;
-
- if (state == (lsp_avgState **) NULL){
- wfprintf(stderr, "lsp_avg_init: invalid parameter\n");
- return -1;
- }
- *state = NULL;
-
- /* allocate memory */
- if ((s = (lsp_avgState *) wmalloc(sizeof(lsp_avgState))) == NULL){
- wfprintf(stderr, "lsp_avg_init: can not malloc state structure\n");
- return -1;
- }
- lsp_avg_reset(s);
- *state = s;
-
- return 0;
- }
-
- /*
- **************************************************************************
- *
- * Function : lsp_avg_reset
- * Purpose : Resets state memory
- *
- **************************************************************************
- */
- int lsp_avg_reset (lsp_avgState *st)
- {
- if (st == (lsp_avgState *) NULL){
- wfprintf(stderr, "lsp_avg_reset: invalid parameter\n");
- return -1;
- }
- Copy(mean_lsf, &st->lsp_meanSave[0], M);
-
- return 0;
- }
-
- /*
- **************************************************************************
- *
- * Function : lsp_avg_exit
- * Purpose : The memory used for state memory is freed
- *
- **************************************************************************
- */
- void lsp_avg_exit (lsp_avgState **state)
- {
- if (state == NULL || *state == NULL)
- return;
- /* deallocate memory */
- wfree(*state);
- *state = NULL;
-
- return;
- }
- /*
- **************************************************************************
- *
- * Function : lsp_avg
- * Purpose : Calculate the LSP averages
- *
- **************************************************************************
- */
- void lsp_avg (
- lsp_avgState *st, /* i/o : State struct Q15 */
- Word16 *lsp /* i : state of the state machine Q15 */
- )
- {
- Word16 i;
- Word32 L_tmp; /* Q31 */
- for (i = 0; i < M; i++) {
- /* mean = 0.84*mean */
- L_tmp = L_deposit_h_ex(st->lsp_meanSave[i]);
- L_tmp = L_msu_ex(L_tmp, EXPCONST, st->lsp_meanSave[i]);
- /* Add 0.16 of newest LSPs to mean */
- L_tmp = L_mac_ex(L_tmp, EXPCONST, lsp[i]);
- /* Save means */
- st->lsp_meanSave[i] = round_ex(L_tmp); move16(); /* Q15 */
- }
- return;
- }
|