Coverage Report

Created: 2026-02-07 06:17

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
734k
                                              WORD32 aot) {
50
734k
  WORD32 i, sfb, tempcnt;
51
734k
  FLOAT32 tmp;
52
734k
  FLOAT32 *ptr_tns_sfb_mean = ptr_shared_buffer1;
53
734k
  FLOAT32 temp1, temp2;
54
734k
  FLOAT32 *ptr_spec;
55
734k
  FLOAT32 *ptr_ws1;
56
734k
  WORD sfb_width, j;
57
58
5.12M
  for (sfb = lpc_start_band; sfb < lpc_stop_band; sfb++) {
59
4.38M
    FLOAT32 sfb_nrg_tmp = ptr_sfb_energy[sfb];
60
4.38M
    ptr_tns_sfb_mean[sfb] = 1 / ((FLOAT32)sqrt(sfb_nrg_tmp) + 1e-30f);
61
4.38M
  }
62
63
734k
  sfb = lpc_start_band;
64
65
734k
  tmp = ptr_tns_sfb_mean[sfb];
66
67
5.12M
  for (i = lpc_start_line; i < lpc_stop_line; i += sfb_width) {
68
4.38M
    ptr_spec = &ptr_weighted_spec[i];
69
4.38M
    WORD start = i, stop = ptr_sfb_offset[sfb + 1];
70
71
4.38M
    stop = MIN(stop, lpc_stop_line);
72
4.38M
    sfb_width = stop - start;
73
74
46.7M
    for (j = (sfb_width >> 1) - 1; j >= 0; j--) {
75
42.3M
      *ptr_spec++ = tmp;
76
42.3M
      *ptr_spec++ = tmp;
77
42.3M
    }
78
4.38M
    sfb++;
79
80
4.38M
    if ((sfb + 1) < lpc_stop_band) {
81
3.00M
      tmp = ptr_tns_sfb_mean[sfb];
82
3.00M
    }
83
4.38M
  }
84
85
  /* Filter down */
86
734k
  if (aot == AOT_AAC_LC || aot == AOT_SBR || aot == AOT_PS || aot == AOT_AAC_ELD) {
87
83.3M
    for (i = lpc_stop_line - 2; i >= lpc_start_line; i--) {
88
82.6M
      ptr_weighted_spec[i] = (ptr_weighted_spec[i] + ptr_weighted_spec[i + 1]) * 0.5f;
89
82.6M
    }
90
83.3M
    for (i = lpc_start_line + 1; i < lpc_stop_line; i++) {
91
82.6M
      ptr_weighted_spec[i] = (ptr_weighted_spec[i] + ptr_weighted_spec[i - 1]) * 0.5f;
92
82.6M
    }
93
94
    /* Weight and normalize */
95
84.0M
    for (i = lpc_start_line; i < lpc_stop_line; i++) {
96
83.3M
      ptr_weighted_spec[i] = ptr_weighted_spec[i] * ptr_spectrum[i];
97
83.3M
    }
98
710k
  } else if (aot == AOT_AAC_LD || aot == AOT_AAC_ELD) {
99
23.3k
    WORD32 remaining;
100
23.3k
    FLOAT32 multout_temp;
101
102
23.3k
    ptr_ws1 = &ptr_weighted_spec[lpc_stop_line - 1];
103
23.3k
    tempcnt = (lpc_stop_line - lpc_start_line) >> 2;
104
23.3k
    remaining = lpc_stop_line - lpc_start_line - (tempcnt << 2);
105
106
23.3k
    temp1 = *ptr_ws1--;
107
23.3k
    temp2 = (*ptr_ws1 + temp1);
108
361k
    for (i = tempcnt - 1; i >= 0; i--) {
109
338k
      *ptr_ws1-- = temp2;
110
338k
      temp1 = (*ptr_ws1 + temp2 * 0.5f);
111
338k
      *ptr_ws1-- = temp1;
112
338k
      temp2 = (*ptr_ws1 + temp1 * 0.5f);
113
338k
      *ptr_ws1-- = temp2;
114
338k
      temp1 = (*ptr_ws1 + temp2 * 0.5f);
115
338k
      *ptr_ws1-- = temp1;
116
338k
      temp2 = (*ptr_ws1 + temp1 * 0.5f);
117
338k
    }
118
23.3k
    ptr_ws1++;
119
23.3k
    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.3k
    ptr_weighted_spec[lpc_start_line + 1] = (FLOAT32)(
127
23.3k
        ((ptr_weighted_spec[lpc_start_line + 1]) + (ptr_weighted_spec[lpc_start_line])) * 0.5f);
128
23.3k
    multout_temp = (ptr_weighted_spec[lpc_start_line] * ptr_spectrum[lpc_start_line]);
129
23.3k
    ptr_weighted_spec[lpc_start_line] = multout_temp;
130
131
    /* Weight and normalize */
132
23.3k
    ptr_spec = &ptr_spectrum[lpc_start_line + 1];
133
23.3k
    ptr_ws1 = &ptr_weighted_spec[lpc_start_line + 1];
134
135
23.3k
    tempcnt = (lpc_stop_line - lpc_start_line - 2) >> 2;
136
23.3k
    remaining = (lpc_stop_line - lpc_start_line - 2) - (tempcnt << 2);
137
23.3k
    temp2 = *ptr_ws1;
138
139
340k
    for (i = tempcnt - 1; i >= 0; i--) {
140
316k
      temp1 = *(ptr_ws1 + 1);
141
316k
      temp1 = (FLOAT32)((temp1 + temp2) * 0.5f);
142
316k
      multout_temp = (temp2 * *ptr_spec++);
143
316k
      *ptr_ws1++ = multout_temp;
144
145
316k
      temp2 = *(ptr_ws1 + 1);
146
316k
      temp2 = (FLOAT32)((temp2 + temp1) * 0.5f);
147
316k
      multout_temp = (temp1 * *ptr_spec++);
148
316k
      *ptr_ws1++ = multout_temp;
149
150
316k
      temp1 = *(ptr_ws1 + 1);
151
316k
      temp1 = (FLOAT32)((temp2 + temp1) * 0.5f);
152
316k
      multout_temp = (temp2 * *ptr_spec++);
153
316k
      *ptr_ws1++ = multout_temp;
154
155
316k
      temp2 = *(ptr_ws1 + 1);
156
316k
      temp2 = (FLOAT32)((temp2 + temp1) * 0.5f);
157
316k
      multout_temp = (temp1 * *ptr_spec++);
158
316k
      *ptr_ws1++ = multout_temp;
159
316k
    }
160
161
23.3k
    if (remaining) {
162
70.1k
      for (i = remaining - 1; i >= 0; i--) {
163
46.7k
        temp1 = *(ptr_ws1 + 1);
164
165
46.7k
        multout_temp = (temp2 * *ptr_spec++);
166
46.7k
        *ptr_ws1++ = multout_temp;
167
46.7k
        temp2 = (FLOAT32)((temp1 + temp2) * 0.5f);
168
46.7k
      }
169
23.3k
    }
170
171
23.3k
    multout_temp = (temp2 + ptr_spectrum[lpc_stop_line - 1]);
172
173
23.3k
    ptr_weighted_spec[lpc_stop_line - 1] = multout_temp;
174
23.3k
  }
175
734k
}
176
177
VOID ia_enhaacplus_enc_auto_correlation(const FLOAT32 *ptr_input, FLOAT32 *ptr_corr,
178
734k
                                        WORD32 samples, WORD32 corr_coeff) {
179
734k
  WORD32 i, j;
180
734k
  FLOAT32 tmp_var;
181
734k
  WORD32 remaining;
182
734k
  remaining = corr_coeff - ((corr_coeff >> 1) << 1);
183
184
43.0M
  for (i = 0; i < samples; i += 2) {
185
42.3M
    const FLOAT32 *ptr_input1 = &ptr_input[i];
186
42.3M
    FLOAT32 temp1 = *ptr_input1;
187
42.3M
    FLOAT32 temp2 = *(ptr_input1 + 1);
188
42.3M
    FLOAT32 inp_tmp1 = *ptr_input1++;
189
270M
    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.3M
    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.3M
  }
207
734k
}
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
338k
                                               FLOAT32 *ptr_output) {
212
338k
  FLOAT32 state_par[TEMPORAL_NOISE_SHAPING_MAX_ORDER] = {0};
213
338k
  WORD32 j;
214
215
338k
  if (order <= 0) {
216
12
    return;
217
12
  }
218
219
65.8M
  for (j = 0; j < num_lines; j++) {
220
65.5M
    WORD32 i;
221
65.5M
    FLOAT32 x = ptr_signal[j];
222
65.5M
    FLOAT32 accu, tmp, tmp_save;
223
224
65.5M
    tmp_save = x;
225
65.5M
    accu = x;
226
227
456M
    for (i = 0; i < order - 1; i++) {
228
390M
      tmp = (accu * ptr_par_coeff[i]);
229
230
390M
      tmp += state_par[i];
231
232
390M
      accu += (state_par[i] * ptr_par_coeff[i]);
233
234
390M
      state_par[i] = tmp_save;
235
390M
      tmp_save = tmp;
236
390M
    }
237
238
    /* last stage: only need half operations */
239
65.5M
    accu += (state_par[order - 1] * ptr_par_coeff[order - 1]);
240
241
65.5M
    state_par[order - 1] = tmp_save;
242
243
65.5M
    ptr_output[j] = accu;
244
65.5M
  }
245
338k
}