[go: nahoru, domu]

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.173
22    ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
23    Available from http://www.3gpp.org
24
25(C) 2007, 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 Pathname: ./cpp/include/dtx.h
35
36     Date: 01/04/2007
37
38------------------------------------------------------------------------------
39 REVISION HISTORY
40
41 Description:
42------------------------------------------------------------------------------
43 INCLUDE DESCRIPTION
44    Static memory, constants and frametypes for the DTX
45------------------------------------------------------------------------------
46*/
47#ifndef DTX_H
48#define DTX_H
49
50
51/*----------------------------------------------------------------------------
52; INCLUDES
53----------------------------------------------------------------------------*/
54
55#ifdef __cplusplus
56extern "C"
57{
58#endif
59
60    /*----------------------------------------------------------------------------
61    ; MACROS
62    ; Define module specific macros here
63    ----------------------------------------------------------------------------*/
64
65    /*----------------------------------------------------------------------------
66    ; EXTERNAL VARIABLES REFERENCES
67    ----------------------------------------------------------------------------*/
68
69    /*----------------------------------------------------------------------------
70    ; DEFINES AND SIMPLE TYPEDEF'S
71    ----------------------------------------------------------------------------*/
72
73#define DTX_MAX_EMPTY_THRESH 50
74#define DTX_HIST_SIZE 8
75#define DTX_HIST_SIZE_MIN_ONE 7
76#define DTX_ELAPSED_FRAMES_THRESH (24 + 7 -1)
77#define DTX_HANG_CONST 7                   /* yields eight frames of SP HANGOVER  */
78#define INV_MED_THRESH 14564
79#define ISF_GAP  128                       /* 50 */
80#define ONE_MINUS_ISF_GAP 16384 - ISF_GAP
81
82#define ISF_GAP   128
83#define ISF_DITH_GAP   448
84#define ISF_FACTOR_LOW 256
85#define ISF_FACTOR_STEP 2
86
87#define GAIN_THR 180
88#define GAIN_FACTOR 75
89
90    typedef struct
91    {
92        int16 isf_hist[M * DTX_HIST_SIZE];
93        int16 log_en_hist[DTX_HIST_SIZE];
94        int16 hist_ptr;
95        int16 log_en_index;
96        int16 cng_seed;
97
98        /* DTX handler stuff */
99        int16 dtxHangoverCount;
100        int16 decAnaElapsedCount;
101        int32 D[28];
102        int32 sumD[DTX_HIST_SIZE];
103    } dtx_encState;
104
105#define SPEECH 0
106#define DTX 1
107#define DTX_MUTE 2
108
109#define TX_SPEECH 0
110#define TX_SID_FIRST 1
111#define TX_SID_UPDATE 2
112#define TX_NO_DATA 3
113
114#define RX_SPEECH_GOOD 0
115#define RX_SPEECH_PROBABLY_DEGRADED 1
116#define RX_SPEECH_LOST 2
117#define RX_SPEECH_BAD 3
118#define RX_SID_FIRST 4
119#define RX_SID_UPDATE 5
120#define RX_SID_BAD 6
121#define RX_NO_DATA 7
122
123    /*****************************************************************************
124     *
125     * DEFINITION OF DATA TYPES
126     *****************************************************************************/
127
128    typedef struct
129    {
130        int16 since_last_sid;
131        int16 true_sid_period_inv;
132        int16 log_en;
133        int16 old_log_en;
134        int16 level;
135        int16 isf[M];
136        int16 isf_old[M];
137        int16 cng_seed;
138
139        int16 isf_hist[M * DTX_HIST_SIZE];
140        int16 log_en_hist[DTX_HIST_SIZE];
141        int16 hist_ptr;
142
143        int16 dtxHangoverCount;
144        int16 decAnaElapsedCount;
145
146        int16 sid_frame;
147        int16 valid_data;
148        int16 dtxHangoverAdded;
149
150        int16 dtxGlobalState;                 /* contains previous state */
151        /* updated in main decoder */
152
153        int16 data_updated;                   /* marker to know if CNI data is ever renewed */
154
155        int16 dither_seed;
156        int16 CN_dith;
157
158    } dtx_decState;
159
160    int16 dtx_enc_init(dtx_encState ** st, int16 isf_init[]);
161    int16 dtx_enc_reset(dtx_encState * st, int16 isf_init[]);
162    void dtx_enc_exit(dtx_encState ** st);
163
164    int16 dtx_enc(
165        dtx_encState * st,                    /* i/o : State struct                                         */
166        int16 isf[M],                        /* o   : CN ISF vector                                        */
167        int16 * exc2,                        /* o   : CN excitation                                        */
168        int16 ** prms
169    );
170
171    int16 dtx_buffer(
172        dtx_encState * st,                    /* i/o : State struct                    */
173        int16 isf_new[],                     /* i   : isf vector                      */
174        int32 enr,                           /* i   : residual energy (in L_FRAME)    */
175        int16 codec_mode
176    );
177
178    void tx_dtx_handler(dtx_encState * st,     /* i/o : State struct           */
179                        int16 vad_flag,                      /* i   : vad decision           */
180                        int16 * usedMode                     /* i/o : mode changed or not    */
181                       );
182
183    void Qisf_ns(
184        int16 * isf1,                        /* input : ISF in the frequency domain (0..0.5) */
185        int16 * isf_q,                       /* output: quantized ISF                        */
186        int16 * indice                       /* output: quantization indices                 */
187    );
188
189
190    int16 dtx_dec_amr_wb_reset(dtx_decState * st, const int16 isf_init[]);
191
192    int16 dtx_dec_amr_wb(
193        dtx_decState * st,                    /* i/o : State struct                                          */
194        int16 * exc2,                        /* o   : CN excitation                                          */
195        int16 new_state,                     /* i   : New DTX state                                          */
196        int16 isf[],                         /* o   : CN ISF vector                                          */
197        int16 ** prms
198    );
199
200    void dtx_dec_amr_wb_activity_update(
201        dtx_decState * st,
202        int16 isf[],
203        int16 exc[]);
204
205
206    int16 rx_amr_wb_dtx_handler(
207        dtx_decState * st,                    /* i/o : State struct     */
208        int16 frame_type                     /* i   : Frame type       */
209    );
210
211    void Disf_ns(
212        int16 * indice,                      /* input:  quantization indices                  */
213        int16 * isf_q                        /* input : ISF in the frequency domain (0..0.5)  */
214    );
215
216    void aver_isf_history(
217        int16 isf_old[],
218        int16 indices[],
219        int32 isf_aver[]
220    );
221    void find_frame_indices(
222        int16 isf_old_tx[],
223        int16 indices[],
224        dtx_encState * st
225    );
226
227    int16 dithering_control(
228        dtx_encState * st
229    );
230    void CN_dithering(
231        int16 isf[M],
232        int32 * L_log_en_int,
233        int16 * dither_seed
234    );
235
236#ifdef __cplusplus
237}
238#endif
239
240#endif  /*  DTX_H  */
241
242
243