Coverage Report

Created: 2025-12-10 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/encoder/ixheaace_group_data.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 <string.h>
22
#include <stdlib.h>
23
#include "ixheaac_type_def.h"
24
#include "ixheaac_constants.h"
25
#include "ixheaace_psy_const.h"
26
#include "ixheaace_tns.h"
27
#include "ixheaace_tns_params.h"
28
#include "ixheaace_rom.h"
29
#include "ixheaace_common_rom.h"
30
#include "ixheaace_bitbuffer.h"
31
#include "ixheaace_aac_constants.h"
32
#include "ixheaace_block_switch.h"
33
#include "ixheaace_psy_data.h"
34
#include "ixheaace_interface.h"
35
#include "ixheaace_group_data.h"
36
37
#include "ixheaac_basic_ops32.h"
38
#include "ixheaac_basic_ops16.h"
39
#include "ixheaac_basic_ops40.h"
40
#include "ixheaac_basic_ops.h"
41
42
VOID iaace_group_short_data(FLOAT32 *ptr_mdct_spectrum, FLOAT32 *ptr_tmp_spectrum,
43
                            ixheaace_sfb_energy *pstr_sfb_threshold,
44
                            ixheaace_sfb_energy *pstr_sfb_energy,
45
                            ixheaace_sfb_energy *pstr_sfb_energy_ms,
46
                            ixheaace_sfb_energy *pstr_sfb_spreaded_energy, const WORD32 sfb_cnt,
47
                            const WORD32 *ptr_sfb_offset, const FLOAT32 *ptr_sfb_min_snr,
48
                            WORD32 *ptr_grouped_sfb_offset, WORD32 *ptr_max_sfb_per_group,
49
                            FLOAT32 *ptr_grouped_sfb_min_snr, const WORD32 no_of_groups,
50
66.0k
                            const WORD32 *ptr_group_len, WORD32 frame_length) {
51
66.0k
  WORD32 i, j;
52
66.0k
  WORD32 line;
53
66.0k
  WORD32 sfb;
54
66.0k
  WORD32 grp;
55
66.0k
  WORD32 wnd;
56
66.0k
  WORD32 offset;
57
66.0k
  WORD32 highest_sfb;
58
59
  /* For short: regroup and cumulate energies und thresholds group-wise */
60
  /* Calculate sfb_cnt */
61
62
66.0k
  highest_sfb = 0;
63
64
594k
  for (wnd = 0; wnd < TRANS_FAC; wnd++) {
65
2.29M
    for (sfb = sfb_cnt - 1; sfb >= highest_sfb; sfb--) {
66
29.8M
      for (line = ptr_sfb_offset[sfb + 1] - 1; line >= ptr_sfb_offset[sfb]; line--) {
67
28.0M
        if (ptr_mdct_spectrum[wnd * (frame_length / 8) + line] != 0.0) {
68
500k
          break;
69
500k
        }
70
28.0M
      }
71
72
2.27M
      if (line >= ptr_sfb_offset[sfb]) {
73
500k
        break;
74
500k
      }
75
2.27M
    }
76
528k
    highest_sfb = MAX(highest_sfb, sfb);
77
528k
  }
78
79
66.0k
  highest_sfb = highest_sfb > 0 ? highest_sfb : 0;
80
81
66.0k
  *ptr_max_sfb_per_group = highest_sfb + 1;
82
83
  /* Calculate ptr_sfb_offset */
84
66.0k
  i = 0;
85
66.0k
  offset = 0;
86
87
319k
  for (grp = 0; grp < no_of_groups; grp++) {
88
3.96M
    for (sfb = 0; sfb < sfb_cnt; sfb++) {
89
3.71M
      ptr_grouped_sfb_offset[i++] = offset + ptr_sfb_offset[sfb] * ptr_group_len[grp];
90
3.71M
    }
91
92
253k
    offset += ptr_group_len[grp] * (frame_length / 8);
93
253k
  }
94
95
66.0k
  ptr_grouped_sfb_offset[i++] = frame_length;
96
97
  /* Calculate min SNR */
98
99
66.0k
  i = 0;
100
66.0k
  offset = 0;
101
102
319k
  for (grp = 0; grp < no_of_groups; grp++) {
103
253k
    memcpy(&ptr_grouped_sfb_min_snr[i], &ptr_sfb_min_snr[0], sfb_cnt * sizeof(*ptr_sfb_min_snr));
104
253k
    i += sfb_cnt;
105
106
253k
    offset += ptr_group_len[grp] * (frame_length / 8);
107
253k
  }
108
109
66.0k
  wnd = 0;
110
66.0k
  i = 0;
111
112
319k
  for (grp = 0; grp < no_of_groups; grp++) {
113
3.96M
    for (sfb = 0; sfb < sfb_cnt; sfb++) {
114
3.71M
      FLOAT32 thresh = pstr_sfb_threshold->short_nrg[wnd][sfb];
115
116
7.72M
      for (j = 1; j < ptr_group_len[grp]; j++) {
117
4.01M
        thresh += pstr_sfb_threshold->short_nrg[wnd + j][sfb];
118
4.01M
      }
119
120
3.71M
      pstr_sfb_threshold->long_nrg[i++] = thresh;
121
3.71M
    }
122
253k
    wnd += ptr_group_len[grp];
123
253k
  }
124
125
  /* Sum up sfb energies -  left/right */
126
66.0k
  wnd = 0;
127
66.0k
  i = 0;
128
129
319k
  for (grp = 0; grp < no_of_groups; grp++) {
130
3.96M
    for (sfb = 0; sfb < sfb_cnt; sfb++) {
131
3.71M
      FLOAT32 energy = pstr_sfb_energy->short_nrg[wnd][sfb];
132
133
7.72M
      for (j = 1; j < ptr_group_len[grp]; j++) {
134
4.01M
        energy += pstr_sfb_energy->short_nrg[wnd + j][sfb];
135
4.01M
      }
136
137
3.71M
      pstr_sfb_energy->long_nrg[i++] = energy;
138
3.71M
    }
139
253k
    wnd += ptr_group_len[grp];
140
253k
  }
141
142
  /* Sum up sfb energies mid/side */
143
66.0k
  wnd = 0;
144
66.0k
  i = 0;
145
146
319k
  for (grp = 0; grp < no_of_groups; grp++) {
147
3.96M
    for (sfb = 0; sfb < sfb_cnt; sfb++) {
148
3.71M
      FLOAT32 energy = pstr_sfb_energy_ms->short_nrg[wnd][sfb];
149
150
7.72M
      for (j = 1; j < ptr_group_len[grp]; j++) {
151
4.01M
        energy += pstr_sfb_energy_ms->short_nrg[wnd + j][sfb];
152
4.01M
      }
153
154
3.71M
      pstr_sfb_energy_ms->long_nrg[i++] = energy;
155
3.71M
    }
156
253k
    wnd += ptr_group_len[grp];
157
253k
  }
158
159
  /* Sum up sfb spreaded energies */
160
66.0k
  wnd = 0;
161
66.0k
  i = 0;
162
163
319k
  for (grp = 0; grp < no_of_groups; grp++) {
164
3.96M
    for (sfb = 0; sfb < sfb_cnt; sfb++) {
165
3.71M
      FLOAT32 energy = pstr_sfb_spreaded_energy->short_nrg[wnd][sfb];
166
167
7.72M
      for (j = 1; j < ptr_group_len[grp]; j++) {
168
4.01M
        energy += pstr_sfb_spreaded_energy->short_nrg[wnd + j][sfb];
169
4.01M
      }
170
3.71M
      pstr_sfb_spreaded_energy->long_nrg[i++] = energy;
171
3.71M
    }
172
253k
    wnd += ptr_group_len[grp];
173
253k
  }
174
175
  /* Re-group spectrum */
176
66.0k
  wnd = 0;
177
66.0k
  i = 0;
178
179
319k
  for (grp = 0; grp < no_of_groups; grp++) {
180
3.96M
    for (sfb = 0; sfb < sfb_cnt; sfb++) {
181
11.4M
      for (j = 0; j < ptr_group_len[grp]; j++) {
182
73.2M
        for (line = ptr_sfb_offset[sfb]; line < ptr_sfb_offset[sfb + 1]; line++) {
183
65.5M
          ptr_tmp_spectrum[i++] = ptr_mdct_spectrum[(wnd + j) * (frame_length / 8) + line];
184
65.5M
        }
185
7.72M
      }
186
3.71M
    }
187
253k
    wnd += ptr_group_len[grp];
188
253k
  }
189
190
66.0k
  memcpy(ptr_mdct_spectrum, ptr_tmp_spectrum, frame_length * sizeof(*ptr_mdct_spectrum));
191
66.0k
}