Line data Source code
1 : /******************************************************************************
2 : * ETSI TS 103 634 V1.5.1 *
3 : * Low Complexity Communication Codec Plus (LC3plus) *
4 : * *
5 : * Copyright licence is solely granted through ETSI Intellectual Property *
6 : * Rights Policy, 3rd April 2019. No patent licence is granted by implication, *
7 : * estoppel or otherwise. *
8 : ******************************************************************************/
9 :
10 : #include "functions.h"
11 : #include "setup_dec_lc3.h"
12 :
13 : /* if decoder is null only size is reported */
14 : /*assume 10ms for memory allocation for now */
15 0 : int alloc_decoder(LC3PLUS_Dec *decoder, int samplerate, int channels)
16 : {
17 0 : int ch = 0;
18 0 : size_t size = sizeof(LC3PLUS_Dec);
19 0 : void * ltpf_mem_x = NULL, *ltpf_mem_y = NULL, *stDec_ola_mem_fx = NULL;
20 0 : int max_len = DYN_MAX_LEN_EXT(samplerate); /*NB sing 80 as minimum value changes BE for NB */
21 0 : Word32 * plc_longterm_advc_tdc = NULL, *plc_longterm_advc_ns = NULL;
22 0 : Word16 longterm_analysis_counter_max = 0, longterm_analysis_counter_max_bytebuffer = 0;
23 :
24 0 : void *q_old_res_fx = NULL;
25 0 : Word16 *sharedBuf = NULL;
26 : #if defined(ENABLE_PC)
27 0 : void *q_old_d_fx = NULL;
28 : #endif
29 0 : void *plcAd = NULL, *PhECU_f0est = NULL, *PhECU_plocs = NULL;
30 :
31 0 : for (ch = 0; ch < channels; ch++)
32 : {
33 0 : DecSetup *setup = balloc(decoder, &size, sizeof(DecSetup));
34 : #ifdef ENABLE_HR_MODE
35 0 : int q_old_len = MIN(CODEC_FS(samplerate) * 100 / 10000, MAX_BW_HR);
36 : #else
37 : int q_old_len = MIN(CODEC_FS(samplerate) * 100 / 10000, MAX_BW );
38 : #endif
39 0 : int x_old_len = DYN_MAX_LEN_PCM_PLC(samplerate); /* max(pitchmax + frame ms, M+1 + pitchmax + frame/2) */
40 0 : int fs_idx = (samplerate / 10000); /* floor= integer truncation is needed here */
41 :
42 0 : ltpf_mem_x = balloc(decoder, &size, sizeof(*setup->ltpf_mem_x) * (max_len + max_len / 40 - 2));
43 : ltpf_mem_y =
44 0 : balloc(decoder, &size,
45 0 : sizeof(*setup->ltpf_mem_y) * (max_len + CEILING(MAX_PITCH_12K8 * max_len, 128) + (max_len / 80)));
46 :
47 0 : stDec_ola_mem_fx = balloc(decoder, &size, sizeof(*setup->stDec_ola_mem_fx) * DYN_MAX_MDCT_LEN(samplerate));
48 :
49 : #if defined(ENABLE_PC)
50 0 : q_old_d_fx = balloc(decoder, &size, sizeof(*setup->q_old_d_fx) * q_old_len);
51 : #endif
52 0 : sharedBuf = balloc(decoder, &size, sizeof(*setup->q_old_d_fx) * q_old_len + sizeof(*setup->plcAd->x_old_tot_fx) * x_old_len);
53 :
54 : /* To save static RAM, a large buffer sharedBuf is used to share
55 : * space for q_old_d_fx, x_old_tot_fx and X_sav_fx (note:
56 : * PHASE_ECU operates only at 10ms and standard precision)
57 : *
58 : * If partial Concealment is active, q_old_d_fx is saved in a separate buffer
59 : *
60 : * The following graph provides an overview about the memory
61 : * sharing for 10ms and normal resolution:
62 : */
63 :
64 : /* Total buffer | <--- sharedBuf ---> | */
65 : /* ConcealMethod 3or4 | <---q_old_d_fx---> | <-------------------- x_old_tot_fx ------------------> | */
66 : /* ConcealMethod 3 | <---q_old_d_fx---> | |<------- M+1+pitch_max+ (frame_len/2)----------> | */ /* first BFI-frame only? */
67 : /* Meth 2,prevBfi=0 | | <------- 16 ms xfp ------->| */
68 : /* Meth 2 | ^ X_sav_fx ptr | <-------- maintained old_tot_fx ---------> | */ /* pitchmax samples maintained */
69 : /* Meth 2 | <----- X_sav 16 ms ----------> | ^xfp_fx ptr | */
70 : /* Meth2 ,prevBfi=1 | | <-12.25(forTDC),3.75(PLC2)->| */ /*the part used by PhECU is 3.75ms */
71 : /* ConcealMethod 2 |<- <10ms ->| */
72 0 : int max_plocs = DYN_MAX_PLOCS(samplerate);
73 0 : plcAd = balloc(decoder, &size, sizeof(*setup->plcAd));
74 0 : PhECU_f0est = balloc(decoder, &size, sizeof(*setup->plcAd->PhECU_f0est) * max_plocs);
75 0 : PhECU_plocs = balloc(decoder, &size, sizeof(*setup->plcAd->PhECU_plocs) * max_plocs);
76 : #ifdef ENABLE_HR_MODE
77 0 : q_old_res_fx = balloc(decoder, &size, sizeof(*setup->q_old_res_fx) * max_len);
78 : #else
79 : q_old_res_fx = balloc(decoder, &size, sizeof(*setup->q_old_res_fx) * MIN(max_len, MAX_BW));
80 : #endif
81 :
82 : /* longterm_analysis_counter_max = PLC_LONGTERM_ANALYSIS_MS * (100.0f / 25.0f);*/
83 : /* assert(longterm_analysis_counter_max == (PLC_LONGTERM_ANALYSIS_MS * (100 /25))); */ /* test integer division for compatibility */
84 : /* longterm_analysis_counter_max_bytebuffer = floor(longterm_analysis_counter_max / 30.0); */
85 : /* assert(longterm_analysis_counter_max_bytebuffer == (longterm_analysis_counter_max / 30)); */ /* test integer division for compatibility */
86 :
87 : /* longterm_analysis_counter_max = (longterm_analysis_counter_max_bytebuffer+1) * 30; */
88 :
89 0 : longterm_analysis_counter_max = plc_fadeout_param_maxlen[0];
90 0 : longterm_analysis_counter_max_bytebuffer = plc_fadeout_param_maxbytes[0];
91 :
92 0 : plc_longterm_advc_tdc = balloc(decoder, &size, sizeof(Word32) * longterm_analysis_counter_max_bytebuffer);
93 0 : plc_longterm_advc_ns = balloc(decoder, &size, sizeof(Word32) * longterm_analysis_counter_max_bytebuffer);
94 :
95 0 : if (decoder)
96 : {
97 0 : decoder->channel_setup[ch] = setup;
98 0 : setup->ltpf_mem_x = ltpf_mem_x;
99 0 : setup->ltpf_mem_y = ltpf_mem_y;
100 0 : setup->stDec_ola_mem_fx = stDec_ola_mem_fx;
101 0 : setup->q_old_res_fx = q_old_res_fx;
102 : #if defined(ENABLE_PC)
103 0 : setup->q_old_d_fx = q_old_d_fx;
104 : #else
105 : setup->q_old_d_fx = sharedBuf;
106 : #endif
107 0 : setup->plcAd = plcAd;
108 : }
109 0 : if (decoder && plcAd)
110 : {
111 : #ifdef ENABLE_HR_MODE
112 0 : if (fs_idx > 4)
113 : {
114 0 : fs_idx = 4;
115 : }
116 : #endif
117 :
118 0 : setup->plcAd->x_old_tot_fx = &sharedBuf[q_old_len];
119 0 : setup->plcAd->PhECU_f0est = PhECU_f0est;
120 0 : setup->plcAd->PhECU_xfp_fx = &(setup->plcAd->x_old_tot_fx[x_old_len-LprotSzPtr[fs_idx]]); /* point to the last 16ms of the x_old_tot_fx */
121 0 : setup->plcAd->PhECU_X_sav_fx = sharedBuf; /* reuse of lprot(=num_FsByResQ0[fs_idx]) values from this point fwd, i.e beyond the end of q_old_fx */
122 0 : setup->plcAd->PhECU_plocs = PhECU_plocs;
123 :
124 0 : setup->plcAd->longterm_analysis_counter_max = longterm_analysis_counter_max;
125 0 : setup->plcAd->longterm_analysis_counter_max_bytebuffer = longterm_analysis_counter_max_bytebuffer;
126 :
127 0 : setup->plcAd->plc_longterm_advc_tdc = plc_longterm_advc_tdc;
128 0 : setup->plcAd->plc_longterm_advc_ns = plc_longterm_advc_ns;
129 : }
130 : }
131 :
132 0 : return (int)size;
133 : }
134 :
135 0 : LC3PLUS_Error FillDecSetup(LC3PLUS_Dec *decoder, int samplerate, int channels, LC3PLUS_PlcMode plc_mode
136 : #ifdef ENABLE_HR_MODE
137 : , int hrmode
138 : #endif
139 : )
140 : {
141 0 : int ch = 0;
142 :
143 0 : memset(decoder, 0, lc3plus_dec_get_size(samplerate, channels, plc_mode));
144 0 : alloc_decoder(decoder, samplerate, channels);
145 :
146 : #ifdef ENABLE_HR_MODE
147 0 : decoder->hrmode = hrmode != 0;
148 : #endif
149 :
150 0 : decoder->fs = CODEC_FS(samplerate);
151 0 : decoder->fs_out = samplerate;
152 0 : decoder->fs_idx = FS2FS_IDX(decoder->fs);
153 0 : decoder->channels = channels;
154 0 : decoder->frame_dms = 100;
155 0 : decoder->plcMeth = plc_mode;
156 : {
157 0 : decoder->BW_cutoff_bits = BW_cutoff_bits_all[decoder->fs_idx];
158 : }
159 0 : decoder->ltpf_mem_x_len = extract_l(L_shr_pos(Mpy_32_16_lc3plus(L_max(16000, decoder->fs), 16778), 11)) - 2;
160 0 : decoder->ltpf_mem_y_len = extract_l(L_shr_pos(Mpy_32_16_lc3plus(decoder->fs, 18678) - 1, 5)) + 1 +
161 0 : extract_l(L_shr_pos(Mpy_32_16_lc3plus(L_max(16000, decoder->fs), 16778), 12));
162 :
163 0 : set_dec_frame_params(decoder);
164 :
165 0 : for (ch = 0; ch < decoder->channels; ch++)
166 : {
167 0 : DecSetup *setup = decoder->channel_setup[ch];
168 0 : setup->plc_damping = 32767;
169 0 : setup->ltpf_mem_scale_fac_idx = -1;
170 0 : move16();
171 :
172 0 : setup->pc_seed = 24607;
173 0 : setup->ns_seed = 24607;
174 0 : setup->ns_cum_alpha = 32767;
175 :
176 0 : int i = 0;
177 : /* 0 = 0kHz 1= 8kHz, 2= 16 kHz 3= 24 , 4 = 32 5=40 6=48kHz */
178 : #if (PHECU_XFP_LA == 0)
179 0 : Word16 oneMsTab_LA[5] = {0, 0, 0, 0, 0};
180 : #else
181 : #if (PHECU_XFP_LA == 4)
182 : Word16 oneMsTab_LA[7] = {0 /*unused*/, 2, 4, 6, 8, 10 /*unused*/, 12};
183 : #else
184 : Word16 oneMsTab_LA[7] = {0 /*unused*/, 8, 16, 24, 32, 40 /*unused*/, 48};
185 : #endif
186 : #endif
187 0 : Word16 oneMsTab[5] = {8, 16, 24, 32, 48};
188 :
189 0 : setup->plcAd->stab_fac = 32767;
190 0 : setup->plcAd->tdc_seed = 24607;
191 0 : setup->plcAd->tdc_preemph_fac = plc_preemph_fac[decoder->fs_idx];
192 0 : setup->plcAd->tdc_lpc_order = 16;
193 0 : setup->plcAd->PhECU_fs_idx_fx =
194 0 : mult(decoder->frame_length,
195 : (Word16)(32768.0 / 99.0)); /* truncation needed , i.e no rounding can be applied here */
196 : /* idx=frame/80, 0=8kHZ, 1=16kHz, 2=24 kHz, 3=32 kHz 5=*, 4=48 */
197 :
198 0 : setup->plcAd->max_len_pcm_plc = DYN_MAX_LEN_PCM_PLC(decoder->fs);
199 :
200 0 : if ((decoder->hrmode == 0) && (samplerate <= 48000))
201 : {
202 0 : setup->plcAd->PhECU_frame_ms = (Word16)(
203 0 : decoder->frame_dms * 0.1); /* needed in PLCUpdate and PLC main functions, adjusted in first frame */
204 0 : setup->plcAd->PhECU_seed_fx = 21845;
205 0 : setup->plcAd->PhECU_LprotOrg_fx =
206 0 : shl_pos(oneMsTab[setup->plcAd->PhECU_fs_idx_fx], 4); /* 16 *1ms = 1.6 *framelength */
207 0 : setup->plcAd->PhECU_Lprot_fx = setup->plcAd->PhECU_LprotOrg_fx;
208 0 : setup->plcAd->PhECU_LA = oneMsTab_LA[setup->plcAd->PhECU_fs_idx_fx];
209 0 : setup->plcAd->PhECU_whr_tot_taper = sub(setup->plcAd->PhECU_Lprot_fx, decoder->frame_length); /* 3+3 ms */
210 0 : setup->plcAd->PhECU_whr_tot_flat = decoder->frame_length; /* 10 ms */
211 0 : setup->plcAd->PhECU_LDWIN_OLAP = shr_pos(decoder->frame_length, 2); /* 2.5 ms */
212 0 : setup->plcAd->max_lprot = DYN_MAX_LPROT(decoder->fs);
213 0 : setup->plcAd->max_plocs = DYN_MAX_PLOCS(decoder->fs);
214 0 : setup->plcAd->PhECU_margin_xfp = 0;
215 0 : setup->plcAd->PhECU_L_oold_xfp_w_E_fx = LTOT_MIN_MAN;
216 0 : setup->plcAd->PhECU_L_old_xfp_w_E_fx = LTOT_MIN_MAN;
217 :
218 0 : setup->plcAd->PhECU_oold_xfp_w_E_exp_fx = UNINIT_OR_UNSAFE_OOLD_SENTINEL;
219 0 : setup->plcAd->PhECU_old_xfp_w_E_exp_fx = LTOT_INIT_FLAG;
220 :
221 0 : setup->plcAd->PhECU_oold_Ltot_exp_fx = UNINIT_OR_UNSAFE_OOLD_SENTINEL;
222 0 : setup->plcAd->PhECU_old_Ltot_exp_fx = LTOT_INIT_FLAG;
223 :
224 :
225 0 : for (i = 0; i < MAX_LGW; i++)
226 : {
227 0 : setup->plcAd->PhECU_oold_grp_shape_fx[i] =
228 : GRP_SHAPE_INIT; /* negative value will be replaced in very first calculation */
229 0 : setup->plcAd->PhECU_old_grp_shape_fx[i] = GRP_SHAPE_INIT;
230 : }
231 : /* t_adv=ctrl.FRAME/2 + ctrl.PhECU.LprotOrg/2 - ctrl.PhECU.LA + LDWIN_OLAP/2; */
232 0 : i = add(add(decoder->frame_length, setup->plcAd->PhECU_LprotOrg_fx), setup->plcAd->PhECU_LDWIN_OLAP);
233 0 : setup->plcAd->PhECU_t_adv = sub(shr_pos(i, 1), setup->plcAd->PhECU_LA);
234 :
235 0 : for (i = 0; i < MAX_LGW; i++)
236 : {
237 0 : setup->plcAd->PhECU_mag_chg_1st[i] = 32767;
238 : }
239 0 : setup->plcAd->PhECU_beta_mute = 16384;
240 0 : setup->plcAd->PhECU_nonpure_tone_flag = -1;
241 : }
242 : }
243 :
244 0 : lc3plus_dec_set_ep_enabled(decoder, 0);
245 0 : return LC3PLUS_OK;
246 : }
247 :
248 : /* set frame config params */
249 0 : void set_dec_frame_params(LC3PLUS_Dec *decoder)
250 : {
251 0 : Word16 tmp = 0;
252 : Word16 n;
253 :
254 0 : decoder->frame_length = extract_l(L_shr_pos(Mpy_32_16_lc3plus(decoder->fs, 20972), 6)); /* fs * 0.01*2^6 */
255 :
256 : #ifdef ENABLE_HR_MODE
257 0 : if (decoder->hrmode)
258 : {
259 0 : decoder->BW_cutoff_bits = 0;
260 : }
261 : #endif
262 :
263 0 : SWITCH (decoder->frame_dms)
264 : {
265 0 : case 25:
266 0 : decoder->frame_length = shr_pos(decoder->frame_length, 2);
267 0 : decoder->la_zeroes = LowDelayShapes_n960_la_zeroes_2_5ms[decoder->fs_idx];
268 0 : decoder->stDec_ola_mem_fx_len = sub(decoder->frame_length, decoder->la_zeroes);
269 :
270 : #ifdef ENABLE_HR_MODE
271 0 : if (decoder->hrmode)
272 : {
273 0 : decoder->bands_number = bands_number_2_5ms_HR[decoder->fs_idx];
274 0 : decoder->bands_offset = bands_offset_2_5ms_HR[decoder->fs_idx - 4];
275 0 : decoder->W_fx = LowDelayShapes_n960_HRA_2_5ms[decoder->fs_idx - 4];
276 0 : decoder->W_size = LowDelayShapes_n960_len_2_5ms[decoder->fs_idx];
277 0 : decoder->yLen = decoder->frame_length;
278 : }
279 : else
280 : #endif
281 : {
282 0 : decoder->bands_number = bands_number_2_5ms[decoder->fs_idx];
283 0 : decoder->bands_offset = bands_offset_2_5ms[decoder->fs_idx];
284 0 : decoder->W_fx = LowDelayShapes_n960_2_5ms[decoder->fs_idx];
285 0 : decoder->W_size = LowDelayShapes_n960_len_2_5ms[decoder->fs_idx];
286 0 : decoder->yLen = s_min(MAX_BW >> 2, decoder->frame_length);
287 : }
288 :
289 0 : if (decoder->fs_idx == 0)
290 : {
291 : int ch;
292 0 : for (ch = 0; ch < decoder->channels; ch++)
293 : {
294 0 : DecSetup *setup = decoder->channel_setup[ch];
295 0 : if (setup->plcAd != NULL)
296 : {
297 0 : setup->plcAd->tdc_lpc_order = 8;
298 : }
299 : }
300 : }
301 0 : BREAK;
302 0 : case 50:
303 0 : decoder->frame_length = shr_pos(decoder->frame_length, 1);
304 0 : decoder->la_zeroes = LowDelayShapes_n960_la_zeroes_5ms[decoder->fs_idx];
305 0 : decoder->stDec_ola_mem_fx_len = sub(decoder->frame_length, decoder->la_zeroes);
306 :
307 : #ifdef ENABLE_HR_MODE
308 0 : if (decoder->hrmode)
309 : {
310 0 : decoder->bands_offset = bands_offset_5ms_HR[decoder->fs_idx - 4];
311 0 : decoder->W_fx = LowDelayShapes_n960_HRA_5ms[decoder->fs_idx - 4];
312 0 : decoder->W_size = LowDelayShapes_n960_len_5ms[decoder->fs_idx];
313 0 : decoder->yLen = decoder->frame_length;
314 0 : decoder->bands_number = bands_number_5ms[decoder->fs_idx];
315 : }
316 : else
317 : #endif
318 : {
319 0 : decoder->bands_offset = bands_offset_5ms[decoder->fs_idx];
320 0 : decoder->W_fx = LowDelayShapes_n960_5ms[decoder->fs_idx];
321 0 : decoder->W_size = LowDelayShapes_n960_len_5ms[decoder->fs_idx];
322 0 : decoder->yLen = s_min(MAX_BW >> 1, decoder->frame_length);
323 0 : decoder->bands_number = bands_number_5ms[decoder->fs_idx];
324 : }
325 0 : BREAK;
326 :
327 0 : case 75:
328 0 : tmp = shr_pos(decoder->frame_length, 2);
329 0 : decoder->frame_length = add(tmp, add(tmp, tmp));
330 0 : decoder->la_zeroes = LowDelayShapes_n960_la_zeroes_7_5ms[decoder->fs_idx];
331 0 : decoder->stDec_ola_mem_fx_len = sub(decoder->frame_length, decoder->la_zeroes);
332 : #ifdef ENABLE_HR_MODE
333 0 : if (decoder->hrmode)
334 : {
335 0 : decoder->bands_offset = bands_offset_7_5ms_HR[decoder->fs_idx - 4];
336 0 : decoder->W_fx = LowDelayShapes_n960_HRA_7_5ms[decoder->fs_idx - 4];
337 0 : decoder->W_size = LowDelayShapes_n960_len_7_5ms[decoder->fs_idx];
338 0 : decoder->yLen = decoder->frame_length;
339 0 : decoder->bands_number = bands_number_7_5ms[decoder->fs_idx];
340 : }
341 : else
342 : #endif
343 : {
344 0 : decoder->bands_offset = bands_offset_7_5ms[decoder->fs_idx];
345 0 : decoder->W_fx = LowDelayShapes_n960_7_5ms[decoder->fs_idx];
346 0 : decoder->W_size = LowDelayShapes_n960_len_7_5ms[decoder->fs_idx];
347 0 : decoder->yLen = s_min((MAX_BW >> 2) * 3, decoder->frame_length);
348 0 : decoder->bands_number = bands_number_7_5ms[decoder->fs_idx];
349 : }
350 0 : BREAK;
351 :
352 0 : case 100:
353 0 : decoder->la_zeroes = LowDelayShapes_n960_la_zeroes[decoder->fs_idx];
354 0 : decoder->stDec_ola_mem_fx_len = sub(decoder->frame_length, decoder->la_zeroes);
355 0 : decoder->bands_number = 64;
356 :
357 : #ifdef ENABLE_HR_MODE
358 0 : if (decoder->hrmode)
359 : {
360 0 : decoder->bands_offset = bands_offset_HR[decoder->fs_idx - 4];
361 0 : decoder->W_fx = LowDelayShapes_n960_HRA[decoder->fs_idx - 4];
362 0 : decoder->W_size = LowDelayShapes_n960_len[decoder->fs_idx];
363 0 : decoder->yLen = decoder->frame_length;
364 : }
365 : else
366 : #endif
367 : {
368 0 : decoder->W_fx = LowDelayShapes_n960[decoder->fs_idx];
369 0 : decoder->W_size = LowDelayShapes_n960_len[decoder->fs_idx];
370 0 : decoder->bands_offset = bands_offset[decoder->fs_idx];
371 0 : decoder->yLen = s_min(MAX_BW, decoder->frame_length);
372 : }
373 0 : BREAK;
374 : }
375 :
376 0 : {
377 : int ch;
378 0 : for (ch = 0; ch < decoder->channels; ch++)
379 : {
380 0 : DecSetup *setup = decoder->channel_setup[ch];
381 0 : if (setup->plcAd != NULL)
382 : { /*only set if plcAd was actually allocated */
383 0 : setup->plcAd->longterm_analysis_counter_max = plc_fadeout_param_maxlen[(decoder->frame_dms / 25) - 1];
384 0 : setup->plcAd->longterm_analysis_counter_max_bytebuffer = plc_fadeout_param_maxbytes[(decoder->frame_dms / 25) - 1];
385 0 : setup->plcAd->PhECU_frame_ms = (Word16)(
386 0 : decoder->frame_dms *
387 : 0.1); /* needed in processPLCupdate_fx(), now set properly set in first frame /second time */
388 : }
389 : }
390 : }
391 0 : FOR (n=0; n < PLC_FADEOUT_TYPE_1_IN_MS*10/decoder->frame_dms;n++){
392 0 : decoder->alpha_type_2_table[n] = type_2_fadeout_fx(n, decoder->frame_dms);
393 : }
394 0 : }
395 :
396 0 : LC3PLUS_Error update_dec_bitrate(LC3PLUS_Dec *decoder, int ch, Word16 nBytes)
397 : {
398 0 : int tmp = 0, totalBits = 0;
399 0 : int channel_bytes = 0;
400 : int minBytes, maxBytes;
401 :
402 0 : DecSetup *setup = decoder->channel_setup[ch];
403 0 : channel_bytes = nBytes;
404 :
405 : #ifdef ENABLE_HR_MODE
406 0 : if (decoder->hrmode)
407 : {
408 0 : SWITCH (decoder->frame_dms)
409 : {
410 0 : case 25:
411 0 : maxBytes = 210;
412 0 : minBytes = MIN_NBYTES;
413 0 : BREAK;
414 0 : case 50:
415 0 : maxBytes = 375;
416 0 : minBytes = MIN_NBYTES;
417 0 : BREAK;
418 0 : case 75:
419 0 : maxBytes = 625;
420 0 : minBytes = MIN_NBYTES;
421 0 : BREAK;
422 0 : case 100:
423 0 : maxBytes = 625;
424 0 : minBytes = MIN_NBYTES;
425 0 : BREAK;
426 0 : default: return LC3PLUS_HRMODE_ERROR;
427 : }
428 : }
429 : else
430 : #endif
431 : {
432 0 : minBytes = MIN_NBYTES;
433 0 : maxBytes = MAX_NBYTES_100;
434 : }
435 :
436 0 : if (channel_bytes < minBytes || channel_bytes > maxBytes)
437 : {
438 0 : return LC3PLUS_NUMBYTES_ERROR;
439 : }
440 :
441 0 : setup->targetBytes = channel_bytes;
442 0 : move16();
443 0 : setup->total_bits = shl(setup->targetBytes, 3);
444 0 : setup->enable_lpc_weighting = (setup->total_bits < 480);
445 0 : setup->quantizedGainOff =
446 0 : -(s_min(115, setup->total_bits / (10 * (decoder->fs_idx + 1))) + 105 + 5 * (decoder->fs_idx + 1));
447 0 : tmp = DEPR_i_mult(80, decoder->fs_idx);
448 :
449 : #ifdef ENABLE_HR_MODE
450 0 : if (decoder->hrmode && decoder->fs_idx == 5)
451 : {
452 0 : setup->quantizedGainOff = MAX(setup->quantizedGainOff, -181);
453 : }
454 : #endif
455 :
456 0 : totalBits = setup->total_bits;
457 :
458 :
459 0 : SWITCH (decoder->frame_dms)
460 : {
461 0 : case 25:
462 0 : setup->enable_lpc_weighting = 0;
463 : /* total_bits * 2.4 */
464 0 : totalBits = extract_l(L_shr(L_mult0(19661, setup->total_bits), 13));
465 0 : BREAK;
466 0 : case 50:
467 0 : setup->enable_lpc_weighting = setup->total_bits < 240;
468 0 : totalBits = sub(DEPR_i_mult(setup->total_bits, 2), 160);
469 0 : BREAK;
470 0 : case 75:
471 0 : setup->enable_lpc_weighting = setup->total_bits < 360;
472 0 : totalBits = L_shr(L_mult0(10923, setup->total_bits), 13);
473 0 : BREAK;
474 0 : case 100:
475 0 : BREAK;
476 : }
477 :
478 :
479 0 : if (sub(totalBits, add(320, tmp)) < 0)
480 : {
481 0 : setup->ltpf_scale_fac_idx = 0;
482 0 : move16();
483 : }
484 0 : else if (sub(totalBits, add(400, tmp)) < 0)
485 : {
486 0 : setup->ltpf_scale_fac_idx = 1;
487 0 : move16();
488 : }
489 0 : else if (sub(totalBits, add(480, tmp)) < 0)
490 : {
491 0 : setup->ltpf_scale_fac_idx = 2;
492 0 : move16();
493 : }
494 0 : else if (sub(totalBits, add(560, tmp)) < 0)
495 : {
496 0 : setup->ltpf_scale_fac_idx = 3;
497 0 : move16();
498 : }
499 : else
500 : {
501 0 : setup->ltpf_scale_fac_idx = -1;
502 0 : move16();
503 : }
504 :
505 : #ifdef ENABLE_HR_MODE
506 : /* No LTPF in hrmode */
507 0 : if (decoder->hrmode)
508 : {
509 0 : setup->ltpf_scale_fac_idx = -1;
510 0 : move16();
511 : }
512 : #endif
513 :
514 0 : return LC3PLUS_OK;
515 : }
516 :
|