Coverage Report

Created: 2026-01-17 06:57

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
87.8k
                                    WORD16 first_bnd_idx, FLOAT32 *p_qmfh) {
32
87.8k
  WORD32 ksg, k;
33
87.8k
  WORD32 start_band, end_band;
34
87.8k
  WORD32 time_slot;
35
36
87.8k
  FLOAT32 *p_sbr_range_esg = &ptr_pvc_data->sbr_range_esg_arr[0];
37
38
1.49M
  for (time_slot = 0; time_slot < PVC_NUM_TIME_SLOTS; time_slot++) {
39
1.40M
    start_band = first_bnd_idx;
40
1.40M
    end_band = start_band + ptr_pvc_data->nb_high_per_grp - 1;
41
42
9.96M
    for (ksg = 0; ksg < ptr_pvc_data->nb_high; ksg++) {
43
82.1M
      for (k = start_band; k <= end_band; k++) {
44
73.6M
        p_qmfh[k] = (FLOAT32)pow(10.0f, (p_sbr_range_esg[ksg] / 10.0));
45
73.6M
      }
46
8.55M
      start_band += ptr_pvc_data->nb_high_per_grp;
47
8.55M
      if (ksg >= ptr_pvc_data->nb_high - 2) {
48
2.81M
        end_band = SBR_NUM_QMF_BANDS - 1;
49
5.74M
      } else {
50
5.74M
        end_band = start_band + ptr_pvc_data->nb_high_per_grp - 1;
51
5.74M
        if (end_band >= SBR_NUM_QMF_BANDS - 1) {
52
0
          end_band = SBR_NUM_QMF_BANDS - 1;
53
0
        }
54
5.74M
      }
55
8.55M
    }
56
1.40M
    p_sbr_range_esg = p_sbr_range_esg + 8;
57
1.40M
    p_qmfh = p_qmfh + SBR_NUM_QMF_BANDS;
58
1.40M
  }
59
87.8k
  return;
60
87.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
87.8k
                                      WORD32 first_pvc_timeslot) {
65
87.8k
  WORD32 ksg, time_slot, ib;
66
87.8k
  WORD32 lbw, start_band, end_band;
67
87.8k
  FLOAT32 esg;
68
87.8k
  FLOAT32 *p_esg = (FLOAT32 *)ptr_pvc_data->esg;
69
70
87.8k
  lbw = 8 / ptr_pvc_data->pvc_rate;
71
72
1.49M
  for (time_slot = 0; time_slot < PVC_NUM_TIME_SLOTS; time_slot++) {
73
5.62M
    for (ksg = 0; ksg < PVC_NB_LOW; ksg++) {
74
4.21M
      start_band = first_bnd_idx - lbw * PVC_NB_LOW + lbw * ksg;
75
4.21M
      end_band = start_band + lbw - 1;
76
4.21M
      if (start_band >= 0) {
77
2.96M
        esg = 0.0f;
78
14.1M
        for (ib = start_band; ib <= end_band; ib++) {
79
11.1M
          esg += p_qmf_ener[ib];
80
11.1M
        }
81
2.96M
        esg = esg / lbw;
82
2.96M
      } else {
83
1.25M
        esg = PVC_ESG_MIN_VAL;
84
1.25M
      }
85
86
4.21M
      if (esg > PVC_ESG_MIN_VAL) {
87
1.34M
        p_esg[(time_slot + 16 - 1) * 3 + ksg] = 10 * ((FLOAT32)log10(esg));
88
2.87M
      } else {
89
2.87M
        p_esg[(time_slot + 16 - 1) * 3 + ksg] = PVC_10LOG10_ESG_MIN_VAL;
90
2.87M
      }
91
4.21M
    }
92
1.40M
    p_qmf_ener = p_qmf_ener + SBR_NUM_QMF_BANDS_2;
93
1.40M
  }
94
95
87.8k
  if ((ptr_pvc_data->prev_pvc_flg == 0) ||
96
85.8k
      ((first_bnd_idx * ptr_pvc_data->pvc_rate) !=
97
85.8k
       (ptr_pvc_data->prev_first_bnd_idx * ptr_pvc_data->prev_pvc_rate))) {
98
147k
    for (time_slot = 0; time_slot < 16 - 1 + first_pvc_timeslot; time_slot++) {
99
553k
      for (ksg = 0; ksg < PVC_NB_LOW; ksg++) {
100
415k
        p_esg[time_slot * 3 + ksg] =
101
415k
            p_esg[(16 - 1 + first_pvc_timeslot) * 3 + ksg];
102
415k
      }
103
138k
    }
104
9.18k
  }
105
106
87.8k
  return;
107
87.8k
}
108
109
87.8k
static VOID ixheaacd_pvc_time_smoothing(ia_pvc_data_struct *ptr_pvc_data) {
110
87.8k
  WORD32 time_slot;
111
87.8k
  FLOAT32 *p_smooth_esg = (FLOAT32 *)&ptr_pvc_data->smooth_esg_arr[0];
112
1.49M
  for (time_slot = 0; time_slot < PVC_NUM_TIME_SLOTS; time_slot++) {
113
1.40M
    WORD32 ksg, time_slot_idx;
114
1.40M
    FLOAT32 *p_esg = (FLOAT32 *)&ptr_pvc_data->esg[time_slot + 16 - 1][2];
115
1.40M
    FLOAT32 *p_smth_wind_coeff = (FLOAT32 *)&ptr_pvc_data->p_smth_wind_coeff[0];
116
1.40M
    memset(p_smooth_esg, (WORD32)0.f, sizeof(FLOAT32) * PVC_NB_LOW);
117
15.9M
    for (time_slot_idx = 0; time_slot_idx < ptr_pvc_data->num_time_slots;
118
14.5M
         time_slot_idx++) {
119
14.5M
      ksg = PVC_NB_LOW - 1;
120
58.0M
      for (; ksg >= 0; ksg--) {
121
43.5M
        p_smooth_esg[ksg] += (*p_esg) * (*p_smth_wind_coeff);
122
43.5M
        p_esg--;
123
43.5M
      }
124
14.5M
      p_smth_wind_coeff++;
125
14.5M
    }
126
1.40M
    p_smooth_esg = p_smooth_esg + 3;
127
1.40M
  }
128
87.8k
  return;
129
87.8k
}
130
131
87.8k
static VOID ixheaacd_pvc_pred_env_sf(ia_pvc_data_struct *ptr_pvc_data) {
132
87.8k
  WORD32 ksg, kb;
133
87.8k
  WORD32 tab_1_index, tab_2_index;
134
87.8k
  WORD32 time_slot;
135
87.8k
  WORD8 *pred_tab_1, *pred_tab_2;
136
137
87.8k
  FLOAT32 temp;
138
87.8k
  FLOAT32 *p_smooth_esg = &ptr_pvc_data->smooth_esg_arr[0];
139
87.8k
  FLOAT32 *p_sbr_range_esg = &ptr_pvc_data->sbr_range_esg_arr[0];
140
141
1.49M
  for (time_slot = 0; time_slot < PVC_NUM_TIME_SLOTS; time_slot++) {
142
1.40M
    tab_2_index = ptr_pvc_data->pvc_id[time_slot];
143
144
1.40M
    if (tab_2_index < ptr_pvc_data->p_pvc_id_boundary[0]) {
145
508k
      tab_1_index = 0;
146
896k
    } else if (tab_2_index < ptr_pvc_data->p_pvc_id_boundary[1]) {
147
674k
      tab_1_index = 1;
148
674k
    } else {
149
222k
      tab_1_index = 2;
150
222k
    }
151
152
1.40M
    pred_tab_1 =
153
1.40M
        (WORD8 *)(&(ptr_pvc_data->p_pred_coeff_tab_1[tab_1_index * PVC_NB_LOW *
154
1.40M
                                                     ptr_pvc_data->nb_high]));
155
1.40M
    pred_tab_2 = (WORD8 *)(&(
156
1.40M
        ptr_pvc_data->p_pred_coeff_tab_2[tab_2_index * ptr_pvc_data->nb_high]));
157
158
9.96M
    for (ksg = 0; ksg < ptr_pvc_data->nb_high; ksg++) {
159
8.55M
      temp =
160
8.55M
          (FLOAT32)(WORD8)(*(pred_tab_2++)) * ptr_pvc_data->p_q_fac[PVC_NB_LOW];
161
8.55M
      p_sbr_range_esg[ksg] = temp;
162
8.55M
    }
163
5.62M
    for (kb = 0; kb < PVC_NB_LOW; kb++) {
164
29.8M
      for (ksg = 0; ksg < ptr_pvc_data->nb_high; ksg++) {
165
25.6M
        temp = (FLOAT32)(WORD8)(*(pred_tab_1++)) * ptr_pvc_data->p_q_fac[kb];
166
25.6M
        p_sbr_range_esg[ksg] += temp * p_smooth_esg[kb];
167
25.6M
      }
168
4.21M
    }
169
1.40M
    p_smooth_esg = p_smooth_esg + 3;
170
1.40M
    p_sbr_range_esg = p_sbr_range_esg + 8;
171
1.40M
  }
172
173
87.8k
  return;
174
87.8k
}
175
176
WORD32 ixheaacd_pvc_process(ia_pvc_data_struct *ptr_pvc_data,
177
                            WORD16 first_bnd_idx, WORD32 first_pvc_timeslot,
178
87.8k
                            FLOAT32 *p_qmf_ener, FLOAT32 *p_qmfh) {
179
87.8k
  switch (ptr_pvc_data->pvc_mode) {
180
3.95k
    case 1:
181
3.95k
      ptr_pvc_data->nb_high = PVC_NB_HIGH_MODE1;
182
3.95k
      ptr_pvc_data->nb_high_per_grp = 8 / ptr_pvc_data->pvc_rate;
183
3.95k
      ptr_pvc_data->p_pred_coeff_tab_1 =
184
3.95k
          (WORD8 *)ixheaacd_pred_coeff_table_1_mode_1;
185
3.95k
      ptr_pvc_data->p_pred_coeff_tab_2 =
186
3.95k
          (WORD8 *)ixheaacd_pred_coeff_table_2_mode_1;
187
3.95k
      ptr_pvc_data->p_pvc_id_boundary =
188
3.95k
          (UWORD8 *)ixheaacd_pred_coeff_pvc_id_boundaries_1;
189
3.95k
      ptr_pvc_data->p_q_fac = (FLOAT32 *)ixheaacd_q_factor_table_mode_1;
190
3.95k
      if (ptr_pvc_data->ns_mode) {
191
380
        ptr_pvc_data->num_time_slots = 4;
192
380
        ptr_pvc_data->p_smth_wind_coeff =
193
380
            (FLOAT32 *)ixheaacd_pvc_smoothing_wind_tab_ns4;
194
3.57k
      } else {
195
3.57k
        ptr_pvc_data->num_time_slots = 16;
196
3.57k
        ptr_pvc_data->p_smth_wind_coeff =
197
3.57k
            (FLOAT32 *)ixheaacd_pvc_smoothing_wind_tab_ns16;
198
3.57k
      }
199
3.95k
      break;
200
83.8k
    case 2:
201
83.8k
      ptr_pvc_data->nb_high = PVC_NB_HIGH_MODE2;
202
83.8k
      ptr_pvc_data->nb_high_per_grp = 12 / ptr_pvc_data->pvc_rate;
203
83.8k
      ptr_pvc_data->p_pred_coeff_tab_1 =
204
83.8k
          (WORD8 *)ixheaacd_pred_coeff_table_1_mode_2;
205
83.8k
      ptr_pvc_data->p_pred_coeff_tab_2 =
206
83.8k
          (WORD8 *)ixheaacd_pred_coeff_table_2_mode_2;
207
83.8k
      ptr_pvc_data->p_pvc_id_boundary =
208
83.8k
          (UWORD8 *)ixheaacd_pred_coeff_pvc_id_boundaries_2;
209
83.8k
      ptr_pvc_data->p_q_fac = (FLOAT32 *)ixheaacd_q_factor_table_mode_2;
210
83.8k
      if (ptr_pvc_data->ns_mode) {
211
17.5k
        ptr_pvc_data->num_time_slots = 3;
212
17.5k
        ptr_pvc_data->p_smth_wind_coeff =
213
17.5k
            (FLOAT32 *)ixheaacd_pvc_smoothing_wind_tab_ns3;
214
66.2k
      } else {
215
66.2k
        ptr_pvc_data->num_time_slots = 12;
216
66.2k
        ptr_pvc_data->p_smth_wind_coeff =
217
66.2k
            (FLOAT32 *)ixheaacd_pvc_smoothing_wind_tab_ns12;
218
66.2k
      }
219
83.8k
      break;
220
79
    default:
221
79
      return -1;
222
87.8k
  }
223
87.8k
  ptr_pvc_data->prev_pvc_id = ptr_pvc_data->pvc_id[PVC_NUM_TIME_SLOTS - 1];
224
225
87.8k
  ixheaacd_pvc_qmf_grouping(ptr_pvc_data, first_bnd_idx, p_qmf_ener,
226
87.8k
                            first_pvc_timeslot);
227
228
87.8k
  ixheaacd_pvc_time_smoothing(ptr_pvc_data);
229
230
87.8k
  ixheaacd_pvc_pred_env_sf(ptr_pvc_data);
231
232
87.8k
  ixheaacd_pvc_sb_parsing(ptr_pvc_data, first_bnd_idx, p_qmfh);
233
234
87.8k
  memcpy((FLOAT32 *)(&ptr_pvc_data->esg[0][0]),
235
87.8k
         (FLOAT32 *)(&ptr_pvc_data->esg[PVC_NUM_TIME_SLOTS][0]),
236
87.8k
         sizeof(FLOAT32) * (PVC_NUM_TIME_SLOTS - 1) * 3);
237
238
87.8k
  return 0;
239
87.8k
}