1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23 Available from http://www.3gpp.org
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 ****************************************************************************************/
32 ------------------------------------------------------------------------------
35 This file contains all the constant definitions, prototype and structure
36 definitions needed by vad_2.c
38 ------------------------------------------------------------------------------
41 /*----------------------------------------------------------------------------
42 ; CONTINUE ONLY IF NOT ALREADY DEFINED
43 ----------------------------------------------------------------------------*/
45 #define vad_2_h "$Id $"
47 /*----------------------------------------------------------------------------
49 ----------------------------------------------------------------------------*/
52 /*--------------------------------------------------------------------------*/
58 /*----------------------------------------------------------------------------
60 ; Define module specific macros here
61 ----------------------------------------------------------------------------*/
63 /*----------------------------------------------------------------------------
65 ; Include all pre-processor statements here.
66 ----------------------------------------------------------------------------*/
83 #define UPDATE_THLD 35
84 #define HYSTER_CNT_THLD 6
85 #define UPDATE_CNT_THLD 50
87 #define SHIFT_STATE_0 0 /* channel energy scaled as 22,9 */
88 #define SHIFT_STATE_1 1 /* channel energy scaled as 27,4 */
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() */
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() */
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 */
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 */
110 #define PRE_EMP_FAC (-26214) /* -0.8 scaled as 0,15 */
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 */
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 */
118 #define FFT_HEADROOM 2
119 /*----------------------------------------------------------------------------
120 ; EXTERNAL VARIABLES REFERENCES
121 ; Declare variables used in this module but defined elsewhere
122 ----------------------------------------------------------------------------*/
124 /*----------------------------------------------------------------------------
126 ----------------------------------------------------------------------------*/
128 /*----------------------------------------------------------------------------
129 ; ENUMERATED TYPEDEF'S
130 ----------------------------------------------------------------------------*/
132 /*----------------------------------------------------------------------------
133 ; STRUCTURES TYPEDEF'S
134 ----------------------------------------------------------------------------*/
141 Word16 last_update_cnt;
142 Word16 ch_enrg_long_db[NUM_CHAN]; /* scaled as 7,8 */
145 Word32 Lch_enrg[NUM_CHAN]; /* scaled as 22,9 or 27,4 */
146 Word32 Lch_noise[NUM_CHAN]; /* scaled as 22,9 */
148 Word16 last_normb_shift; /* last block norm shift count */
150 Word16 tsnr; /* total signal-to-noise ratio in dB (scaled as 7,8) */
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) */
157 Word16 shift_state; /* use 22,9 or 27,4 scaling for ch_enrg[] */
161 Flag LTP_flag; /* Use to indicate the the LTP gain is > LTP_THRESH */
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);
173 void r_fft(Word16 *farray_ptr, Flag *pOverflow);
175 void LTP_flag_update(vadState2 *st, Word16 mode, Flag *pOverflow);
177 /*----------------------------------------------------------------------------
179 ----------------------------------------------------------------------------*/
184 #endif /* _VAD2_H_ */