Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 :
5 : #include <stdint.h>
6 : #include "options.h" /* Compilation switches */
7 : #include "cnst.h" /* Common constants */
8 : #include "rom_com.h" /* Static table prototypes */
9 : #include "prot_fx.h" /* Function prototypes */
10 :
11 : /*---------------------------------------------------------------------*
12 : * decod_amr_wb_fx()
13 : *
14 : * Decode excitation signal in AMR-WB IO mode
15 : *---------------------------------------------------------------------*/
16 :
17 0 : void decod_amr_wb_fx(
18 : Decoder_State *st_fx, /* i/o: decoder static memory */
19 : const Word16 *Aq_fx, /* i : LP filter coefficients Q12 */
20 : Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/
21 : Word16 *exc_fx, /* i/o: adapt. excitation exc Qx */
22 : Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Qx */
23 : Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */
24 : Word16 *voice_factors_fx, /* o : voicing factors Q15 */
25 : Word16 *gain_buf /* o : floating pitch gain for each subframe Q14 */
26 : )
27 : {
28 : Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */
29 : Word16 gain_pit_fx, gain_code16; /* pitch gain */
30 : Word32 L_gain_code_fx; /* gain/normalized gain of the algebraic excitation */
31 : Word32 L_norm_gain_code_fx; /* normalized gain of the algebraic excitation */
32 : Word16 gain_inov_fx; /* Innovation gain */
33 : Word16 voice_fac_fx; /* voicing factor */
34 : Word16 code_fx[L_SUBFR]; /* algebraic codevector */
35 : const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient */
36 : Word16 *pt_pitch_fx; /* pointer to floating pitch */
37 : Word16 i_subfr; /* tmp variables */
38 : Word16 pitch_limit_flag;
39 : Word32 L_Voice_fac_ave, L_tmp;
40 : Word16 lp_flag;
41 : AMRWB_IO_DEC_HANDLE hAmrwb_IO;
42 0 : hAmrwb_IO = st_fx->hAmrwb_IO;
43 : MUSIC_POSTFILT_HANDLE hMusicPF;
44 0 : hMusicPF = st_fx->hMusicPF;
45 :
46 : /*------------------------------------------------------------------*
47 : * Initializations
48 : *------------------------------------------------------------------*/
49 :
50 0 : p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */
51 0 : pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */
52 0 : L_Voice_fac_ave = 0;
53 0 : move32();
54 0 : pitch_limit_flag = 0;
55 0 : move16(); /* always restrained pitch Q range in IO mode */
56 :
57 0 : lp_flag = NORMAL_OPERATION;
58 0 : move16(); /* always restrained pitch Q range in IO mode */
59 0 : if ( LT_32( st_fx->core_brate, ACELP_11k60 ) )
60 : {
61 0 : lp_flag = LOW_PASS;
62 0 : move16(); /* always restrained pitch Q range in IO mode */
63 : }
64 : /*------------------------------------------------------------------*
65 : * ACELP subframe loop
66 : *------------------------------------------------------------------*/
67 :
68 0 : FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR )
69 : {
70 : /*----------------------------------------------------------------------*
71 : * Decode pitch lag
72 : *----------------------------------------------------------------------*/
73 :
74 : #ifdef REMOVE_EVS_DUPLICATES
75 0 : *pt_pitch_fx = pit_decode_ivas_fx( st_fx, st_fx->core_brate, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR, 0, NULL );
76 : #else
77 : *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR );
78 : #endif
79 :
80 : /*--------------------------------------------------------------*
81 : * Find the adaptive codebook vector
82 : *--------------------------------------------------------------*/
83 :
84 0 : pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
85 :
86 : /*--------------------------------------------------------------*
87 : * LP filtering of the adaptive excitation
88 : *--------------------------------------------------------------*/
89 :
90 0 : lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr, L_SUBFR, L_FRAME, lp_flag, exc_fx );
91 : /*--------------------------------------------------------------*
92 : * Innovation decoding
93 : *--------------------------------------------------------------*/
94 :
95 0 : inov_decode_fx( st_fx, st_fx->core_brate, 1, L_FRAME, 0, i_subfr, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR );
96 :
97 : /*--------------------------------------------------------------*
98 : * Gain decoding
99 : * Estimate spectrum tilt and voicing
100 : *--------------------------------------------------------------*/
101 :
102 0 : gain_dec_amr_wb_fx( st_fx, st_fx->core_brate, &gain_pit_fx, &L_gain_code_fx, hAmrwb_IO->past_qua_en_fx, &gain_inov_fx, code_fx, &L_norm_gain_code_fx );
103 :
104 : /* update LP filtered gains for the case of frame erasures */
105 0 : lp_gain_updt_fx( i_subfr, gain_pit_fx, L_norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME );
106 :
107 0 : st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, L_gain_code_fx, &voice_fac_fx, st_fx->Q_exc );
108 0 : move16();
109 :
110 0 : Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_SUBFR, 0,
111 0 : L_gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr, -1 );
112 :
113 0 : gain_code16 = round_fx( L_shl( L_gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/
114 :
115 : /*----------------------------------------------------------------------*
116 : * Find the total excitation
117 : *----------------------------------------------------------------------*/
118 :
119 0 : Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr, code_fx, L_SUBFR );
120 :
121 : /*----------------------------------------------------------------*
122 : * Excitation enhancements
123 : *----------------------------------------------------------------*/
124 :
125 0 : enhancer_fx( st_fx->core_brate, 1, -1, i_subfr, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx,
126 0 : L_norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc );
127 :
128 : /*-----------------------------------------------------------------*
129 : * HF gain modification factors at 23.85 kbps
130 : *-----------------------------------------------------------------*/
131 :
132 0 : IF( EQ_32( st_fx->core_brate, ACELP_23k85 ) )
133 : {
134 0 : hf_gain_fx[i_subfr / 64] = (Word16) get_next_indice( st_fx, 4 );
135 0 : move16();
136 : }
137 :
138 : /*voice_fac = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac;*/
139 0 : L_tmp = L_mult( VF_2nd_PARAM_FX, mult_r( voice_fac_fx, voice_fac_fx ) );
140 0 : L_tmp = L_mac( L_tmp, VF_1st_PARAM_FX, voice_fac_fx );
141 0 : voice_fac_fx = mac_r( L_tmp, VF_0th_PARAM_FX, 32767 ); // 1.0f in Q15
142 :
143 : Word16 idx;
144 0 : idx = 0;
145 0 : move16();
146 0 : IF( i_subfr != 0 )
147 : {
148 0 : idx = idiv1616( i_subfr, L_SUBFR );
149 : }
150 :
151 : /*voice_factors[i_subfr/L_SUBFR] = min( max(0.0f, voice_fac), 1.0f);*/
152 0 : voice_factors_fx[idx] = s_min( s_max( 0, voice_fac_fx ), 32767 /*1.0f in Q15*/ ); // Q15
153 0 : move16();
154 0 : p_Aq_fx += ( M + 1 );
155 0 : pt_pitch_fx++;
156 :
157 0 : L_Voice_fac_ave = L_mac( L_Voice_fac_ave, 8192, voice_fac_fx ); // .25f in Q15
158 0 : gain_buf[idx] = gain_pit_fx;
159 0 : move16();
160 : }
161 :
162 0 : hAmrwb_IO->lt_voice_fac_fx = round_fx( L_Voice_fac_ave ); // Q0
163 0 : move16();
164 :
165 0 : return;
166 : }
|