Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 /****************************************************************************************
     19 Portions of this file are derived from the following 3GPP standard:
     20 
     21     3GPP TS 26.073
     22     ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
     23     Available from http://www.3gpp.org
     24 
     25 (C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
     26 Permission to distribute, modify and use this file under the standard license
     27 terms listed above has been obtained from the copyright holder.
     28 ****************************************************************************************/
     29 /*
     30 ------------------------------------------------------------------------------
     31 
     32 
     33 
     34  Pathname: ./audio/gsm-amr/c/src/lsp_avg.c
     35  Functions:
     36 
     37 
     38      Date: 04/14/2000
     39 
     40 ------------------------------------------------------------------------------
     41  REVISION HISTORY
     42 
     43  Description: Removed the functions lsp_avg_init and lsp_avg_exit.
     44  The lsp_avg related structure is no longer dynamically allocated.
     45 
     46  Also, placed code in the proper PV Software Template.
     47 
     48  Description: Per review comments, updated the inputs/outputs section
     49  for the function lsp_avg.
     50 
     51  Description: Changed to accept the pOverflow flag for EPOC compatibility.
     52 
     53  Description: Per review comments, I added a description of pOverflow
     54  to the input/output section of the template.  I also removed an unnecessary
     55  include file, <stdio.h>
     56 
     57  Description: Removed q_plsf_5.tab from Include section and added
     58               q_plsf_5_tbl.h to Include section. Changed "mean_lsf"
     59               to "mean_lsf_5" in lsp_avg_reset().
     60 
     61  Description:  Replaced OSCL mem type functions and eliminated include
     62                files that now are chosen by OSCL definitions
     63 
     64  Description:  Replaced "int" and/or "char" with OSCL defined types.
     65 
     66  Description: Changed round function name to pv_round to avoid conflict with
     67               round function in C standard library.
     68 
     69  Description:
     70 
     71 ------------------------------------------------------------------------------
     72  MODULE DESCRIPTION
     73 
     74     LSP averaging and history
     75 ------------------------------------------------------------------------------
     76 */
     77 
     78 /*----------------------------------------------------------------------------
     79 ; INCLUDES
     80 ----------------------------------------------------------------------------*/
     81 #include "lsp_avg.h"
     82 #include "basic_op.h"
     83 #include "oper_32b.h"
     84 #include "copy.h"
     85 #include "q_plsf_5_tbl.h"
     86 
     87 /*----------------------------------------------------------------------------
     88 ; MACROS
     89 ; Define module specific macros here
     90 ----------------------------------------------------------------------------*/
     91 
     92 /*----------------------------------------------------------------------------
     93 ; DEFINES
     94 ; Include all pre-processor statements here. Include conditional
     95 ; compile variables also.
     96 ----------------------------------------------------------------------------*/
     97 
     98 /*----------------------------------------------------------------------------
     99 ; LOCAL FUNCTION DEFINITIONS
    100 ; Function Prototype declaration
    101 ----------------------------------------------------------------------------*/
    102 
    103 /*----------------------------------------------------------------------------
    104 ; LOCAL VARIABLE DEFINITIONS
    105 ; Variable declaration - defined here and used outside this module
    106 ----------------------------------------------------------------------------*/
    107 
    108 /*----------------------------------------------------------------------------
    109 ; EXTERNAL FUNCTION REFERENCES
    110 ; Declare functions defined elsewhere and referenced in this module
    111 ----------------------------------------------------------------------------*/
    112 
    113 /*----------------------------------------------------------------------------
    114 ; EXTERNAL VARIABLES REFERENCES
    115 ; Declare variables used in this module but defined elsewhere
    116 ----------------------------------------------------------------------------*/
    117 
    118 /*
    119 ------------------------------------------------------------------------------
    120  FUNCTION NAME: lsp_avg_reset
    121 ------------------------------------------------------------------------------
    122  INPUT AND OUTPUT DEFINITIONS
    123 
    124  Inputs:
    125     st = pointer to structure of type lsp_avgState
    126 
    127  Outputs:
    128     fields of the structure pointed to by state are initialized.
    129 
    130  Returns:
    131     return_value = 0, if reset was successful; -1, otherwise (int)
    132 
    133  Global Variables Used:
    134     None
    135 
    136  Local Variables Needed:
    137     None
    138 
    139 ------------------------------------------------------------------------------
    140  FUNCTION DESCRIPTION
    141 
    142 
    143 ------------------------------------------------------------------------------
    144  REQUIREMENTS
    145 
    146  None
    147 
    148 ------------------------------------------------------------------------------
    149  REFERENCES
    150 
    151 lsp_avg.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
    152 
    153 ------------------------------------------------------------------------------
    154  PSEUDO-CODE
    155 
    156 int lsp_avg_reset (lsp_avgState *st)
    157 {
    158   if (st == (lsp_avgState *) NULL){
    159       // fprintf(stderr, "lsp_avg_reset: invalid parameter\n");
    160       return -1;
    161   }
    162 
    163   Copy(mean_lsf, &st->lsp_meanSave[0], M);
    164 
    165   return 0;
    166 }
    167 
    168 ------------------------------------------------------------------------------
    169  RESOURCES USED [optional]
    170 
    171  When the code is written for a specific target processor the
    172  the resources used should be documented below.
    173 
    174  HEAP MEMORY USED: x bytes
    175 
    176  STACK MEMORY USED: x bytes
    177 
    178  CLOCK CYCLES: (cycle count equation for this function) + (variable
    179                 used to represent cycle count for each subroutine
    180                 called)
    181      where: (cycle count variable) = cycle count for [subroutine
    182                                      name]
    183 
    184 ------------------------------------------------------------------------------
    185  CAUTION [optional]
    186  [State any special notes, constraints or cautions for users of this function]
    187 
    188 ------------------------------------------------------------------------------
    189 */
    190 
    191 Word16 lsp_avg_reset(lsp_avgState *st)
    192 {
    193     if (st == (lsp_avgState *) NULL)
    194     {
    195         /* fprintf(stderr, "lsp_avg_reset: invalid parameter\n"); */
    196         return -1;
    197     }
    198 
    199     Copy(mean_lsf_5, &st->lsp_meanSave[0], M);
    200 
    201     return 0;
    202 }
    203 
    204 
    205 /*
    206 ------------------------------------------------------------------------------
    207  FUNCTION NAME: lsp_avg
    208 ------------------------------------------------------------------------------
    209  INPUT AND OUTPUT DEFINITIONS
    210 
    211  Inputs:
    212     st  = pointer to structure of type lsp_avgState
    213     lsp = pointer to Word16, which reflects the state of the state machine
    214 
    215  Outputs:
    216     st = pointer to structure of type lsp_avgState
    217     pOverflow = pointer to type Flag -- overflow indicator
    218 
    219  Returns:
    220     None
    221 
    222  Global Variables Used:
    223     None
    224 
    225  Local Variables Needed:
    226     None
    227 
    228 ------------------------------------------------------------------------------
    229  FUNCTION DESCRIPTION
    230 
    231 
    232 ------------------------------------------------------------------------------
    233  REQUIREMENTS
    234 
    235  None
    236 
    237 ------------------------------------------------------------------------------
    238  REFERENCES
    239 
    240 lsp_avg.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
    241 
    242 ------------------------------------------------------------------------------
    243  PSEUDO-CODE
    244 
    245 
    246 void lsp_avg (
    247     lsp_avgState *st,         // i/o : State struct                 Q15
    248     Word16 *lsp               // i   : state of the state machine   Q15
    249 )
    250 {
    251     Word16 i;
    252     Word32 L_tmp;            // Q31
    253 
    254     for (i = 0; i < M; i++) {
    255 
    256        // mean = 0.84*mean
    257        L_tmp = L_deposit_h(st->lsp_meanSave[i]);
    258        L_tmp = L_msu(L_tmp, EXPCONST, st->lsp_meanSave[i]);
    259 
    260        // Add 0.16 of newest LSPs to mean
    261        L_tmp = L_mac(L_tmp, EXPCONST, lsp[i]);
    262 
    263        // Save means
    264        st->lsp_meanSave[i] = pv_round(L_tmp);   // Q15
    265     }
    266 
    267     return;
    268 }
    269 
    270 ------------------------------------------------------------------------------
    271  RESOURCES USED [optional]
    272 
    273  When the code is written for a specific target processor the
    274  the resources used should be documented below.
    275 
    276  HEAP MEMORY USED: x bytes
    277 
    278  STACK MEMORY USED: x bytes
    279 
    280  CLOCK CYCLES: (cycle count equation for this function) + (variable
    281                 used to represent cycle count for each subroutine
    282                 called)
    283      where: (cycle count variable) = cycle count for [subroutine
    284                                      name]
    285 
    286 ------------------------------------------------------------------------------
    287  CAUTION [optional]
    288  [State any special notes, constraints or cautions for users of this function]
    289 
    290 ------------------------------------------------------------------------------
    291 */
    292 
    293 void lsp_avg(
    294     lsp_avgState *st,         /* i/o : State struct                 Q15 */
    295     Word16 *lsp,              /* i   : state of the state machine   Q15 */
    296     Flag   *pOverflow         /* o   : Flag set when overflow occurs    */
    297 )
    298 {
    299     Word16 i;
    300     Word32 L_tmp;            /* Q31 */
    301 
    302     for (i = 0; i < M; i++)
    303     {
    304 
    305         /* mean = 0.84*mean */
    306         L_tmp = L_deposit_h(st->lsp_meanSave[i]);
    307         L_tmp = L_msu(L_tmp, EXPCONST, st->lsp_meanSave[i], pOverflow);
    308 
    309         /* Add 0.16 of newest LSPs to mean */
    310         L_tmp = L_mac(L_tmp, EXPCONST, lsp[i], pOverflow);
    311 
    312         /* Save means */
    313         st->lsp_meanSave[i] = pv_round(L_tmp, pOverflow);   /* Q15 */
    314     }
    315 
    316     return;
    317 }
    318