Coverage Report

Created: 2026-06-10 06:29

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
770k
                                              WORD32 aot) {
50
770k
  WORD32 i, sfb, tempcnt;
51
770k
  FLOAT32 tmp;
52
770k
  FLOAT32 *ptr_tns_sfb_mean = ptr_shared_buffer1;
53
770k
  FLOAT32 temp1, temp2;
54
770k
  FLOAT32 *ptr_spec;
55
770k
  FLOAT32 *ptr_ws1;
56
770k
  WORD sfb_width, j;
57
58
5.10M
  for (sfb = lpc_start_band; sfb < lpc_stop_band; sfb++) {
59
4.33M
    FLOAT32 sfb_nrg_tmp = ptr_sfb_energy[sfb];
60
4.33M
    ptr_tns_sfb_mean[sfb] = 1 / ((FLOAT32)sqrt(sfb_nrg_tmp) + 1e-30f);
61
4.33M
  }
62
63
770k
  sfb = lpc_start_band;
64
65
770k
  tmp = ptr_tns_sfb_mean[sfb];
66
67
5.10M
  for (i = lpc_start_line; i < lpc_stop_line; i += sfb_width) {
68
4.33M
    ptr_spec = &ptr_weighted_spec[i];
69
4.33M
    WORD start = i, stop = ptr_sfb_offset[sfb + 1];
70
71
4.33M
    stop = MIN(stop, lpc_stop_line);
72
4.33M
    sfb_width = stop - start;
73
74
46.2M
    for (j = (sfb_width >> 1) - 1; j >= 0; j--) {
75
41.9M
      *ptr_spec++ = tmp;
76
41.9M
      *ptr_spec++ = tmp;
77
41.9M
    }
78
4.33M
    sfb++;
79
80
4.33M
    if ((sfb + 1) < lpc_stop_band) {
81
2.87M
      tmp = ptr_tns_sfb_mean[sfb];
82
2.87M
    }
83
4.33M
  }
84
85
  /* Filter down */
86
770k
  if (aot == AOT_AAC_LC || aot == AOT_SBR || aot == AOT_PS || aot == AOT_AAC_ELD) {
87
82.8M
    for (i = lpc_stop_line - 2; i >= lpc_start_line; i--) {
88
82.0M
      ptr_weighted_spec[i] = (ptr_weighted_spec[i] + ptr_weighted_spec[i + 1]) * 0.5f;
89
82.0M
    }
90
82.8M
    for (i = lpc_start_line + 1; i < lpc_stop_line; i++) {
91
82.0M
      ptr_weighted_spec[i] = (ptr_weighted_spec[i] + ptr_weighted_spec[i - 1]) * 0.5f;
92
82.0M
    }
93
94
    /* Weight and normalize */
95
83.5M
    for (i = lpc_start_line; i < lpc_stop_line; i++) {
96
82.7M
      ptr_weighted_spec[i] = ptr_weighted_spec[i] * ptr_spectrum[i];
97
82.7M
    }
98
747k
  } else if (aot == AOT_AAC_LD || aot == AOT_AAC_ELD) {
99
23.1k
    WORD32 remaining;
100
23.1k
    FLOAT32 multout_temp;
101
102
23.1k
    ptr_ws1 = &ptr_weighted_spec[lpc_stop_line - 1];
103
23.1k
    tempcnt = (lpc_stop_line - lpc_start_line) >> 2;
104
23.1k
    remaining = lpc_stop_line - lpc_start_line - (tempcnt << 2);
105
106
23.1k
    temp1 = *ptr_ws1--;
107
23.1k
    temp2 = (*ptr_ws1 + temp1);
108
305k
    for (i = tempcnt - 1; i >= 0; i--) {
109
281k
      *ptr_ws1-- = temp2;
110
281k
      temp1 = (*ptr_ws1 + temp2 * 0.5f);
111
281k
      *ptr_ws1-- = temp1;
112
281k
      temp2 = (*ptr_ws1 + temp1 * 0.5f);
113
281k
      *ptr_ws1-- = temp2;
114
281k
      temp1 = (*ptr_ws1 + temp2 * 0.5f);
115
281k
      *ptr_ws1-- = temp1;
116
281k
      temp2 = (*ptr_ws1 + temp1 * 0.5f);
117
281k
    }
118
23.1k
    ptr_ws1++;
119
23.1k
    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
23.1k
    ptr_weighted_spec[lpc_start_line + 1] = (FLOAT32)(
127
23.1k
        ((ptr_weighted_spec[lpc_start_line + 1]) + (ptr_weighted_spec[lpc_start_line])) * 0.5f);
128
23.1k
    multout_temp = (ptr_weighted_spec[lpc_start_line] * ptr_spectrum[lpc_start_line]);
129
23.1k
    ptr_weighted_spec[lpc_start_line] = multout_temp;
130
131
    /* Weight and normalize */
132
23.1k
    ptr_spec = &ptr_spectrum[lpc_start_line + 1];
133
23.1k
    ptr_ws1 = &ptr_weighted_spec[lpc_start_line + 1];
134
135
23.1k
    tempcnt = (lpc_stop_line - lpc_start_line - 2) >> 2;
136
23.1k
    remaining = (lpc_stop_line - lpc_start_line - 2) - (tempcnt << 2);
137
23.1k
    temp2 = *ptr_ws1;
138
139
283k
    for (i = tempcnt - 1; i >= 0; i--) {
140
260k
      temp1 = *(ptr_ws1 + 1);
141
260k
      temp1 = (FLOAT32)((temp1 + temp2) * 0.5f);
142
260k
      multout_temp = (temp2 * *ptr_spec++);
143
260k
      *ptr_ws1++ = multout_temp;
144
145
260k
      temp2 = *(ptr_ws1 + 1);
146
260k
      temp2 = (FLOAT32)((temp2 + temp1) * 0.5f);
147
260k
      multout_temp = (temp1 * *ptr_spec++);
148
260k
      *ptr_ws1++ = multout_temp;
149
150
260k
      temp1 = *(ptr_ws1 + 1);
151
260k
      temp1 = (FLOAT32)((temp2 + temp1) * 0.5f);
152
260k
      multout_temp = (temp2 * *ptr_spec++);
153
260k
      *ptr_ws1++ = multout_temp;
154
155
260k
      temp2 = *(ptr_ws1 + 1);
156
260k
      temp2 = (FLOAT32)((temp2 + temp1) * 0.5f);
157
260k
      multout_temp = (temp1 * *ptr_spec++);
158
260k
      *ptr_ws1++ = multout_temp;
159
260k
    }
160
161
23.1k
    if (remaining) {
162
69.5k
      for (i = remaining - 1; i >= 0; i--) {
163
46.3k
        temp1 = *(ptr_ws1 + 1);
164
165
46.3k
        multout_temp = (temp2 * *ptr_spec++);
166
46.3k
        *ptr_ws1++ = multout_temp;
167
46.3k
        temp2 = (FLOAT32)((temp1 + temp2) * 0.5f);
168
46.3k
      }
169
23.1k
    }
170
171
23.1k
    multout_temp = (temp2 + ptr_spectrum[lpc_stop_line - 1]);
172
173
23.1k
    ptr_weighted_spec[lpc_stop_line - 1] = multout_temp;
174
23.1k
  }
175
770k
}
176
177
VOID ia_enhaacplus_enc_auto_correlation(const FLOAT32 *ptr_input, FLOAT32 *ptr_corr,
178
770k
                                        WORD32 samples, WORD32 corr_coeff) {
179
770k
  WORD32 i, j;
180
770k
  FLOAT32 tmp_var;
181
770k
  WORD32 remaining;
182
770k
  remaining = corr_coeff - ((corr_coeff >> 1) << 1);
183
184
42.7M
  for (i = 0; i < samples; i += 2) {
185
41.9M
    const FLOAT32 *ptr_input1 = &ptr_input[i];
186
41.9M
    FLOAT32 temp1 = *ptr_input1;
187
41.9M
    FLOAT32 temp2 = *(ptr_input1 + 1);
188
41.9M
    FLOAT32 inp_tmp1 = *ptr_input1++;
189
263M
    for (j = 0; j < (corr_coeff >> 1) << 1; j++) {
190
221M
      FLOAT32 inp_tmp2;
191
221M
      tmp_var = (temp1 * inp_tmp1);
192
221M
      inp_tmp2 = *ptr_input1++;
193
221M
      tmp_var += (temp2 * inp_tmp2);
194
221M
      ptr_corr[j] += tmp_var;
195
221M
      j++;
196
221M
      tmp_var = (temp1 * inp_tmp2);
197
221M
      inp_tmp1 = *ptr_input1++;
198
221M
      tmp_var += (temp2 * inp_tmp1);
199
221M
      ptr_corr[j] += (tmp_var);
200
221M
    }
201
41.9M
    if (remaining) {
202
31.7M
      tmp_var = (temp1 * inp_tmp1);
203
31.7M
      tmp_var += (temp2 * *ptr_input1);
204
31.7M
      ptr_corr[j] += (tmp_var);
205
31.7M
    }
206
41.9M
  }
207
770k
}
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
321k
                                               FLOAT32 *ptr_output) {
212
321k
  FLOAT32 state_par[TEMPORAL_NOISE_SHAPING_MAX_ORDER] = {0};
213
321k
  WORD32 j;
214
215
321k
  if (order <= 0) {
216
96
    return;
217
96
  }
218
219
65.3M
  for (j = 0; j < num_lines; j++) {
220
64.9M
    WORD32 i;
221
64.9M
    FLOAT32 x = ptr_signal[j];
222
64.9M
    FLOAT32 accu, tmp, tmp_save;
223
224
64.9M
    tmp_save = x;
225
64.9M
    accu = x;
226
227
471M
    for (i = 0; i < order - 1; i++) {
228
406M
      tmp = (accu * ptr_par_coeff[i]);
229
230
406M
      tmp += state_par[i];
231
232
406M
      accu += (state_par[i] * ptr_par_coeff[i]);
233
234
406M
      state_par[i] = tmp_save;
235
406M
      tmp_save = tmp;
236
406M
    }
237
238
    /* last stage: only need half operations */
239
64.9M
    accu += (state_par[order - 1] * ptr_par_coeff[order - 1]);
240
241
64.9M
    state_par[order - 1] = tmp_save;
242
243
64.9M
    ptr_output[j] = accu;
244
64.9M
  }
245
321k
}