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
34 Filename: /audio/gsm_amr/c/include/dtx_dec.h
35
36     Date: 02/06/2002
37
38------------------------------------------------------------------------------
39 REVISION HISTORY
40
41 Description:  Replaced "int" and/or "char" with OSCL defined types.
42
43 Description: Moved _cplusplus #ifdef after Include section.
44
45 Description:
46
47------------------------------------------------------------------------------
48 INCLUDE DESCRIPTION
49
50    File             : dtx_dec.h
51    Purpose          : Decode comfort noice when in DTX
52
53------------------------------------------------------------------------------
54*/
55
56/*----------------------------------------------------------------------------
57; CONTINUE ONLY IF NOT ALREADY DEFINED
58----------------------------------------------------------------------------*/
59#ifndef DTX_DEC_H
60#define DTX_DEC_H
61#define dtx_dec_h "$Id $"
62
63/*----------------------------------------------------------------------------
64; INCLUDES
65----------------------------------------------------------------------------*/
66#include "typedef.h"
67#include "d_plsf.h"
68#include "gc_pred.h"
69#include "c_g_aver.h"
70#include "frame.h"
71#include "dtx_common_def.h"
72/*--------------------------------------------------------------------------*/
73#ifdef __cplusplus
74extern "C"
75{
76#endif
77
78    /*----------------------------------------------------------------------------
79    ; MACROS
80    ; Define module specific macros here
81    ----------------------------------------------------------------------------*/
82
83    /*----------------------------------------------------------------------------
84    ; DEFINES
85    ; Include all pre-processor statements here.
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    /*----------------------------------------------------------------------------
99    ; ENUMERATED TYPEDEF'S
100    ----------------------------------------------------------------------------*/
101    enum DTXStateType {SPEECH = 0, DTX, DTX_MUTE};
102
103    /*----------------------------------------------------------------------------
104    ; STRUCTURES TYPEDEF'S
105    ----------------------------------------------------------------------------*/
106    typedef struct
107    {
108        Word16 since_last_sid;
109        Word16 true_sid_period_inv;
110        Word16 log_en;
111        Word16 old_log_en;
112        Word32 L_pn_seed_rx;
113        Word16 lsp[M];
114        Word16 lsp_old[M];
115
116        Word16 lsf_hist[M*DTX_HIST_SIZE];
117        Word16 lsf_hist_ptr;
118        Word16 lsf_hist_mean[M*DTX_HIST_SIZE];
119        Word16 log_pg_mean;
120        Word16 log_en_hist[DTX_HIST_SIZE];
121        Word16 log_en_hist_ptr;
122
123        Word16 log_en_adjust;
124
125        Word16 dtxHangoverCount;
126        Word16 decAnaElapsedCount;
127
128        Word16 sid_frame;
129        Word16 valid_data;
130        Word16 dtxHangoverAdded;
131
132        enum DTXStateType dtxGlobalState;     /* contains previous state */
133        /* updated in main decoder */
134
135        Word16 data_updated;      /* marker to know if CNI data is ever renewed */
136
137    } dtx_decState;
138
139    /*----------------------------------------------------------------------------
140    ; GLOBAL FUNCTION DEFINITIONS
141    ; Function Prototype declaration
142    ----------------------------------------------------------------------------*/
143
144    /*
145     *  Function    : dtx_dec_reset
146     *  Purpose     : Resets state memory
147     *  Returns     : 0 on success
148     */
149    Word16 dtx_dec_reset(dtx_decState *st);
150
151    /*
152     *  Function    : dtx_dec
153     *  Purpose     :
154     *  Description :
155     */
156    void dtx_dec(
157        dtx_decState *st,                /* i/o : State struct                    */
158        Word16 mem_syn[],                /* i/o : AMR decoder state               */
159        D_plsfState* lsfState,           /* i/o : decoder lsf states              */
160        gc_predState* predState,         /* i/o : prediction states               */
161        Cb_gain_averageState* averState, /* i/o : CB gain average states          */
162        enum DTXStateType new_state,     /* i   : new DTX state                   */
163        enum Mode mode,                  /* i   : AMR mode                        */
164        Word16 parm[],                   /* i   : Vector of synthesis parameters  */
165        Word16 synth[],                  /* o   : synthesised speech              */
166        Word16 A_t[],                    /* o   : decoded LP filter in 4 subframes*/
167        Flag   *pOverflow
168    );
169
170    void dtx_dec_activity_update(dtx_decState *st,
171                                 Word16 lsf[],
172                                 Word16 frame[],
173                                 Flag   *pOverflow);
174
175    /*
176     *  Function    : rx_dtx_handler
177     *  Purpose     : reads the frame type and checks history
178     *  Description : to decide what kind of DTX/CNI action to perform
179     */
180    enum DTXStateType rx_dtx_handler(dtx_decState *st,           /* i/o : State struct */
181                                     enum RXFrameType frame_type,/* i   : Frame type   */
182                                     Flag *pOverflow);
183
184    /*----------------------------------------------------------------------------
185    ; END
186    ----------------------------------------------------------------------------*/
187#ifdef __cplusplus
188}
189#endif
190
191#endif /* DEC_AMR_H_ */
192