Coverage Report

Created: 2026-01-10 06:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_mps_m1m2_common.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
#include "ixheaac_type_def.h"
21
#include "ixheaacd_mps_struct_def.h"
22
#include "ixheaacd_error_codes.h"
23
#include "ixheaacd_mps_res_rom.h"
24
#include "ixheaacd_mps_aac_struct.h"
25
#include "ixheaac_constants.h"
26
#include "ixheaac_basic_ops32.h"
27
#include "ixheaac_basic_ops40.h"
28
#include "ixheaacd_bitbuffer.h"
29
#include "ixheaacd_common_rom.h"
30
#include "ixheaacd_sbrdecsettings.h"
31
#include "ixheaacd_sbr_scale.h"
32
#include "ixheaacd_env_extr_part.h"
33
#include "ixheaacd_sbr_rom.h"
34
#include "ixheaacd_hybrid.h"
35
#include "ixheaacd_ps_dec.h"
36
#include "ixheaac_error_standards.h"
37
#include "ixheaacd_mps_polyphase.h"
38
#include "ixheaacd_config.h"
39
#include "ixheaacd_qmf_dec.h"
40
#include "ixheaacd_mps_dec.h"
41
#include "ixheaacd_mps_macro_def.h"
42
#include "ixheaacd_mps_bitdec.h"
43
#include "ixheaacd_mps_calc_m1m2_tree_config.h"
44
45
14.4k
VOID ixheaacd_buffer_m1(ia_heaac_mps_state_struct *pstr_mps_state) {
46
14.4k
  ia_mps_dec_m1_param_struct *m1_param = pstr_mps_state->array_struct->m1_param;
47
14.4k
  WORD32 pb, row, col;
48
49
14.4k
  ia_mps_persistent_mem *persistent_mem = &pstr_mps_state->mps_persistent_mem;
50
14.4k
  WORD32 *m1_param_real_prev = persistent_mem->m1_param_real_prev;
51
14.4k
  WORD32 *m1_param_imag_prev = persistent_mem->m1_param_imag_prev;
52
53
14.4k
  WORD32 *m1_param_real, *m1_param_imag;
54
55
14.4k
  WORD32 *p_m1_param_real, *p_m1_param_re;
56
57
14.4k
  WORD32 num_parameter_bands = pstr_mps_state->num_parameter_bands;
58
14.4k
  WORD32 num_v_channels = pstr_mps_state->num_v_channels;
59
14.4k
  WORD32 num_x_channels = pstr_mps_state->num_x_channels;
60
14.4k
  WORD32 m1_param_imag_present = pstr_mps_state->m1_param_imag_present;
61
62
14.4k
  WORD32 num_parameter_sets_prev;
63
64
14.4k
  pstr_mps_state->num_parameter_sets_prev = pstr_mps_state->num_parameter_sets;
65
14.4k
  num_parameter_sets_prev = pstr_mps_state->num_parameter_sets_prev;
66
67
14.4k
  if (m1_param_imag_present) {
68
10.4k
    WORD32 *p_m1_param_imag = &m1_param->m1_param_imag[0][0][0][0];
69
10.4k
    p_m1_param_real = &m1_param->m1_param_real[0][0][0][0];
70
91.1k
    for (row = 0; row < num_v_channels; row++) {
71
80.7k
      WORD32 *p_m1_param_im = p_m1_param_imag;
72
80.7k
      p_m1_param_re = p_m1_param_real;
73
74
543k
      for (col = 0; col < num_x_channels; col++) {
75
462k
        m1_param_real = p_m1_param_re + (num_parameter_sets_prev - 1) * MAX_PARAMETER_BANDS;
76
462k
        m1_param_imag = p_m1_param_im + (num_parameter_sets_prev - 1) * MAX_PARAMETER_BANDS;
77
78
9.54M
        for (pb = 0; pb < num_parameter_bands; pb++) {
79
9.08M
          *m1_param_real_prev++ = *m1_param_real++;
80
9.08M
          *m1_param_imag_prev++ = *m1_param_imag++;
81
9.08M
        }
82
462k
        p_m1_param_re += PBXPS;
83
462k
        p_m1_param_im += PBXPS;
84
462k
      }
85
80.7k
      p_m1_param_real += MAX_INPUT_CHANNELS_MPS * PBXPS;
86
80.7k
      p_m1_param_imag += MAX_INPUT_CHANNELS_MPS * PBXPS;
87
80.7k
    }
88
10.4k
  } else {
89
4.06k
    p_m1_param_real = &m1_param->m1_param_real[0][0][0][0];
90
29.7k
    for (row = 0; row < num_v_channels; row++) {
91
25.6k
      p_m1_param_re = p_m1_param_real;
92
123k
      for (col = 0; col < num_x_channels; col++) {
93
97.8k
        m1_param_real = p_m1_param_re + (num_parameter_sets_prev - 1) * MAX_PARAMETER_BANDS;
94
1.83M
        for (pb = 0; pb < num_parameter_bands; pb++) *m1_param_real_prev++ = *m1_param_real++;
95
96
97.8k
        p_m1_param_re += PBXPS;
97
97.8k
      }
98
25.6k
      p_m1_param_real += MAX_INPUT_CHANNELS_MPS * PBXPS;
99
25.6k
    }
100
4.06k
  }
101
14.4k
}
102
103
14.4k
VOID ixheaacd_buffer_m2(ia_heaac_mps_state_struct *pstr_mps_state) {
104
14.4k
  WORD32 num_direct_signals = pstr_mps_state->num_direct_signals;
105
14.4k
  WORD32 pb, row, col, col_counter = num_direct_signals + pstr_mps_state->num_decor_signals;
106
107
14.4k
  ia_mps_persistent_mem *persistent_mem = &pstr_mps_state->mps_persistent_mem;
108
14.4k
  ia_mps_dec_m2_param_struct *m2_param = pstr_mps_state->aux_struct->m2_param;
109
110
14.4k
  WORD32 *m2_decor_real_prev = persistent_mem->m2_decor_real_prev;
111
14.4k
  WORD32 *m2_decor_imag_prev = persistent_mem->m2_decor_imag_prev;
112
113
14.4k
  WORD32 *m2_resid_real_prev = persistent_mem->m2_resid_real_prev;
114
14.4k
  WORD32 *m2_resid_imag_prev = persistent_mem->m2_resid_imag_prev;
115
116
14.4k
  WORD32 *m2_decor_real, *m2_decor_imag, *m2_resid_real, *m2_resid_imag;
117
14.4k
  WORD32 idx = -1;
118
119
14.4k
  WORD32 resid_col_counter;
120
121
14.4k
  WORD32 num_parameter_bands = pstr_mps_state->num_parameter_bands;
122
14.4k
  WORD32 num_output_channels = pstr_mps_state->num_output_channels;
123
14.4k
  WORD32 num_parameter_sets_prev = pstr_mps_state->num_parameter_sets_prev;
124
125
14.4k
  if (pstr_mps_state->residual_coding)
126
447
    resid_col_counter = col_counter;
127
14.0k
  else
128
14.0k
    resid_col_counter = num_direct_signals;
129
130
14.4k
  if (pstr_mps_state->m2_param_imag_present) {
131
0
    for (row = 0; row < num_output_channels; row++) {
132
0
      for (col = num_direct_signals; col < col_counter; col++) {
133
0
        if (pstr_mps_state->m2_param_present[row][col] & 1) {
134
0
          idx++;
135
0
          m2_decor_real = &m2_param->m2_decor_real[idx][num_parameter_sets_prev - 1][0];
136
137
0
          for (pb = 0; pb < num_parameter_bands; pb++) *m2_decor_real_prev++ = *m2_decor_real++;
138
139
0
          m2_decor_imag = &m2_param->m2_decor_imag[idx][num_parameter_sets_prev - 1][0];
140
141
0
          for (pb = 0; pb < num_parameter_bands; pb++) *m2_decor_imag_prev++ = *m2_decor_imag++;
142
0
        }
143
0
      }
144
0
    }
145
146
0
    idx = -1;
147
0
    for (row = 0; row < num_output_channels; row++) {
148
0
      for (col = 0; col < resid_col_counter; col++) {
149
0
        if (pstr_mps_state->m2_param_present[row][col] & 2) {
150
0
          idx++;
151
0
          m2_resid_real = &m2_param->m2_resid_real[idx][num_parameter_sets_prev - 1][0];
152
153
0
          for (pb = 0; pb < num_parameter_bands; pb++) *m2_resid_real_prev++ = *m2_resid_real++;
154
0
          m2_resid_imag = &m2_param->m2_resid_imag[idx][num_parameter_sets_prev - 1][0];
155
0
          for (pb = 0; pb < num_parameter_bands; pb++) *m2_resid_imag_prev++ = *m2_resid_imag++;
156
0
        }
157
0
      }
158
0
    }
159
14.4k
  } else {
160
126k
    for (row = 0; row < num_output_channels; row++) {
161
357k
      for (col = num_direct_signals; col < col_counter; col++) {
162
245k
        if (pstr_mps_state->m2_param_present[row][col] & 1) {
163
70.5k
          idx++;
164
70.5k
          m2_decor_real = &m2_param->m2_decor_real[idx][num_parameter_sets_prev - 1][0];
165
166
1.25M
          for (pb = 0; pb < num_parameter_bands; pb++) *m2_decor_real_prev++ = *m2_decor_real++;
167
70.5k
        }
168
245k
      }
169
111k
    }
170
171
14.4k
    idx = -1;
172
126k
    for (row = 0; row < num_output_channels; row++) {
173
705k
      for (col = 0; col < resid_col_counter; col++) {
174
593k
        if (pstr_mps_state->m2_param_present[row][col] & 2) {
175
114k
          idx++;
176
114k
          m2_resid_real = &m2_param->m2_resid_real[idx][num_parameter_sets_prev - 1][0];
177
178
2.18M
          for (pb = 0; pb < num_parameter_bands; pb++) *m2_resid_real_prev++ = *m2_resid_real++;
179
114k
        }
180
593k
      }
181
111k
    }
182
14.4k
  }
183
14.4k
}
184
185
1.38k
static VOID ixheaacd_update_alpha(ia_heaac_mps_state_struct *pstr_mps_state) {
186
1.38k
  WORD32 alpha;
187
188
1.38k
  WORD32 *arbdmx_alpha_prev = pstr_mps_state->mps_persistent_mem.arbdmx_alpha_prev;
189
1.38k
  ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
190
1.38k
  WORD32 *arbdmx_alpha = p_aux_struct->arbdmx_alpha;
191
192
1.38k
  WORD32 n_ch_in = pstr_mps_state->num_input_channels;
193
1.38k
  WORD32 ch;
194
195
3.55k
  for (ch = 0; ch < n_ch_in; ch++) {
196
2.16k
    *arbdmx_alpha_prev++ = arbdmx_alpha[ch];
197
198
2.16k
    if (pstr_mps_state->arbitrary_downmix == 2) {
199
289
      alpha = arbdmx_alpha[ch];
200
201
289
      if (p_aux_struct->arbdmx_residual_abs[ch]) {
202
146
        alpha -= POINT_THREE_THREE_Q15;
203
204
146
        if (alpha < 0) alpha = 0;
205
146
      } else {
206
143
        alpha += POINT_THREE_THREE_Q15;
207
208
143
        if (alpha > ONE_IN_Q15) alpha = ONE_IN_Q15;
209
143
      }
210
1.87k
    } else {
211
1.87k
      alpha = ONE_IN_Q15;
212
1.87k
    }
213
214
2.16k
    arbdmx_alpha[ch] = alpha;
215
2.16k
  }
216
1.38k
}
217
218
14.4k
VOID ixheaacd_calc_m1m2(ia_heaac_mps_state_struct *pstr_mps_state) {
219
14.4k
  WORD32 up_mix_type = pstr_mps_state->up_mix_type;
220
14.4k
  WORD32 binaural_quality = pstr_mps_state->binaural_quality;
221
222
14.4k
  if (pstr_mps_state->arbitrary_downmix != 0) {
223
1.38k
    ixheaacd_update_alpha(pstr_mps_state);
224
1.38k
  }
225
226
14.4k
  switch (pstr_mps_state->tree_config) {
227
399
    case TREE_5151: {
228
399
      if (up_mix_type == 3) {
229
0
        ixheaacd_calc_m1m2_51s1(pstr_mps_state);
230
399
      } else {
231
399
        ixheaacd_calc_m1m2_5151(pstr_mps_state);
232
399
      }
233
399
    } break;
234
461
    case TREE_5152: {
235
461
      if (up_mix_type == 3) {
236
0
        ixheaacd_calc_m1m2_51s2(pstr_mps_state);
237
461
      } else {
238
461
        ixheaacd_calc_m1m2_5152(pstr_mps_state);
239
461
      }
240
461
    } break;
241
1.19k
    case TREE_525:
242
1.19k
      if (up_mix_type == 1) {
243
0
        ixheaacd_calc_m1m2_emm(pstr_mps_state);
244
1.19k
      } else if (up_mix_type == 2) {
245
0
        if (binaural_quality == 1) {
246
0
          ixheaacd_calc_m1m2_5227(pstr_mps_state);
247
0
        }
248
1.19k
      } else {
249
1.19k
        ixheaacd_calc_m1m2_5251(pstr_mps_state);
250
1.19k
      }
251
1.19k
      break;
252
1.01k
    case TREE_7271:
253
1.01k
      if (up_mix_type == 0) {
254
1.01k
        ixheaacd_calc_m1m2_7271(pstr_mps_state);
255
1.01k
      } else if (up_mix_type == 2) {
256
0
        if (binaural_quality == 1) {
257
0
          ixheaacd_calc_m1m2_5227(pstr_mps_state);
258
0
        }
259
0
      }
260
1.01k
      break;
261
501
    case TREE_7272:
262
501
      if (up_mix_type == 0) {
263
501
        ixheaacd_calc_m1m2_7272(pstr_mps_state);
264
501
      } else if (up_mix_type == 2) {
265
0
        if (binaural_quality == 1) {
266
0
          ixheaacd_calc_m1m2_5227(pstr_mps_state);
267
0
        }
268
0
      }
269
501
      break;
270
504
    case TREE_7571:
271
504
      ixheaacd_calc_m1m2_7571(pstr_mps_state);
272
504
      break;
273
10.3k
    case TREE_7572:
274
10.3k
      ixheaacd_calc_m1m2_7572(pstr_mps_state);
275
10.3k
      break;
276
0
    default:
277
0
      break;
278
14.4k
  };
279
280
14.4k
  return;
281
14.4k
}