Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2026 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 237834 : 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 237834 : 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 237834 : push_wmops( "ivas_ism_enc" );
97 :
98 : /*------------------------------------------------------------------*
99 : * Initialization
100 : *-----------------------------------------------------------------*/
101 :
102 237834 : error = IVAS_ERR_OK;
103 :
104 237834 : dtx_flag = 0;
105 237834 : sid_flag = 0;
106 237834 : flag_noisy_speech = 0;
107 :
108 237834 : nchan_ism = st_ivas->hEncoderConfig->nchan_ism;
109 237834 : set_s( md_diff_flag, 1, nchan_ism );
110 :
111 237834 : nchan_transport_ism = st_ivas->nchan_transport;
112 237834 : if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ )
113 : {
114 18492 : nchan_transport_ism = 1;
115 18492 : nchan_ism = 1;
116 : }
117 219342 : else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
118 : {
119 52216 : nchan_transport_ism = st_ivas->hEncoderConfig->nchan_ism;
120 : }
121 :
122 : /*------------------------------------------------------------------*
123 : * Preprocesing
124 : *-----------------------------------------------------------------*/
125 :
126 813722 : for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
127 : {
128 575888 : hSCE = st_ivas->hSCE[sce_id];
129 575888 : st = hSCE->hCoreCoder[0];
130 :
131 : /*------------------------------------------------------------------*
132 : * Initialization - general
133 : *-----------------------------------------------------------------*/
134 :
135 575888 : mvr2r( data[sce_id], st->input, input_frame );
136 :
137 575888 : st->element_mode = IVAS_SCE;
138 :
139 : /*------------------------------------------------------------------*
140 : * SCE initialization - core coder
141 : *-----------------------------------------------------------------*/
142 :
143 575888 : st->idchan = 0;
144 575888 : st->core = -1;
145 575888 : st->core_brate = -1; /* updated in dtx() */
146 575888 : st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth;
147 575888 : st->input_bwidth = st->last_input_bwidth; /* updated in BWD */
148 575888 : st->bwidth = st->last_bwidth; /* updated in BWD */
149 575888 : 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 575888 : RunTransientDetection( st->input, input_frame, st->hTranDet );
160 575888 : currFlatness[0] = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 0 );
161 :
162 : /*----------------------------------------------------------------*
163 : * Configuration of core encoder
164 : *----------------------------------------------------------------*/
165 :
166 : /* Force to MODE1 in IVAS */
167 575888 : st->codec_mode = MODE1;
168 :
169 575888 : 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 : #ifndef FIX_2344_ALIGN_PREPROC
180 : error =
181 : #endif
182 575888 : 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],
183 575888 : &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],
184 575888 : 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],
185 575888 : 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 );
186 : #ifndef FIX_2344_ALIGN_PREPROC
187 : if ( error != IVAS_ERR_OK )
188 : {
189 : return error;
190 : }
191 : #endif
192 :
193 575888 : if ( st_ivas->hEncoderConfig->Opt_DTX_ON )
194 : {
195 97306 : vad_flag[sce_id] = vad_flag_dtx[sce_id][0];
196 : }
197 : else
198 : {
199 478582 : vad_flag[sce_id] = st->vad_flag;
200 : }
201 : }
202 :
203 : /*------------------------------------------------------------------*
204 : * DTX analysis
205 : *-----------------------------------------------------------------*/
206 :
207 237834 : if ( st_ivas->hEncoderConfig->Opt_DTX_ON )
208 : {
209 : /* compute the dominant sce_id using long term energy */
210 39066 : ivas_ism_get_sce_id_dtx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame );
211 :
212 : /* analysis and decision about DTX */
213 39066 : 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 );
214 :
215 39066 : if ( sid_flag )
216 : {
217 : /* estimate coherence between objects */
218 734 : ivas_ism_coh_estim_dtx_enc( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame );
219 : }
220 :
221 : #ifdef DEBUG_MODE_PARAM_ISM
222 : if ( st_ivas->hParamIsmDec != NULL )
223 : dbgwrite( &( st_ivas->hParamIsmDec->hParamIsm->flag_noisy_speech ), sizeof( int16_t ), 1, 1, "./res/ParamISM_noisy_speech_flag_enc.dat" );
224 : dbgwrite( &( st_ivas->hISMDTX->dtx_flag ), sizeof( int16_t ), 1, 1, "./res/ParamISM_DTX_CNG_flag_enc.dat" );
225 : dbgwrite( &( st_ivas->hISMDTX->sce_id_dtx ), sizeof( int16_t ), 1, input_frame, "./res/sce_id_dtx" );
226 : dbgwrite( &( dtx_flag ), sizeof( int16_t ), 1, input_frame, "./res/dtx_flag" );
227 : #endif
228 : }
229 :
230 : /*------------------------------------------------------------------*
231 : * Analysis of objects, configuration and decision about bitrates per channel
232 : * Metadata quantization and encoding
233 : *-----------------------------------------------------------------*/
234 :
235 237834 : if ( st_ivas->ism_mode == ISM_MODE_PARAM )
236 : {
237 33240 : ivas_param_ism_compute_noisy_speech_flag( st_ivas );
238 33240 : flag_noisy_speech = st_ivas->hParamIsm->flag_noisy_speech;
239 : }
240 :
241 237834 : if ( dtx_flag )
242 : {
243 2630 : 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 );
244 : }
245 235204 : else if ( st_ivas->ism_mode == ISM_MODE_PARAM )
246 : {
247 32437 : 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,
248 32437 : 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 )
249 : {
250 0 : return error;
251 : }
252 : }
253 : else /* ISM_MODE_DISC */
254 : {
255 202767 : if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ )
256 : {
257 70708 : ism_total_brate = 0;
258 201430 : for ( i = 0; i < st_ivas->nSCE; i++ )
259 : {
260 130722 : ism_total_brate += st_ivas->hSCE[i]->element_brate;
261 : }
262 : }
263 : else
264 : {
265 132059 : ism_total_brate = st_ivas->hEncoderConfig->ivas_total_brate;
266 : }
267 :
268 202767 : ism_total_brate_ref = ism_total_brate;
269 :
270 466885 : 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,
271 466885 : 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 )
272 : {
273 0 : return error;
274 : }
275 :
276 202767 : if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT )
277 : {
278 70708 : st_ivas->hCPE[0]->brate_surplus = ism_total_brate_ref - ism_total_brate;
279 : }
280 : }
281 :
282 237834 : update_last_metadata( nchan_ism, st_ivas->hIsmMetaData, md_diff_flag );
283 :
284 : /*----------------------------------------------------------------*
285 : * Write IVAS format signaling in SID frames
286 : *----------------------------------------------------------------*/
287 :
288 237834 : st = st_ivas->hSCE[0]->hCoreCoder[0];
289 :
290 237834 : if ( sid_flag )
291 : {
292 734 : ivas_write_format_sid( st_ivas->hEncoderConfig->ivas_format, IVAS_SCE, st->hBstr, -1, -1 );
293 : }
294 :
295 : /*only metadata encoding is needed for this case*/
296 237834 : if ( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT )
297 : {
298 0 : assert( st_ivas->ism_mode != ISM_MODE_NONE );
299 0 : return error;
300 : }
301 :
302 : /*------------------------------------------------------------------*
303 : * CoreCoders encoding
304 : *-----------------------------------------------------------------*/
305 :
306 813722 : for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
307 : {
308 575888 : hSCE = st_ivas->hSCE[sce_id];
309 575888 : st = hSCE->hCoreCoder[0];
310 :
311 : /* update pointer to the buffer of indices of the next channel */
312 575888 : if ( sce_id > 0 )
313 : {
314 338054 : st->hBstr->ind_list = prev_st->hBstr->ind_list + prev_st->hBstr->nb_ind_tot;
315 : }
316 :
317 575888 : if ( st->low_rate_mode )
318 : {
319 10039 : st->bwidth = WB;
320 : }
321 :
322 : /*----------------------------------------------------------------*
323 : * Core codec configuration
324 : *----------------------------------------------------------------*/
325 :
326 : /* IGF reconfiguration */
327 575888 : if ( hSCE->last_element_brate != hSCE->element_brate || st->last_bwidth != st->bwidth )
328 : {
329 : int16_t igf;
330 8016 : igf = getIgfPresent( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->max_bwidth, st->rf_mode );
331 8016 : 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 )
332 : {
333 0 : return error;
334 : }
335 : }
336 :
337 : /* set ACELP@12k8 / ACELP@16k flag for flexible ACELP core */
338 575888 : if ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA )
339 : {
340 6271 : st->flag_ACELP16k = set_ACELP_flag( IVAS_SCE, hSCE->element_brate, st->core_brate, 0, 0, -1, -1 );
341 : }
342 569617 : else if ( st->low_rate_mode )
343 : {
344 10039 : st->flag_ACELP16k = 0;
345 : }
346 : else
347 : {
348 559578 : st->flag_ACELP16k = set_ACELP_flag( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 );
349 : }
350 :
351 : /* modify the coder_type depending on the total_brate per channel */
352 575888 : coder_type_modif( st, relE[sce_id][0] );
353 :
354 : /*----------------------------------------------------------------*
355 : * Encoder
356 : *----------------------------------------------------------------*/
357 :
358 575888 : if ( !dtx_flag || ( dtx_flag && sce_id == st_ivas->hISMDTX->sce_id_dtx ) )
359 : {
360 572247 : 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 )
361 : {
362 0 : return error;
363 : }
364 : }
365 :
366 : /*----------------------------------------------------------------*
367 : * Common updates
368 : *----------------------------------------------------------------*/
369 :
370 : /* update input samples buffer */
371 575888 : mvr2r( st->input, st->old_input_signal, input_frame );
372 :
373 575888 : hSCE->last_element_brate = hSCE->element_brate;
374 :
375 : /* Store previous attack detection flag */
376 575888 : st->hTranDet->transientDetector.prev_bIsAttackPresent = st->hTranDet->transientDetector.bIsAttackPresent;
377 :
378 575888 : prev_st = st;
379 : }
380 :
381 237834 : if ( dtx_flag )
382 : {
383 8901 : for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
384 : {
385 6271 : if ( sce_id != st_ivas->hISMDTX->sce_id_dtx )
386 : {
387 3641 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->last_core;
388 3641 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core_brate = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->core_brate;
389 3641 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_L_frame = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->last_L_frame;
390 : }
391 : }
392 : }
393 :
394 : #ifdef DEBUG_MODE_INFO
395 : if ( dtx_flag )
396 : {
397 : float tmpF;
398 : int16_t id, n;
399 :
400 : n = 0;
401 : for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
402 : {
403 : if ( sce_id != st_ivas->hISMDTX->sce_id_dtx )
404 : {
405 : st = st_ivas->hSCE[sce_id]->hCoreCoder[0];
406 : id = st->id_element;
407 :
408 : dbgwrite( &st->core, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "core", n, id, ENC ) );
409 : dbgwrite( &st->extl, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "extl", n, id, ENC ) );
410 : dbgwrite( &st->bwidth, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "bwidth", n, id, ENC ) );
411 : tmpF = st->total_brate / 1000.0f;
412 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "total_brate", n, id, ENC ) );
413 : tmpF = st->core_brate / 1000.0f;
414 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "core_brate", n, id, ENC ) );
415 : tmpF = st->extl_brate / 1000.0f;
416 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "extl_brate", n, id, ENC ) );
417 :
418 : dbgwrite( &st->coder_type, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type", n, id, ENC ) );
419 : dbgwrite( &st->coder_type_raw, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type_raw", n, id, ENC ) );
420 : dbgwrite( &st->vad_flag, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "vad_flag", n, id, ENC ) );
421 : dbgwrite( &st->localVAD, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "localVAD", n, id, ENC ) );
422 :
423 : dbgwrite( &st->lp_noise, sizeof( float ), 1, input_frame, fname( debug_dir, "lp_noise", n, id, ENC ) );
424 : }
425 : }
426 : }
427 : #endif
428 237834 : pop_wmops();
429 :
430 237834 : return error;
431 : }
432 :
433 :
434 : /*-------------------------------------------------------------------------
435 : * ivas_ism_enc_config()
436 : *
437 : * - select ISM format mode
438 : * - reconfigure the ISM format encoder
439 : *-------------------------------------------------------------------------*/
440 :
441 167126 : ivas_error ivas_ism_enc_config(
442 : Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
443 : )
444 : {
445 : ivas_error error;
446 : ISM_MODE last_ism_mode;
447 : int16_t nchan_transport_old;
448 : int16_t nSCE_old, nCPE_old;
449 :
450 167126 : error = IVAS_ERR_OK;
451 167126 : last_ism_mode = st_ivas->ism_mode;
452 :
453 : /* select ISM format mode */
454 167126 : st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->hEncoderConfig->nchan_inp, st_ivas->hEncoderConfig->ivas_total_brate );
455 :
456 : /* ISM bit-rate switching */
457 167126 : if ( ( st_ivas->ism_mode != last_ism_mode ) || ( st_ivas->hEncoderConfig->ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) )
458 : {
459 : int32_t element_brate_tmp[MAX_NUM_OBJECTS];
460 :
461 1179 : nchan_transport_old = st_ivas->nchan_transport;
462 :
463 : /* Reset and Initialize */
464 1179 : if ( st_ivas->ism_mode == ISM_MODE_PARAM )
465 : {
466 353 : st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE;
467 : }
468 : else
469 : {
470 826 : st_ivas->nchan_transport = st_ivas->hEncoderConfig->nchan_inp;
471 : }
472 :
473 1179 : nCPE_old = st_ivas->nCPE;
474 1179 : nSCE_old = st_ivas->nSCE;
475 1179 : st_ivas->nSCE = st_ivas->nchan_transport;
476 1179 : st_ivas->nCPE = 0;
477 :
478 1179 : 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 )
479 : {
480 0 : return error;
481 : }
482 :
483 1179 : 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 )
484 : {
485 0 : return error;
486 : }
487 :
488 1179 : if ( st_ivas->ism_mode == ISM_MODE_PARAM && last_ism_mode == ISM_MODE_DISC )
489 : {
490 : /* Allocate and Initialize the memory used by ParamISM when switch from Discrete ISM */
491 342 : if ( ( error = ivas_param_ism_enc_open( st_ivas ) ) != IVAS_ERR_OK )
492 : {
493 0 : return error;
494 : }
495 : }
496 :
497 1179 : if ( st_ivas->ism_mode == ISM_MODE_DISC && last_ism_mode == ISM_MODE_PARAM )
498 : {
499 : /* Deallocate the memory used by ParamISM when switch to Discrete ISM */
500 341 : ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs );
501 : }
502 : }
503 :
504 167126 : return error;
505 : }
|