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 : #ifdef DEBUGGING
36 : #include "debug.h"
37 : #endif
38 : #include "cnst.h"
39 : #include "rom_com.h"
40 : #include "prot.h"
41 : #include "ivas_cnst.h"
42 : #include "ivas_prot.h"
43 : #include "wmc_auto.h"
44 : #include <math.h>
45 :
46 : #ifdef DEBUG_MODE_ACELP
47 : extern float snr_[2][320];
48 : #endif
49 :
50 :
51 : /*-------------------------------------------------------------------*
52 : * ivas_core_enc()
53 : *
54 : * Principal IVAS core coder routine, where number of core channels is 1 or 2
55 : *-------------------------------------------------------------------*/
56 :
57 768638 : ivas_error ivas_core_enc(
58 : SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */
59 : CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */
60 : MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */
61 : const int16_t n_CoreChannels, /* i : number of core channels to be coded */
62 : float old_inp_12k8[][L_INP_12k8], /* i : buffer of old input signal */
63 : float old_inp_16k[][L_INP], /* i : buffer of old input signal */
64 : float ener[], /* i : residual energy from Levinson-Durbin */
65 : float A[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */
66 : float Aw[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes */
67 : float epsP[][M + 1], /* i : LP prediction errors */
68 : float lsp_new[][M], /* i : LSPs at the end of the frame */
69 : float lsp_mid[][M], /* i : LSPs in the middle of the frame */
70 : const int16_t vad_hover_flag[], /* i : VAD hanglover flag */
71 : int16_t attack_flag[], /* i : attack flag (GSC or TC) */
72 : float realBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */
73 : float imagBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */
74 : float old_wsp[][L_WSP], /* i : weighted input signal buffer */
75 : const int16_t loc_harm[], /* i : harmonicity flag */
76 : const float cor_map_sum[], /* i : speech/music clasif. parameter */
77 : const int16_t vad_flag_dtx[], /* i : HE-SAD flag with additional DTX HO */
78 : float enerBuffer[][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */
79 : float fft_buff[][2 * L_FFT], /* i : FFT buffer */
80 : const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag */
81 : const int16_t ivas_format, /* i : IVAS format */
82 : const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */
83 : )
84 : {
85 : int16_t n, input_frame;
86 : int16_t cpe_id, MCT_flag;
87 : Encoder_State **sts, *st;
88 : STEREO_ICBWE_ENC_HANDLE hStereoICBWE;
89 : STEREO_TD_ENC_DATA_HANDLE hStereoTD;
90 : float *inp[CPE_CHANNELS];
91 : float new_inp_resamp16k[CPE_CHANNELS][L_FRAME16k]; /* new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */
92 : float old_syn_12k8_16k[CPE_CHANNELS][L_FRAME16k]; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */
93 : float *shb_speech, *hb_speech, *new_swb_speech;
94 : float new_swb_speech_buffer[L_FRAME48k + STEREO_DFT_OVL_MAX];
95 : float bwe_exc_extended[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET];
96 : float voice_factors[CPE_CHANNELS][NB_SUBFR16k];
97 : int16_t Voicing_flag[CPE_CHANNELS];
98 : float pitch_buf[CPE_CHANNELS][NB_SUBFR16k];
99 : int16_t unbits[CPE_CHANNELS];
100 : float tdm_lsfQ_PCh[M];
101 : int16_t last_element_mode, tdm_Pitch_reuse_flag;
102 : int32_t element_brate, last_element_brate, input_Fs;
103 : int16_t diff_nBits;
104 : ivas_error error;
105 : int16_t max_num_indices_BWE;
106 :
107 768638 : push_wmops( "ivas_core_enc" );
108 :
109 768638 : error = IVAS_ERR_OK;
110 :
111 : /*------------------------------------------------------------------*
112 : * General initialization
113 : *-----------------------------------------------------------------*/
114 :
115 768638 : if ( hSCE != NULL )
116 : {
117 347783 : cpe_id = -1;
118 347783 : MCT_flag = 0;
119 347783 : sts = hSCE->hCoreCoder;
120 347783 : hStereoTD = NULL;
121 347783 : hStereoICBWE = NULL;
122 347783 : element_brate = hSCE->element_brate;
123 347783 : last_element_brate = hSCE->last_element_brate;
124 347783 : last_element_mode = IVAS_SCE;
125 347783 : tdm_Pitch_reuse_flag = -1;
126 : }
127 : else
128 : {
129 420855 : cpe_id = hCPE->cpe_id;
130 420855 : MCT_flag = 0;
131 420855 : if ( hMCT != NULL )
132 : {
133 270308 : MCT_flag = 1;
134 : }
135 420855 : sts = hCPE->hCoreCoder;
136 420855 : hStereoICBWE = hCPE->hStereoICBWE;
137 420855 : element_brate = hCPE->element_brate;
138 420855 : last_element_brate = hCPE->last_element_brate;
139 420855 : last_element_mode = hCPE->last_element_mode;
140 :
141 420855 : if ( hCPE->hStereoTD != NULL )
142 : {
143 3791 : hStereoTD = hCPE->hStereoTD;
144 3791 : tdm_Pitch_reuse_flag = hCPE->hStereoTD->tdm_Pitch_reuse_flag;
145 : }
146 : else
147 : {
148 417064 : hStereoTD = NULL;
149 417064 : tdm_Pitch_reuse_flag = -1;
150 : }
151 : }
152 :
153 768638 : input_Fs = sts[0]->input_Fs;
154 768638 : input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC );
155 :
156 1898452 : for ( n = 0; n < n_CoreChannels; n++ )
157 : {
158 1129814 : st = sts[n];
159 :
160 : /*------------------------------------------------------------------*
161 : * Initializiation per core-coder channel
162 : *-----------------------------------------------------------------*/
163 :
164 : #ifdef DEBUG_MODE_ACELP
165 : set_f( snr_[n], 0.0f, 320 );
166 : #endif
167 :
168 1129814 : st->extl = -1;
169 1129814 : unbits[n] = 0;
170 :
171 1129814 : st->element_brate = element_brate;
172 :
173 : /*---------------------------------------------------------------------*
174 : * Pre-processing, incl. Decision matrix
175 : *---------------------------------------------------------------------*/
176 :
177 1129814 : if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], MCT_flag, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK )
178 : {
179 0 : return error;
180 : }
181 :
182 1129814 : if ( st->element_mode == IVAS_CPE_MDCT || st->element_mode == IVAS_SCE )
183 : {
184 1062553 : st->enablePlcWaveadjust = 0;
185 : }
186 : }
187 :
188 : /*------------------------------------------------------------------*
189 : * Sanity check in combined format coding
190 : *-----------------------------------------------------------------*/
191 :
192 768638 : diff_nBits = 0;
193 768638 : if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 )
194 : {
195 101 : ivas_combined_format_brate_sanity( element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &diff_nBits );
196 : }
197 :
198 : /*---------------------------------------------------------------------*
199 : * Core Encoding
200 : *---------------------------------------------------------------------*/
201 :
202 1898452 : for ( n = 0; n < n_CoreChannels; n++ )
203 : {
204 1129814 : st = sts[n];
205 :
206 : /* update pointer to the buffer of indices of the second channel */
207 1129814 : if ( n == 1 && st->element_mode == IVAS_CPE_TD )
208 : {
209 : /* adjust the pointer to the buffer of indices of the secondary channel (make space for BWE indices) */
210 3791 : max_num_indices_BWE = get_BWE_max_num_indices( sts[0]->extl_brate );
211 3791 : st->hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot + max_num_indices_BWE;
212 :
213 : /* write TD stereo spatial parameters */
214 3791 : move_indices( hStereoTD->tdm_hBstr_tmp.ind_list, st->hBstr->ind_list, hStereoTD->tdm_hBstr_tmp.nb_ind_tot );
215 3791 : st->hBstr->nb_ind_tot += hStereoTD->tdm_hBstr_tmp.nb_ind_tot;
216 3791 : st->hBstr->nb_bits_tot += hStereoTD->tdm_hBstr_tmp.nb_bits_tot;
217 :
218 3791 : reset_indices_enc( &hStereoTD->tdm_hBstr_tmp, MAX_IND_TDM_TMP );
219 : }
220 :
221 : /*---------------------------------------------------------------------*
222 : * Write signaling info into the bitstream
223 : *---------------------------------------------------------------------*/
224 :
225 1129814 : if ( !MCT_flag || ( MCT_flag && cpe_id == 0 ) )
226 : {
227 791076 : ivas_signaling_enc( st, MCT_flag, element_brate, tdm_SM_or_LRTD_Pri, tdm_Pitch_reuse_flag );
228 : }
229 :
230 : /*---------------------------------------------------------------------*
231 : * Preprocessing (preparing) for ACELP/HQ core switching
232 : *---------------------------------------------------------------------*/
233 :
234 1129814 : core_switching_pre_enc( st, old_inp_12k8[n], old_inp_16k[n], sts[0]->active_cnt, last_element_mode );
235 :
236 : /*---------------------------------------------------------------------*
237 : * ACELP core encoding
238 : * TCX core encoding
239 : * HQ core encoding
240 : *---------------------------------------------------------------------*/
241 :
242 1129814 : if ( st->core == ACELP_CORE )
243 : {
244 : /* ACELP core encoder */
245 180687 : if ( ( error = acelp_core_enc( st, inp[n], ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], pitch_buf[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh ) ) != IVAS_ERR_OK )
246 : {
247 0 : return error;
248 : }
249 : }
250 :
251 1129814 : if ( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE ) && st->element_mode != IVAS_CPE_MDCT )
252 : {
253 : /* TCX core encoder */
254 235212 : stereo_tcx_core_enc( st, old_inp_12k8[n] + L_INP_MEM, old_inp_16k[n] + L_INP_MEM, Aw[n], lsp_new[n], lsp_mid[n], pitch_buf[n], last_element_mode, vad_hover_flag[0] );
255 : }
256 :
257 1129814 : if ( st->core == HQ_CORE )
258 : {
259 : /* HQ core encoder */
260 8017 : hq_core_enc( st, st->input, input_frame, NORMAL_HQ_CORE, Voicing_flag[n], vad_hover_flag[0] );
261 : }
262 :
263 : /*---------------------------------------------------------------------*
264 : * TD stereo updates
265 : *---------------------------------------------------------------------*/
266 :
267 1129814 : if ( st->element_mode == IVAS_CPE_TD && n == 0 )
268 : {
269 3791 : td_stereo_param_updt( st->lsp_old, st->lsf_old, pitch_buf[0], NULL, tdm_lsfQ_PCh, hStereoTD->tdm_Pri_pitch_buf, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc );
270 : }
271 : }
272 :
273 :
274 : /*---------------------------------------------------------------------*
275 : * MDCT stereo: joint TCX Core Encoding
276 : *---------------------------------------------------------------------*/
277 :
278 768638 : if ( sts[0]->element_mode == IVAS_CPE_MDCT )
279 : {
280 357385 : if ( sts[0]->core_brate > SID_2k40 && sts[1]->core_brate > SID_2k40 )
281 : {
282 352949 : if ( MCT_flag )
283 : {
284 270308 : ivas_mdct_core_whitening_enc( hCPE, old_inp_16k, old_wsp, pitch_buf, hMCT->p_mdst_spectrum_long[cpe_id], hMCT->tnsBits[cpe_id], hMCT->p_orig_spectrum_long[cpe_id],
285 270308 : hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], hMCT->hBstr, 1, hMCT->nchan_out_woLFE );
286 : }
287 : else
288 : {
289 82641 : stereo_mdct_core_enc( hCPE, old_inp_16k, old_wsp, pitch_buf );
290 : }
291 : }
292 4436 : else if ( sts[0]->core_brate == SID_2k40 && sts[1]->core_brate == SID_2k40 )
293 : {
294 : /* synch CNG configs between channels */
295 1869 : for ( n = 0; n < CPE_CHANNELS; n++ )
296 : {
297 1246 : st = sts[n];
298 1246 : if ( ( st->hFdCngEnc->hFdCngCom->frameSize != st->L_frame ) || ( st->hFdCngEnc->hFdCngCom->CngBandwidth != st->bwidth ) )
299 : {
300 266 : configureFdCngEnc( st->hFdCngEnc, max( st->bwidth, WB ), st->L_frame == L_FRAME16k ? ACELP_16k40 : ACELP_9k60 );
301 : }
302 : }
303 :
304 623 : if ( sts[0]->cng_sba_flag )
305 : {
306 207 : FdCngEncodeDiracMDCTStereoSID( hCPE );
307 : }
308 : else
309 : {
310 416 : FdCngEncodeMDCTStereoSID( hCPE );
311 : }
312 : }
313 : }
314 :
315 :
316 : /*---------------------------------------------------------------------*
317 : * Postprocessing, BWEs and Updates
318 : *---------------------------------------------------------------------*/
319 :
320 1898452 : for ( n = 0; n < n_CoreChannels; n++ )
321 : {
322 1129814 : st = sts[n];
323 :
324 : /*---------------------------------------------------------------------*
325 : * Postprocessing for ACELP/HQ core switching
326 : *---------------------------------------------------------------------*/
327 :
328 1129814 : core_switching_post_enc( st, old_inp_12k8[n], old_inp_16k[n], A[n] );
329 :
330 : /*---------------------------------------------------------------------*
331 : * WB TBE encoding
332 : * WB BWE encoding
333 : *---------------------------------------------------------------------*/
334 :
335 1129814 : hb_speech = new_swb_speech_buffer; /* reuse existing buffer: hb_speech[L_FRAME16k/4]; */
336 :
337 1129814 : if ( input_Fs >= 16000 && st->bwidth < SWB && st->hBWE_TD != NULL )
338 : {
339 : /* Common pre-processing for WB TBE and WB BWE */
340 43722 : wb_pre_proc( st, last_element_mode, new_inp_resamp16k[n], hb_speech );
341 : }
342 :
343 1129814 : if ( st->extl == WB_TBE )
344 : {
345 : /* WB TBE encoder */
346 7241 : wb_tbe_enc( st, hb_speech, bwe_exc_extended[n], voice_factors[n], pitch_buf[n] );
347 : }
348 1122573 : else if ( st->extl == WB_BWE && n == 0 && st->element_mode != IVAS_CPE_MDCT )
349 : {
350 : /* WB BWE encoder */
351 11573 : wb_bwe_enc( st, new_inp_resamp16k[n] );
352 : }
353 :
354 : /*---------------------------------------------------------------------*
355 : * SWB(FB) TBE encoding
356 : * SWB(FB) BWE encoding
357 : *---------------------------------------------------------------------*/
358 :
359 1129814 : new_swb_speech = new_swb_speech_buffer + STEREO_DFT_OVL_MAX;
360 1129814 : set_f( new_swb_speech_buffer, 0, L_FRAME48k + STEREO_DFT_OVL_MAX );
361 1129814 : shb_speech = new_inp_resamp16k[n]; /* reuse existing buffer: shb_speech[L_FRAME16k] */
362 :
363 1129814 : if ( !st->Opt_SC_VBR && input_Fs >= 32000 && st->hBWE_TD != NULL )
364 : {
365 : /* Common pre-processing for SWB(FB) TBE and SWB(FB) BWE */
366 395991 : swb_pre_proc( st, new_swb_speech, shb_speech, realBuffer[n], imagBuffer[n], hCPE );
367 : }
368 733823 : else if ( input_Fs >= 32000 )
369 : {
370 669278 : if ( st->hBWE_TD != NULL )
371 : {
372 0 : InitSWBencBufferStates( st->hBWE_TD, shb_speech );
373 : }
374 : }
375 :
376 : /* SWB TBE encoder */
377 1129814 : if ( st->extl == SWB_TBE || st->extl == FB_TBE )
378 : {
379 115658 : if ( st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 )
380 : {
381 : float fb_exc[L_FRAME16k];
382 :
383 115658 : swb_tbe_enc( st, hStereoICBWE, shb_speech, bwe_exc_extended[n], voice_factors[n], fb_exc, pitch_buf[n] );
384 :
385 115658 : if ( st->extl == FB_TBE )
386 : {
387 : /* FB TBE encoder */
388 43877 : fb_tbe_enc( st, st->input, fb_exc );
389 : }
390 : }
391 : }
392 1014156 : else if ( st->extl == SWB_BWE || st->extl == FB_BWE )
393 : {
394 : /* SWB(FB) BWE encoder */
395 11916 : swb_bwe_enc( st, last_element_mode, old_inp_12k8[n], old_inp_16k[n], old_syn_12k8_16k[n], new_swb_speech, shb_speech );
396 : }
397 :
398 : /*---------------------------------------------------------------------*
399 : * SWB DTX/CNG encoding
400 : *---------------------------------------------------------------------*/
401 :
402 1129814 : if ( st->hTdCngEnc != NULL && st->Opt_DTX_ON && ( input_frame >= L_FRAME32k || st->element_mode == IVAS_CPE_DFT ) )
403 : {
404 : /* SHB DTX/CNG encoder */
405 44242 : swb_CNG_enc( st, shb_speech, old_syn_12k8_16k[n] );
406 : }
407 :
408 : /*-------------------------------------------------------------------*
409 : * Inter-channel BWE encoding
410 : *-------------------------------------------------------------------*/
411 :
412 1129814 : if ( n == 0 && input_Fs >= 32000 && hStereoICBWE != NULL )
413 : {
414 48232 : stereo_icBWE_preproc( hCPE, input_frame, new_swb_speech_buffer /*tmp buffer*/ );
415 :
416 48232 : stereo_icBWE_enc( hCPE, shb_speech, new_swb_speech_buffer, voice_factors[0] );
417 : }
418 :
419 : /*---------------------------------------------------------------------*
420 : * Channel-aware mode - write signaling information into the bitstream
421 : *---------------------------------------------------------------------*/
422 :
423 1129814 : signaling_enc_rf( st );
424 :
425 : /*---------------------------------------------------------------------*
426 : * Common updates
427 : *---------------------------------------------------------------------*/
428 :
429 1129814 : if ( !MCT_flag ) /* for MCT do this later, otherwise there can be a problem because TCX quant happens later and might get the wrong last_core on a bit rate switch */
430 : {
431 589198 : updt_enc_common( st );
432 : }
433 : }
434 :
435 : /*------------------------------------------------------------------*
436 : * Write potentially unused bits in combined format coding
437 : *-----------------------------------------------------------------*/
438 :
439 768638 : if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 )
440 : {
441 101 : while ( diff_nBits > 0 )
442 : {
443 0 : n = min( diff_nBits, 16 );
444 0 : push_indice( sts[0]->hBstr, IND_UNUSED, 0, n );
445 0 : diff_nBits -= n;
446 : }
447 : }
448 :
449 : #ifdef DEBUG_MODE_INFO
450 : for ( n = 0; n < n_CoreChannels; n++ )
451 : {
452 : float tmpF;
453 : int16_t tmpS, id;
454 : #if defined DEBUG_MODE_ACELP || defined DEBUG_MODE_TCX
455 : int16_t k, _pitch[3], _pitch_buf[5];
456 : #endif
457 :
458 : st = sts[n];
459 : id = st->id_element;
460 :
461 : dbgwrite( &st->core, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "core", n, id, ENC ) );
462 : dbgwrite( &st->extl, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "extl", n, id, ENC ) );
463 : dbgwrite( &st->bwidth, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "bwidth", n, id, ENC ) );
464 : tmpF = st->total_brate / 1000.0f;
465 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "total_brate", n, id, ENC ) );
466 : tmpS = st->bits_frame_nominal;
467 : dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "bits_nominal", n, id, ENC ) );
468 : tmpF = st->core_brate / 1000.0f;
469 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "core_brate", n, id, ENC ) );
470 : tmpF = st->extl_brate / 1000.0f;
471 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "extl_brate", n, id, ENC ) );
472 :
473 : dbgwrite( &st->coder_type, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type", n, id, ENC ) );
474 : dbgwrite( &st->coder_type_raw, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type_raw", n, id, ENC ) );
475 : dbgwrite( &st->clas, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "clas", n, id, ENC ) );
476 : dbgwrite( &st->cng_type, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "cng_type", n, id, ENC ) );
477 : dbgwrite( &st->L_frame, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "L_frame", n, id, ENC ) );
478 : dbgwrite( &st->vad_flag, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "vad_flag", n, id, ENC ) );
479 : dbgwrite( &st->localVAD, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "localVAD", n, id, ENC ) );
480 :
481 : dbgwrite( &st->count_WB, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "count_WB", n, id, ENC ) );
482 : dbgwrite( &st->count_SWB, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "count_SWB", n, id, ENC ) );
483 :
484 : #ifdef DEBUG_MODE_ACELP
485 : dbgwrite( snr_[n], sizeof( float ), 320, 1, fname( debug_dir, "snr", n, id, ENC ) );
486 : #endif
487 : dbgwrite( &st->sp_aud_decision0, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "sp_aud_decision0", n, id, ENC ) );
488 : dbgwrite( &st->sp_aud_decision1, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "sp_aud_decision1", n, id, ENC ) );
489 : dbgwrite( &st->sp_aud_decision2, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "sp_aud_decision2", n, id, ENC ) );
490 :
491 : dbgwrite( &st->lp_noise, sizeof( float ), 1, input_frame, fname( debug_dir, "lp_noise", n, id, ENC ) );
492 :
493 : #if ( defined DEBUG_MODE_ACELP ) || ( defined DEBUG_MODE_TCX )
494 : if ( st->coder_type == INACTIVE || st->coder_type == UNVOICED )
495 : {
496 : _pitch[0] = 0;
497 : _pitch[1] = 0;
498 : _pitch[2] = 0;
499 : }
500 : else
501 : {
502 : _pitch[0] = st->pitch[0];
503 : _pitch[1] = st->pitch[1];
504 : _pitch[2] = st->pitch[2];
505 : }
506 : dbgwrite( &_pitch[0], sizeof( int16_t ), 1, ( input_frame / 8 * 3 ), fname( debug_dir, "pitch", n, id, ENC ) );
507 : dbgwrite( &_pitch[1], sizeof( int16_t ), 1, ( input_frame / 8 * 3 ), fname( debug_dir, "pitch", n, id, ENC ) );
508 : dbgwrite( &_pitch[2], sizeof( int16_t ), 1, ( input_frame / 8 * 2 ), fname( debug_dir, "pitch", n, id, ENC ) );
509 :
510 : if ( ( st->coder_type == INACTIVE ) || ( st->coder_type == UNVOICED ) )
511 : {
512 : set_s( _pitch_buf, 0, NB_SUBFR16k );
513 : }
514 : else if ( st->L_frame != L_FRAME )
515 : {
516 : for ( k = 0; k < NB_SUBFR16k; k++ )
517 : _pitch_buf[k] = (int16_t) ( pitch_buf[n][k] + 0.5f );
518 : }
519 : else
520 : {
521 : for ( k = 0; k < NB_SUBFR; k++ )
522 : _pitch_buf[k] = (int16_t) ( pitch_buf[n][k] * 5.0f / 4.0f + 0.5f );
523 : }
524 : if ( st->L_frame != L_FRAME )
525 : {
526 : for ( k = 0; k < NB_SUBFR16k; k++ )
527 : dbgwrite( &_pitch_buf[k], sizeof( int16_t ), 1, L_SUBFR, fname( debug_dir, "pitchCL", n, id, ENC ) );
528 : }
529 : else
530 : {
531 : for ( k = 0; k < NB_SUBFR; k++ )
532 : dbgwrite( &_pitch_buf[k], sizeof( int16_t ), 1, L_SUBFR16k, fname( debug_dir, "pitchCL", n, id, ENC ) );
533 : }
534 : #endif
535 :
536 : #ifdef DEBUG_MODE_ACELP
537 : if ( st->core != ACELP_CORE )
538 : {
539 : tmpF = 0.0f;
540 : dbgwrite( &tmpF, sizeof( float ), 1, st->L_frame, fname( debug_dir, "exc.enc", n, id, ENC ) );
541 : dbgwrite( &tmpF, sizeof( float ), 1, st->L_frame, fname( debug_dir, "resid", n, id, ENC ) );
542 : }
543 : if ( n_CoreChannels == 1 )
544 : {
545 : tmpS = -1;
546 : dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type", 2, id, ENC ) );
547 : tmpF = 0.0f;
548 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "total_brate", 2, id, ENC ) );
549 : tmpF = 0.0f;
550 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "core_brate", 2, id, ENC ) );
551 : tmpF = 0.0f;
552 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "extl_brate", 2, id, ENC ) );
553 : dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "vad_flag", 2, id, ENC ) );
554 : dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "localVAD", 2, id, ENC ) );
555 : }
556 :
557 : #endif
558 : }
559 : #endif
560 :
561 768638 : pop_wmops();
562 :
563 768638 : return error;
564 : }
|