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/****************************************************************************************
19Portions 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)
26Permission to distribute, modify and use this file under the standard license
27terms listed above has been obtained from the copyright holder.
28****************************************************************************************/
29/*
30********************************************************************************
31**-------------------------------------------------------------------------**
32**                                                                         **
33**     GSM AMR-NB speech codec   R98   Version 7.5.0   March 2, 2001       **
34**                               R99   Version 3.2.0                       **
35**                               REL-4 Version 4.0.0                       **
36**                                                                         **
37**-------------------------------------------------------------------------**
38********************************************************************************
39*
40*      File             : cnst_vad.h
41*      Purpose          : Constants and definitions for VAD
42*
43********************************************************************************
44*/
45#ifndef cnst_vad_h
46#define cnst_vad_h "$Id $"
47
48#define FRAME_LEN 160    /* Length (samples) of the input frame          */
49#define COMPLEN 9        /* Number of sub-bands used by VAD              */
50#define INV_COMPLEN 3641 /* 1.0/COMPLEN*2^15                             */
51#define LOOKAHEAD 40     /* length of the lookahead used by speech coder */
52
53#define UNITY 512        /* Scaling used with SNR calculation            */
54#define UNIRSHFT 6       /* = log2(MAX_16/UNITY)                         */
55
56#define TONE_THR (Word16)(0.65*MAX_16) /* Threshold for tone detection   */
57
58/* Constants for background spectrum update */
59#define ALPHA_UP1   (Word16)((1.0 - 0.95)*MAX_16)  /* Normal update, upwards:   */
60#define ALPHA_DOWN1 (Word16)((1.0 - 0.936)*MAX_16) /* Normal update, downwards  */
61#define ALPHA_UP2   (Word16)((1.0 - 0.985)*MAX_16) /* Forced update, upwards    */
62#define ALPHA_DOWN2 (Word16)((1.0 - 0.943)*MAX_16) /* Forced update, downwards  */
63#define ALPHA3      (Word16)((1.0 - 0.95)*MAX_16)  /* Update downwards          */
64#define ALPHA4      (Word16)((1.0 - 0.9)*MAX_16)   /* For stationary estimation */
65#define ALPHA5      (Word16)((1.0 - 0.5)*MAX_16)   /* For stationary estimation */
66
67/* Constants for VAD threshold */
68#define VAD_THR_HIGH 1260 /* Highest threshold                 */
69#define VAD_THR_LOW  720  /* Lowest threshold                  */
70#define VAD_P1 0          /* Noise level for highest threshold */
71#define VAD_P2 6300       /* Noise level for lowest threshold  */
72#define VAD_SLOPE (Word16)(MAX_16*(float)(VAD_THR_LOW-VAD_THR_HIGH)/(float)(VAD_P2-VAD_P1))
73
74/* Parameters for background spectrum recovery function */
75#define STAT_COUNT 20         /* threshold of stationary detection counter         */
76#define STAT_COUNT_BY_2 10    /* threshold of stationary detection counter         */
77#define CAD_MIN_STAT_COUNT 5  /* threshold of stationary detection counter         */
78
79#define STAT_THR_LEVEL 184    /* Threshold level for stationarity detection        */
80#define STAT_THR 1000         /* Threshold for stationarity detection              */
81
82/* Limits for background noise estimate */
83#define NOISE_MIN 40          /* minimum */
84#define NOISE_MAX 16000       /* maximum */
85#define NOISE_INIT 150        /* initial */
86
87/* Constants for VAD hangover addition */
88#define HANG_NOISE_THR 100
89#define BURST_LEN_HIGH_NOISE 4
90#define HANG_LEN_HIGH_NOISE 7
91#define BURST_LEN_LOW_NOISE 5
92#define HANG_LEN_LOW_NOISE 4
93
94/* Thresholds for signal power */
95#define VAD_POW_LOW (Word32)15000     /* If input power is lower,                    */
96/*     VAD is set to 0                         */
97#define POW_PITCH_THR (Word32)343040  /* If input power is lower, pitch              */
98/*     detection is ignored                    */
99
100#define POW_COMPLEX_THR (Word32)15000 /* If input power is lower, complex            */
101/* flags  value for previous frame  is un-set  */
102
103
104/* Constants for the filter bank */
105#define LEVEL_SHIFT 0      /* scaling                                  */
106#define COEFF3   13363     /* coefficient for the 3rd order filter     */
107#define COEFF5_1 21955     /* 1st coefficient the for 5th order filter */
108#define COEFF5_2 6390      /* 2nd coefficient the for 5th order filter */
109
110/* Constants for pitch detection */
111#define LTHRESH 4
112#define NTHRESH 4
113
114/* Constants for complex signal VAD  */
115#define CVAD_THRESH_ADAPT_HIGH  (Word16)(0.6 * MAX_16) /* threshold for adapt stopping high    */
116#define CVAD_THRESH_ADAPT_LOW  (Word16)(0.5 * MAX_16)  /* threshold for adapt stopping low     */
117#define CVAD_THRESH_IN_NOISE  (Word16)(0.65 * MAX_16)  /* threshold going into speech on       */
118/* a short term basis                   */
119
120#define CVAD_THRESH_HANG  (Word16)(0.70 * MAX_16)      /* threshold                            */
121#define CVAD_HANG_LIMIT  (Word16)(100)                 /* 2 second estimation time             */
122#define CVAD_HANG_LENGTH  (Word16)(250)                /* 5 second hangover                    */
123
124#define CVAD_LOWPOW_RESET (Word16) (0.40 * MAX_16)     /* init in low power segment            */
125#define CVAD_MIN_CORR (Word16) (0.40 * MAX_16)         /* lowest adaptation value              */
126
127#define CVAD_BURST 20                                  /* speech burst length for speech reset */
128#define CVAD_ADAPT_SLOW (Word16)(( 1.0 - 0.98) * MAX_16)        /* threshold for slow adaption */
129#define CVAD_ADAPT_FAST (Word16)((1.0 - 0.92) * MAX_16)         /* threshold for fast adaption */
130#define CVAD_ADAPT_REALLY_FAST (Word16)((1.0 - 0.80) * MAX_16)  /* threshold for really fast   */
131/* adaption                    */
132
133#endif
134