Home | History | Annotate | Download | only in include
      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  Filename: /audio/gsm_amr/c/include/vad2.h
     31 
     32 ------------------------------------------------------------------------------
     33  REVISION HISTORY
     34 
     35  Description: Placed header file in the proper template format.  Added
     36  parameter pOverflow for the basic math ops.
     37 
     38  Description: Added pOverflow to the r_fft function prototype.
     39 
     40  Description: Added pOverflow to the LTP_flag_update prototype.
     41 
     42  Description:  Replaced "int" and/or "char" with OSCL defined types.
     43 
     44  Description: Moved _cplusplus #ifdef after Include section.
     45 
     46  Who:                       Date:
     47  Description:
     48 
     49 ------------------------------------------------------------------------------
     50  INCLUDE DESCRIPTION
     51 
     52  This file contains all the constant definitions, prototype and structure
     53  definitions needed by vad_2.c
     54 
     55 ------------------------------------------------------------------------------
     56 */
     57 
     58 /*----------------------------------------------------------------------------
     59 ; CONTINUE ONLY IF NOT ALREADY DEFINED
     60 ----------------------------------------------------------------------------*/
     61 #ifndef vad_2_h
     62 #define vad_2_h "$Id $"
     63 
     64 /*----------------------------------------------------------------------------
     65 ; INCLUDES
     66 ----------------------------------------------------------------------------*/
     67 #include "typedef.h"
     68 
     69 /*--------------------------------------------------------------------------*/
     70 #ifdef __cplusplus
     71 extern "C"
     72 {
     73 #endif
     74 
     75     /*----------------------------------------------------------------------------
     76     ; MACROS
     77     ; Define module specific macros here
     78     ----------------------------------------------------------------------------*/
     79 
     80     /*----------------------------------------------------------------------------
     81     ; DEFINES
     82     ; Include all pre-processor statements here.
     83     ----------------------------------------------------------------------------*/
     84 
     85 #define     YES     1
     86 #define     NO      0
     87 #define     ON      1
     88 #define     OFF     0
     89 #define     TRUE        1
     90 #define     FALSE       0
     91 
     92 #define     FRM_LEN                 80
     93 #define     DELAY                   24
     94 #define     FFT_LEN                 128
     95 
     96 #define     NUM_CHAN                16
     97 #define     LO_CHAN                 0
     98 #define     HI_CHAN                 15
     99 
    100 #define     UPDATE_THLD             35
    101 #define     HYSTER_CNT_THLD         6
    102 #define     UPDATE_CNT_THLD         50
    103 
    104 #define     SHIFT_STATE_0       0       /* channel energy scaled as 22,9 */
    105 #define     SHIFT_STATE_1       1       /* channel energy scaled as 27,4 */
    106 
    107 #define     NOISE_FLOOR_CHAN_0  512     /* 1.0    scaled as 22,9 */
    108 #define     MIN_CHAN_ENRG_0     32      /* 0.0625 scaled as 22,9 */
    109 #define     MIN_NOISE_ENRG_0    32      /* 0.0625 scaled as 22,9 */
    110 #define     INE_NOISE_0     8192        /* 16.0   scaled as 22,9 */
    111 #define     FRACTIONAL_BITS_0   9       /* used as input to fn10Log10() */
    112 
    113 #define     NOISE_FLOOR_CHAN_1  16      /* 1.0    scaled as 27,4 */
    114 #define     MIN_CHAN_ENRG_1     1       /* 0.0625 scaled as 27,4 */
    115 #define     MIN_NOISE_ENRG_1    1       /* 0.0625 scaled as 27,4 */
    116 #define     INE_NOISE_1     256     /* 16.0   scaled as 27,4 */
    117 #define     FRACTIONAL_BITS_1   4       /* used as input to fn10Log10() */
    118 
    119 #define     STATE_1_TO_0_SHIFT_R    (FRACTIONAL_BITS_1-FRACTIONAL_BITS_0)   /* state correction factor */
    120 #define     STATE_0_TO_1_SHIFT_R    (FRACTIONAL_BITS_0-FRACTIONAL_BITS_1)   /* state correction factor */
    121 
    122 #define         HIGH_ALPHA              29491       /* 0.9 scaled as 0,15 */
    123 #define         LOW_ALPHA               22938       /* 0.7 scaled as 0,15 */
    124 #define         ALPHA_RANGE             (HIGH_ALPHA - LOW_ALPHA)
    125 #define         DEV_THLD                7168        /* 28.0 scaled as 7,8 */
    126 
    127 #define         PRE_EMP_FAC             (-26214)    /* -0.8 scaled as 0,15 */
    128 
    129 #define         CEE_SM_FAC              18022       /* 0.55 scaled as 0,15 */
    130 #define         ONE_MINUS_CEE_SM_FAC    14746       /* 0.45 scaled as 0,15 */
    131 
    132 #define         CNE_SM_FAC              3277        /* 0.1 scaled as 0,15 */
    133 #define         ONE_MINUS_CNE_SM_FAC    29491       /* 0.9 scaled as 0,15 */
    134 
    135 #define         FFT_HEADROOM            2
    136     /*----------------------------------------------------------------------------
    137     ; EXTERNAL VARIABLES REFERENCES
    138     ; Declare variables used in this module but defined elsewhere
    139     ----------------------------------------------------------------------------*/
    140 
    141     /*----------------------------------------------------------------------------
    142     ; SIMPLE TYPEDEF'S
    143     ----------------------------------------------------------------------------*/
    144 
    145     /*----------------------------------------------------------------------------
    146     ; ENUMERATED TYPEDEF'S
    147     ----------------------------------------------------------------------------*/
    148 
    149     /*----------------------------------------------------------------------------
    150     ; STRUCTURES TYPEDEF'S
    151     ----------------------------------------------------------------------------*/
    152 
    153     typedef struct
    154     {
    155         Word16 pre_emp_mem;
    156         Word16 update_cnt;
    157         Word16 hyster_cnt;
    158         Word16 last_update_cnt;
    159         Word16 ch_enrg_long_db[NUM_CHAN];   /* scaled as 7,8  */
    160 
    161         Word32 Lframe_cnt;
    162         Word32 Lch_enrg[NUM_CHAN];  /* scaled as 22,9 or 27,4 */
    163         Word32 Lch_noise[NUM_CHAN]; /* scaled as 22,9 */
    164 
    165         Word16 last_normb_shift;    /* last block norm shift count */
    166 
    167         Word16 tsnr;            /* total signal-to-noise ratio in dB (scaled as 7,8) */
    168         Word16 hangover;
    169         Word16 burstcount;
    170         Word16 fupdate_flag;        /* forced update flag from previous frame */
    171         Word16 negSNRvar;       /* Negative SNR variance (scaled as 7,8) */
    172         Word16 negSNRbias;      /* sensitivity bias from negative SNR variance (scaled as 15,0) */
    173 
    174         Word16 shift_state;     /* use 22,9 or 27,4 scaling for ch_enrg[] */
    175 
    176         Word32 L_R0;
    177         Word32 L_Rmax;
    178         Flag   LTP_flag;        /* Use to indicate the the LTP gain is > LTP_THRESH */
    179 
    180     } vadState2;
    181     /*----------------------------------------------------------------------------
    182     ; GLOBAL FUNCTION DEFINITIONS
    183     ; Function Prototype declaration
    184     ----------------------------------------------------------------------------*/
    185     Word16  vad2(Word16 *farray_ptr, vadState2 *st, Flag *pOverflow);
    186     Word16 vad2_init(vadState2 **st);
    187     Word16 vad2_reset(vadState2 *st);
    188     void    vad2_exit(vadState2 **state);
    189 
    190     void    r_fft(Word16 *farray_ptr, Flag *pOverflow);
    191 
    192     void    LTP_flag_update(vadState2 *st, Word16 mode, Flag *pOverflow);
    193 
    194     /*----------------------------------------------------------------------------
    195     ; END
    196     ----------------------------------------------------------------------------*/
    197 #ifdef __cplusplus
    198 }
    199 #endif
    200 
    201 #endif /* _VAD2_H_ */
    202 
    203 
    204