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 : #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 11420105 : 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 11420105 : push_wmops( "ivas_core_enc" );
108 :
109 11420105 : error = IVAS_ERR_OK;
110 :
111 : /*------------------------------------------------------------------*
112 : * General initialization
113 : *-----------------------------------------------------------------*/
114 :
115 11420105 : if ( hSCE != NULL )
116 : {
117 4091766 : cpe_id = -1;
118 4091766 : MCT_flag = 0;
119 4091766 : sts = hSCE->hCoreCoder;
120 4091766 : hStereoTD = NULL;
121 4091766 : hStereoICBWE = NULL;
122 4091766 : element_brate = hSCE->element_brate;
123 4091766 : last_element_brate = hSCE->last_element_brate;
124 4091766 : last_element_mode = IVAS_SCE;
125 4091766 : tdm_Pitch_reuse_flag = -1;
126 : }
127 : else
128 : {
129 7328339 : cpe_id = hCPE->cpe_id;
130 7328339 : MCT_flag = 0;
131 7328339 : if ( hMCT != NULL )
132 : {
133 4769534 : MCT_flag = 1;
134 : }
135 7328339 : sts = hCPE->hCoreCoder;
136 7328339 : hStereoICBWE = hCPE->hStereoICBWE;
137 7328339 : element_brate = hCPE->element_brate;
138 7328339 : last_element_brate = hCPE->last_element_brate;
139 7328339 : last_element_mode = hCPE->last_element_mode;
140 :
141 7328339 : if ( hCPE->hStereoTD != NULL )
142 : {
143 31177 : hStereoTD = hCPE->hStereoTD;
144 31177 : tdm_Pitch_reuse_flag = hCPE->hStereoTD->tdm_Pitch_reuse_flag;
145 : }
146 : else
147 : {
148 7297162 : hStereoTD = NULL;
149 7297162 : tdm_Pitch_reuse_flag = -1;
150 : }
151 : }
152 :
153 11420105 : input_Fs = sts[0]->input_Fs;
154 11420105 : input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC );
155 :
156 29255760 : for ( n = 0; n < n_CoreChannels; n++ )
157 : {
158 17835655 : 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 17835655 : st->extl = -1;
169 17835655 : unbits[n] = 0;
170 :
171 17835655 : st->element_brate = element_brate;
172 :
173 : /*---------------------------------------------------------------------*
174 : * Pre-processing, incl. Decision matrix
175 : *---------------------------------------------------------------------*/
176 :
177 17835655 : 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 );
178 :
179 17835655 : if ( st->element_mode == IVAS_CPE_MDCT || st->element_mode == IVAS_SCE )
180 : {
181 16860512 : st->enablePlcWaveadjust = 0;
182 : }
183 : }
184 :
185 : /*------------------------------------------------------------------*
186 : * Sanity check in combined format coding
187 : *-----------------------------------------------------------------*/
188 :
189 11420105 : diff_nBits = 0;
190 11420105 : if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 )
191 : {
192 16911 : 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 );
193 : }
194 :
195 : /*---------------------------------------------------------------------*
196 : * Core Encoding
197 : *---------------------------------------------------------------------*/
198 :
199 29255760 : for ( n = 0; n < n_CoreChannels; n++ )
200 : {
201 17835655 : st = sts[n];
202 :
203 : /* update pointer to the buffer of indices of the second channel */
204 17835655 : if ( n == 1 && st->element_mode == IVAS_CPE_TD )
205 : {
206 : /* adjust the pointer to the buffer of indices of the secondary channel (make space for BWE indices) */
207 31177 : max_num_indices_BWE = get_BWE_max_num_indices( sts[0]->extl_brate );
208 31177 : st->hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot + max_num_indices_BWE;
209 :
210 : /* write TD stereo spatial parameters */
211 31177 : move_indices( hStereoTD->tdm_hBstr_tmp.ind_list, st->hBstr->ind_list, hStereoTD->tdm_hBstr_tmp.nb_ind_tot );
212 31177 : st->hBstr->nb_ind_tot += hStereoTD->tdm_hBstr_tmp.nb_ind_tot;
213 31177 : st->hBstr->nb_bits_tot += hStereoTD->tdm_hBstr_tmp.nb_bits_tot;
214 :
215 31177 : reset_indices_enc( &hStereoTD->tdm_hBstr_tmp, MAX_IND_TDM_TMP );
216 : }
217 :
218 : /*---------------------------------------------------------------------*
219 : * Write signaling info into the bitstream
220 : *---------------------------------------------------------------------*/
221 :
222 17835655 : if ( !MCT_flag || ( MCT_flag && cpe_id == 0 ) )
223 : {
224 11688531 : ivas_signaling_enc( st, MCT_flag, element_brate, tdm_SM_or_LRTD_Pri, tdm_Pitch_reuse_flag );
225 : }
226 :
227 : /*---------------------------------------------------------------------*
228 : * Preprocessing (preparing) for ACELP/HQ core switching
229 : *---------------------------------------------------------------------*/
230 :
231 17835655 : core_switching_pre_enc( st, old_inp_12k8[n], old_inp_16k[n], sts[0]->active_cnt, last_element_mode );
232 :
233 : /*---------------------------------------------------------------------*
234 : * ACELP core encoding
235 : * TCX core encoding
236 : * HQ core encoding
237 : *---------------------------------------------------------------------*/
238 :
239 17835655 : if ( st->core == ACELP_CORE )
240 : {
241 : /* ACELP core encoder */
242 1955131 : 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 )
243 : {
244 0 : return error;
245 : }
246 : }
247 :
248 17835655 : if ( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE ) && st->element_mode != IVAS_CPE_MDCT )
249 : {
250 : /* TCX core encoder */
251 3056246 : 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] );
252 : }
253 :
254 17835655 : if ( st->core == HQ_CORE )
255 : {
256 : /* HQ core encoder */
257 86688 : hq_core_enc( st, st->input, input_frame, NORMAL_HQ_CORE, Voicing_flag[n], vad_hover_flag[0] );
258 : }
259 :
260 : /*---------------------------------------------------------------------*
261 : * TD stereo updates
262 : *---------------------------------------------------------------------*/
263 :
264 17835655 : if ( st->element_mode == IVAS_CPE_TD && n == 0 )
265 : {
266 31177 : td_stereo_param_updt( st->lsp_old, st->lsf_old, pitch_buf[0], tdm_lsfQ_PCh, hStereoTD->tdm_Pri_pitch_buf, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc );
267 : }
268 : }
269 :
270 : /*---------------------------------------------------------------------*
271 : * MDCT stereo: joint TCX Core Encoding
272 : *---------------------------------------------------------------------*/
273 :
274 11420105 : if ( sts[0]->element_mode == IVAS_CPE_MDCT )
275 : {
276 6384373 : if ( sts[0]->core_brate > SID_2k40 && sts[1]->core_brate > SID_2k40 )
277 : {
278 6368795 : if ( MCT_flag )
279 : {
280 4769534 : 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],
281 4769534 : hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], hMCT->hBstr, 1, hMCT->nchan_out_woLFE );
282 : }
283 : else
284 : {
285 1599261 : stereo_mdct_core_enc( hCPE, old_inp_16k, old_wsp, pitch_buf );
286 : }
287 : }
288 15578 : else if ( sts[0]->core_brate == SID_2k40 && sts[1]->core_brate == SID_2k40 )
289 : {
290 : /* synch CNG configs between channels */
291 7008 : for ( n = 0; n < CPE_CHANNELS; n++ )
292 : {
293 4672 : st = sts[n];
294 4672 : if ( ( st->hFdCngEnc->hFdCngCom->frameSize != st->L_frame ) || ( st->hFdCngEnc->hFdCngCom->CngBandwidth != st->bwidth ) )
295 : {
296 1512 : configureFdCngEnc( st->hFdCngEnc, max( st->bwidth, WB ), st->L_frame == L_FRAME16k ? ACELP_16k40 : ACELP_9k60 );
297 : }
298 : }
299 :
300 2336 : if ( sts[0]->cng_sba_flag )
301 : {
302 540 : FdCngEncodeDiracMDCTStereoSID( hCPE );
303 : }
304 : else
305 : {
306 1796 : FdCngEncodeMDCTStereoSID( hCPE );
307 : }
308 : }
309 : }
310 :
311 : /*---------------------------------------------------------------------*
312 : * Postprocessing, BWEs and Updates
313 : *---------------------------------------------------------------------*/
314 :
315 29255760 : for ( n = 0; n < n_CoreChannels; n++ )
316 : {
317 17835655 : st = sts[n];
318 :
319 : /*---------------------------------------------------------------------*
320 : * Postprocessing for ACELP/HQ core switching
321 : *---------------------------------------------------------------------*/
322 :
323 17835655 : core_switching_post_enc( st, old_inp_12k8[n], old_inp_16k[n], A[n] );
324 :
325 : /*---------------------------------------------------------------------*
326 : * WB TBE encoding
327 : * WB BWE encoding
328 : *---------------------------------------------------------------------*/
329 :
330 17835655 : hb_speech = new_swb_speech_buffer; /* reuse existing buffer: hb_speech[L_FRAME16k/4]; */
331 :
332 17835655 : if ( input_Fs >= 16000 && st->bwidth < SWB && st->hBWE_TD != NULL )
333 : {
334 : /* Common pre-processing for WB TBE and WB BWE */
335 825448 : wb_pre_proc( st, last_element_mode, new_inp_resamp16k[n], hb_speech );
336 : }
337 :
338 17835655 : if ( st->extl == WB_TBE )
339 : {
340 : /* WB TBE encoder */
341 76612 : wb_tbe_enc( st, hb_speech, bwe_exc_extended[n], voice_factors[n], pitch_buf[n] );
342 : }
343 17759043 : else if ( st->extl == WB_BWE && n == 0 && st->element_mode != IVAS_CPE_MDCT )
344 : {
345 : /* WB BWE encoder */
346 298215 : wb_bwe_enc( st, new_inp_resamp16k[n] );
347 : }
348 :
349 : /*---------------------------------------------------------------------*
350 : * SWB(FB) TBE encoding
351 : * SWB(FB) BWE encoding
352 : *---------------------------------------------------------------------*/
353 :
354 17835655 : new_swb_speech = new_swb_speech_buffer + STEREO_DFT_OVL_MAX;
355 17835655 : set_f( new_swb_speech_buffer, 0, L_FRAME48k + STEREO_DFT_OVL_MAX );
356 17835655 : shb_speech = new_inp_resamp16k[n]; /* reuse existing buffer: shb_speech[L_FRAME16k] */
357 :
358 17835655 : if ( !st->Opt_SC_VBR && input_Fs >= 32000 && st->hBWE_TD != NULL )
359 : {
360 : /* Common pre-processing for SWB(FB) TBE and SWB(FB) BWE */
361 4702693 : swb_pre_proc( st, new_swb_speech, shb_speech, realBuffer[n], imagBuffer[n], hCPE );
362 : }
363 13132962 : else if ( input_Fs >= 32000 )
364 : {
365 11805571 : if ( st->hBWE_TD != NULL )
366 : {
367 0 : InitSWBencBufferStates( st->hBWE_TD, shb_speech );
368 : }
369 : }
370 :
371 : /* SWB TBE encoder */
372 17835655 : if ( st->extl == SWB_TBE || st->extl == FB_TBE )
373 : {
374 1225926 : if ( st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 )
375 : {
376 : float fb_exc[L_FRAME16k];
377 :
378 1225926 : swb_tbe_enc( st, hStereoICBWE, shb_speech, bwe_exc_extended[n], voice_factors[n], fb_exc, pitch_buf[n] );
379 :
380 1225926 : if ( st->extl == FB_TBE )
381 : {
382 : /* FB TBE encoder */
383 433831 : fb_tbe_enc( st, st->input, fb_exc );
384 : }
385 : }
386 : }
387 16609729 : else if ( st->extl == SWB_BWE || st->extl == FB_BWE )
388 : {
389 : /* SWB(FB) BWE encoder */
390 120447 : 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 );
391 : }
392 :
393 : /*---------------------------------------------------------------------*
394 : * SWB DTX/CNG encoding
395 : *---------------------------------------------------------------------*/
396 :
397 17835655 : if ( st->hTdCngEnc != NULL && st->Opt_DTX_ON && ( input_frame >= L_FRAME32k || st->element_mode == IVAS_CPE_DFT ) )
398 : {
399 : /* SHB DTX/CNG encoder */
400 674421 : swb_CNG_enc( st, shb_speech, old_syn_12k8_16k[n] );
401 : }
402 :
403 : /*-------------------------------------------------------------------*
404 : * Inter-channel BWE encoding
405 : *-------------------------------------------------------------------*/
406 :
407 17835655 : if ( n == 0 && input_Fs >= 32000 && hStereoICBWE != NULL )
408 : {
409 764736 : stereo_icBWE_preproc( hCPE, input_frame, new_swb_speech_buffer /*tmp buffer*/ );
410 :
411 764736 : stereo_icBWE_enc( hCPE, shb_speech, new_swb_speech_buffer, voice_factors[0] );
412 : }
413 :
414 : /*---------------------------------------------------------------------*
415 : * Common updates
416 : *---------------------------------------------------------------------*/
417 :
418 17835655 : 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 */
419 : {
420 8296587 : updt_enc_common( st );
421 : }
422 : }
423 :
424 : /*------------------------------------------------------------------*
425 : * Write potentially unused bits in combined format coding
426 : *-----------------------------------------------------------------*/
427 :
428 11420105 : if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 )
429 : {
430 17313 : while ( diff_nBits > 0 )
431 : {
432 402 : n = min( diff_nBits, 16 );
433 402 : push_indice( sts[0]->hBstr, IND_UNUSED, 0, n );
434 402 : diff_nBits -= n;
435 : }
436 : }
437 :
438 : #ifdef DEBUG_MODE_INFO
439 : for ( n = 0; n < n_CoreChannels; n++ )
440 : {
441 : float tmpF;
442 : int16_t tmpS, id;
443 : #if defined DEBUG_MODE_ACELP || defined DEBUG_MODE_TCX
444 : int16_t k, _pitch[3], _pitch_buf[5];
445 : #endif
446 :
447 : st = sts[n];
448 : id = st->id_element;
449 :
450 : dbgwrite( &st->core, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "core", n, id, ENC ) );
451 : dbgwrite( &st->extl, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "extl", n, id, ENC ) );
452 : dbgwrite( &st->bwidth, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "bwidth", n, id, ENC ) );
453 : tmpF = st->total_brate / 1000.0f;
454 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "total_brate", n, id, ENC ) );
455 : tmpS = st->bits_frame_nominal;
456 : dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "bits_nominal", n, id, ENC ) );
457 : tmpF = st->core_brate / 1000.0f;
458 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "core_brate", n, id, ENC ) );
459 : tmpF = st->extl_brate / 1000.0f;
460 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "extl_brate", n, id, ENC ) );
461 :
462 : dbgwrite( &st->coder_type, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type", n, id, ENC ) );
463 : dbgwrite( &st->coder_type_raw, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type_raw", n, id, ENC ) );
464 : dbgwrite( &st->clas, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "clas", n, id, ENC ) );
465 : dbgwrite( &st->cng_type, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "cng_type", n, id, ENC ) );
466 : dbgwrite( &st->L_frame, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "L_frame", n, id, ENC ) );
467 : dbgwrite( &st->vad_flag, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "vad_flag", n, id, ENC ) );
468 : dbgwrite( &st->localVAD, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "localVAD", n, id, ENC ) );
469 :
470 : dbgwrite( &st->count_WB, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "count_WB", n, id, ENC ) );
471 : dbgwrite( &st->count_SWB, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "count_SWB", n, id, ENC ) );
472 :
473 : #ifdef DEBUG_MODE_ACELP
474 : dbgwrite( snr_[n], sizeof( float ), 320, 1, fname( debug_dir, "snr", n, id, ENC ) );
475 : #endif
476 : dbgwrite( &st->sp_aud_decision0, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "sp_aud_decision0", n, id, ENC ) );
477 : dbgwrite( &st->sp_aud_decision1, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "sp_aud_decision1", n, id, ENC ) );
478 : dbgwrite( &st->sp_aud_decision2, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "sp_aud_decision2", n, id, ENC ) );
479 :
480 : dbgwrite( &st->lp_noise, sizeof( float ), 1, input_frame, fname( debug_dir, "lp_noise", n, id, ENC ) );
481 :
482 : #if ( defined DEBUG_MODE_ACELP ) || ( defined DEBUG_MODE_TCX )
483 : if ( st->coder_type == INACTIVE || st->coder_type == UNVOICED )
484 : {
485 : _pitch[0] = 0;
486 : _pitch[1] = 0;
487 : _pitch[2] = 0;
488 : }
489 : else
490 : {
491 : _pitch[0] = st->pitch[0];
492 : _pitch[1] = st->pitch[1];
493 : _pitch[2] = st->pitch[2];
494 : }
495 : dbgwrite( &_pitch[0], sizeof( int16_t ), 1, ( input_frame / 8 * 3 ), fname( debug_dir, "pitch", n, id, ENC ) );
496 : dbgwrite( &_pitch[1], sizeof( int16_t ), 1, ( input_frame / 8 * 3 ), fname( debug_dir, "pitch", n, id, ENC ) );
497 : dbgwrite( &_pitch[2], sizeof( int16_t ), 1, ( input_frame / 8 * 2 ), fname( debug_dir, "pitch", n, id, ENC ) );
498 :
499 : if ( ( st->coder_type == INACTIVE ) || ( st->coder_type == UNVOICED ) )
500 : {
501 : set_s( _pitch_buf, 0, NB_SUBFR16k );
502 : }
503 : else if ( st->L_frame != L_FRAME )
504 : {
505 : for ( k = 0; k < NB_SUBFR16k; k++ )
506 : _pitch_buf[k] = (int16_t) ( pitch_buf[n][k] + 0.5f );
507 : }
508 : else
509 : {
510 : for ( k = 0; k < NB_SUBFR; k++ )
511 : _pitch_buf[k] = (int16_t) ( pitch_buf[n][k] * 5.0f / 4.0f + 0.5f );
512 : }
513 : if ( st->L_frame != L_FRAME )
514 : {
515 : for ( k = 0; k < NB_SUBFR16k; k++ )
516 : dbgwrite( &_pitch_buf[k], sizeof( int16_t ), 1, L_SUBFR, fname( debug_dir, "pitchCL", n, id, ENC ) );
517 : }
518 : else
519 : {
520 : for ( k = 0; k < NB_SUBFR; k++ )
521 : dbgwrite( &_pitch_buf[k], sizeof( int16_t ), 1, L_SUBFR16k, fname( debug_dir, "pitchCL", n, id, ENC ) );
522 : }
523 : #endif
524 :
525 : #ifdef DEBUG_MODE_ACELP
526 : if ( st->core != ACELP_CORE )
527 : {
528 : tmpF = 0.0f;
529 : dbgwrite( &tmpF, sizeof( float ), 1, st->L_frame, fname( debug_dir, "exc.enc", n, id, ENC ) );
530 : dbgwrite( &tmpF, sizeof( float ), 1, st->L_frame, fname( debug_dir, "resid", n, id, ENC ) );
531 : }
532 : if ( n_CoreChannels == 1 )
533 : {
534 : tmpS = -1;
535 : dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type", 2, id, ENC ) );
536 : tmpF = 0.0f;
537 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "total_brate", 2, id, ENC ) );
538 : tmpF = 0.0f;
539 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "core_brate", 2, id, ENC ) );
540 : tmpF = 0.0f;
541 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "extl_brate", 2, id, ENC ) );
542 : dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "vad_flag", 2, id, ENC ) );
543 : dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "localVAD", 2, id, ENC ) );
544 : }
545 :
546 : #endif
547 : }
548 : #endif
549 :
550 11420105 : pop_wmops();
551 :
552 11420105 : return error;
553 : }
|