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 <assert.h>
38 : #include <stdint.h>
39 : #include "options.h"
40 : #include "cnst.h"
41 : #include "stl.h"
42 : #include "basop_util.h"
43 : #include "prot_fx.h"
44 : #include "rom_com.h"
45 : #include "wmc_auto.h"
46 :
47 : Word16
48 17224 : DecodeIndex_fx(
49 : Decoder_State *st,
50 : const Word16 Bandwidth,
51 : Word16 *PeriodicityIndex )
52 : {
53 : TCX_LTP_DEC_HANDLE hTcxLtpDec;
54 : TCX_DEC_HANDLE hTcxDec;
55 :
56 17224 : hTcxLtpDec = st->hTcxLtpDec;
57 17224 : hTcxDec = st->hTcxDec;
58 :
59 17224 : test();
60 17224 : IF( hTcxDec->tcx_hm_LtpPitchLag > 0 && GT_16( hTcxLtpDec->tcxltp_gain, kLtpHmGainThr ) )
61 : {
62 : Word16 LtpPitchIndex;
63 9296 : LtpPitchIndex = sub( mult_r( hTcxDec->tcx_hm_LtpPitchLag, shl( 1, sub( 15, kLtpHmFractionalResolution ) ) ), 2 );
64 :
65 9296 : *PeriodicityIndex = kLtpHmFlag;
66 9296 : move16();
67 9296 : *PeriodicityIndex = s_or( *PeriodicityIndex, get_next_indice_fx( st, NumRatioBits[Bandwidth][LtpPitchIndex] ) );
68 9296 : move16();
69 9296 : *PeriodicityIndex = add( *PeriodicityIndex, 1 );
70 9296 : move16();
71 9296 : *PeriodicityIndex = s_or( *PeriodicityIndex, shl( LtpPitchIndex, 9 ) );
72 9296 : move16();
73 :
74 9296 : return NumRatioBits[Bandwidth][LtpPitchIndex];
75 : }
76 : ELSE
77 : {
78 7928 : *PeriodicityIndex = get_next_indice_fx( st, 8 );
79 7928 : move16();
80 7928 : return 8;
81 : }
82 : }
83 :
84 : /*-------------------------------------------------------------------*
85 : * tcx_hm_dequantize_gain()
86 : *
87 : *
88 : *-------------------------------------------------------------------*/
89 :
90 5210 : static Word16 tcx_hm_dequantize_gain_fx(
91 : Word16 coder_type, /* i : coder type Q0 */
92 : Word16 gain_idx, /* i: quantization index Q0 */
93 : Word16 *gain /* o: dequantized gain Q11 */
94 : )
95 : {
96 :
97 5210 : assert( 0 <= coder_type && coder_type <= UNVOICED );
98 :
99 : /* safety check in case of bit errors */
100 5210 : test();
101 5210 : IF( !( 0 <= gain_idx && LT_16( gain_idx, ( 1 << kTcxHmNumGainBits ) ) ) )
102 : {
103 0 : *gain = 0;
104 0 : move16();
105 0 : return 1;
106 : }
107 :
108 5210 : *gain = qGains[coder_type][gain_idx];
109 5210 : move16();
110 :
111 5210 : return 0;
112 : }
113 :
114 : /*-------------------------------------------------------------------*
115 : * tcx_hm_decode_ivas()
116 : *
117 : *
118 : *-------------------------------------------------------------------*/
119 5210 : void tcx_hm_decode(
120 : const Word16 L_frame, /* i : number of spectral lines */
121 : Word32 env[], /* i/o: envelope shape (Q16) */
122 : const Word16 targetBits, /* i : target bit budget */
123 : const Word16 coder_type, /* i : GC/VC coder type */
124 : const Word16 prm_hm[], /* i : HM parameters */
125 : const Word16 LtpPitchLag, /* i : LTP pitch lag or -1 if none */
126 : Word16 *hm_bits /* o : bit consumption */
127 : )
128 : {
129 : Word16 NumTargetBits;
130 : Word16 fract_res;
131 : Word32 lag;
132 : Word16 gain;
133 : Word16 L_frame_m_256;
134 : Word16 p[2 * kTcxHmParabolaHalfWidth + 1];
135 :
136 :
137 5210 : *hm_bits = 0;
138 5210 : move16();
139 :
140 5210 : L_frame_m_256 = sub( L_frame, 256 );
141 :
142 5210 : test();
143 5210 : IF( !( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) ) )
144 : {
145 : /* A bit error was encountered */
146 0 : *hm_bits = -1;
147 0 : move16();
148 0 : return;
149 : }
150 :
151 5210 : NumTargetBits = CountIndexBits( ( L_frame_m_256 >= 0 ), prm_hm[1] );
152 :
153 5210 : NumTargetBits = add( NumTargetBits, targetBits );
154 :
155 5210 : IF( EQ_16( coder_type, VOICED ) )
156 : {
157 1848 : NumTargetBits = add( NumTargetBits, kTcxHmNumGainBits );
158 : }
159 :
160 5210 : *hm_bits = add( sub( NumTargetBits, targetBits ), 1 );
161 5210 : move16();
162 :
163 : /* Convert the index to lag */
164 5210 : test();
165 5210 : UnmapIndex( prm_hm[1], ( L_frame_m_256 >= 0 ), LtpPitchLag,
166 5210 : ( ( LE_16( NumTargetBits, kSmallerLagsTargetBitsThreshold ) ) || ( L_frame_m_256 < 0 ) ),
167 : &fract_res, &lag );
168 :
169 : /* Render the harmonic model */
170 5210 : IF( tcx_hm_render( lag, fract_res, p ) )
171 : {
172 : /* A bit error was encountered */
173 0 : *hm_bits = -1;
174 0 : move16();
175 0 : return;
176 : }
177 :
178 : /* Dequantize gain */
179 5210 : IF( tcx_hm_dequantize_gain_fx( (Word16) EQ_16( coder_type, VOICED ), prm_hm[2], &gain ) )
180 : {
181 : /* A bit error was encountered */
182 0 : *hm_bits = -1;
183 0 : move16();
184 0 : return;
185 : }
186 :
187 5210 : tcx_hm_modify_envelope( gain, lag, fract_res, p, env, L_frame );
188 :
189 :
190 5210 : return;
191 : }
|