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 : #include <stdint.h>
34 : #include "options.h"
35 : #include "cnst.h"
36 : #include "stat_enc.h"
37 : #include "rom_com.h"
38 : #include "ivas_rom_com.h"
39 : #include "ivas_cnst.h"
40 : #include "prot_fx.h"
41 : #include "wmc_auto.h"
42 : #include "ivas_prot_fx.h"
43 6763 : void tdm_low_rate_dec_fx(
44 : Decoder_State *st, /* i/o: decoder static memory */
45 : Word16 dct_epit[], /* o : GSC excitation in DCT domain Q_exc*/
46 : Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/
47 : Word16 *voice_factors, /* o : voicing factors Q15*/
48 : Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/
49 : Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/
50 : Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/
51 : const Word16 *lsf_new /* i : ISFs at the end of the frame Q8/100 (2.56x)*/
52 : )
53 : {
54 : Word16 tmp_nb_bits_tot, pit_band_idx;
55 : GSC_DEC_HANDLE hGSCDec;
56 : Word16 Diff_len, nb_subfr;
57 : Word16 attack_flag;
58 : Word16 last_bin;
59 : Word16 exc_wo_nf_fx[L_FRAME];
60 :
61 6763 : hGSCDec = st->hGSCDec;
62 :
63 : /*---------------------------------------------------------------*
64 : * Initialization
65 : *---------------------------------------------------------------*/
66 :
67 6763 : nb_subfr = 2;
68 6763 : move16();
69 :
70 6763 : st->GSC_IVAS_mode = 0;
71 6763 : move16();
72 6763 : st->GSC_noisy_speech = 1;
73 6763 : move16();
74 6763 : hGSCDec->noise_lev = 14; /* Q0 */
75 6763 : move16();
76 :
77 6763 : pit_band_idx = 10 + BAND1k2; /* Q0 */
78 6763 : hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */
79 6763 : move16();
80 6763 : move16();
81 :
82 6763 : st->tilt_code_fx = 0;
83 6763 : move16();
84 6763 : set16_fx( exc, 0, L_FRAME );
85 6763 : set16_fx( dct_epit, 0, L_FRAME );
86 6763 : set16_fx( pitch_buf, shl( L_SUBFR, Q6 ), NB_SUBFR );
87 6763 : st->bpf_off = 1;
88 6763 : move16();
89 :
90 6763 : st->bfi_pitch_fx = mean_fx( pitch_buf, 4 ); /* Q6 */
91 6763 : move16();
92 6763 : st->bfi_pitch_frame = L_FRAME; /* Q0 */
93 6763 : move16();
94 6763 : Diff_len = L_FRAME / 2;
95 6763 : move16();
96 6763 : st->bpf_off = 0;
97 6763 : move16();
98 6763 : attack_flag = 0;
99 6763 : move16();
100 :
101 6763 : move16();
102 6763 : move16();
103 6763 : move16();
104 6763 : move16();
105 : /*--------------------------------------------------------------------------------------*
106 : * GSC decoder
107 : *--------------------------------------------------------------------------------------*/
108 :
109 : /* find the current total number of bits used */
110 6763 : tmp_nb_bits_tot = st->next_bit_pos; /* Q0 */
111 6763 : move16();
112 :
113 6763 : move16();
114 6763 : if ( EQ_16( st->element_mode, IVAS_CPE_TD ) )
115 : {
116 27 : tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); /* Q0 */
117 : }
118 :
119 6763 : if ( EQ_16( st->tdm_LRTD_flag, 1 ) )
120 : {
121 11 : tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); /* Q0 */
122 : }
123 :
124 6763 : if ( st->extl_brate_orig > 0 )
125 : {
126 : /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */
127 70 : tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); /* Q0 */
128 : }
129 :
130 6763 : gsc_dec_ivas_fx( st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st->coder_type, &last_bin, lsf_new, exc_wo_nf_fx, &st->Q_exc );
131 :
132 : /*--------------------------------------------------------------------------------------*
133 : * iDCT transform
134 : *--------------------------------------------------------------------------------------*/
135 :
136 6763 : edct_16fx( dct_epit, exc, L_FRAME, find_guarded_bits_fx( L_FRAME ), IVAS_CPE_TD );
137 :
138 6763 : edct_16fx( exc_wo_nf_fx, exc_wo_nf_fx, L_FRAME, find_guarded_bits_fx( L_FRAME ), IVAS_CPE_TD );
139 :
140 6763 : IF( bwe_exc != NULL )
141 : {
142 6747 : Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[0], &bwe_exc[0], st->hGSCDec->last_exc_dct_in_fx,
143 6747 : L_FRAME, L_FRAME * HIBND_ACB_L_FAC, L_shl( st->lp_gainc_fx, 13 /* Q3 -> Q16*/ ), &( st->Q_exc ), st->Q_subfr, NULL, 0, st->coder_type );
144 : }
145 : ELSE
146 : {
147 16 : Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[0], NULL, st->hGSCDec->last_exc_dct_in_fx,
148 16 : L_FRAME, L_FRAME * HIBND_ACB_L_FAC, L_shl( st->lp_gainc_fx, 13 /* Q3 -> Q16*/ ), &( st->Q_exc ), st->Q_subfr, NULL, 0, st->coder_type );
149 : }
150 : /*----------------------------------------------------------------------*
151 : * Remove potential pre-echo in case an onset has been detected
152 : *----------------------------------------------------------------------*/
153 :
154 6763 : pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, attack_flag, st->Q_exc, st->last_coder_type, st->L_frame );
155 :
156 :
157 : /*--------------------------------------------------------------------------------------*
158 : * Update BWE excitation
159 : *--------------------------------------------------------------------------------------*/
160 :
161 6763 : set16_fx( voice_factors, 0, NB_SUBFR16k );
162 :
163 6763 : IF( st->hBWE_TD != NULL )
164 : {
165 6747 : IF( st->tdm_LRTD_flag )
166 : {
167 11 : interp_code_5over2_fx( exc, bwe_exc, L_FRAME );
168 : }
169 : ELSE
170 : {
171 6736 : set16_fx( bwe_exc, 0, L_FRAME32k );
172 : }
173 : }
174 :
175 : /*--------------------------------------------------------------------------------------*
176 : * Updates
177 : *--------------------------------------------------------------------------------------*/
178 :
179 6763 : Copy( exc, exc2, L_FRAME ); /* Q_exc */
180 6763 : Copy( exc_wo_nf_fx, exc, L_FRAME ); /* Q_exc */
181 :
182 : /*--------------------------------------------------------------------------------------*
183 : * Channel aware mode parameters
184 : *--------------------------------------------------------------------------------------*/
185 :
186 6763 : set16_fx( st->tilt_code_dec_fx, 0, NB_SUBFR16k );
187 :
188 6763 : return;
189 : }
190 :
191 : /*---------------------------------------------------------------------*
192 : * decod_gen_2sbfr()
193 : *
194 : * Decode generic (GC), 2 subframes mode
195 : *---------------------------------------------------------------------*/
196 : /*---------------------------------------------------------------------*
197 : * decod_gen_2sbfr_ivas_fx()
198 : *
199 : * Decode generic (GC), 2 subframes mode
200 : *---------------------------------------------------------------------*/
201 :
202 0 : void decod_gen_2sbfr_ivas_fx(
203 : Decoder_State *st, /* i/o: decoder static memory */
204 : const Word16 sharpFlag, /* i : formant sharpening flag `Q0*/
205 : const Word16 *Aq, /* i : LP filter coefficient Q12*/
206 : Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/
207 : Word16 *voice_factors, /* o : voicing factors Q15*/
208 : Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/
209 : Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/
210 : Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/
211 : Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/
212 : const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/
213 : const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel Q6*/
214 : )
215 : {
216 : Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */
217 0 : Word16 gain_pit = 0; /* pitch gain */
218 0 : move16();
219 0 : Word32 gain_code = 0; /* gain/normalized gain of the algebraic excitation */
220 0 : move32();
221 0 : Word32 norm_gain_code = 0; /* normalized gain of the algebraic excitation */
222 0 : move32();
223 0 : Word16 gain_inov = 0; /* Innovation gain */
224 0 : move16();
225 : Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */
226 : Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */
227 : Word16 voice_fac; /* voicing factor */
228 : Word16 code[2 * L_SUBFR]; /* algebraic codevector */
229 : const Word16 *p_Aq; /* Pointer to frame LP coefficient */
230 : Word16 *pt_pitch; /* pointer to Word16 pitch */
231 : Word16 i_subfr; /* tmp variables */
232 : Word16 L_frame;
233 : Word16 pitch_limit_flag;
234 : Word16 error;
235 :
236 : /*------------------------------------------------------------------*
237 : * Initialization
238 : *------------------------------------------------------------------*/
239 :
240 0 : L_frame = L_FRAME;
241 0 : move16();
242 :
243 0 : T0 = PIT_MIN;
244 0 : move16();
245 0 : T0_frac = 0;
246 0 : move16();
247 0 : error = 0;
248 0 : move16();
249 :
250 0 : move16();
251 0 : move16();
252 0 : move16();
253 : /*------------------------------------------------------------------*
254 : * ACELP subframe loop
255 : *------------------------------------------------------------------*/
256 :
257 0 : p_Aq = Aq; /* pointer to interpolated LPC parameters Q12*/
258 0 : pt_pitch = pitch_buf; /* pointer to the pitch buffer Q6*/
259 :
260 0 : FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += 2 * L_SUBFR )
261 : {
262 : /*----------------------------------------------------------------------*
263 : * Decode pitch lag
264 : *----------------------------------------------------------------------*/
265 :
266 0 : *pt_pitch = pit_decode_ivas_fx( st, st->core_brate, 0, L_frame, i_subfr, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, 2 * L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); /* Q6 */
267 :
268 0 : test();
269 0 : test();
270 0 : IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) && !( st->tdm_LRTD_flag ) ) )
271 : {
272 0 : tbe_celp_exc( L_frame, i_subfr, T0, T0_frac, &error, bwe_exc );
273 : }
274 :
275 : /*--------------------------------------------------------------*
276 : * Find the adaptive codebook vector
277 : *--------------------------------------------------------------*/
278 :
279 0 : pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, 2 * L_SUBFR + 1, inter4_2_fx_Q15, L_INTERPOL2, PIT_UP_SAMP );
280 :
281 : /*--------------------------------------------------------------*
282 : * LP filtering of the adaptive excitation
283 : *--------------------------------------------------------------*/
284 :
285 0 : lp_filt_exc_dec_fx( st, MODE1, i_subfr, 2 * L_SUBFR, L_frame, st->acelp_cfg.ltf_mode, exc );
286 :
287 : /*--------------------------------------------------------------*
288 : * Innovation decoding
289 : *--------------------------------------------------------------*/
290 :
291 0 : inov_decode_ivas_fx( st, st->core_brate, 0, L_frame, sharpFlag, i_subfr, p_Aq, st->tilt_code_fx, *pt_pitch, code, 2 * L_SUBFR );
292 :
293 : /*--------------------------------------------------------------*
294 : * Gain decoding
295 : * Estimate spectrum tilt and voicing
296 : *--------------------------------------------------------------*/
297 :
298 0 : gain_dec_lbr_ivas_fx( st, GENERIC, i_subfr, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, gc_mem, gp_mem, 2 * L_SUBFR );
299 0 : st->tilt_code_fx = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, st->Q_exc, 2 * L_SUBFR, 0 ); /* Q15 */
300 0 : move16();
301 :
302 : /* update LP filtered gains for the case of frame erasures */
303 0 : lp_gain_updt_ivas_fx( i_subfr, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame );
304 0 : lp_gain_updt_ivas_fx( add( i_subfr, L_SUBFR ), gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame );
305 :
306 : /*----------------------------------------------------------------------*
307 : * Find the total excitation
308 : *----------------------------------------------------------------------*/
309 :
310 0 : Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], ( bwe_exc != NULL ) ? &bwe_exc[i_subfr * HIBND_ACB_L_FAC] : NULL, st->hGSCDec->last_exc_dct_in_fx,
311 0 : 2 * L_SUBFR, 2 * L_SUBFR * HIBND_ACB_L_FAC, gain_code, &( st->Q_exc ), st->Q_subfr, exc2, i_subfr, st->coder_type );
312 :
313 0 : Word16 gain_code16 = round_fx( L_shl( gain_code, st->Q_exc ) ); /*Q_exc*/
314 0 : Acelp_dec_total_exc( exc, exc2, gain_code16, gain_pit, i_subfr, code, 2 * L_SUBFR );
315 : /*-----------------------------------------------------------------*
316 : * Prepare TBE excitation
317 : *-----------------------------------------------------------------*/
318 0 : prep_tbe_exc_ivas_fx( L_frame, 2 * L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/], bwe_exc, 0, NULL, st->Q_exc, T0, T0_frac, GENERIC, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag );
319 0 : voice_factors[i_subfr / L_SUBFR + 1] = voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/]; /* Q15 */
320 0 : move16();
321 :
322 : /*----------------------------------------------------------------*
323 : * Excitation enhancements (update of total excitation signal)
324 : * called twice because adapting it to double the subfr length would need lot of modifications
325 : *----------------------------------------------------------------*/
326 0 : enhancer_ivas_fx2( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code, exc2, gain_pit, &st->dm_fx, st->Q_exc );
327 :
328 0 : enhancer_ivas_fx2( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code + L_SUBFR, exc2 + L_SUBFR, gain_pit, &st->dm_fx, st->Q_exc );
329 :
330 0 : p_Aq += 2 * ( M + 1 ); /* Q12 */
331 :
332 0 : pt_pitch++;
333 0 : *pt_pitch = *( pt_pitch - 1 ); /* Q6 */
334 0 : move16();
335 0 : pt_pitch++;
336 :
337 0 : gain_buf[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = gain_pit; /* Q14 */
338 0 : move16();
339 0 : gain_buf[( i_subfr + L_SUBFR ) / L_SUBFR /*(i_subfr+L_SUBFR) / L_SUBFR*/] = gain_pit; /* Q14 */
340 0 : move16();
341 0 : st->tilt_code_dec_fx[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = st->tilt_code_fx; /* Q15 */
342 0 : move16();
343 0 : st->tilt_code_dec_fx[( i_subfr + L_SUBFR ) / L_SUBFR /*( i_subfr + L_SUBFR ) / L_SUBFR*/] = st->tilt_code_fx; /* Q15 */
344 0 : move16();
345 : }
346 :
347 : /* SC-VBR */
348 0 : st->prev_gain_pit_dec_fx = gain_pit; /* Q14 */
349 0 : move16();
350 :
351 0 : return;
352 : }
|