Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / enc / src / vad1.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
31  Filename: vad1.h
32
33 ------------------------------------------------------------------------------
34  INCLUDE DESCRIPTION
35
36  This file contains all the constant definitions, prototype and structure
37  definitions needed by vad_1.c
38
39 ------------------------------------------------------------------------------
40 */
41
42 /*----------------------------------------------------------------------------
43 ; CONTINUE ONLY IF NOT ALREADY DEFINED
44 ----------------------------------------------------------------------------*/
45 #ifndef vad_1_h
46 #define vad_1_h "$Id $"
47
48 /*----------------------------------------------------------------------------
49 ; INCLUDES
50 ----------------------------------------------------------------------------*/
51 #include "typedef.h"
52 #include "cnst_vad.h"
53
54 /*--------------------------------------------------------------------------*/
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #endif
59
60     /*----------------------------------------------------------------------------
61     ; MACROS
62     ; Define module specific macros here
63     ----------------------------------------------------------------------------*/
64
65     /*----------------------------------------------------------------------------
66     ; DEFINES
67     ; Include all pre-processor statements here.
68     ----------------------------------------------------------------------------*/
69
70     /*----------------------------------------------------------------------------
71     ; EXTERNAL VARIABLES REFERENCES
72     ; Declare variables used in this module but defined elsewhere
73     ----------------------------------------------------------------------------*/
74
75     /*----------------------------------------------------------------------------
76     ; SIMPLE TYPEDEF'S
77     ----------------------------------------------------------------------------*/
78
79     /*----------------------------------------------------------------------------
80     ; ENUMERATED TYPEDEF'S
81     ----------------------------------------------------------------------------*/
82
83     /*----------------------------------------------------------------------------
84     ; STRUCTURES TYPEDEF'S
85     ----------------------------------------------------------------------------*/
86     /* state variable */
87     typedef struct
88     {
89
90         Word16 bckr_est[COMPLEN];    /* background noise estimate                */
91         Word16 ave_level[COMPLEN];   /* averaged input components for stationary */
92         /*    estimation                            */
93         Word16 old_level[COMPLEN];   /* input levels of the previous frame       */
94         Word16 sub_level[COMPLEN];   /* input levels calculated at the end of
95                                       a frame (lookahead)                   */
96         Word16 a_data5[3][2];        /* memory for the filter bank               */
97         Word16 a_data3[5];           /* memory for the filter bank               */
98
99         Word16 burst_count;          /* counts length of a speech burst          */
100         Word16 hang_count;           /* hangover counter                         */
101         Word16 stat_count;           /* stationary counter                       */
102
103         /* Note that each of the following three variables (vadreg, pitch and tone)
104            holds 15 flags. Each flag reserves 1 bit of the variable. The newest
105            flag is in the bit 15 (assuming that LSB is bit 1 and MSB is bit 16). */
106         Word16 vadreg;               /* flags for intermediate VAD decisions     */
107         Word16 pitch;                /* flags for pitch detection                */
108         Word16 tone;                 /* flags for tone detection                 */
109         Word16 complex_high;         /* flags for complex detection              */
110         Word16 complex_low;          /* flags for complex detection              */
111
112         Word16 oldlag_count, oldlag; /* variables for pitch detection            */
113
114         Word16 complex_hang_count;   /* complex hangover counter, used by VAD    */
115         Word16 complex_hang_timer;   /* hangover initiator, used by CAD          */
116
117         Word16 best_corr_hp;         /* FIP filtered value Q15                   */
118
119         Word16 speech_vad_decision;  /* final decision                           */
120         Word16 complex_warning;      /* complex background warning               */
121
122         Word16 sp_burst_count;       /* counts length of a speech burst incl     */
123         Word16 corr_hp_fast;         /* filtered value                           */
124     } vadState1;
125     /*----------------------------------------------------------------------------
126     ; GLOBAL FUNCTION DEFINITIONS
127     ; Function Prototype declaration
128     ----------------------------------------------------------------------------*/
129     Word16 vad1_init(vadState1 **st);
130     /* initialize one instance of the pre processing state.
131        Stores pointer to filter status struct in *st. This pointer has to
132        be passed to vad in each call.
133        returns 0 on success
134      */
135
136     Word16 vad1_reset(vadState1 *st);
137     /* reset of pre processing state (i.e. set state memory to zero)
138        returns 0 on success
139      */
140
141     void vad1_exit(vadState1 **st);
142     /* de-initialize pre processing state (i.e. free status struct)
143        stores NULL in *st
144      */
145
146     void vad_complex_detection_update(vadState1 *st,       /* i/o : State struct     */
147                                       Word16 best_corr_hp /* i   : best Corr Q15    */
148                                      );
149
150     void vad_tone_detection(vadState1 *st,  /* i/o : State struct            */
151                             Word32 t0,     /* i   : autocorrelation maxima  */
152                             Word32 t1,     /* i   : energy                  */
153                             Flag   *pOverflow
154                            );
155
156     void vad_tone_detection_update(
157         vadState1 *st,             /* i/o : State struct              */
158         Word16 one_lag_per_frame,  /* i   : 1 if one open-loop lag is
159                                               calculated per each frame,
160                                               otherwise 0                     */
161         Flag *pOverflow
162     );
163
164     void vad_pitch_detection(vadState1 *st,   /* i/o : State struct                  */
165                              Word16 lags[],  /* i   : speech encoder open loop lags */
166                              Flag   *pOverflow
167                             );
168
169     Word16 vad1(vadState1 *st,   /* i/o : State struct                      */
170                 Word16 in_buf[], /* i   : samples of the input frame
171                                 inbuf[159] is the very last sample,
172                                 incl lookahead                          */
173                 Flag *pOverflow
174                );
175
176     /*----------------------------------------------------------------------------
177     ; END
178     ----------------------------------------------------------------------------*/
179 #ifdef __cplusplus
180 }
181 #endif
182
183 #endif /* _VAD1_H_ */
184
185