Coverage Report

Created: 2025-10-27 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/encoder/ixheaace_tns_hp.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 <stddef.h>
23
#include "ixheaac_type_def.h"
24
#include "ixheaac_constants.h"
25
#include "impd_drc_common_enc.h"
26
#include "impd_drc_uni_drc.h"
27
#include "impd_drc_tables.h"
28
#include "impd_drc_api.h"
29
#include "ixheaace_api.h"
30
#include "ixheaace_aac_constants.h"
31
#include "ixheaace_common_rom.h"
32
#include "ixheaace_psy_const.h"
33
#include "ixheaace_tns.h"
34
#include "ixheaace_tns_params.h"
35
#include "ixheaace_rom.h"
36
#include "ixheaace_bitbuffer.h"
37
#include "ixheaace_psy_configuration.h"
38
#include "ixheaace_tns_func.h"
39
#include "ixheaac_basic_ops32.h"
40
#include "ixheaac_basic_ops16.h"
41
#include "ixheaac_basic_ops40.h"
42
#include "ixheaac_basic_ops.h"
43
44
VOID ia_enhaacplus_enc_calc_weighted_spectrum(FLOAT32 *ptr_spectrum, FLOAT32 *ptr_weighted_spec,
45
                                              FLOAT32 *ptr_sfb_energy,
46
                                              const WORD32 *ptr_sfb_offset, WORD32 lpc_start_line,
47
                                              WORD32 lpc_stop_line, WORD32 lpc_start_band,
48
                                              WORD32 lpc_stop_band, FLOAT32 *ptr_shared_buffer1,
49
797k
                                              WORD32 aot) {
50
797k
  WORD32 i, sfb, tempcnt;
51
797k
  FLOAT32 tmp;
52
797k
  FLOAT32 *ptr_tns_sfb_mean = ptr_shared_buffer1;
53
797k
  FLOAT32 temp1, temp2;
54
797k
  FLOAT32 *ptr_spec;
55
797k
  FLOAT32 *ptr_ws1;
56
797k
  WORD sfb_width, j;
57
58
4.96M
  for (sfb = lpc_start_band; sfb < lpc_stop_band; sfb++) {
59
4.17M
    FLOAT32 sfb_nrg_tmp = ptr_sfb_energy[sfb];
60
4.17M
    ptr_tns_sfb_mean[sfb] = 1 / ((FLOAT32)sqrt(sfb_nrg_tmp) + 1e-30f);
61
4.17M
  }
62
63
797k
  sfb = lpc_start_band;
64
65
797k
  tmp = ptr_tns_sfb_mean[sfb];
66
67
4.96M
  for (i = lpc_start_line; i < lpc_stop_line; i += sfb_width) {
68
4.17M
    ptr_spec = &ptr_weighted_spec[i];
69
4.17M
    WORD start = i, stop = ptr_sfb_offset[sfb + 1];
70
71
4.17M
    stop = MIN(stop, lpc_stop_line);
72
4.17M
    sfb_width = stop - start;
73
74
46.3M
    for (j = (sfb_width >> 1) - 1; j >= 0; j--) {
75
42.2M
      *ptr_spec++ = tmp;
76
42.2M
      *ptr_spec++ = tmp;
77
42.2M
    }
78
4.17M
    sfb++;
79
80
4.17M
    if ((sfb + 1) < lpc_stop_band) {
81
2.64M
      tmp = ptr_tns_sfb_mean[sfb];
82
2.64M
    }
83
4.17M
  }
84
85
  /* Filter down */
86
797k
  if (aot == AOT_AAC_LC || aot == AOT_SBR || aot == AOT_PS || aot == AOT_AAC_ELD) {
87
83.2M
    for (i = lpc_stop_line - 2; i >= lpc_start_line; i--) {
88
82.4M
      ptr_weighted_spec[i] = (ptr_weighted_spec[i] + ptr_weighted_spec[i + 1]) * 0.5f;
89
82.4M
    }
90
83.2M
    for (i = lpc_start_line + 1; i < lpc_stop_line; i++) {
91
82.4M
      ptr_weighted_spec[i] = (ptr_weighted_spec[i] + ptr_weighted_spec[i - 1]) * 0.5f;
92
82.4M
    }
93
94
    /* Weight and normalize */
95
84.0M
    for (i = lpc_start_line; i < lpc_stop_line; i++) {
96
83.2M
      ptr_weighted_spec[i] = ptr_weighted_spec[i] * ptr_spectrum[i];
97
83.2M
    }
98
776k
  } else if (aot == AOT_AAC_LD || aot == AOT_AAC_ELD) {
99
20.8k
    WORD32 remaining;
100
20.8k
    FLOAT32 multout_temp;
101
102
20.8k
    ptr_ws1 = &ptr_weighted_spec[lpc_stop_line - 1];
103
20.8k
    tempcnt = (lpc_stop_line - lpc_start_line) >> 2;
104
20.8k
    remaining = lpc_stop_line - lpc_start_line - (tempcnt << 2);
105
106
20.8k
    temp1 = *ptr_ws1--;
107
20.8k
    temp2 = (*ptr_ws1 + temp1);
108
314k
    for (i = tempcnt - 1; i >= 0; i--) {
109
293k
      *ptr_ws1-- = temp2;
110
293k
      temp1 = (*ptr_ws1 + temp2 * 0.5f);
111
293k
      *ptr_ws1-- = temp1;
112
293k
      temp2 = (*ptr_ws1 + temp1 * 0.5f);
113
293k
      *ptr_ws1-- = temp2;
114
293k
      temp1 = (*ptr_ws1 + temp2 * 0.5f);
115
293k
      *ptr_ws1-- = temp1;
116
293k
      temp2 = (*ptr_ws1 + temp1 * 0.5f);
117
293k
    }
118
20.8k
    ptr_ws1++;
119
20.8k
    if (remaining) {
120
0
      for (i = remaining - 1; i >= 0; i--) {
121
0
        temp1 = *ptr_ws1--;
122
0
        *ptr_ws1 = (*ptr_ws1 + temp1 * 0.5f);
123
0
      }
124
0
    }
125
126
20.8k
    ptr_weighted_spec[lpc_start_line + 1] = (FLOAT32)(
127
20.8k
        ((ptr_weighted_spec[lpc_start_line + 1]) + (ptr_weighted_spec[lpc_start_line])) * 0.5f);
128
20.8k
    multout_temp = (ptr_weighted_spec[lpc_start_line] * ptr_spectrum[lpc_start_line]);
129
20.8k
    ptr_weighted_spec[lpc_start_line] = multout_temp;
130
131
    /* Weight and normalize */
132
20.8k
    ptr_spec = &ptr_spectrum[lpc_start_line + 1];
133
20.8k
    ptr_ws1 = &ptr_weighted_spec[lpc_start_line + 1];
134
135
20.8k
    tempcnt = (lpc_stop_line - lpc_start_line - 2) >> 2;
136
20.8k
    remaining = (lpc_stop_line - lpc_start_line - 2) - (tempcnt << 2);
137
20.8k
    temp2 = *ptr_ws1;
138
139
295k
    for (i = tempcnt - 1; i >= 0; i--) {
140
275k
      temp1 = *(ptr_ws1 + 1);
141
275k
      temp1 = (FLOAT32)((temp1 + temp2) * 0.5f);
142
275k
      multout_temp = (temp2 * *ptr_spec++);
143
275k
      *ptr_ws1++ = multout_temp;
144
145
275k
      temp2 = *(ptr_ws1 + 1);
146
275k
      temp2 = (FLOAT32)((temp2 + temp1) * 0.5f);
147
275k
      multout_temp = (temp1 * *ptr_spec++);
148
275k
      *ptr_ws1++ = multout_temp;
149
150
275k
      temp1 = *(ptr_ws1 + 1);
151
275k
      temp1 = (FLOAT32)((temp2 + temp1) * 0.5f);
152
275k
      multout_temp = (temp2 * *ptr_spec++);
153
275k
      *ptr_ws1++ = multout_temp;
154
155
275k
      temp2 = *(ptr_ws1 + 1);
156
275k
      temp2 = (FLOAT32)((temp2 + temp1) * 0.5f);
157
275k
      multout_temp = (temp1 * *ptr_spec++);
158
275k
      *ptr_ws1++ = multout_temp;
159
275k
    }
160
161
20.8k
    if (remaining) {
162
62.5k
      for (i = remaining - 1; i >= 0; i--) {
163
41.7k
        temp1 = *(ptr_ws1 + 1);
164
165
41.7k
        multout_temp = (temp2 * *ptr_spec++);
166
41.7k
        *ptr_ws1++ = multout_temp;
167
41.7k
        temp2 = (FLOAT32)((temp1 + temp2) * 0.5f);
168
41.7k
      }
169
20.8k
    }
170
171
20.8k
    multout_temp = (temp2 + ptr_spectrum[lpc_stop_line - 1]);
172
173
20.8k
    ptr_weighted_spec[lpc_stop_line - 1] = multout_temp;
174
20.8k
  }
175
797k
}
176
177
VOID ia_enhaacplus_enc_auto_correlation(const FLOAT32 *ptr_input, FLOAT32 *ptr_corr,
178
797k
                                        WORD32 samples, WORD32 corr_coeff) {
179
797k
  WORD32 i, j;
180
797k
  FLOAT32 tmp_var;
181
797k
  WORD32 remaining;
182
797k
  remaining = corr_coeff - ((corr_coeff >> 1) << 1);
183
184
43.0M
  for (i = 0; i < samples; i += 2) {
185
42.2M
    const FLOAT32 *ptr_input1 = &ptr_input[i];
186
42.2M
    FLOAT32 temp1 = *ptr_input1;
187
42.2M
    FLOAT32 temp2 = *(ptr_input1 + 1);
188
42.2M
    FLOAT32 inp_tmp1 = *ptr_input1++;
189
269M
    for (j = 0; j < (corr_coeff >> 1) << 1; j++) {
190
227M
      FLOAT32 inp_tmp2;
191
227M
      tmp_var = (temp1 * inp_tmp1);
192
227M
      inp_tmp2 = *ptr_input1++;
193
227M
      tmp_var += (temp2 * inp_tmp2);
194
227M
      ptr_corr[j] += tmp_var;
195
227M
      j++;
196
227M
      tmp_var = (temp1 * inp_tmp2);
197
227M
      inp_tmp1 = *ptr_input1++;
198
227M
      tmp_var += (temp2 * inp_tmp1);
199
227M
      ptr_corr[j] += (tmp_var);
200
227M
    }
201
42.2M
    if (remaining) {
202
33.5M
      tmp_var = (temp1 * inp_tmp1);
203
33.5M
      tmp_var += (temp2 * *ptr_input1);
204
33.5M
      ptr_corr[j] += (tmp_var);
205
33.5M
    }
206
42.2M
  }
207
797k
}
208
209
VOID ia_enhaacplus_enc_analysis_filter_lattice(const FLOAT32 *ptr_signal, WORD32 num_lines,
210
                                               const FLOAT32 *ptr_par_coeff, WORD32 order,
211
401k
                                               FLOAT32 *ptr_output) {
212
401k
  FLOAT32 state_par[TEMPORAL_NOISE_SHAPING_MAX_ORDER] = {0};
213
401k
  WORD32 j;
214
215
401k
  if (order <= 0) {
216
11
    return;
217
11
  }
218
219
74.9M
  for (j = 0; j < num_lines; j++) {
220
74.5M
    WORD32 i;
221
74.5M
    FLOAT32 x = ptr_signal[j];
222
74.5M
    FLOAT32 accu, tmp, tmp_save;
223
224
74.5M
    tmp_save = x;
225
74.5M
    accu = x;
226
227
557M
    for (i = 0; i < order - 1; i++) {
228
482M
      tmp = (accu * ptr_par_coeff[i]);
229
230
482M
      tmp += state_par[i];
231
232
482M
      accu += (state_par[i] * ptr_par_coeff[i]);
233
234
482M
      state_par[i] = tmp_save;
235
482M
      tmp_save = tmp;
236
482M
    }
237
238
    /* last stage: only need half operations */
239
74.5M
    accu += (state_par[order - 1] * ptr_par_coeff[order - 1]);
240
241
74.5M
    state_par[order - 1] = tmp_save;
242
243
74.5M
    ptr_output[j] = accu;
244
74.5M
  }
245
401k
}