Coverage Report

Created: 2026-02-07 06:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/encoder/iusace_psy_utils.c
Line
Count
Source
1
/******************************************************************************
2
 *                                                                            *
3
 * Copyright (C) 2023 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
 */
20
21
#include <math.h>
22
#include <string.h>
23
24
#include "ixheaac_type_def.h"
25
#include "ixheaace_adjust_threshold_data.h"
26
#include "iusace_block_switch_const.h"
27
#include "iusace_cnst.h"
28
#include "iusace_bitbuffer.h"
29
#include "ixheaace_mps_common_define.h"
30
31
/* DRC */
32
#include "impd_drc_common_enc.h"
33
#include "impd_drc_uni_drc.h"
34
#include "impd_drc_tables.h"
35
#include "impd_drc_api.h"
36
#include "impd_drc_uni_drc_eq.h"
37
#include "impd_drc_uni_drc_filter_bank.h"
38
#include "impd_drc_gain_enc.h"
39
#include "impd_drc_struct_def.h"
40
41
#include "iusace_tns_usac.h"
42
#include "iusace_psy_mod.h"
43
#include "iusace_tns_usac.h"
44
#include "iusace_config.h"
45
#include "iusace_psy_utils.h"
46
#include "iusace_fd_qc_util.h"
47
#include "iusace_fd_qc_adjthr.h"
48
#include "ixheaac_error_standards.h"
49
#include "ixheaace_error_codes.h"
50
51
extern ia_sfb_info_struct iusace_sfb_info_1024[12];
52
extern ia_sfb_info_struct iusace_sfb_info_768[12];
53
54
static const FLOAT32 iusace_bark_quiet_thr_val[] = {
55
    15.0f, 10.0f, 7.0f, 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,  0.0f,  0.0f, 0.0f,
56
    0.0f,  0.0f,  0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 5.0f, 10.0f, 20.0f, 30.0f};
