Coverage Report

Created: 2026-06-13 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/encoder/ixheaace_fd_enc.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 "iusace_type_def.h"
23
#include "iusace_bitbuffer.h"
24
#include "iusace_cnst.h"
25
#include "impd_drc_common_enc.h"
26
#include "impd_drc_uni_drc.h"
27
#include "impd_drc_api.h"
28
#include "impd_drc_uni_drc_eq.h"
29
#include "impd_drc_uni_drc_filter_bank.h"
30
#include "impd_drc_gain_enc.h"
31
#include "impd_drc_struct_def.h"
32
33
#include "ixheaace_memory_standards.h"
34
#include "iusace_tns_usac.h"
35
#include "iusace_psy_mod.h"
36
#include "iusace_config.h"
37
#include "ixheaace_adjust_threshold_data.h"
38
#include "iusace_fd_qc_util.h"
39
#include "iusace_config.h"
40
#include "iusace_arith_enc.h"
41
#include "iusace_fd_quant.h"
42
#include "iusace_ms.h"
43
#include "iusace_signal_classifier.h"
44
#include "iusace_block_switch_const.h"
45
#include "iusace_block_switch_struct_def.h"
46
#include "ixheaace_sbr_header.h"
47
#include "ixheaace_config.h"
48
#include "ixheaace_asc_write.h"
49
#include "iusace_main.h"
50
#include "iusace_write_bitstream.h"
51
#include "iusace_lpd.h"
52
#include "ixheaace_cplx_pred.h"
53
#include "iusace_func_prototypes.h"
54
55
IA_ERRORCODE iusace_fd_encode(ia_sfb_params_struct *pstr_sfb_prms, WORD32 usac_independancy_flag,
56
                              ia_usac_data_struct *pstr_usac_data,
57
                              ia_usac_encoder_config_struct *pstr_usac_config,
58
                              ia_bit_buf_struct *pstr_it_bit_buff, WORD32 nr_core_coder_ch,
59
                              WORD32 chn, WORD32 ele_id, WORD32 *bit_written,
60
231k
                              WORD32 *is_quant_spec_zero, WORD32 *is_gain_limited) {
61
231k
  iusace_scratch_mem *pstr_scratch = &pstr_usac_data->str_scratch;
62
231k
  IA_ERRORCODE err_code = 0;
63
231k
  WORD32 i_ch, idx = 0;
64
231k
  WORD32 *ptr_num_fac_bits = pstr_scratch->ptr_num_fac_bits;
65
231k
  WORD32 tns_data_present[2] = {0};
66
231k
  WORD32 *ptr_core_mode_next = pstr_usac_data->core_mode_next;
67
231k
  WORD32 *ptr_core_mode_prev = pstr_usac_data->core_mode_prev;
68
231k
  *bit_written = 0;
69
231k
  memset(pstr_scratch->ptr_num_fac_bits, 0,
70
231k
         MAX_TIME_CHANNELS * sizeof(pstr_scratch->ptr_num_fac_bits[0]));
71
646k
  for (i_ch = chn; i_ch < chn + nr_core_coder_ch; i_ch++) {
72
414k
    tns_data_present[idx] = pstr_usac_data->pstr_tns_info[i_ch] != NULL;
73
74
414k
    if (tns_data_present[idx]) {
75
199k
      tns_data_present[idx] = pstr_usac_data->pstr_tns_info[i_ch]->tns_data_present;
76
199k
    }
77
414k
    idx++;
78
414k
  }
79
80
231k
  idx = 0;
81
646k
  for (i_ch = chn; i_ch < chn + nr_core_coder_ch; i_ch++) {
82
414k
    memset(pstr_scratch->p_reconstructed_time_signal[idx], 0, 4096 * sizeof(FLOAT64));
83
414k
    err_code = iusace_fd_fac(
84
414k
        pstr_sfb_prms->grouped_sfb_offset[i_ch], pstr_sfb_prms->max_sfb[i_ch],
85
414k
        pstr_usac_data->ptr_2frame_time_data[i_ch], pstr_sfb_prms->window_sequence[i_ch],
86
414k
        pstr_scratch->p_reconstructed_time_signal[idx], pstr_usac_data->td_encoder[i_ch],
87
414k
        ((pstr_usac_data->td_encoder[i_ch]->prev_mode == 0) && ptr_core_mode_prev[i_ch]) ==
88
414k
            CORE_MODE_TD,
89
414k
        ptr_core_mode_next[i_ch] == CORE_MODE_TD, pstr_usac_data->fac_out_stream[i_ch],
90
414k
        &ptr_num_fac_bits[i_ch], pstr_scratch);
91
414k
    if (err_code) {
92
0
      return err_code;
93
0
    }
94
414k
    idx++;
95
414k
  }
96
97
231k
  err_code = iusace_quantize_spec(pstr_sfb_prms, usac_independancy_flag, nr_core_coder_ch,
98
231k
                                  pstr_usac_data, pstr_usac_config, chn, ele_id,
99
231k
                                  is_quant_spec_zero, is_gain_limited);
100
231k
  if (err_code) return err_code;
101
102
630k
  for (i_ch = chn; i_ch < chn + nr_core_coder_ch; i_ch++) {
103
403k
    pstr_sfb_prms->window_shape[i_ch] =
104
403k
        pstr_usac_data->str_psy_mod.str_psy_out_data[i_ch].window_shape;
105
403k
  }
106
107
226k
  if (nr_core_coder_ch == 1) {
108
49.0k
    iusace_write_bits_buf(pstr_it_bit_buff, tns_data_present[0], 1);
109
49.0k
    *bit_written = *bit_written + 1;
110
49.0k
  }
111
226k
  if (nr_core_coder_ch == 2) {
112
177k
    *bit_written = *bit_written + iusace_write_cpe(pstr_sfb_prms, pstr_it_bit_buff,
113
177k
                                                   tns_data_present, usac_independancy_flag,
114
177k
                                                   pstr_usac_config, pstr_usac_data, chn);
115
177k
  }
116
117
226k
  idx = 0;
118
630k
  for (i_ch = chn; i_ch < chn + nr_core_coder_ch; i_ch++) {
119
403k
    *bit_written =
120
403k
        *bit_written + iusace_write_fd_data(pstr_it_bit_buff, pstr_sfb_prms,
121
403k
                                            ptr_num_fac_bits[i_ch], usac_independancy_flag,
122
403k
                                            pstr_usac_data, pstr_usac_config, i_ch, ele_id, idx);
123
403k
    idx++;
124
403k
  }
125
126
226k
  return err_code;
127
231k
}