Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : /*====================================================================================
34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
35 : ====================================================================================*/
36 :
37 : #include <stdint.h>
38 : #include "options.h"
39 : #ifdef DEBUGGING
40 : #include "debug.h"
41 : #endif
42 : #include "cnst.h"
43 : #include "prot.h"
44 : #include "wmc_auto.h"
45 :
46 : /*-------------------------------------------------------------------*
47 : * decod_tran()
48 : *
49 : * Decode transition (TC) frames
50 : *-------------------------------------------------------------------*/
51 :
52 41832 : void decod_tran(
53 : Decoder_State *st, /* i/o: decoder static memory */
54 : const int16_t L_frame, /* i : length of the frame */
55 : const int16_t tc_subfr, /* i : TC subframe index */
56 : const float *Aq, /* i : LP filter coefficient */
57 : const float Es_pred, /* i : predicted scaled innov. energy */
58 : float *pitch_buf, /* o : floating pitch values for each subframe*/
59 : float *voice_factors, /* o : voicing factors */
60 : float *exc, /* i/o: adapt. excitation exc */
61 : float *exc2, /* i/o: adapt. excitation/total exc */
62 : float *bwe_exc, /* i/o: excitation for SWB TBE */
63 : int16_t *unbits, /* i/o: number of unused bits */
64 : const int16_t sharpFlag, /* i : formant sharpening flag */
65 : float *gain_buf /* o : floating pitch gain for each subframe */
66 : )
67 : {
68 : int16_t T0, T0_frac, T0_min, T0_max; /* integer pitch variables */
69 : float gain_code; /* Quantized algebraic codeebook gain */
70 : float norm_gain_code; /* normalized algebraic codeebook gain */
71 41832 : float gain_pit = 0; /* Quantized pitch gain */
72 : float voice_fac; /* Voicing factor */
73 : float gain_inov; /* inovation gain */
74 : float code[L_SUBFR]; /* algebraic codevector */
75 : const float *p_Aq; /* pointer to lp filter coefficient */
76 : float *pt_pitch; /* pointer to floating pitch */
77 : int16_t i_subfr, i; /* tmp variables */
78 : int16_t position; /* TC related flag */
79 41832 : float gain_preQ = 0; /* Gain of prequantizer excitation */
80 : float code_preQ[L_SUBFR]; /* Prequantizer excitation */
81 : int16_t Jopt_flag; /* flag indicating zero adaptive contribtuion */
82 : float norm_gain_preQ;
83 :
84 41832 : gain_preQ = 0;
85 41832 : set_f( code_preQ, 0, L_SUBFR );
86 :
87 : /*----------------------------------------------------------------*
88 : * ACELP subframe loop
89 : *----------------------------------------------------------------*/
90 :
91 41832 : p_Aq = Aq;
92 41832 : pt_pitch = pitch_buf;
93 41832 : Jopt_flag = 0;
94 41832 : norm_gain_preQ = 0.0f;
95 :
96 228915 : for ( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR )
97 : {
98 : /*------------------------------------------------------------*
99 : * TC : subframe determination &
100 : * adaptive/glottal part of excitation construction
101 : *------------------------------------------------------------*/
102 :
103 187083 : transition_dec( st, L_frame, i_subfr, tc_subfr, &Jopt_flag, exc, &T0, &T0_frac, &T0_min, &T0_max, &pt_pitch, &position, bwe_exc );
104 :
105 : /*-----------------------------------------------------------------*
106 : * Transform domain contribution decoding - active frames
107 : *-----------------------------------------------------------------*/
108 :
109 187083 : if ( st->core_brate >= MIN_BRATE_AVQ_EXC )
110 : {
111 19200 : transf_cdbk_dec( st, 0, i_subfr, Es_pred, 0, &gain_preQ, &norm_gain_preQ, code_preQ, unbits );
112 : }
113 :
114 : /*-----------------------------------------------------------------*
115 : * ACELP codebook search + pitch sharpening
116 : *-----------------------------------------------------------------*/
117 :
118 187083 : inov_decode( st, st->core_brate, 0, L_frame, sharpFlag, i_subfr, p_Aq, st->tilt_code, *pt_pitch, code, L_SUBFR );
119 :
120 : /*-----------------------------------------------------------------*
121 : * De-quantize the gains
122 : * Update tilt of code: 0.0 (unvoiced) to 0.5 (voiced)
123 : *-----------------------------------------------------------------*/
124 :
125 187083 : if ( Jopt_flag == 0 )
126 : {
127 : /* 2/3-bit decoding */
128 58674 : gain_dec_tc( st, i_subfr, Es_pred, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code );
129 : }
130 : else
131 : {
132 : /* 5-bit decoding */
133 128409 : if ( st->core_brate > ACELP_32k )
134 : {
135 8844 : gain_dec_SQ( st, i_subfr, code, Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code );
136 : }
137 : else
138 : {
139 119565 : gain_dec_mless( st, L_frame, st->coder_type, i_subfr, tc_subfr, code, Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code );
140 : }
141 : }
142 :
143 : /* update LP filtered gains for the case of frame erasures */
144 187083 : lp_gain_updt( i_subfr, gain_pit, norm_gain_code + norm_gain_preQ, &st->lp_gainp, &st->lp_gainc, L_frame );
145 :
146 187083 : st->tilt_code = est_tilt( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0 );
147 :
148 : /*----------------------------------------------------------------------*
149 : * Find the total excitation
150 : *----------------------------------------------------------------------*/
151 :
152 12160395 : for ( i = 0; i < L_SUBFR; i++ )
153 : {
154 11973312 : exc2[i + i_subfr] = gain_pit * exc[i + i_subfr];
155 11973312 : exc[i + i_subfr] = exc2[i + i_subfr] + gain_code * code[i];
156 : }
157 :
158 : /*-----------------------------------------------------------------*
159 : * Add the ACELP pre-quantizer contribution
160 : *-----------------------------------------------------------------*/
161 :
162 187083 : if ( st->core_brate >= MIN_BRATE_AVQ_EXC )
163 : {
164 1248000 : for ( i = 0; i < L_SUBFR; i++ )
165 : {
166 1228800 : exc2[i + i_subfr] += gain_preQ * code_preQ[i];
167 1228800 : exc[i + i_subfr] += gain_preQ * code_preQ[i];
168 : }
169 : }
170 :
171 : /*-----------------------------------------------------------------*
172 : * Prepare TBE excitation
173 : *-----------------------------------------------------------------*/
174 :
175 187083 : prep_tbe_exc( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, gain_preQ, code_preQ, T0, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag );
176 :
177 : /*----------------------------------------------------------------*
178 : * Excitation enhancements (update of total excitation signal)
179 : *----------------------------------------------------------------*/
180 :
181 187083 : if ( st->core_brate > ACELP_32k )
182 : {
183 12975 : mvr2r( exc + i_subfr, exc2 + i_subfr, L_SUBFR );
184 : }
185 : else
186 : {
187 174108 : enhancer( MODE1, st->core_brate, -1, 0, st->coder_type, L_frame, voice_fac, st->stab_fac, norm_gain_code, gain_inov, &st->gc_threshold, code, exc2 + i_subfr, gain_pit, st->dispMem );
188 : }
189 :
190 187083 : p_Aq += ( M + 1 );
191 187083 : pt_pitch++;
192 187083 : st->tilt_code_dec[i_subfr / L_SUBFR] = st->tilt_code;
193 187083 : gain_buf[i_subfr / L_SUBFR] = gain_pit;
194 : }
195 :
196 : /* SC-VBR */
197 41832 : st->prev_gain_pit_dec = gain_pit;
198 :
199 41832 : return;
200 : }
|