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 <stdint.h>
34 : #include "options.h"
35 : #include "ivas_cnst.h"
36 : #include "prot.h"
37 : #include "ivas_prot.h"
38 : #include "ivas_stat_enc.h"
39 : #ifdef DEBUGGING
40 : #include "debug.h"
41 : #endif
42 : #include "wmc_auto.h"
43 :
44 :
45 : /*-------------------------------------------------------------------*
46 : * ivas_ism_enc()
47 : *
48 : * ISM CoreCoders encoding routine
49 : *-------------------------------------------------------------------*/
50 :
51 109022 : ivas_error ivas_ism_enc(
52 : Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
53 : float *data[], /* i : input signal [channels][samples] */
54 : const int16_t input_frame, /* i : input frame length per channel */
55 : int16_t *nb_bits_metadata, /* i : number of metadata bits */
56 : const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */
57 : )
58 : {
59 : SCE_ENC_HANDLE hSCE;
60 : Encoder_State *st;
61 : int16_t sce_id;
62 : float old_inp_12k8[MAX_NUM_OBJECTS][1][L_INP_12k8]; /* buffer of input signal @ 12k8 */
63 : float old_inp_16k[MAX_NUM_OBJECTS][1][L_INP]; /* buffer of input signal @ 16kHz */
64 : int16_t vad_flag[MAX_NUM_OBJECTS]; /* VAD flag */
65 : float ener[MAX_NUM_OBJECTS][1]; /* residual energy from Levinson-Durbin */
66 : float relE[MAX_NUM_OBJECTS][1]; /* frame relative energy */
67 : float A[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */
68 : float Aw[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )]; /* weighted A(z) unquantized for subframes */
69 : float epsP[MAX_NUM_OBJECTS][1][M + 1]; /* LP prediction errors */
70 : float lsp_new[MAX_NUM_OBJECTS][1][M]; /* LSPs at the end of the frame */
71 : float lsp_mid[MAX_NUM_OBJECTS][1][M]; /* ISPs in the middle of the frame */
72 : int16_t vad_hover_flag[MAX_NUM_OBJECTS][1]; /* VAD hangover flag */
73 : int16_t attack_flag[MAX_NUM_OBJECTS][1]; /* attack flag (GSC or TC) */
74 : float realBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */
75 : float imagBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */
76 : float old_wsp[MAX_NUM_OBJECTS][1][L_WSP]; /* old weighted input signal */
77 : float pitch_fr[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch values */
78 : float voicing_fr[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch gains */
79 : int16_t loc_harm[MAX_NUM_OBJECTS][1]; /* harmonicity flag */
80 : float cor_map_sum[MAX_NUM_OBJECTS][1]; /* speech/music clasif. parameter */
81 : int16_t vad_flag_dtx[MAX_NUM_OBJECTS][1]; /* HE-SAD flag with additional DTX HO */
82 : float enerBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */
83 : float currFlatness[1]; /* flatness parameter */
84 : float fft_buff[MAX_NUM_OBJECTS][1][2 * L_FFT]; /* FFT buffer */
85 : float fr_bands[1][2 * NB_BANDS]; /* energy in frequency bands */
86 : float Etot_LR[1]; /* total energy; correlation shift */
87 : float lf_E[1][2 * VOIC_BINS]; /* per bin spectrum energy in lf */
88 : int16_t localVAD_HE_SAD[1]; /* local HE VAD */
89 : int16_t nchan_ism, dtx_flag, sid_flag, flag_noisy_speech;
90 : int16_t md_diff_flag[MAX_NUM_OBJECTS];
91 109022 : Encoder_State *prev_st = NULL;
92 : int32_t ism_total_brate_ref, ism_total_brate;
93 : int16_t i, nchan_transport_ism;
94 : ivas_error error;
95 :
96 109022 : push_wmops( "ivas_ism_enc" );
97 :
98 : /*------------------------------------------------------------------*
99 : * Initialization
100 : *-----------------------------------------------------------------*/
101 :
102 109022 : error = IVAS_ERR_OK;
103 :
104 109022 : dtx_flag = 0;
105 109022 : sid_flag = 0;
106 109022 : flag_noisy_speech = 0;
107 :
108 109022 : nchan_ism = st_ivas->hEncoderConfig->nchan_ism;
109 109022 : set_s( md_diff_flag, 1, nchan_ism );
110 :
111 109022 : nchan_transport_ism = st_ivas->nchan_transport;
112 109022 : if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ )
113 : {
114 2054 : nchan_transport_ism = 1;
115 2054 : nchan_ism = 1;
116 : }
117 106968 : else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
118 : {
119 3142 : nchan_transport_ism = st_ivas->hEncoderConfig->nchan_ism;
120 : }
121 :
122 : /*------------------------------------------------------------------*
123 : * Preprocesing
124 : *-----------------------------------------------------------------*/
125 :
126 388472 : for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
127 : {
128 279450 : hSCE = st_ivas->hSCE[sce_id];
129 279450 : st = hSCE->hCoreCoder[0];
130 :
131 : /*------------------------------------------------------------------*
132 : * Initialization - general
133 : *-----------------------------------------------------------------*/
134 :
135 279450 : mvr2r( data[sce_id], st->input, input_frame );
136 :
137 279450 : st->element_mode = IVAS_SCE;
138 :
139 : /*------------------------------------------------------------------*
140 : * SCE initialization - core coder
141 : *-----------------------------------------------------------------*/
142 :
143 279450 : st->idchan = 0;
144 279450 : st->core = -1;
145 279450 : st->core_brate = -1; /* updated in dtx() */
146 279450 : st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth;
147 279450 : st->input_bwidth = st->last_input_bwidth; /* updated in BWD */
148 279450 : st->bwidth = st->last_bwidth; /* updated in BWD */
149 279450 : st->rate_switching_reset = 0;
150 : #ifdef DEBUGGING
151 : st->force = st_ivas->hEncoderConfig->force;
152 : st->id_element = sce_id;
153 : #endif
154 :
155 : /*---------------------------------------------------------------*
156 : * Time Domain Transient Detector
157 : *---------------------------------------------------------------*/
158 :
159 279450 : RunTransientDetection( st->input, input_frame, st->hTranDet );
160 279450 : currFlatness[0] = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 0 );
161 :
162 : /*----------------------------------------------------------------*
163 : * Configuration of core encoder
164 : *----------------------------------------------------------------*/
165 :
166 : /* Force to MODE1 in IVAS */
167 279450 : st->codec_mode = MODE1;
168 :
169 279450 : st->bits_frame_nominal = (int16_t) ( ( hSCE->element_brate / FRAMES_PER_SEC ) - ISM_NB_BITS_METADATA_NOMINAL );
170 :
171 : /*----------------------------------------------------------------*
172 : * Front Pre-processing
173 : *----------------------------------------------------------------*/
174 :
175 : #ifdef DEBUGGING
176 : st_ivas->noClipping += check_clipping( hSCE->hCoreCoder[0]->input, input_frame, &st_ivas->maxOverload, &st_ivas->minOverload );
177 :
178 : #endif
179 279450 : error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0],
180 279450 : &ener[sce_id][0], &relE[sce_id][0], A[sce_id][0], Aw[sce_id][0], epsP[sce_id][0], lsp_new[sce_id][0], lsp_mid[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0],
181 279450 : realBuffer[sce_id][0], imagBuffer[sce_id][0], old_wsp[sce_id][0], pitch_fr[sce_id][0], voicing_fr[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0],
182 279450 : fft_buff[sce_id][0], A[sce_id][0], lsp_new[sce_id][0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate );
183 279450 : if ( error != IVAS_ERR_OK )
184 : {
185 0 : return error;
186 : }
187 :
188 279450 : if ( st_ivas->hEncoderConfig->Opt_DTX_ON )
189 : {
190 38116 : vad_flag[sce_id] = vad_flag_dtx[sce_id][0];
191 : }
192 : else
193 : {
194 241334 : vad_flag[sce_id] = st->vad_flag;
195 : }
196 : }
197 :
198 : /*------------------------------------------------------------------*
199 : * DTX analysis
200 : *-----------------------------------------------------------------*/
201 :
202 109022 : if ( st_ivas->hEncoderConfig->Opt_DTX_ON )
203 : {
204 : /* compute the dominant sce_id using long term energy */
205 14826 : ivas_ism_get_sce_id_dtx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame );
206 :
207 : /* analysis and decision about DTX */
208 14826 : dtx_flag = ivas_ism_dtx_enc( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, st_ivas->nchan_transport, vad_flag, st_ivas->hIsmMetaData, md_diff_flag, &sid_flag );
209 :
210 14826 : if ( sid_flag )
211 : {
212 : /* estimate coherence between objects */
213 555 : ivas_ism_coh_estim_dtx_enc( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame );
214 : }
215 :
216 : #ifdef DEBUG_MODE_PARAM_ISM
217 : if ( st_ivas->hParamIsmDec != NULL )
218 : dbgwrite( &( st_ivas->hParamIsmDec->hParamIsm->flag_noisy_speech ), sizeof( int16_t ), 1, 1, "./res/ParamISM_noisy_speech_flag_enc.dat" );
219 : dbgwrite( &( st_ivas->hISMDTX->dtx_flag ), sizeof( int16_t ), 1, 1, "./res/ParamISM_DTX_CNG_flag_enc.dat" );
220 : dbgwrite( &( st_ivas->hISMDTX->sce_id_dtx ), sizeof( int16_t ), 1, input_frame, "./res/sce_id_dtx" );
221 : dbgwrite( &( dtx_flag ), sizeof( int16_t ), 1, input_frame, "./res/dtx_flag" );
222 : #endif
223 : }
224 :
225 : /*------------------------------------------------------------------*
226 : * Analysis of objects, configuration and decision about bitrates per channel
227 : * Metadata quantization and encoding
228 : *-----------------------------------------------------------------*/
229 :
230 109022 : if ( st_ivas->ism_mode == ISM_MODE_PARAM )
231 : {
232 20720 : ivas_param_ism_compute_noisy_speech_flag( st_ivas );
233 20720 : flag_noisy_speech = st_ivas->hParamIsm->flag_noisy_speech;
234 : }
235 :
236 109022 : if ( dtx_flag )
237 : {
238 2153 : ivas_ism_metadata_sid_enc( st_ivas->hISMDTX, flag_noisy_speech, nchan_ism, st_ivas->nchan_transport, st_ivas->ism_mode, st_ivas->hIsmMetaData, sid_flag, md_diff_flag, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata );
239 : }
240 106869 : else if ( st_ivas->ism_mode == ISM_MODE_PARAM )
241 : {
242 20377 : if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData,
243 20377 : nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK )
244 : {
245 0 : return error;
246 : }
247 : }
248 : else /* ISM_MODE_DISC */
249 : {
250 86492 : if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ )
251 : {
252 5196 : ism_total_brate = 0;
253 15710 : for ( i = 0; i < st_ivas->nSCE; i++ )
254 : {
255 10514 : ism_total_brate += st_ivas->hSCE[i]->element_brate;
256 : }
257 : }
258 : else
259 : {
260 81296 : ism_total_brate = st_ivas->hEncoderConfig->ivas_total_brate;
261 : }
262 :
263 86492 : ism_total_brate_ref = ism_total_brate;
264 :
265 249084 : if ( ( error = ivas_ism_metadata_enc( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData,
266 249084 : nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.hOmasaData->lp_noise_CPE : 0, flag_omasa_ener_brate, st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt ) : NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK )
267 : {
268 0 : return error;
269 : }
270 :
271 86492 : if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT )
272 : {
273 5196 : st_ivas->hCPE[0]->brate_surplus = ism_total_brate_ref - ism_total_brate;
274 : }
275 : }
276 :
277 109022 : update_last_metadata( nchan_ism, st_ivas->hIsmMetaData, md_diff_flag );
278 :
279 : /*----------------------------------------------------------------*
280 : * Write IVAS format signaling in SID frames
281 : *----------------------------------------------------------------*/
282 :
283 109022 : st = st_ivas->hSCE[0]->hCoreCoder[0];
284 :
285 109022 : if ( sid_flag )
286 : {
287 555 : ivas_write_format_sid( st_ivas->hEncoderConfig->ivas_format, IVAS_SCE, st->hBstr, -1, -1 );
288 : }
289 :
290 : /*only metadata encoding is needed for this case*/
291 109022 : if ( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT )
292 : {
293 0 : assert( st_ivas->ism_mode != ISM_MODE_NONE );
294 0 : return error;
295 : }
296 :
297 : /*------------------------------------------------------------------*
298 : * CoreCoders encoding
299 : *-----------------------------------------------------------------*/
300 :
301 388472 : for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
302 : {
303 279450 : hSCE = st_ivas->hSCE[sce_id];
304 279450 : st = hSCE->hCoreCoder[0];
305 :
306 : /* update pointer to the buffer of indices of the next channel */
307 279450 : if ( sce_id > 0 )
308 : {
309 170428 : st->hBstr->ind_list = prev_st->hBstr->ind_list + prev_st->hBstr->nb_ind_tot;
310 : }
311 :
312 279450 : if ( st->low_rate_mode )
313 : {
314 7534 : st->bwidth = WB;
315 : }
316 :
317 : /*----------------------------------------------------------------*
318 : * Core codec configuration
319 : *----------------------------------------------------------------*/
320 :
321 : /* IGF reconfiguration */
322 279450 : if ( hSCE->last_element_brate != hSCE->element_brate || st->last_bwidth != st->bwidth )
323 : {
324 : int16_t igf;
325 3932 : igf = getIgfPresent( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->max_bwidth, st->rf_mode );
326 3932 : if ( ( error = IGF_Reconfig( &st->hIGFEnc, igf, 0, st->bits_frame_nominal * FRAMES_PER_SEC, st->max_bwidth, st->element_mode, st->rf_mode ) ) != IVAS_ERR_OK )
327 : {
328 0 : return error;
329 : }
330 : }
331 :
332 : /* set ACELP@12k8 / ACELP@16k flag for flexible ACELP core */
333 279450 : if ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA )
334 : {
335 5283 : st->flag_ACELP16k = set_ACELP_flag( IVAS_SCE, hSCE->element_brate, st->core_brate, 0, 0, -1, -1 );
336 : }
337 274167 : else if ( st->low_rate_mode )
338 : {
339 7534 : st->flag_ACELP16k = 0;
340 : }
341 : else
342 : {
343 266633 : st->flag_ACELP16k = set_ACELP_flag( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 );
344 : }
345 :
346 : /* modify the coder_type depending on the total_brate per channel */
347 279450 : coder_type_modif( st, relE[sce_id][0] );
348 :
349 : /*----------------------------------------------------------------*
350 : * Encoder
351 : *----------------------------------------------------------------*/
352 :
353 279450 : if ( !dtx_flag || ( dtx_flag && sce_id == st_ivas->hISMDTX->sce_id_dtx ) )
354 : {
355 276320 : if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, ISM_FORMAT, 0 ) ) != IVAS_ERR_OK )
356 : {
357 0 : return error;
358 : }
359 : }
360 :
361 : /*----------------------------------------------------------------*
362 : * Common updates
363 : *----------------------------------------------------------------*/
364 :
365 : /* update input samples buffer */
366 279450 : mvr2r( st->input, st->old_input_signal, input_frame );
367 :
368 279450 : hSCE->last_element_brate = hSCE->element_brate;
369 :
370 : /* Store previous attack detection flag */
371 279450 : st->hTranDet->transientDetector.prev_bIsAttackPresent = st->hTranDet->transientDetector.bIsAttackPresent;
372 :
373 279450 : prev_st = st;
374 : }
375 :
376 109022 : if ( dtx_flag )
377 : {
378 7436 : for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
379 : {
380 5283 : if ( sce_id != st_ivas->hISMDTX->sce_id_dtx )
381 : {
382 3130 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->last_core;
383 3130 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core_brate = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->core_brate;
384 3130 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_L_frame = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->last_L_frame;
385 : }
386 : }
387 : }
388 :
389 : #ifdef DEBUG_MODE_INFO
390 : if ( dtx_flag )
391 : {
392 : float tmpF;
393 : int16_t id, n;
394 :
395 : n = 0;
396 : for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
397 : {
398 : if ( sce_id != st_ivas->hISMDTX->sce_id_dtx )
399 : {
400 : st = st_ivas->hSCE[sce_id]->hCoreCoder[0];
401 : id = st->id_element;
402 :
403 : dbgwrite( &st->core, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "core", n, id, ENC ) );
404 : dbgwrite( &st->extl, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "extl", n, id, ENC ) );
405 : dbgwrite( &st->bwidth, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "bwidth", n, id, ENC ) );
406 : tmpF = st->total_brate / 1000.0f;
407 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "total_brate", n, id, ENC ) );
408 : tmpF = st->core_brate / 1000.0f;
409 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "core_brate", n, id, ENC ) );
410 : tmpF = st->extl_brate / 1000.0f;
411 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "extl_brate", n, id, ENC ) );
412 :
413 : dbgwrite( &st->coder_type, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type", n, id, ENC ) );
414 : dbgwrite( &st->coder_type_raw, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type_raw", n, id, ENC ) );
415 : dbgwrite( &st->vad_flag, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "vad_flag", n, id, ENC ) );
416 : dbgwrite( &st->localVAD, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "localVAD", n, id, ENC ) );
417 :
418 : dbgwrite( &st->lp_noise, sizeof( float ), 1, input_frame, fname( debug_dir, "lp_noise", n, id, ENC ) );
419 : }
420 : }
421 : }
422 : #endif
423 109022 : pop_wmops();
424 :
425 109022 : return error;
426 : }
427 :
428 :
429 : /*-------------------------------------------------------------------------
430 : * ivas_ism_enc_config()
431 : *
432 : * - select ISM format mode
433 : * - reconfigure the ISM format encoder
434 : *-------------------------------------------------------------------------*/
435 :
436 103826 : ivas_error ivas_ism_enc_config(
437 : Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
438 : )
439 : {
440 : ivas_error error;
441 : ISM_MODE last_ism_mode;
442 : int16_t nchan_transport_old;
443 : int16_t nSCE_old, nCPE_old;
444 :
445 103826 : error = IVAS_ERR_OK;
446 103826 : last_ism_mode = st_ivas->ism_mode;
447 :
448 : /* select ISM format mode */
449 103826 : st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->hEncoderConfig->nchan_inp, st_ivas->hEncoderConfig->ivas_total_brate );
450 :
451 : /* ISM bit-rate switching */
452 103826 : if ( ( st_ivas->ism_mode != last_ism_mode ) || ( st_ivas->hEncoderConfig->ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) )
453 : {
454 : int32_t element_brate_tmp[MAX_NUM_OBJECTS];
455 :
456 947 : nchan_transport_old = st_ivas->nchan_transport;
457 :
458 : /* Reset and Initialize */
459 947 : if ( st_ivas->ism_mode == ISM_MODE_PARAM )
460 : {
461 312 : st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE;
462 : }
463 : else
464 : {
465 635 : st_ivas->nchan_transport = st_ivas->hEncoderConfig->nchan_inp;
466 : }
467 :
468 947 : nCPE_old = st_ivas->nCPE;
469 947 : nSCE_old = st_ivas->nSCE;
470 947 : st_ivas->nSCE = st_ivas->nchan_transport;
471 947 : st_ivas->nCPE = 0;
472 :
473 947 : if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hEncoderConfig->nchan_inp, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK )
474 : {
475 0 : return error;
476 : }
477 :
478 947 : if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ) ) != IVAS_ERR_OK )
479 : {
480 0 : return error;
481 : }
482 :
483 947 : if ( st_ivas->ism_mode == ISM_MODE_PARAM && last_ism_mode == ISM_MODE_DISC )
484 : {
485 : /* Allocate and Initialize the memory used by ParamISM when switch from Discrete ISM */
486 303 : if ( ( error = ivas_param_ism_enc_open( st_ivas ) ) != IVAS_ERR_OK )
487 : {
488 0 : return error;
489 : }
490 : }
491 :
492 947 : if ( st_ivas->ism_mode == ISM_MODE_DISC && last_ism_mode == ISM_MODE_PARAM )
493 : {
494 : /* Deallocate the memory used by ParamISM when switch to Discrete ISM */
495 306 : ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs );
496 : }
497 : }
498 :
499 103826 : return error;
500 : }
|