57
58
VOID iusace_calc_band_energy(const FLOAT64 *ptr_spec_coeffs, const WORD32 *band_offset,
59
1.75M
                             const WORD32 num_bands, FLOAT32 *ptr_band_energy, WORD32 sfb_count) {
60
1.75M
  WORD32 i, j;
61
62
1.75M
  j = 0;
63
1.75M
  memset(ptr_band_energy, 0, sfb_count * sizeof(FLOAT32));
64
34.4M
  for (i = 0; i < num_bands; i++) {
65
478M
    while (j < band_offset[i + 1]) {
66
445M
      ptr_band_energy[i] += (FLOAT32)(ptr_spec_coeffs[j] * ptr_spec_coeffs[j]);
67
445M
      j++;
68
445M
    }
69
32.6M
  }
70
1.75M
  return;
71
1.75M
}
72
73
VOID iusace_find_max_spreading(const WORD32 sfb_count, const FLOAT32 *ptr_mask_low_fac,
74
3.03M
                               const FLOAT32 *ptr_mask_high_fac, FLOAT32 *ptr_spreaded_enegry) {
75
3.03M
  WORD32 i;
76
77
58.1M
  for (i = 1; i < sfb_count; i++) {
78
55.0M
    ptr_spreaded_enegry[i] =
79
55.0M
        MAX(ptr_spreaded_enegry[i], ptr_mask_high_fac[i] * ptr_spreaded_enegry[i - 1]);
80
55.0M
  }
81
82
58.1M
  for (i = sfb_count - 2; i >= 0; i--) {
83
55.0M
    ptr_spreaded_enegry[i] =
84
55.0M
        MAX(ptr_spreaded_enegry[i], ptr_mask_low_fac[i] * ptr_spreaded_enegry[i + 1]);
85
55.0M
  }
86
3.03M
  return;
87
3.03M
}
88
89
VOID iusace_pre_echo_control(FLOAT32 *ptr_thr_nm1, WORD32 sfb_count, FLOAT32 max_allowed_inc_fac,
90
1.51M
                             FLOAT32 min_remaining_thr_fac, FLOAT32 *ptr_threshold) {
91
1.51M
  WORD32 i;
92
1.51M
  FLOAT32 thr1, thr2;
93
94
30.5M
  for (i = 0; i < sfb_count; i++) {
95
29.0M
    thr1 = max_allowed_inc_fac * (ptr_thr_nm1[i]);
96
29.0M
    thr2 = min_remaining_thr_fac * ptr_threshold[i];
97
98
29.0M
    ptr_thr_nm1[i] = ptr_threshold[i];
99
100
29.0M
    if (ptr_threshold[i] > thr1) {
101
2.85M
      ptr_threshold[i] = thr1;
102
2.85M
    }
103
29.0M
    if (thr2 > ptr_threshold[i]) {
104
1.40M
      ptr_threshold[i] = thr2;
105
1.40M
    }
106
29.0M
  }
107
1.51M
  return;
108
1.51M
}
109
110
static VOID iusace_sfb_init(WORD32 sample_rate, WORD32 block_type, WORD32 *ptr_sfb_offset,
111
12.0k
                            WORD32 *ptr_sfb_count, WORD32 ccfl) {
112
12.0k
  const WORD16 *ptr_sfb_params = 0;
113
12.0k
  WORD32 start_offset, block_len = 0;
114
12.0k
  const ia_sfb_info_struct *pstr_sfb_info_tbls = &iusace_sfb_info_1024[0];
115
12.0k
  WORD32 sampling_rate_mapped = iusace_map_sample_rate(sample_rate);
116
12.0k
  WORD16 prev_val = 0;
117
12.0k
  if (ccfl == LEN_SUPERFRAME_768) {
118
2.75k
    pstr_sfb_info_tbls = &iusace_sfb_info_768[0];
119
2.75k
  }
120
121
122
12.0k
  if (block_type == ONLY_LONG_SEQUENCE) {
123
6.00k
    block_len = ccfl;
124
6.00k
    switch (sampling_rate_mapped) {
125
407
      case 96000:
126
407
        ptr_sfb_params = pstr_sfb_info_tbls[11].cb_offset_long;
127
407
        break;
128
79
      case 88200:
129
79
        ptr_sfb_params = pstr_sfb_info_tbls[10].cb_offset_long;
130
79
        break;
131
63
      case 64000:
132
63
        ptr_sfb_params = pstr_sfb_info_tbls[9].cb_offset_long;
133
63
        break;
134
191
      case 48000:
135
191
        ptr_sfb_params = pstr_sfb_info_tbls[8].cb_offset_long;
136
191
        break;
137
289
      case 44100:
138
289
        ptr_sfb_params = pstr_sfb_info_tbls[7].cb_offset_long;
139
289
        break;
140
786
      case 32000:
141
786
      case 29400:
142
786
        ptr_sfb_params = pstr_sfb_info_tbls[6].cb_offset_long;
143
786
        break;
144
1.23k
      case 24000:
145
1.23k
        ptr_sfb_params = pstr_sfb_info_tbls[5].cb_offset_long;
146
1.23k
        break;
147
468
      case 22050:
148
468
        ptr_sfb_params = pstr_sfb_info_tbls[4].cb_offset_long;
149
468
        break;
150
871
      case 16000:
151
871
      case 14700:
152
871
        ptr_sfb_params = pstr_sfb_info_tbls[3].cb_offset_long;
153
871
        break;
154
873
      case 12000:
155
873
        ptr_sfb_params = pstr_sfb_info_tbls[2].cb_offset_long;
156
873
        break;
157
237
      case 11025:
158
237
        ptr_sfb_params = pstr_sfb_info_tbls[1].cb_offset_long;
159
237
        break;
160
510
      case 8000:
161
510
        ptr_sfb_params = pstr_sfb_info_tbls[0].cb_offset_long;
162
510
        break;
163
0
      default:
164
0
        ptr_sfb_params = pstr_sfb_info_tbls[8].cb_offset_long;
165
0
        break;
166
6.00k
    }
167
6.00k
  } else {
168
6.00k
    block_len = ccfl >> 3;
169
6.00k
    switch (sampling_rate_mapped) {
170
407
      case 96000:
171
407
        ptr_sfb_params = pstr_sfb_info_tbls[11].cb_offset_short;
172
407
        break;
173
79
      case 88200:
174
79
        ptr_sfb_params = pstr_sfb_info_tbls[10].cb_offset_short;
175
79
        break;
176
63
      case 64000:
177
63
        ptr_sfb_params = pstr_sfb_info_tbls[9].cb_offset_short;
178
63
        break;
179
191
      case 48000:
180
191
        ptr_sfb_params = pstr_sfb_info_tbls[8].cb_offset_short;
181
191
        break;
182
289
      case 44100:
183
289
        ptr_sfb_params = pstr_sfb_info_tbls[7].cb_offset_short;
184
289
        break;
185
786
      case 32000:
186
786
      case 29400:
187
786
        ptr_sfb_params = pstr_sfb_info_tbls[6].cb_offset_short;
188
786
        break;
189
1.23k
      case 24000:
190
1.23k
        ptr_sfb_params = pstr_sfb_info_tbls[5].cb_offset_short;
191
1.23k
        break;
192
468
      case 22050:
193
468
        ptr_sfb_params = pstr_sfb_info_tbls[4].cb_offset_short;
194
468
        break;
195
871
      case 16000:
196
871
      case 14700:
197
871
        ptr_sfb_params = pstr_sfb_info_tbls[3].cb_offset_short;
198
871
        break;
199
873
      case 12000:
200
873
        ptr_sfb_params = pstr_sfb_info_tbls[2].cb_offset_short;
201
873
        break;
202
237
      case 11025:
203
237
        ptr_sfb_params = pstr_sfb_info_tbls[1].cb_offset_short;
204
237
        break;
205
510
      case 8000:
206
510
        ptr_sfb_params = pstr_sfb_info_tbls[0].cb_offset_short;
207
510
        break;
208
0
      default:
209
0
        ptr_sfb_params = pstr_sfb_info_tbls[8].cb_offset_short;
210
0
        break;
211
6.00k
    }
212
6.00k
  }
213
214
12.0k
  *ptr_sfb_count = 0;
215
12.0k
  start_offset = 0;
216
217
351k
  do {
218
351k
    ptr_sfb_offset[*ptr_sfb_count] = start_offset;
219
351k
    if (*ptr_sfb_count == 0)
220
12.0k
      prev_val = 0;
221
339k
    else
222
339k
      prev_val = ptr_sfb_params[*ptr_sfb_count - 1];
223
351k
    start_offset += ptr_sfb_params[*ptr_sfb_count] - prev_val;
224
351k
    (*ptr_sfb_count)++;
225
351k
  } while (start_offset < block_len);
226
227
12.0k
  ptr_sfb_offset[*ptr_sfb_count] = start_offset;
228
229
12.0k
  return;
230
12.0k
}
231
232
703k
static FLOAT32 iusace_atan_approx(FLOAT32 val) {
233
703k
  if (val < (FLOAT32)1.0) {
234
412k
    return (val / ((FLOAT32)1.0f + (FLOAT32)0.280872f * val * val));
235
412k
  } else {
236
290k
    return ((FLOAT32)1.57079633f - val / ((FLOAT32)0.280872f + val * val));
237
290k
  }
238
703k
}
239
240
static FLOAT32 iusace_calc_bark_line_value(WORD32 num_lines, WORD32 fft_line,
241
351k
                                           WORD32 sample_rate) {
242
351k
  FLOAT32 center_freq, temp, b_value;
243
244
351k
  center_freq = (FLOAT32)fft_line * ((FLOAT32)sample_rate * (FLOAT32)0.5f) / (FLOAT32)num_lines;
245
351k
  temp = (FLOAT32)iusace_atan_approx((FLOAT32)1.3333333e-4f * center_freq);
246
351k
  b_value = (FLOAT32)13.3f * iusace_atan_approx((FLOAT32)0.00076f * center_freq) +
247
351k
            (FLOAT32)3.5f * temp * temp;
248
249
351k
  return (b_value);
250
351k
}
251
252
static VOID iusace_bark_values_init(WORD32 sfb_count, WORD32 *ptr_sfb_offset, WORD32 num_lines,
253
12.0k
                                    WORD32 sample_rate, FLOAT32 *ptr_b_value) {
254
12.0k
  WORD32 i;
255
12.0k
  FLOAT32 b_val0, b_val1;
256
12.0k
  b_val0 = 0.0f;
257
258
363k
  for (i = 0; i < sfb_count; i++) {
259
351k
    b_val1 = iusace_calc_bark_line_value(num_lines, ptr_sfb_offset[i + 1], sample_rate);
260
351k
    ptr_b_value[i] = (b_val0 + b_val1) * (FLOAT32)0.5f;
261
351k
    b_val0 = b_val1;
262
351k
  }
263
12.0k
  return;
264
12.0k
}
265
266
static VOID iusace_thr_quiet_init(WORD32 sfb_count, WORD32 *ptr_sfb_offset, FLOAT32 *ptr_bark_val,
267
12.0k
                                  FLOAT32 *ptr_thr_quiet) {
268
12.0k
  WORD32 i;
269
12.0k
  FLOAT32 bark_thr_quiet;
270
271
363k
  for (i = 0; i < sfb_count; i++) {
272
351k
    WORD32 b_val1, b_val2;
273
274
351k
    if (i > 0) {
275
339k
      b_val1 = (WORD32)(ptr_bark_val[i] + ptr_bark_val[i - 1]) >> 1;
276
339k
    } else {
277
12.0k
      b_val1 = (WORD32)(ptr_bark_val[i]) >> 1;
278
12.0k
    }
279
280
351k
    if (i < sfb_count - 1) {
281
339k
      b_val2 = (WORD32)(ptr_bark_val[i] + ptr_bark_val[i + 1]) >> 1;
282
339k
    } else {
283
12.0k
      b_val2 = (WORD32)(ptr_bark_val[i]);
284
12.0k
    }
285
351k
    b_val1 = MIN(b_val1, (WORD32)MAX_BARK_VALUE);
286
351k
    b_val2 = MIN(b_val2, (WORD32)MAX_BARK_VALUE);
287
351k
    bark_thr_quiet = MIN(iusace_bark_quiet_thr_val[b_val1], iusace_bark_quiet_thr_val[b_val2]);
288
289
351k
    ptr_thr_quiet[i] = (FLOAT32)pow(10.0f, (bark_thr_quiet - 20.0f) * (FLOAT32)0.1f) * 16887.8f *
290
351k
                       (FLOAT32)(ptr_sfb_offset[i + 1] - ptr_sfb_offset[i]);
291
351k
  }
292
12.0k
  return;
293
12.0k
}
294
295
static VOID iusace_spreading_init(WORD32 sfb_count, FLOAT32 *ptr_bark_val,
296
                                  FLOAT32 *ptr_mask_low_fac, FLOAT32 *ptr_mask_high_fac,
297
                                  FLOAT32 *ptr_mask_low_fac_spr_energy,
298
                                  FLOAT32 *ptr_mask_high_fac_spr_energy, const WORD32 bit_rate,
299
12.0k
                                  WORD32 block_type) {
300
12.0k
  WORD32 i;
301
12.0k
  FLOAT32 mask_low_spr_energy, mask_high_spr_energy;
302
303
12.0k
  if (block_type != EIGHT_SHORT_SEQUENCE) {
304
6.00k
    mask_low_spr_energy = MASK_LOW_SP_ENERGY_L;
305
6.00k
    mask_high_spr_energy = (bit_rate > 22000) ? MASK_HIGH_SP_ENERGY_L : MASK_HIGH_SP_ENERGY_L_LBR;
306
6.00k
  } else {
307
6.00k
    mask_low_spr_energy = MASK_LOW_SP_ENERGY_S;
308
6.00k
    mask_high_spr_energy = MASK_HIGH_SP_ENERGY_S;
309
6.00k
  }
310
311
363k
  for (i = 0; i < sfb_count; i++) {
312
351k
    if (i > 0) {
313
339k
      FLOAT32 db_val;
314
339k
      FLOAT32 diff_val = (ptr_bark_val[i] - ptr_bark_val[i - 1]);
315
316
339k
      db_val = MASK_HIGH_FAC * diff_val;
317
339k
      ptr_mask_high_fac[i] = (FLOAT32)pow(10.0f, -db_val);
318
339k
      db_val = MASK_LOW_FAC * diff_val;
319
339k
      ptr_mask_low_fac[i - 1] = (FLOAT32)pow(10.0f, -db_val);
320
339k
      db_val = mask_high_spr_energy * diff_val;
321
339k
      ptr_mask_high_fac_spr_energy[i] = (FLOAT32)pow(10.0f, -db_val);
322
339k
      db_val = mask_low_spr_energy * diff_val;
323
339k
      ptr_mask_low_fac_spr_energy[i - 1] = (FLOAT32)pow(10.0f, -db_val);
324
339k
    } else {
325
12.0k
      ptr_mask_high_fac[i] = 0.0f;
326
12.0k
      ptr_mask_low_fac[sfb_count - 1] = 0.0f;
327
12.0k
      ptr_mask_high_fac_spr_energy[i] = 0.0f;
328
12.0k
      ptr_mask_low_fac_spr_energy[sfb_count - 1] = 0.0f;
329
12.0k
    }
330
351k
  }
331
12.0k
  return;
332
12.0k
}
333
334
static VOID iusace_min_snr_init(const WORD32 bit_rate, const WORD32 sample_rate,
335
                                const WORD32 num_lines, const WORD32 *ptr_sfb_offset,
336
                                const FLOAT32 *ptr_bark_value, const WORD32 sfb_active,
337
12.0k
                                FLOAT32 *ptr_sfb_min_snr) {
338
12.0k
  WORD32 sfb;
339
12.0k
  FLOAT32 bark_fac;
340
12.0k
  FLOAT32 bark_width;
341
12.0k
  FLOAT32 pe_per_window, pe_part;
342
12.0k
  FLOAT32 snr;
343
12.0k
  FLOAT32 b_val0, b_val1;
344
345
12.0k
  if (sfb_active == 0) {
346
0
    bark_fac = 1.0f;
347
12.0k
  } else {
348
12.0k
    bark_fac = (FLOAT32)1.0 / MIN(ptr_bark_value[sfb_active - 1] / MAX_BARK_VALUE, (FLOAT32)1.0);
349
12.0k
  }
350
351
12.0k
  pe_per_window =
352
12.0k
      iusace_bits_to_pe((FLOAT32)bit_rate / (FLOAT32)sample_rate * (FLOAT32)num_lines);
353
354
12.0k
  b_val0 = (FLOAT32)0.0f;
355
356
353k
  for (sfb = 0; sfb < sfb_active; sfb++) {
357
341k
    b_val1 = (FLOAT32)2.0 * ptr_bark_value[sfb] - b_val0;
358
341k
    bark_width = b_val1 - b_val0;
359
341k
    b_val0 = b_val1;
360
361
341k
    pe_part = pe_per_window * (FLOAT32)0.024f * bark_fac;
362
341k
    pe_part *= bark_width;
363
341k
    pe_part /= (FLOAT32)(ptr_sfb_offset[sfb + 1] - ptr_sfb_offset[sfb]);
364
341k
    snr = (FLOAT32)pow(2.0f, pe_part) - 1.5f;
365
341k
    snr = 1.0f / MAX(snr, 1.0f);
366
341k
    snr = MIN(snr, 0.8f);
367
341k
    snr = MAX(snr, 0.003f);
368
341k
    ptr_sfb_min_snr[sfb] = snr;
369
341k
  }
370
12.0k
  return;
371
12.0k
}
372
373
VOID iusace_psy_long_config_init(WORD32 bit_rate, WORD32 sample_rate, WORD32 band_width,
374
6.00k
                                 ia_psy_mod_long_config_struct *pstr_psy_config, WORD32 ccfl) {
375
6.00k
  WORD32 sfb;
376
6.00k
  FLOAT32 sfb_bark_val[MAX_NUM_GROUPED_SFB];
377
378
6.00k
  iusace_sfb_init(sample_rate, ONLY_LONG_SEQUENCE, pstr_psy_config->sfb_offset,
379
6.00k
                  &(pstr_psy_config->sfb_count), ccfl);
380
381
6.00k
  iusace_bark_values_init(pstr_psy_config->sfb_count, pstr_psy_config->sfb_offset,
382
6.00k
                          pstr_psy_config->sfb_offset[pstr_psy_config->sfb_count], sample_rate,
383
6.00k
                          sfb_bark_val);
384
385
6.00k
  iusace_thr_quiet_init(pstr_psy_config->sfb_count, pstr_psy_config->sfb_offset, sfb_bark_val,
386
6.00k
                        pstr_psy_config->sfb_thr_quiet);
387
388
6.00k
  iusace_spreading_init(
389
6.00k
      pstr_psy_config->sfb_count, sfb_bark_val, pstr_psy_config->sfb_mask_low_fac,
390
6.00k
      pstr_psy_config->sfb_mask_high_fac, pstr_psy_config->sfb_mask_low_fac_spr_ener,
391
6.00k
      pstr_psy_config->sfb_mask_high_fac_spr_ener, bit_rate, ONLY_LONG_SEQUENCE);
392
393
6.00k
  pstr_psy_config->ratio = C_RATIO;
394
6.00k
  pstr_psy_config->max_allowed_inc_fac = 2.0f;
395
6.00k
  pstr_psy_config->min_remaining_thr_fac = 0.01f;
396
397
6.00k
  pstr_psy_config->clip_energy = (CLIP_ENERGY_VALUE_LONG * ccfl) / FRAME_LEN_LONG;
398
6.00k
  pstr_psy_config->low_pass_line = (WORD32)((2 * band_width * ccfl) / sample_rate);
399
400
264k
  for (sfb = 0; sfb < pstr_psy_config->sfb_count; sfb++) {
401
260k
    if (pstr_psy_config->sfb_offset[sfb] >= pstr_psy_config->low_pass_line) break;
402
260k
  }
403
6.00k
  pstr_psy_config->sfb_active = sfb;
404
405
6.00k
  iusace_min_snr_init(bit_rate, sample_rate,
406
6.00k
                      pstr_psy_config->sfb_offset[pstr_psy_config->sfb_count],
407
6.00k
                      pstr_psy_config->sfb_offset, sfb_bark_val, pstr_psy_config->sfb_active,
408
6.00k
                      pstr_psy_config->sfb_min_snr);
409
410
6.00k
  return;
411
6.00k
}
412
413
VOID iusace_psy_short_config_init(WORD32 bit_rate, WORD32 sample_rate, WORD32 band_width,
414
6.00k
                                  ia_psy_mod_short_config_struct *pstr_psy_config, WORD32 ccfl) {
415
6.00k
  WORD32 sfb;
416
6.00k
  WORD32 frame_len_short = (ccfl * FRAME_LEN_SHORT_128) / FRAME_LEN_LONG;
417
6.00k
  FLOAT32 sfb_bark_val[MAX_NUM_GROUPED_SFB];
418
419
6.00k
  iusace_sfb_init(sample_rate, EIGHT_SHORT_SEQUENCE, pstr_psy_config->sfb_offset,
420
6.00k
                  &(pstr_psy_config->sfb_count), ccfl);
421
422
6.00k
  iusace_bark_values_init(pstr_psy_config->sfb_count, pstr_psy_config->sfb_offset,
423
6.00k
                          pstr_psy_config->sfb_offset[pstr_psy_config->sfb_count], sample_rate,
424
6.00k
                          sfb_bark_val);
425
426
6.00k
  iusace_thr_quiet_init(pstr_psy_config->sfb_count, pstr_psy_config->sfb_offset, sfb_bark_val,
427
6.00k
                        pstr_psy_config->sfb_thr_quiet);
428
429
6.00k
  iusace_spreading_init(
430
6.00k
      pstr_psy_config->sfb_count, sfb_bark_val, pstr_psy_config->sfb_mask_low_fac,
431
6.00k
      pstr_psy_config->sfb_mask_high_fac, pstr_psy_config->sfb_mask_low_fac_spr_ener,
432
6.00k
      pstr_psy_config->sfb_mask_high_fac_spr_ener, bit_rate, EIGHT_SHORT_SEQUENCE);
433
434
6.00k
  pstr_psy_config->ratio = C_RATIO;
435
6.00k
  pstr_psy_config->max_allowed_inc_fac = 2.0f;
436
6.00k
  pstr_psy_config->min_remaining_thr_fac = 0.01f;
437
438
6.00k
  pstr_psy_config->clip_energy =
439
6.00k
      (CLIP_ENERGY_VALUE_SHORT * frame_len_short) / FRAME_LEN_SHORT_128;
440
6.00k
  pstr_psy_config->low_pass_line = (WORD32)((2 * band_width * frame_len_short) / sample_rate);
441
442
89.1k
  for (sfb = 0; sfb < pstr_psy_config->sfb_count; sfb++) {
443
84.3k
    if (pstr_psy_config->sfb_offset[sfb] >= pstr_psy_config->low_pass_line) break;
444
84.3k
  }
445
6.00k
  pstr_psy_config->sfb_active = sfb;
446
447
6.00k
  iusace_min_snr_init(bit_rate, sample_rate,
448
6.00k
                      pstr_psy_config->sfb_offset[pstr_psy_config->sfb_count],
449
6.00k
                      pstr_psy_config->sfb_offset, sfb_bark_val, pstr_psy_config->sfb_active,
450
6.00k
                      pstr_psy_config->sfb_min_snr);
451
452
6.00k
  return;
453
6.00k
}
454
455
IA_ERRORCODE iusace_sfb_params_init(WORD32 sample_rate, WORD32 frame_len, WORD32 *ptr_sfb_width,
456
558k
                                    WORD32 *num_sfb, WORD32 win_seq) {
457
558k
  WORD32 i, j, k;
458
558k
  ia_sfb_info_struct *ptr_sr_info = NULL;
459
558k
  WORD32 sampling_rate_mapped = 0;
460
461
558k
  if (frame_len == 1024) {
462
382k
    ptr_sr_info = &iusace_sfb_info_1024[0];
463
382k
  } else {
464
176k
    ptr_sr_info = &iusace_sfb_info_768[0];
465
176k
  }
466
467
558k
  if (sample_rate < 0)
468
0
  {
469
0
    return IA_EXHEAACE_INIT_FATAL_USAC_INVALID_CORE_SAMPLE_RATE;
470
0
  }
471
472
558k
  sampling_rate_mapped = iusace_map_sample_rate(sample_rate);
473
474
3.53M
  while (ptr_sr_info->sample_rate != sampling_rate_mapped) {
475
2.97M
    if (ptr_sr_info->sample_rate == -1) {
476
0
      return IA_EXHEAACE_INIT_FATAL_USAC_INVALID_CORE_SAMPLE_RATE;
477
0
    }
478
2.97M
    ptr_sr_info++;
479
2.97M
  }
480
481
558k
  j = 0;
482
24.7M
  for (i = 0; i < ptr_sr_info->num_sfb_long; i++) {
483
24.1M
    k = ptr_sr_info->cb_offset_long[i];
484
24.1M
    ptr_sr_info->sfb_width_long[i] = k - j;
485
24.1M
    j = k;
486
24.1M
  }
487
558k
  j = 0;
488
8.36M
  for (i = 0; i < ptr_sr_info->num_sfb_short; i++) {
489
7.80M
    k = ptr_sr_info->cb_offset_short[i];
490
7.80M
    ptr_sr_info->sfb_width_short[i] = k - j;
491
7.80M
    j = k;
492
7.80M
  }
493
494
558k
  switch (win_seq) {
495
154k
    case EIGHT_SHORT_SEQUENCE:
496
154k
      memcpy(ptr_sfb_width, ptr_sr_info->sfb_width_short, (MAX_SFB_SHORT) * sizeof(WORD32));
497
154k
      *num_sfb = ptr_sr_info->num_sfb_short;
498
154k
      break;
499
309k
    case ONLY_LONG_SEQUENCE:
500
358k
    case LONG_START_SEQUENCE:
501
358k
    case STOP_START_SEQUENCE:
502
403k
    case LONG_STOP_SEQUENCE:
503
403k
    default:
504
403k
      memcpy(ptr_sfb_width, ptr_sr_info->sfb_width_long, MAX_SFB_LONG * sizeof(WORD32));
505
403k
      *num_sfb = ptr_sr_info->num_sfb_long;
506
403k
      break;
507
558k
  }
508
509
558k
  return IA_NO_ERROR;
510
558k
}