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 - Wideband (AMR-WB) speech codec
23 Available from http://www.3gpp.org
25 (C) 2007, 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 ****************************************************************************************/
30 ------------------------------------------------------------------------------
34 Pathname: ./cpp/include/dtx.h
36 ------------------------------------------------------------------------------
38 Static memory, constants and frametypes for the DTX
39 ------------------------------------------------------------------------------
45 /*----------------------------------------------------------------------------
47 ----------------------------------------------------------------------------*/
54 /*----------------------------------------------------------------------------
56 ; Define module specific macros here
57 ----------------------------------------------------------------------------*/
59 /*----------------------------------------------------------------------------
60 ; EXTERNAL VARIABLES REFERENCES
61 ----------------------------------------------------------------------------*/
63 /*----------------------------------------------------------------------------
64 ; DEFINES AND SIMPLE TYPEDEF'S
65 ----------------------------------------------------------------------------*/
67 #define DTX_MAX_EMPTY_THRESH 50
68 #define DTX_HIST_SIZE 8
69 #define DTX_HIST_SIZE_MIN_ONE 7
70 #define DTX_ELAPSED_FRAMES_THRESH (24 + 7 -1)
71 #define DTX_HANG_CONST 7 /* yields eight frames of SP HANGOVER */
72 #define INV_MED_THRESH 14564
73 #define ISF_GAP 128 /* 50 */
74 #define ONE_MINUS_ISF_GAP 16384 - ISF_GAP
77 #define ISF_DITH_GAP 448
78 #define ISF_FACTOR_LOW 256
79 #define ISF_FACTOR_STEP 2
82 #define GAIN_FACTOR 75
86 int16 isf_hist[M * DTX_HIST_SIZE];
87 int16 log_en_hist[DTX_HIST_SIZE];
92 /* DTX handler stuff */
93 int16 dtxHangoverCount;
94 int16 decAnaElapsedCount;
96 int32 sumD[DTX_HIST_SIZE];
104 #define TX_SID_FIRST 1
105 #define TX_SID_UPDATE 2
108 #define RX_SPEECH_GOOD 0
109 #define RX_SPEECH_PROBABLY_DEGRADED 1
110 #define RX_SPEECH_LOST 2
111 #define RX_SPEECH_BAD 3
112 #define RX_SID_FIRST 4
113 #define RX_SID_UPDATE 5
117 /*****************************************************************************
119 * DEFINITION OF DATA TYPES
120 *****************************************************************************/
124 int16 since_last_sid;
125 int16 true_sid_period_inv;
133 int16 isf_hist[M * DTX_HIST_SIZE];
134 int16 log_en_hist[DTX_HIST_SIZE];
137 int16 dtxHangoverCount;
138 int16 decAnaElapsedCount;
142 int16 dtxHangoverAdded;
144 int16 dtxGlobalState; /* contains previous state */
145 /* updated in main decoder */
147 int16 data_updated; /* marker to know if CNI data is ever renewed */
154 int16 dtx_enc_init(dtx_encState ** st, int16 isf_init[]);
155 int16 dtx_enc_reset(dtx_encState * st, int16 isf_init[]);
156 void dtx_enc_exit(dtx_encState ** st);
159 dtx_encState * st, /* i/o : State struct */
160 int16 isf[M], /* o : CN ISF vector */
161 int16 * exc2, /* o : CN excitation */
166 dtx_encState * st, /* i/o : State struct */
167 int16 isf_new[], /* i : isf vector */
168 int32 enr, /* i : residual energy (in L_FRAME) */
172 void tx_dtx_handler(dtx_encState * st, /* i/o : State struct */
173 int16 vad_flag, /* i : vad decision */
174 int16 * usedMode /* i/o : mode changed or not */
178 int16 * isf1, /* input : ISF in the frequency domain (0..0.5) */
179 int16 * isf_q, /* output: quantized ISF */
180 int16 * indice /* output: quantization indices */
184 int16 dtx_dec_amr_wb_reset(dtx_decState * st, const int16 isf_init[]);
186 int16 dtx_dec_amr_wb(
187 dtx_decState * st, /* i/o : State struct */
188 int16 * exc2, /* o : CN excitation */
189 int16 new_state, /* i : New DTX state */
190 int16 isf[], /* o : CN ISF vector */
194 void dtx_dec_amr_wb_activity_update(
200 int16 rx_amr_wb_dtx_handler(
201 dtx_decState * st, /* i/o : State struct */
202 int16 frame_type /* i : Frame type */
206 int16 * indice, /* input: quantization indices */
207 int16 * isf_q /* input : ISF in the frequency domain (0..0.5) */
210 void aver_isf_history(
215 void find_frame_indices(
221 int16 dithering_control(
226 int32 * L_log_en_int,