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 0 : *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, 0, NULL );
75 :
76 : /*--------------------------------------------------------------*
77 : * Find the adaptive codebook vector
78 : *--------------------------------------------------------------*/
79 :
80 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 );
81 :
82 : /*--------------------------------------------------------------*
83 : * LP filtering of the adaptive excitation
84 : *--------------------------------------------------------------*/
85 :
86 0 : lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr, L_SUBFR, L_FRAME, lp_flag, exc_fx );
87 : /*--------------------------------------------------------------*
88 : * Innovation decoding
89 : *--------------------------------------------------------------*/
90 :
91 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 );
92 :
93 : /*--------------------------------------------------------------*
94 : * Gain decoding
95 : * Estimate spectrum tilt and voicing
96 : *--------------------------------------------------------------*/
97 :
98 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 );
99 :
100 : /* update LP filtered gains for the case of frame erasures */
101 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 );
102 :
103 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 );
104 0 : move16();
105 :
106 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,
107 0 : L_gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr, -1 );
108 :
109 0 : gain_code16 = round_fx( L_shl( L_gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/
110 :
111 : /*----------------------------------------------------------------------*
112 : * Find the total excitation
113 : *----------------------------------------------------------------------*/
114 :
115 0 : Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr, code_fx, L_SUBFR );
116 :
117 : /*----------------------------------------------------------------*
118 : * Excitation enhancements
119 : *----------------------------------------------------------------*/
120 :
121 0 : enhancer_fx( st_fx->core_brate, 1, -1, i_subfr, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx,
122 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 );
123 :
124 : /*-----------------------------------------------------------------*
125 : * HF gain modification factors at 23.85 kbps
126 : *-----------------------------------------------------------------*/
127 :
128 0 : IF( EQ_32( st_fx->core_brate, ACELP_23k85 ) )
129 : {
130 0 : hf_gain_fx[i_subfr / 64] = (Word16) get_next_indice( st_fx, 4 );
131 0 : move16();
132 : }
133 :
134 : /*voice_fac = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac;*/
135 0 : L_tmp = L_mult( VF_2nd_PARAM_FX, mult_r( voice_fac_fx, voice_fac_fx ) );
136 0 : L_tmp = L_mac( L_tmp, VF_1st_PARAM_FX, voice_fac_fx );
137 0 : voice_fac_fx = mac_r( L_tmp, VF_0th_PARAM_FX, 32767 ); // 1.0f in Q15
138 :
139 : Word16 idx;
140 0 : idx = 0;
141 0 : move16();
142 0 : IF( i_subfr != 0 )
143 : {
144 0 : idx = idiv1616( i_subfr, L_SUBFR );
145 : }
146 :
147 : /*voice_factors[i_subfr/L_SUBFR] = min( max(0.0f, voice_fac), 1.0f);*/
148 0 : voice_factors_fx[idx] = s_min( s_max( 0, voice_fac_fx ), 32767 /*1.0f in Q15*/ ); // Q15
149 0 : move16();
150 0 : p_Aq_fx += ( M + 1 );
151 0 : pt_pitch_fx++;
152 :
153 0 : L_Voice_fac_ave = L_mac( L_Voice_fac_ave, 8192, voice_fac_fx ); // .25f in Q15
154 0 : gain_buf[idx] = gain_pit_fx;
155 0 : move16();
156 : }
157 :
158 0 : hAmrwb_IO->lt_voice_fac_fx = round_fx( L_Voice_fac_ave ); // Q0
159 0 : move16();
160 :
161 0 : return;
162 : }
|