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 
32 
33 
34  Filename: /audio/gsm_amr/c/src/include/bgnscd.h
35 
36      Date: 12/29/2002
37 
38 ------------------------------------------------------------------------------
39  REVISION HISTORY
40 
41  Description: Moved _cplusplus #ifdef after Include section.
42 
43  Description:
44 
45 ------------------------------------------------------------------------------
46  INCLUDE DESCRIPTION
47 
48       File             : bgnscd.h
49       Purpose          : Background noise source charateristic detector (SCD)
50 
51 ------------------------------------------------------------------------------
52 */
53 
54 #ifndef _BGNSCD_H_
55 #define _BGNSCD_H_
56 
57 /*----------------------------------------------------------------------------
58 ; INCLUDES
59 ----------------------------------------------------------------------------*/
60 #include "typedef.h"
61 #include "cnst.h"
62 
63 /*--------------------------------------------------------------------------*/
64 #ifdef __cplusplus
65 extern "C"
66 {
67 #endif
68 
69     /*----------------------------------------------------------------------------
70     ; MACROS
71     ; [Define module specific macros here]
72     ----------------------------------------------------------------------------*/
73 
74     /*----------------------------------------------------------------------------
75     ; DEFINES
76     ; [Include all pre-processor statements here.]
77     ----------------------------------------------------------------------------*/
78 #define L_ENERGYHIST 60
79 #define INV_L_FRAME 102
80 
81 
82     /* 2*(160*x)^2 / 65536  where x is FLP values 150,5 and 50 */
83 #define FRAMEENERGYLIMIT  17578         /* 150 */
84 #define LOWERNOISELIMIT      20         /*   5 */
85 #define UPPERNOISELIMIT    1953         /*  50 */
86 
87 
88     /*----------------------------------------------------------------------------
89     ; EXTERNAL VARIABLES REFERENCES
90     ; [Declare variables used in this module but defined elsewhere]
91     ----------------------------------------------------------------------------*/
92 
93     /*----------------------------------------------------------------------------
94     ; SIMPLE TYPEDEF'S
95     ----------------------------------------------------------------------------*/
96 
97     /*----------------------------------------------------------------------------
98     ; ENUMERATED TYPEDEF'S
99     ----------------------------------------------------------------------------*/
100 
101     /*----------------------------------------------------------------------------
102     ; STRUCTURES TYPEDEF'S
103     ----------------------------------------------------------------------------*/
104     typedef struct
105     {
106         /* history vector of past synthesis speech energy */
107         Word16 frameEnergyHist[L_ENERGYHIST];
108 
109         /* state flags */
110         Word16 bgHangover; /* counter; number of frames after last speech frame */
111 
112     } Bgn_scdState;
113 
114     /*----------------------------------------------------------------------------
115     ; GLOBAL FUNCTION DEFINITIONS
116     ; [List function prototypes here]
117     ----------------------------------------------------------------------------*/
118     /*
119      *  Function    : Bgn_scd_init
120      *  Purpose     : Allocates initializes state memory
121      *  Description : Stores pointer to filter status struct in *st. This
122      *                pointer has to be passed to Bgn_scd in each call.
123      *  Returns     : 0 on success
124      */
125     Word16 Bgn_scd_init(Bgn_scdState **st);
126 
127     /*
128      *  Function    : Bgn_scd_reset
129      *  Purpose     : Resets state memory
130      *  Returns     : 0 on success
131      */
132     Word16 Bgn_scd_reset(Bgn_scdState *st);
133 
134     /*
135      *  Function    : Bgn_scd_exit
136      *  Purpose     : The memory used for state memory is freed
137      *  Description : Stores NULL in *s
138      *  Returns     : void
139      */
140     void Bgn_scd_exit(Bgn_scdState **st);
141 
142     /*
143      *  Function    : Bgn_scd
144      *  Purpose     : Charaterice synthesis speech and detect background noise
145      *  Returns     : background noise decision; 0 = bgn, 1 = no bgn
146      */
147     Word16 Bgn_scd(Bgn_scdState *st,       /* i : State variables for bgn SCD         */
148                    Word16 ltpGainHist[],  /* i : LTP gain history                    */
149                    Word16 speech[],       /* o : synthesis speech frame              */
150                    Word16 *voicedHangover,/* o : # of frames after last voiced frame */
151                    Flag   *pOverflow
152                   );
153 
154 
155 #ifdef __cplusplus
156 }
157 #endif
158 
159 #endif  /* _BGNSCD_H_ */
160