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 "rom_com.h"
44 : #include "prot.h"
45 : #include "wmc_auto.h"
46 :
47 : /*---------------------------------------------------------------------*
48 : * decod_amr_wb()
49 : *
50 : * Decode excitation signal in AMR-WB IO mode
51 : *---------------------------------------------------------------------*/
52 :
53 0 : void decod_amr_wb(
54 : Decoder_State *st, /* i/o: decoder static memory */
55 : const float *Aq, /* i : LP filter coefficients */
56 : float *pitch_buf, /* o : floating pitch values for each subframe */
57 : float *exc, /* i/o: adapt. excitation exc */
58 : float *exc2, /* i/o: adapt. excitation/total exc */
59 : int16_t hf_gain[NB_SUBFR], /* o : decoded HF gain */
60 : float *voice_factors, /* o : voicing factors */
61 : float *gain_buf /* o : floating pitch gain for each subframe */
62 : )
63 : {
64 : int16_t T0, T0_frac, T0_min, T0_max; /* integer pitch variables */
65 : float gain_pit; /* pitch gain */
66 : float gain_code; /* gain/normalized gain of the algebraic excitation */
67 : float norm_gain_code; /* normalized gain of the algebraic excitation */
68 : float gain_inov; /* Innovation gain */
69 : float voice_fac; /* voicing factor */
70 : float code[L_SUBFR]; /* algebraic codevector */
71 : const float *p_Aq; /* Pointer to frame LP coefficient */
72 : float *pt_pitch; /* pointer to floating pitch */
73 : int16_t i_subfr, i; /* tmp variables */
74 : int16_t pitch_limit_flag;
75 : int16_t lp_flag;
76 :
77 : /*-----------------------------------------------------------------*
78 : * Select LP filtering flag
79 : *-----------------------------------------------------------------*/
80 :
81 0 : if ( st->core_brate < ACELP_11k60 )
82 : {
83 0 : lp_flag = LOW_PASS;
84 : }
85 : else
86 : {
87 0 : lp_flag = NORMAL_OPERATION;
88 : }
89 :
90 : /*------------------------------------------------------------------*
91 : * ACELP subframe loop
92 : *------------------------------------------------------------------*/
93 :
94 0 : p_Aq = Aq; /* pointer to interpolated LPC parameters */
95 0 : pt_pitch = pitch_buf; /* pointer to the pitch buffer */
96 0 : st->hAmrwb_IO->lt_voice_fac = 0.0f;
97 0 : pitch_limit_flag = 0; /* always restrained pitch Q range in IO mode */
98 :
99 0 : for ( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR )
100 : {
101 : /*----------------------------------------------------------------------*
102 : * Decode pitch lag
103 : *----------------------------------------------------------------------*/
104 :
105 0 : *pt_pitch = pit_decode( st, st->core_brate, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR, 0, NULL );
106 :
107 : /*--------------------------------------------------------------*
108 : * Find the adaptive codebook vector
109 : *--------------------------------------------------------------*/
110 :
111 0 : pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
112 :
113 : /*--------------------------------------------------------------*
114 : * LP filtering of the adaptive excitation
115 : *--------------------------------------------------------------*/
116 :
117 0 : lp_filt_exc_dec( st, MODE1, i_subfr, L_SUBFR, L_FRAME, lp_flag, exc );
118 :
119 : /*--------------------------------------------------------------*
120 : * Innovation decoding
121 : *--------------------------------------------------------------*/
122 :
123 0 : inov_decode( st, st->core_brate, 1, L_FRAME, 0, i_subfr, p_Aq, st->tilt_code, *pt_pitch, code, L_SUBFR );
124 :
125 : /*--------------------------------------------------------------*
126 : * Gain decoding
127 : * Estimate spectrum tilt and voicing
128 : *--------------------------------------------------------------*/
129 :
130 0 : gain_dec_amr_wb( st, st->core_brate, &gain_pit, &gain_code, st->hAmrwb_IO->past_qua_en, &gain_inov, code, &norm_gain_code );
131 :
132 : /* update LP filtered gains for the case of frame erasures */
133 0 : lp_gain_updt( i_subfr, gain_pit, norm_gain_code, &st->lp_gainp, &st->lp_gainc, L_FRAME );
134 :
135 0 : st->tilt_code = est_tilt( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0 );
136 :
137 : /*----------------------------------------------------------------------*
138 : * Find the total excitation
139 : *----------------------------------------------------------------------*/
140 :
141 0 : for ( i = 0; i < L_SUBFR; i++ )
142 : {
143 0 : exc2[i + i_subfr] = gain_pit * exc[i + i_subfr];
144 0 : exc[i + i_subfr] = exc2[i + i_subfr] + gain_code * code[i];
145 : }
146 :
147 : /*----------------------------------------------------------------*
148 : * Excitation enhancements
149 : *----------------------------------------------------------------*/
150 :
151 0 : enhancer( MODE1, st->core_brate, -1, 1, -1, L_FRAME, voice_fac, st->stab_fac, norm_gain_code, gain_inov, &st->gc_threshold, code, exc2 + i_subfr, gain_pit, st->dispMem );
152 :
153 : /*-----------------------------------------------------------------*
154 : * HF gain modification factors at 23.85 kbps
155 : *-----------------------------------------------------------------*/
156 :
157 0 : if ( st->core_brate == ACELP_23k85 )
158 : {
159 0 : hf_gain[i_subfr / L_SUBFR] = get_next_indice( st, 4 );
160 : }
161 :
162 0 : voice_fac = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac;
163 0 : voice_factors[i_subfr / L_SUBFR] = min( max( 0.0f, voice_fac ), 1.0f );
164 :
165 0 : p_Aq += ( M + 1 );
166 0 : pt_pitch++;
167 :
168 0 : st->hAmrwb_IO->lt_voice_fac += 0.25f * voice_fac;
169 0 : gain_buf[i_subfr / L_SUBFR] = gain_pit;
170 : }
171 :
172 0 : return;
173 : }
|