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