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 <assert.h>
34 : #include <stdint.h>
35 : #include "options.h"
36 : #include "prot.h"
37 : #include "rom_com.h"
38 : #ifdef DEBUGGING
39 : #include "debug.h"
40 : #endif
41 : #include "wmc_auto.h"
42 : #include "cnst.h"
43 : #include "basop_proto_func.h"
44 : #include "stat_com.h"
45 : #include "ivas_prot.h"
46 : #include "ivas_stat_dec.h"
47 : #include "ivas_stat_com.h"
48 :
49 :
50 : /*-----------------------------------------------------------------*
51 : * ivas_mct_side_bits() *
52 : * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
53 : * Read mct related side bits and distribute bits per channel *
54 : *-----------------------------------------------------------------*/
55 :
56 302823 : void ivas_mct_side_bits(
57 : MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */
58 : CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */
59 : const int16_t nCPE, /* i : number of CPEs */
60 : Decoder_State *st0, /* i : decoder handle for Bstr */
61 : const int16_t bfi, /* i : BFI flag */
62 : uint16_t *bitstream, /* o : bitstream indices */
63 : const int32_t ivas_total_brate, /* i : IVAS total bitrate */
64 : const int16_t nb_bits_metadata /* i : number of metadata bits */
65 : )
66 : {
67 : int16_t ch, cpe_id, nChannels, i, k, nSubframes;
68 : int16_t nf_side_bits, availableBits, next_bit_pos, nf_bits;
69 : int16_t chBitRatios[MCT_MAX_CHANNELS];
70 : Decoder_State *st, *sts[MCT_MAX_CHANNELS];
71 :
72 302823 : nf_side_bits = 0;
73 302823 : nChannels = hMCT->nchan_out_woLFE;
74 :
75 : /*initializations */
76 1113831 : for ( cpe_id = 0, i = 0; cpe_id < nCPE; cpe_id++ )
77 : {
78 2433024 : for ( ch = 0; ch < CPE_CHANNELS; ch++ )
79 : {
80 1622016 : if ( i < MCT_MAX_CHANNELS )
81 : {
82 1617411 : sts[i] = hCPE[cpe_id]->hCoreCoder[ch];
83 1617411 : i++;
84 : }
85 : }
86 : }
87 :
88 : /*first read IFG bits */
89 302823 : if ( !bfi && st0->igf )
90 : {
91 892515 : for ( ch = 0; ch < nChannels; ch++ )
92 : {
93 731187 : st = sts[ch];
94 731187 : if ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE )
95 : {
96 11778 : continue;
97 : }
98 :
99 719409 : mdct_read_IGF_bits( st, st0 );
100 : }
101 : }
102 :
103 : /*read MCT data and calculate frame bits per channel */
104 937347 : for ( ch = 0; ch < (int16_t) ( hMCT->nchan_out_woLFE * 0.5 ); ch++ )
105 : {
106 634524 : initMdctStereoDecData( hMCT->hBlockData[ch]->hStereoMdct, st0->igf, st0->hIGFDec->igfData.igfInfo.grid, hCPE[0]->element_brate, st0->bwidth );
107 : }
108 :
109 302823 : if ( !bfi )
110 : {
111 296901 : availableBits = 0;
112 :
113 296901 : ivas_mct_dec_mct( hMCT, sts, nChannels );
114 :
115 : /*read channel bitrate ratios from bitstream*/
116 1719531 : for ( ch = 0; ch < nChannels; ch++ )
117 : {
118 1422630 : st = sts[ch];
119 :
120 1422630 : if ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE )
121 : {
122 25578 : chBitRatios[ch] = 0;
123 25578 : st->bits_frame_channel = 0;
124 25578 : continue;
125 : }
126 1397052 : chBitRatios[ch] = get_next_indice( sts[0], NBBITS_MCT_RATIO );
127 :
128 1397052 : nSubframes = ( st->core == TCX_10_CORE ) ? NB_DIV : 1;
129 :
130 2825442 : for ( k = 0; k < nSubframes; k++ )
131 : {
132 1428390 : nf_side_bits += ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL );
133 : }
134 : }
135 :
136 296901 : availableBits = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - sts[0]->next_bit_pos - nf_side_bits );
137 296901 : availableBits -= nb_bits_metadata;
138 :
139 296901 : splitAvailableBitsMCT( (void **) sts, availableBits, chBitRatios, DEC, nChannels );
140 :
141 296901 : next_bit_pos = sts[0]->next_bit_pos;
142 1422630 : for ( ch = 1; ch < nChannels; ch++ )
143 : {
144 1125729 : nf_bits = ( sts[ch - 1]->core == TCX_20_CORE ? 1 : NB_DIV ) * ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL );
145 :
146 1125729 : if ( chBitRatios[ch - 1] == 0 ) /* indicates LFE with no content */
147 : {
148 5547 : nf_bits = 0;
149 : }
150 1125729 : next_bit_pos += sts[ch - 1]->bits_frame_channel + nf_bits;
151 1125729 : sts[ch]->bit_stream = bitstream + next_bit_pos;
152 : }
153 : }
154 :
155 302823 : return;
156 : }
157 :
158 :
159 : /*-------------------------------------------------------------------*
160 : * ivas_mct_core_dec()
161 : *
162 : * IVAS MCT core decoder
163 : *--------------------------------------------------------------------*/
164 :
165 302823 : void ivas_mct_core_dec(
166 : MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */
167 : CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */
168 : const int16_t nCPE, /* i : number of CPEs */
169 : float *signal_out[] /* o : synthesis @internal_FS */
170 : )
171 : {
172 : int16_t i, k, ch, cpe_id, nChannels;
173 : Decoder_State *st, *sts[MCT_MAX_CHANNELS];
174 : float *x[MCT_MAX_CHANNELS][NB_DIV];
175 : int16_t bfi;
176 : /* Framing */
177 : int16_t L_frame, L_frameTCX, nSubframes;
178 : /* TCX */
179 : int16_t tcx_offset;
180 : int16_t tcx_offsetFB;
181 : int16_t left_rect;
182 : int16_t L_spec;
183 : #ifdef DEBUG_MCT
184 : float nrg[MCT_MAX_CHANNELS];
185 : #endif
186 :
187 302823 : push_wmops( "mct_decoding" );
188 :
189 : /*--------------------------------------------------------------------------------*
190 : * Initializations
191 : *--------------------------------------------------------------------------------*/
192 :
193 302823 : nChannels = hMCT->nchan_out_woLFE;
194 :
195 : /*initializations */
196 1113831 : for ( cpe_id = 0, i = 0; cpe_id < nCPE; cpe_id++ )
197 : {
198 2433024 : for ( ch = 0; ch < CPE_CHANNELS; ch++ )
199 : {
200 1622016 : if ( i < MCT_MAX_CHANNELS )
201 : {
202 1617411 : sts[i] = hCPE[cpe_id]->hCoreCoder[ch];
203 1617411 : i++;
204 : }
205 : }
206 : }
207 :
208 302823 : bfi = sts[0]->bfi;
209 :
210 1748355 : for ( ch = 0; ch < nChannels; ch++ )
211 : {
212 : /* Initialization or re-configuration of Stereo TCX */
213 1445532 : sts[ch]->enablePlcWaveadjust = 0;
214 1445532 : x[ch][0] = signal_out[ch];
215 1445532 : x[ch][1] = signal_out[ch] + ( L_FRAME48k / 2 );
216 : }
217 :
218 : /*--------------------------------------------------------------------------------*
219 : * IGF decoding
220 : *--------------------------------------------------------------------------------*/
221 :
222 302823 : if ( sts[0]->igf )
223 : {
224 161328 : if ( !hMCT->currBlockDataCnt )
225 : {
226 269163 : for ( ch = 0; ch < nChannels; ch++ )
227 : {
228 213348 : st = sts[ch];
229 :
230 213348 : if ( sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) /*indicates LFE */
231 : {
232 8025 : continue;
233 : }
234 :
235 205323 : if ( bfi && st->core == ACELP_CORE ) /*no igf processing needed*/
236 : {
237 0 : continue;
238 : }
239 205323 : nSubframes = ( st->core == TCX_10_CORE ) ? NB_DIV : 1;
240 :
241 416175 : for ( k = 0; k < nSubframes; k++ )
242 : {
243 210852 : L_spec = st->hTcxCfg->tcx_coded_lines / nSubframes;
244 :
245 210852 : init_tcx_info( st, st->L_frame / nSubframes, st->hTcxDec->L_frameTCX / nSubframes, k, bfi, &tcx_offset, &tcx_offsetFB, &L_frame, &L_frameTCX, &left_rect, &L_spec );
246 :
247 : /* mono or dual mono IGF decoding */
248 210852 : decoder_tcx_IGF_mono( st, x[ch][k], L_frame, left_rect, bfi, k );
249 : }
250 : }
251 : }
252 : else
253 : {
254 105513 : mctStereoIGF_dec( hMCT, sts, x, bfi );
255 : }
256 : }
257 :
258 302823 : if ( !bfi )
259 : {
260 : /*--------------------------------------------------------------------------------*
261 : * MCT processing
262 : *--------------------------------------------------------------------------------*/
263 :
264 296901 : apply_MCT_dec( hMCT, sts, x );
265 : }
266 :
267 302823 : pop_wmops();
268 :
269 302823 : return;
270 : }
|