Coverage Report

Created: 2026-09-28 07:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_pred_vec_block.c
Line
Count
Source
1
/******************************************************************************
2
 *                                                                            *
3
 * Copyright (C) 2018 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
#include <stdio.h>
21
#include <stdlib.h>
22
#include <math.h>
23
#include <string.h>
24
#include "ixheaac_type_def.h"
25
#include "ixheaac_sbr_const.h"
26
27
#include "ixheaacd_pvc_dec.h"
28
#include "ixheaacd_pvc_rom.h"
29
30
static VOID ixheaacd_pvc_sb_parsing(ia_pvc_data_struct *ptr_pvc_data,
31
91.8k
                                    WORD16 first_bnd_idx, FLOAT32 *p_qmfh) {
32
91.8k
  WORD32 ksg, k;
33
91.8k
  WORD32 start_band, end_band;
34
91.8k
  WORD32 time_slot;
35
36
91.8k
  FLOAT32 *p_sbr_range_esg = &ptr_pvc_data->sbr_range_esg_arr[0];
37
38
1.56M
  for (time_slot = 0; time_slot < PVC_NUM_TIME_SLOTS; time_slot++) {
39
1.46M
    start_band = first_bnd_idx;
40
1.46M
    end_band = start_band + ptr_pvc_data->nb_high_per_grp - 1;
41
42
10.5M
    for (ksg = 0; ksg < ptr_pvc_data->nb_high; ksg++) {
43
78.6M
      for (k = start_band; k <= end_band; k++) {
44
69.6M
        p_qmfh[k] = (FLOAT32)pow(10.0f, (p_sbr_range_esg[ksg] / 10.0));
45
69.6M
      }
46
9.05M
      start_band += ptr_pvc_data->nb_high_per_grp;
47
9.05M
      if (ksg >= ptr_pvc_data->nb_high - 2) {
48
2.93M
        end_band = SBR_NUM_QMF_BANDS - 1;
49
6.11M
      } else {
50
6.11M
        end_band = start_band + ptr_pvc_data->nb_high_per_grp - 1;
51
6.11M
        if (end_band >= SBR_NUM_QMF_BANDS - 1) {
52
0
          end_band = SBR_NUM_QMF_BANDS - 1;
53
0
        }
54
6.11M
      }
55
9.05M
    }
56
1.46M
    p_sbr_range_esg = p_sbr_range_esg + 8;
57
1.46M
    p_qmfh = p_qmfh + SBR_NUM_QMF_BANDS;
58
1.46M
  }
59
91.8k
  return;
60
91.8k
}
61
62
static VOID ixheaacd_pvc_qmf_grouping(ia_pvc_data_struct *ptr_pvc_data,
63
                                      WORD16 first_bnd_idx, FLOAT32 *p_qmf_ener,
64
91.8k
                                      WORD32 first_pvc_timeslot) {
65
91.8k
  WORD32 ksg, time_slot, ib;
66
91.8k
  WORD32 lbw, start_band, end_band;
67
91.8k
  FLOAT32 esg;
68
91.8k
  FLOAT32 *p_esg = (FLOAT32 *)ptr_pvc_data->esg;
69
70
91.8k
  lbw = 8 / ptr_pvc_data->pvc_rate;
71
72
1.56M
  for (time_slot = 0; time_slot < PVC_NUM_TIME_SLOTS; time_slot++) {
73
5.87M
    for (ksg = 0; ksg < PVC_NB_LOW; ksg++) {
74
4.40M
      start_band = first_bnd_idx - lbw * PVC_NB_LOW + lbw * ksg;
75
4.40M
      end_band = start_band + lbw - 1;
76
4.40M
      if (start_band >= 0) {
77
3.93M
        esg = 0.0f;
78
18.5M
        for (ib = start_band; ib <= end_band; ib++) {
79
14.5M
          esg += p_qmf_ener[ib];
80
14.5M
        }
81
3.93M
        esg = esg / lbw;
82
3.93M
      } else {
83
473k
        esg = PVC_ESG_MIN_VAL;
84
473k
      }
85
86
4.40M
      if (esg > PVC_ESG_MIN_VAL) {
87
1.61M
        p_esg[(time_slot + 16 - 1) * 3 + ksg] = 10 * ((FLOAT32)log10(esg));
88
2.79M
      } else {
89
2.79M
        p_esg[(time_slot + 16 - 1) * 3 + ksg] = PVC_10LOG10_ESG_MIN_VAL;
90
2.79M
      }
91
4.40M
    }
92
1.46M
    p_qmf_ener = p_qmf_ener + SBR_NUM_QMF_BANDS_2;
93
1.46M
  }
94
95
91.8k
  if ((ptr_pvc_data->prev_pvc_flg == 0) ||
96
89.6k
      ((first_bnd_idx * ptr_pvc_data->pvc_rate) !=
97
89.6k
       (ptr_pvc_data->prev_first_bnd_idx * ptr_pvc_data->prev_pvc_rate))) {
98
166k
    for (time_slot = 0; time_slot < 16 - 1 + first_pvc_timeslot; time_slot++) {
99
625k
      for (ksg = 0; ksg < PVC_NB_LOW; ksg++) {
100
468k
        p_esg[time_slot * 3 + ksg] =
101
468k
            p_esg[(16 - 1 + first_pvc_timeslot) * 3 + ksg];
102
468k
      }
103
156k
    }
104
10.3k
  }
105
106
91.8k
  return;
107
91.8k
}
108
109
91.8k
static VOID ixheaacd_pvc_time_smoothing(ia_pvc_data_struct *ptr_pvc_data) {
110
91.8k
  WORD32 time_slot;
111
91.8k
  FLOAT32 *p_smooth_esg = (FLOAT32 *)&ptr_pvc_data->smooth_esg_arr[0];
112
1.56M
  for (time_slot = 0; time_slot < PVC_NUM_TIME_SLOTS; time_slot++) {
113
1.46M
    WORD32 ksg, time_slot_idx;
114
1.46M
    FLOAT32 *p_esg = (FLOAT32 *)&ptr_pvc_data->esg[time_slot + 16 - 1][2];
115
1.46M
    FLOAT32 *p_smth_wind_coeff = (FLOAT32 *)&ptr_pvc_data->p_smth_wind_coeff[0];
116
1.46M
    memset(p_smooth_esg, (WORD32)0.f, sizeof(FLOAT32) * PVC_NB_LOW);
117
17.0M
    for (time_slot_idx = 0; time_slot_idx < ptr_pvc_data->num_time_slots;
118
15.6M
         time_slot_idx++) {
119
15.6M
      ksg = PVC_NB_LOW - 1;
120
62.5M
      for (; ksg >= 0; ksg--) {
121
46.8M
        p_smooth_esg[ksg] += (*p_esg) * (*p_smth_wind_coeff);
122
46.8M
        p_esg--;
123
46.8M
      }
124
15.6M
      p_smth_wind_coeff++;
125
15.6M
    }
126
1.46M
    p_smooth_esg = p_smooth_esg + 3;
127
1.46M
  }
128
91.8k
  return;
129
91.8k
}
130
131
91.8k
static VOID ixheaacd_pvc_pred_env_sf(ia_pvc_data_struct *ptr_pvc_data) {
132
91.8k
  WORD32 ksg, kb;
133
91.8k
  WORD32 tab_1_index, tab_2_index;
134
91.8k
  WORD32 time_slot;
135
91.8k
  WORD8 *pred_tab_1, *pred_tab_2;
136
137
91.8k
  FLOAT32 temp;
138
91.8k
  FLOAT32 *p_smooth_esg = &ptr_pvc_data->smooth_esg_arr[0];
139
91.8k
  FLOAT32 *p_sbr_range_esg = &ptr_pvc_data->sbr_range_esg_arr[0];
140
141
1.56M
  for (time_slot = 0; time_slot < PVC_NUM_TIME_SLOTS; time_slot++) {
142
1.46M
    tab_2_index = ptr_pvc_data->pvc_id[time_slot];
143
144
1.46M
    if (tab_2_index < ptr_pvc_data->p_pvc_id_boundary[0]) {
145
650k
      tab_1_index = 0;
146
818k
    } else if (tab_2_index < ptr_pvc_data->p_pvc_id_boundary[1]) {
147
573k
      tab_1_index = 1;
148
573k
    } else {
149
245k
      tab_1_index = 2;
150
245k
    }
151
152
1.46M
    pred_tab_1 =
153
1.46M
        (WORD8 *)(&(ptr_pvc_data->p_pred_coeff_tab_1[tab_1_index * PVC_NB_LOW *
154
1.46M
                                                     ptr_pvc_data->nb_high]));
155
1.46M
    pred_tab_2 = (WORD8 *)(&(
156
1.46M
        ptr_pvc_data->p_pred_coeff_tab_2[tab_2_index * ptr_pvc_data->nb_high]));
157
158
10.5M
    for (ksg = 0; ksg < ptr_pvc_data->nb_high; ksg++) {
159
9.05M
      temp =
160
9.05M
          (FLOAT32)(WORD8)(*(pred_tab_2++)) * ptr_pvc_data->p_q_fac[PVC_NB_LOW];
161
9.05M
      p_sbr_range_esg[ksg] = temp;
162
9.05M
    }
163
5.87M
    for (kb = 0; kb < PVC_NB_LOW; kb++) {
164
31.5M
      for (ksg = 0; ksg < ptr_pvc_data->nb_high; ksg++) {
165
27.1M
        temp = (FLOAT32)(WORD8)(*(pred_tab_1++)) * ptr_pvc_data->p_q_fac[kb];
166
27.1M
        p_sbr_range_esg[ksg] += temp * p_smooth_esg[kb];
167
27.1M
      }
168
4.40M
    }
169
1.46M
    p_smooth_esg = p_smooth_esg + 3;
170
1.46M
    p_sbr_range_esg = p_sbr_range_esg + 8;
171
1.46M
  }
172
173
91.8k
  return;
174
91.8k
}
175
176
WORD32 ixheaacd_pvc_process(ia_pvc_data_struct *ptr_pvc_data,
177
                            WORD16 first_bnd_idx, WORD32 first_pvc_timeslot,
178
91.9k
                            FLOAT32 *p_qmf_ener, FLOAT32 *p_qmfh) {
179
91.9k
  switch (ptr_pvc_data->pvc_mode) {
180
7.45k
    case 1:
181
7.45k
      ptr_pvc_data->nb_high = PVC_NB_HIGH_MODE1;
182
7.45k
      ptr_pvc_data->nb_high_per_grp = 8 / ptr_pvc_data->pvc_rate;
183
7.45k
      ptr_pvc_data->p_pred_coeff_tab_1 =
184
7.45k
          (WORD8 *)ixheaacd_pred_coeff_table_1_mode_1;
185
7.45k
      ptr_pvc_data->p_pred_coeff_tab_2 =
186
7.45k
          (WORD8 *)ixheaacd_pred_coeff_table_2_mode_1;
187
7.45k
      ptr_pvc_data->p_pvc_id_boundary =
188
7.45k
          (UWORD8 *)ixheaacd_pred_coeff_pvc_id_boundaries_1;
189
7.45k
      ptr_pvc_data->p_q_fac = (FLOAT32 *)ixheaacd_q_factor_table_mode_1;
190
7.45k
      if (ptr_pvc_data->ns_mode) {
191
295
        ptr_pvc_data->num_time_slots = 4;
192
295
        ptr_pvc_data->p_smth_wind_coeff =
193
295
            (FLOAT32 *)ixheaacd_pvc_smoothing_wind_tab_ns4;
194
7.16k
      } else {
195
7.16k
        ptr_pvc_data->num_time_slots = 16;
196
7.16k
        ptr_pvc_data->p_smth_wind_coeff =
197
7.16k
            (FLOAT32 *)ixheaacd_pvc_smoothing_wind_tab_ns16;
198
7.16k
      }
199
7.45k
      break;
200
84.4k
    case 2:
201
84.4k
      ptr_pvc_data->nb_high = PVC_NB_HIGH_MODE2;
202
84.4k
      ptr_pvc_data->nb_high_per_grp = 12 / ptr_pvc_data->pvc_rate;
203
84.4k
      ptr_pvc_data->p_pred_coeff_tab_1 =
204
84.4k
          (WORD8 *)ixheaacd_pred_coeff_table_1_mode_2;
205
84.4k
      ptr_pvc_data->p_pred_coeff_tab_2 =
206
84.4k
          (WORD8 *)ixheaacd_pred_coeff_table_2_mode_2;
207
84.4k
      ptr_pvc_data->p_pvc_id_boundary =
208
84.4k
          (UWORD8 *)ixheaacd_pred_coeff_pvc_id_boundaries_2;
209
84.4k
      ptr_pvc_data->p_q_fac = (FLOAT32 *)ixheaacd_q_factor_table_mode_2;
210
84.4k
      if (ptr_pvc_data->ns_mode) {
211
16.8k
        ptr_pvc_data->num_time_slots = 3;
212
16.8k
        ptr_pvc_data->p_smth_wind_coeff =
213
16.8k
            (FLOAT32 *)ixheaacd_pvc_smoothing_wind_tab_ns3;
214
67.5k
      } else {
215
67.5k
        ptr_pvc_data->num_time_slots = 12;
216
67.5k
        ptr_pvc_data->p_smth_wind_coeff =
217
67.5k
            (FLOAT32 *)ixheaacd_pvc_smoothing_wind_tab_ns12;
218
67.5k
      }
219
84.4k
      break;
220
59
    default:
221
59
      return -1;
222
91.9k
  }
223
91.8k
  ptr_pvc_data->prev_pvc_id = ptr_pvc_data->pvc_id[PVC_NUM_TIME_SLOTS - 1];
224
225
91.8k
  ixheaacd_pvc_qmf_grouping(ptr_pvc_data, first_bnd_idx, p_qmf_ener,
226
91.8k
                            first_pvc_timeslot);
227
228
91.8k
  ixheaacd_pvc_time_smoothing(ptr_pvc_data);
229
230
91.8k
  ixheaacd_pvc_pred_env_sf(ptr_pvc_data);
231
232
91.8k
  ixheaacd_pvc_sb_parsing(ptr_pvc_data, first_bnd_idx, p_qmfh);
233
234
91.8k
  memcpy((FLOAT32 *)(&ptr_pvc_data->esg[0][0]),
235
91.8k
         (FLOAT32 *)(&ptr_pvc_data->esg[PVC_NUM_TIME_SLOTS][0]),
236
91.8k
         sizeof(FLOAT32) * (PVC_NUM_TIME_SLOTS - 1) * 3);
237
238
91.8k
  return 0;
239
91.9k
}